File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 5
5
<AssemblyName >PackageManager.UI</AssemblyName >
6
6
<TargetFramework >net461</TargetFramework >
7
7
<ApplicationIcon >Views\Assets\box-search-result.ico</ApplicationIcon >
8
+ <StartupObject >PackageManager.Program</StartupObject >
8
9
</PropertyGroup >
9
10
10
11
<ItemGroup >
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments