2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
4
using System . IO ;
5
- using System . Runtime . InteropServices ;
6
5
using System . Windows ;
7
- using System . Windows . Forms ;
8
- using System . Windows . Interop ;
9
6
using Flow . Launcher . Infrastructure ;
10
7
using Flow . Launcher . Infrastructure . Logger ;
11
8
using Flow . Launcher . Infrastructure . UserSettings ;
12
9
using Flow . Launcher . Plugin . SharedCommands ;
10
+ using Windows . Win32 ;
11
+ using Windows . Win32 . Foundation ;
12
+ using Windows . Win32 . System . Shutdown ;
13
13
using Application = System . Windows . Application ;
14
14
using Control = System . Windows . Controls . Control ;
15
- using FormsApplication = System . Windows . Forms . Application ;
16
15
17
16
namespace Flow . Launcher . Plugin . Sys
18
17
{
@@ -21,33 +20,6 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n
21
20
private PluginInitContext context ;
22
21
private Dictionary < string , string > KeywordTitleMappings = new Dictionary < string , string > ( ) ;
23
22
24
- #region DllImport
25
-
26
- internal const int EWX_LOGOFF = 0x00000000 ;
27
- internal const int EWX_SHUTDOWN = 0x00000001 ;
28
- internal const int EWX_REBOOT = 0x00000002 ;
29
- internal const int EWX_FORCE = 0x00000004 ;
30
- internal const int EWX_POWEROFF = 0x00000008 ;
31
- internal const int EWX_FORCEIFHUNG = 0x00000010 ;
32
-
33
- [ DllImport ( "user32" ) ]
34
- private static extern bool ExitWindowsEx ( uint uFlags , uint dwReason ) ;
35
-
36
- [ DllImport ( "user32" ) ]
37
- private static extern void LockWorkStation ( ) ;
38
-
39
- [ DllImport ( "Shell32.dll" , CharSet = CharSet . Unicode ) ]
40
- private static extern uint SHEmptyRecycleBin ( IntPtr hWnd , uint dwFlags ) ;
41
-
42
- // http://www.pinvoke.net/default.aspx/Enums/HRESULT.html
43
- private enum HRESULT : uint
44
- {
45
- S_FALSE = 0x0001 ,
46
- S_OK = 0x0000
47
- }
48
-
49
- #endregion
50
-
51
23
public Control CreateSettingPanel ( )
52
24
{
53
25
var results = Commands ( ) ;
@@ -206,7 +178,7 @@ private List<Result> Commands()
206
178
MessageBoxButton . YesNo , MessageBoxImage . Warning ) ;
207
179
208
180
if ( result == MessageBoxResult . Yes )
209
- ExitWindowsEx ( EWX_LOGOFF , 0 ) ;
181
+ PInvoke . ExitWindowsEx ( EXIT_WINDOWS_FLAGS . EWX_LOGOFF , 0 ) ;
210
182
211
183
return true ;
212
184
}
@@ -219,7 +191,7 @@ private List<Result> Commands()
219
191
IcoPath = "Images\\ lock.png" ,
220
192
Action = c =>
221
193
{
222
- LockWorkStation ( ) ;
194
+ PInvoke . LockWorkStation ( ) ;
223
195
return true ;
224
196
}
225
197
} ,
@@ -229,7 +201,7 @@ private List<Result> Commands()
229
201
SubTitle = context . API . GetTranslation ( "flowlauncher_plugin_sys_sleep" ) ,
230
202
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xec46 " ) ,
231
203
IcoPath = "Images\\ sleep.png" ,
232
- Action = c => FormsApplication . SetSuspendState ( PowerState . Suspend , false , false )
204
+ Action = c => PInvoke . SetSuspendState ( false , false , false )
233
205
} ,
234
206
new Result
235
207
{
@@ -274,8 +246,8 @@ private List<Result> Commands()
274
246
// http://www.pinvoke.net/default.aspx/shell32/SHEmptyRecycleBin.html
275
247
// FYI, couldn't find documentation for this but if the recycle bin is already empty, it will return -2147418113 (0x8000FFFF (E_UNEXPECTED))
276
248
// 0 for nothing
277
- var result = SHEmptyRecycleBin ( new WindowInteropHelper ( Application . Current . MainWindow ) . Handle , 0 ) ;
278
- if ( result != ( uint ) HRESULT . S_OK && result != ( uint ) 0x8000FFFF )
249
+ var result = PInvoke . SHEmptyRecycleBin ( new ( ) , string . Empty , 0 ) ;
250
+ if ( result != HRESULT . S_OK && result != HRESULT . E_UNEXPECTED )
279
251
{
280
252
context . API . ShowMsgBox ( $ "Error emptying recycle bin, error code: { result } \n " +
281
253
"please refer to https://msdn.microsoft.com/en-us/library/windows/desktop/aa378137" ,
0 commit comments