44using System . Diagnostics ;
55using System . Threading ;
66using System . Threading . Tasks ;
7+ using System . Windows ;
78
89namespace Flow . Launcher . Plugin . SpeedTest
910{
@@ -22,14 +23,41 @@ public class Main : IAsyncPlugin, IPluginI18n
2223 private Timer ? _updateTimer ;
2324 private string ? _lastError ;
2425 private DateTime _lastQueryTime ;
26+ private bool _isDarkTheme ;
2527
2628 public Task InitAsync ( PluginInitContext context )
2729 {
2830 _context = context ;
2931 _settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
32+
33+ var dispatcher = Application . Current ? . Dispatcher ;
34+ if ( dispatcher != null )
35+ {
36+ if ( dispatcher . CheckAccess ( ) )
37+ _isDarkTheme = context . API . IsApplicationDarkTheme ( ) ;
38+ else
39+ dispatcher . Invoke ( ( ) => _isDarkTheme = context . API . IsApplicationDarkTheme ( ) ) ;
40+ }
41+
42+ context . API . ActualApplicationThemeChanged += ( _ , __ ) =>
43+ {
44+ var disp = Application . Current ? . Dispatcher ;
45+ if ( disp != null )
46+ {
47+ if ( disp . CheckAccess ( ) )
48+ _isDarkTheme = _context . API . IsApplicationDarkTheme ( ) ;
49+ else
50+ disp . Invoke ( ( ) => _isDarkTheme = _context . API . IsApplicationDarkTheme ( ) ) ;
51+
52+ _context ? . API . ChangeQuery ( _context . CurrentPluginMetadata . ActionKeyword , true ) ;
53+ }
54+ } ;
55+
3056 return Task . CompletedTask ;
3157 }
3258
59+ private string GetIcon ( ) => _isDarkTheme ? "icon-dark.png" : "icon-light.png" ;
60+
3361 public async Task < List < Result > > QueryAsync ( Query query , CancellationToken token )
3462 {
3563 var results = new List < Result > ( ) ;
@@ -51,8 +79,9 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
5179 {
5280 Title = "Testing your internet speed..." ,
5381 SubTitle = "Connecting to nearest server..." ,
54- IcoPath = "icon.png"
82+ IcoPath = GetIcon ( )
5583 } ) ;
84+
5685 return results ;
5786 }
5887
@@ -62,7 +91,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
6291 {
6392 Title = _currentStatus ?? "Connecting to server..." ,
6493 SubTitle = BuildProgressText ( ) ,
65- IcoPath = "icon.png"
94+ IcoPath = GetIcon ( )
6695 } ) ;
6796 }
6897 else if ( _lastResult != null )
@@ -76,7 +105,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
76105 {
77106 Title = $ "↓ { _lastResult . DownloadSpeed : F1} Mbps ↑ { _lastResult . UploadSpeed : F1} Mbps",
78107 SubTitle = $ "Ping: { _lastResult . Ping : F0} ms • { _lastResult . ServerName } • { timeStr } • Enter to retest",
79- IcoPath = "icon.png" ,
108+ IcoPath = GetIcon ( ) ,
80109 Action = _ =>
81110 {
82111 _lastResult = null ;
@@ -90,21 +119,21 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
90119 {
91120 Title = $ "↓ Download: { _lastResult . DownloadSpeed : F2} Mbps",
92121 SubTitle = $ "Jitter: { _lastResult . DownloadJitter : F1} ms • Latency: { _lastResult . DownloadLatency : F1} ms",
93- IcoPath = "icon.png"
122+ IcoPath = GetIcon ( )
94123 } ) ;
95124
96125 results . Add ( new Result
97126 {
98127 Title = $ "↑ Upload: { _lastResult . UploadSpeed : F2} Mbps",
99128 SubTitle = $ "Jitter: { _lastResult . UploadJitter : F1} ms • Latency: { _lastResult . UploadLatency : F1} ms",
100- IcoPath = "icon.png"
129+ IcoPath = GetIcon ( )
101130 } ) ;
102131
103132 results . Add ( new Result
104133 {
105134 Title = $ "📍 { _lastResult . ServerName } ",
106135 SubTitle = $ "{ _lastResult . ServerLocation } • ISP: { _lastResult . ISP } ",
107- IcoPath = "icon.png"
136+ IcoPath = GetIcon ( )
108137 } ) ;
109138
110139 if ( ! string . IsNullOrEmpty ( _lastResult . ResultUrl ) )
@@ -113,7 +142,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
113142 {
114143 Title = "View detailed results online" ,
115144 SubTitle = _lastResult . ResultUrl ,
116- IcoPath = "icon.png" ,
145+ IcoPath = GetIcon ( ) ,
117146 Action = _ =>
118147 {
119148 Process . Start ( new ProcessStartInfo ( _lastResult . ResultUrl ) { UseShellExecute = true } ) ;
@@ -128,7 +157,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
128157 {
129158 Title = "⚠️ Speed test failed" ,
130159 SubTitle = _lastError + " • Enter to retry" ,
131- IcoPath = "icon.png" ,
160+ IcoPath = GetIcon ( ) ,
132161 Action = _ =>
133162 {
134163 _lastError = null ;
@@ -231,4 +260,4 @@ private void RunTest()
231260 }
232261
233262 public class Settings { }
234- }
263+ }
0 commit comments