Skip to content

Commit 52c2db9

Browse files
authored
Merge pull request #47 from ivangrek/fix-13
Add ability to run plugin manager as modal window
2 parents 62e017a + 086bb2e commit 52c2db9

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/PackageManager.UI/PackageManager.UI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<AssemblyName>PackageManager.UI</AssemblyName>
66
<TargetFramework>net461</TargetFramework>
77
<ApplicationIcon>Views\Assets\box-search-result.ico</ApplicationIcon>
8+
<StartupObject>PackageManager.Program</StartupObject>
89
</PropertyGroup>
910

1011
<ItemGroup>

src/PackageManager.UI/Program.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Threading;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Runtime.InteropServices;
6+
7+
namespace PackageManager
8+
{
9+
public static class Program
10+
{
11+
private const string ApplicationKey = "5CFB158B-8346-4588-926D-99006A5195B6";
12+
private const int RestoreWindowCommandCode = 0x09;
13+
14+
[DllImport("user32.dll")]
15+
[return: MarshalAs(UnmanagedType.Bool)]
16+
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
17+
18+
[DllImport("user32.dll")]
19+
private static extern IntPtr SetForegroundWindow(IntPtr hWnd);
20+
21+
[STAThread]
22+
public static void Main()
23+
{
24+
using var mutex = new Mutex(false, ApplicationKey, out bool createdNew);
25+
26+
if (createdNew)
27+
{
28+
var application = new App();
29+
30+
application.InitializeComponent();
31+
application.Run();
32+
}
33+
else
34+
{
35+
var currentProcess = Process.GetCurrentProcess();
36+
var mainProcess = Process.GetProcesses()
37+
.Where(x => x.Id != currentProcess.Id)
38+
.FirstOrDefault(x => x.ProcessName == currentProcess.ProcessName);
39+
40+
if (mainProcess != null)
41+
{
42+
ShowWindow(mainProcess.MainWindowHandle, RestoreWindowCommandCode);
43+
SetForegroundWindow(mainProcess.MainWindowHandle);
44+
}
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)