@@ -9,25 +9,16 @@ namespace wallpaper
99 class Wallpaper
1010 {
1111 static Timer timer = new Timer ( ) ;
12- static bool isEnable = false ;
13- static List < string > exclude = new List < string > ( ) ;
12+ static string video = string . Empty ;
13+ static List < string > list = new List < string > ( ) ;
1414
1515 public static void Run ( )
1616 {
17- if ( Convert . ToBoolean ( RegistryGet . GetSetting ( "wallpaperExclude" ) ) )
17+ video = RegistryGet . GetSetting ( "videoLocation" ) ;
18+ if ( Convert . ToBoolean ( RegistryGet . GetSetting ( "wallpaperExclude" ) ) &&
19+ ! string . IsNullOrWhiteSpace ( RegistryGet . GetSetting ( "excludeList" ) ) )
1820 {
19- for ( int i = 0 ; i < int . MaxValue ; i ++ )
20- {
21- try
22- {
23- string item = RegistryGet . GetExcludeList ( i . ToString ( ) ) ;
24- exclude . Add ( item ) ;
25- }
26- catch ( Exception )
27- {
28- break ;
29- }
30- }
21+ list = RegistryGet . GetSetting ( "excludeList" ) . Split ( '|' ) . ToList ( ) ;
3122 }
3223 timer . Interval = 1000 ;
3324 timer . Tick += TimerTick ;
@@ -36,49 +27,32 @@ public static void Run()
3627
3728 private static void TimerTick ( object sender , EventArgs e )
3829 {
39- Process [ ] explorer = Process . GetProcessesByName ( "explorer" ) ;
40- Process [ ] mpv = Process . GetProcessesByName ( "mpv" ) ;
41- Process [ ] process = Process . GetProcesses ( ) ;
42- List < string > list = new List < string > ( ) ;
43- foreach ( var item in process )
30+ timer . Enabled = false ;
31+ bool power = SystemInformation . PowerStatus . PowerLineStatus == PowerLineStatus . Online ;
32+ bool screen = Screen . AllScreens . Count ( ) == 1 ;
33+ int explorer = Process . GetProcessesByName ( "explorer" ) . Length ;
34+ int mpv = Process . GetProcessesByName ( "mpv" ) . Length ;
35+ int exclude = Process . GetProcesses ( ) . Select ( item => item . ProcessName ) . Intersect ( list ) . Count ( ) ;
36+ if ( power && screen && explorer != 0 && mpv == 0 && exclude == 0 )
4437 {
45- list . Add ( item . ProcessName ) ;
46- }
47- int excludeNum = list . Intersect ( exclude ) . Count ( ) ;
48- if ( explorer . Length > 0 && mpv . Length < 1 && excludeNum < 1 )
49- {
50- timer . Enabled = false ;
5138 System . Threading . Thread . Sleep ( 1000 ) ;
5239 IntPtr hwndShell = WindowsApi . GetShellWindow ( ) ;
5340 WindowsApi . SendMessageTimeout ( hwndShell , 0x52c , IntPtr . Zero , IntPtr . Zero , 0 , 1000 , IntPtr . Zero ) ;
41+ System . Threading . Thread . Sleep ( 1000 ) ;
5442 IntPtr hwndWorkerW = WindowsApi . GetWindow ( hwndShell , 3 ) ;
55- string file = "\" " + RegistryGet . GetSetting ( "videoLocation" ) + "\" " ;
56- string args = " --hwdec=auto --ao=null --loop-file=yes" ;
5743 Process newMpv = new Process ( ) ;
5844 newMpv . StartInfo . FileName = "mpv.exe" ;
59- newMpv . StartInfo . Arguments = file + args + " --wid=" + hwndWorkerW ;
45+ newMpv . StartInfo . Arguments = $ " \" { video } \" --wid={ hwndWorkerW } --loop-file=yes --hwdec=auto --ao=null" ;
6046 newMpv . Start ( ) ;
61- isEnable = true ;
62- timer . Enabled = true ;
6347 }
64- else if ( excludeNum > 0 )
48+ else if ( ( ! power || ! screen || exclude > 0 ) && mpv != 0 )
6549 {
66- timer . Enabled = false ;
67- if ( isEnable )
68- {
69- Stop ( ) ;
70- isEnable = false ;
71- }
72- timer . Enabled = true ;
50+ IntPtr hwndShell = WindowsApi . GetShellWindow ( ) ;
51+ IntPtr hwndWorkerW = WindowsApi . GetWindow ( hwndShell , 3 ) ;
52+ IntPtr hwndMpv = WindowsApi . GetWindow ( hwndWorkerW , 5 ) ;
53+ WindowsApi . SendMessage ( hwndMpv , 0x0010 , 0 , 0 ) ;
7354 }
74- }
75-
76- public static void Stop ( )
77- {
78- IntPtr hwndShell = WindowsApi . GetShellWindow ( ) ;
79- IntPtr hwndWorkerW = WindowsApi . GetWindow ( hwndShell , 3 ) ;
80- IntPtr hwndMpv = WindowsApi . GetWindow ( hwndWorkerW , 5 ) ;
81- WindowsApi . SendMessage ( hwndMpv , 0x0010 , 0 , 0 ) ;
55+ timer . Enabled = true ;
8256 }
8357 }
8458}
0 commit comments