Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion InvisibleMan-XRay/InvisibleMan-XRay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
<Nullable>enable</Nullable>
<NoWarn>0108;8600;8601;8602;8603;8604;8618;8625;8629;8762</NoWarn>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>Assets/Icon.ico</ApplicationIcon>
<PublishSingleFile>true</PublishSingleFile>
<_SuppressWpfTrimError>true</_SuppressWpfTrimError>
<_SuppressWinFormsTrimError>true</_SuppressWinFormsTrimError>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>partial</TrimMode>
Expand All @@ -28,7 +30,6 @@
<PackageReference Include="QRCoder.Xaml" Version="1.6.0" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.Management" Version="7.0.0" />
<PackageReference Include="System.Windows.Forms" />
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 1 addition & 18 deletions InvisibleMan-XRay/Managers/AppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,12 @@ private void AvoidRunningMultipleInstances()
if (IsThereAnyArg())
PipeManager.SignalOpenedApp(args);
else
ShowAppAlreadyRunningMessageBox();
PipeManager.SignalShowWindow();

Environment.Exit(0);
}

bool IsThereAnyArg() => args.Length != 0;

void ShowAppAlreadyRunningMessageBox()
{
SettingsHandler settingsHandler = new SettingsHandler();

LocalizationHandler localizationHandler = new LocalizationHandler();
localizationHandler.Setup(
getCurrentLanguage: settingsHandler.UserSettings.GetLanguage
);

LocalizationService localizationService = new LocalizationService();
localizationService.Setup(
getLocalizationResource: localizationHandler.GetLocalizationResource
);

MessageBox.Show(localizationService.GetTerm(Localization.APP_ALREADY_RUNNING));
}
}

private void SetApplicationCurrentDirectory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ WindowFactory windowFactory
SetupNotifyHandler();
SetupDeepLinkHandler();
SetupLocalizationHandler();
SetupPipeManager();

void SetupProcessHandler()
{
Expand Down Expand Up @@ -180,6 +181,11 @@ void SetupLocalizationHandler()
getCurrentLanguage: settingsHandler.UserSettings.GetLanguage
);
}

void SetupPipeManager()
{
PipeManager.OnShowWindow += OpenApplication;
}
}

private void OpenApplication()
Expand Down
18 changes: 17 additions & 1 deletion InvisibleMan-XRay/Managers/PipeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ namespace InvisibleManXRay.Managers
public static class PipeManager
{
private const string PIPE_NAME = "InvisibleManXRayPipe";
private const string SHOW_WINDOW_COMMAND = "--show-window";

public static Action<string> OnReceiveArg = delegate{};
public static Action OnShowWindow = delegate{};

public static void ListenForPipes()
{
Expand All @@ -23,7 +25,10 @@ public static void ListenForPipes()
StreamReader reader = new StreamReader(pipeServer);
string message = reader.ReadToEnd();
Application.Current.Dispatcher.BeginInvoke(new Action(delegate {
OnReceiveArg.Invoke(message);
if (message.Trim() == SHOW_WINDOW_COMMAND)
OnShowWindow.Invoke();
else
OnReceiveArg.Invoke(message);
}));

pipeServer.Close();
Expand All @@ -43,6 +48,17 @@ public static void SignalOpenedApp(string[] args)
writer.Close();
}

public static void SignalShowWindow()
{
NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", PIPE_NAME);
pipeClient.Connect();

StreamWriter writer = new StreamWriter(pipeClient);
writer.WriteLine(SHOW_WINDOW_COMMAND);
writer.Flush();
writer.Close();
}

public static void SignalThisApp(string[] args)
{
OnReceiveArg.Invoke(args[0]);
Expand Down