14
14
using CommunityToolkit . Mvvm . DependencyInjection ;
15
15
using CommunityToolkit . Mvvm . Input ;
16
16
using Flow . Launcher . Core . Plugin ;
17
- using Flow . Launcher . Core . Resource ;
18
17
using Flow . Launcher . Infrastructure ;
19
18
using Flow . Launcher . Infrastructure . Hotkey ;
20
19
using Flow . Launcher . Infrastructure . Image ;
@@ -47,8 +46,6 @@ public partial class MainViewModel : BaseModel, ISavable
47
46
private CancellationTokenSource _updateSource ;
48
47
private CancellationToken _updateToken ;
49
48
50
- private readonly Internationalization _translator = InternationalizationManager . Instance ;
51
-
52
49
private ChannelWriter < ResultsForUpdate > _resultsUpdateChannelWriter ;
53
50
private Task _resultsViewUpdateTask ;
54
51
@@ -180,9 +177,9 @@ private void RegisterViewUpdate()
180
177
var resultUpdateChannel = Channel . CreateUnbounded < ResultsForUpdate > ( ) ;
181
178
_resultsUpdateChannelWriter = resultUpdateChannel . Writer ;
182
179
_resultsViewUpdateTask =
183
- Task . Run ( updateAction ) . ContinueWith ( continueAction , TaskContinuationOptions . OnlyOnFaulted ) ;
180
+ Task . Run ( UpdateActionAsync ) . ContinueWith ( continueAction , CancellationToken . None , TaskContinuationOptions . OnlyOnFaulted , TaskScheduler . Default ) ;
184
181
185
- async Task updateAction ( )
182
+ async Task UpdateActionAsync ( )
186
183
{
187
184
var queue = new Dictionary < string , ResultsForUpdate > ( ) ;
188
185
var channelReader = resultUpdateChannel . Reader ;
@@ -249,8 +246,8 @@ private async Task ReloadPluginDataAsync()
249
246
Hide ( ) ;
250
247
251
248
await PluginManager . ReloadDataAsync ( ) . ConfigureAwait ( false ) ;
252
- Notification . Show ( InternationalizationManager . Instance . GetTranslation ( "success" ) ,
253
- InternationalizationManager . Instance . GetTranslation ( "completedSuccessfully" ) ) ;
249
+ Notification . Show ( App . API . GetTranslation ( "success" ) ,
250
+ App . API . GetTranslation ( "completedSuccessfully" ) ) ;
254
251
}
255
252
256
253
[ RelayCommand ]
@@ -272,14 +269,14 @@ public void ReQuery()
272
269
{
273
270
if ( SelectedIsFromQueryResults ( ) )
274
271
{
275
- QueryResults ( isReQuery : true ) ;
272
+ _ = QueryResultsAsync ( isReQuery : true ) ;
276
273
}
277
274
}
278
275
279
276
public void ReQuery ( bool reselect )
280
277
{
281
278
BackToQueryResults ( ) ;
282
- QueryResults ( isReQuery : true , reSelect : reselect ) ;
279
+ _ = QueryResultsAsync ( isReQuery : true , reSelect : reselect ) ;
283
280
}
284
281
285
282
[ RelayCommand ]
@@ -387,11 +384,11 @@ private async Task OpenResultAsync(string index)
387
384
}
388
385
389
386
var hideWindow = await result . ExecuteAsync ( new ActionContext
390
- {
391
- // not null means pressing modifier key + number, should ignore the modifier key
392
- SpecialKeyState = index is not null ? SpecialKeyState . Default : GlobalHotkey . CheckModifiers ( )
393
- } )
394
- . ConfigureAwait ( false ) ;
387
+ {
388
+ // not null means pressing modifier key + number, should ignore the modifier key
389
+ SpecialKeyState = index is not null ? SpecialKeyState . Default : GlobalHotkey . CheckModifiers ( )
390
+ } )
391
+ . ConfigureAwait ( false ) ;
395
392
396
393
if ( SelectedIsFromQueryResults ( ) )
397
394
{
@@ -455,7 +452,6 @@ private void SelectLastResult()
455
452
SelectedResults . SelectLastResult ( ) ;
456
453
}
457
454
458
-
459
455
[ RelayCommand ]
460
456
private void SelectPrevPage ( )
461
457
{
@@ -482,7 +478,6 @@ private void SelectPrevItem()
482
478
{
483
479
SelectedResults . SelectPrevResult ( ) ;
484
480
}
485
-
486
481
}
487
482
488
483
[ RelayCommand ]
@@ -559,7 +554,6 @@ private async Task RegisterClockAndDateUpdateAsync()
559
554
public bool GameModeStatus { get ; set ; } = false ;
560
555
561
556
private string _queryText ;
562
-
563
557
public string QueryText
564
558
{
565
559
get => _queryText ;
@@ -808,8 +802,8 @@ public bool InternalPreviewVisible
808
802
throw new NotImplementedException ( "ResultAreaColumn should match ResultAreaColumnPreviewShown/ResultAreaColumnPreviewHidden value" ) ;
809
803
#else
810
804
Log . Error ( "MainViewModel" , "ResultAreaColumnPreviewHidden/ResultAreaColumnPreviewShown int value not implemented" , "InternalPreviewVisible" ) ;
811
- #endif
812
805
return false ;
806
+ #endif
813
807
}
814
808
}
815
809
@@ -897,7 +891,7 @@ private void CloseExternalPreview()
897
891
ExternalPreviewVisible = false ;
898
892
}
899
893
900
- private void SwitchExternalPreview ( string path , bool sendFailToast = true )
894
+ private static void SwitchExternalPreview ( string path , bool sendFailToast = true )
901
895
{
902
896
_ = PluginManager . SwitchExternalPreviewAsync ( path , sendFailToast ) . ConfigureAwait ( false ) ;
903
897
}
@@ -979,7 +973,7 @@ public void Query(bool isReQuery = false)
979
973
{
980
974
if ( SelectedIsFromQueryResults ( ) )
981
975
{
982
- QueryResults ( isReQuery ) ;
976
+ _ = QueryResultsAsync ( isReQuery ) ;
983
977
}
984
978
else if ( ContextMenuSelected ( ) )
985
979
{
@@ -1042,8 +1036,8 @@ private void QueryHistory()
1042
1036
var results = new List < Result > ( ) ;
1043
1037
foreach ( var h in _history . Items )
1044
1038
{
1045
- var title = _translator . GetTranslation ( "executeQuery" ) ;
1046
- var time = _translator . GetTranslation ( "lastExecuteTime" ) ;
1039
+ var title = App . API . GetTranslation ( "executeQuery" ) ;
1040
+ var time = App . API . GetTranslation ( "lastExecuteTime" ) ;
1047
1041
var result = new Result
1048
1042
{
1049
1043
Title = string . Format ( title , h . Query ) ,
@@ -1077,7 +1071,7 @@ private void QueryHistory()
1077
1071
1078
1072
private readonly IReadOnlyList < Result > _emptyResult = new List < Result > ( ) ;
1079
1073
1080
- private async void QueryResults ( bool isReQuery = false , bool reSelect = true )
1074
+ private async Task QueryResultsAsync ( bool isReQuery = false , bool reSelect = true )
1081
1075
{
1082
1076
_updateSource ? . Cancel ( ) ;
1083
1077
@@ -1155,7 +1149,7 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
1155
1149
1156
1150
var tasks = plugins . Select ( plugin => plugin . Metadata . Disabled switch
1157
1151
{
1158
- false => QueryTask ( plugin , reSelect ) ,
1152
+ false => QueryTaskAsync ( plugin , reSelect ) ,
1159
1153
true => Task . CompletedTask
1160
1154
} ) . ToArray ( ) ;
1161
1155
@@ -1183,7 +1177,7 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
1183
1177
}
1184
1178
1185
1179
// Local function
1186
- async Task QueryTask ( PluginPair plugin , bool reSelect = true )
1180
+ async Task QueryTaskAsync ( PluginPair plugin , bool reSelect = true )
1187
1181
{
1188
1182
// Since it is wrapped within a ThreadPool Thread, the synchronous context is null
1189
1183
// Task.Yield will force it to run in ThreadPool
@@ -1282,13 +1276,13 @@ private Result ContextMenuTopMost(Result result)
1282
1276
{
1283
1277
menu = new Result
1284
1278
{
1285
- Title = InternationalizationManager . Instance . GetTranslation ( "cancelTopMostInThisQuery" ) ,
1279
+ Title = App . API . GetTranslation ( "cancelTopMostInThisQuery" ) ,
1286
1280
IcoPath = "Images\\ down.png" ,
1287
1281
PluginDirectory = Constant . ProgramDirectory ,
1288
1282
Action = _ =>
1289
1283
{
1290
1284
_topMostRecord . Remove ( result ) ;
1291
- App . API . ShowMsg ( InternationalizationManager . Instance . GetTranslation ( "success" ) ) ;
1285
+ App . API . ShowMsg ( App . API . GetTranslation ( "success" ) ) ;
1292
1286
App . API . ReQuery ( ) ;
1293
1287
return false ;
1294
1288
}
@@ -1298,14 +1292,14 @@ private Result ContextMenuTopMost(Result result)
1298
1292
{
1299
1293
menu = new Result
1300
1294
{
1301
- Title = InternationalizationManager . Instance . GetTranslation ( "setAsTopMostInThisQuery" ) ,
1295
+ Title = App . API . GetTranslation ( "setAsTopMostInThisQuery" ) ,
1302
1296
IcoPath = "Images\\ up.png" ,
1303
1297
Glyph = new GlyphInfo ( FontFamily : "/Resources/#Segoe Fluent Icons" , Glyph : "\xeac2 " ) ,
1304
1298
PluginDirectory = Constant . ProgramDirectory ,
1305
1299
Action = _ =>
1306
1300
{
1307
1301
_topMostRecord . AddOrUpdate ( result ) ;
1308
- App . API . ShowMsg ( InternationalizationManager . Instance . GetTranslation ( "success" ) ) ;
1302
+ App . API . ShowMsg ( App . API . GetTranslation ( "success" ) ) ;
1309
1303
App . API . ReQuery ( ) ;
1310
1304
return false ;
1311
1305
}
@@ -1315,10 +1309,10 @@ private Result ContextMenuTopMost(Result result)
1315
1309
return menu ;
1316
1310
}
1317
1311
1318
- private Result ContextMenuPluginInfo ( string id )
1312
+ private static Result ContextMenuPluginInfo ( string id )
1319
1313
{
1320
1314
var metadata = PluginManager . GetPluginForId ( id ) . Metadata ;
1321
- var translator = InternationalizationManager . Instance ;
1315
+ var translator = App . API ;
1322
1316
1323
1317
var author = translator . GetTranslation ( "author" ) ;
1324
1318
var website = translator . GetTranslation ( "website" ) ;
@@ -1400,12 +1394,16 @@ public void Show()
1400
1394
} ) ;
1401
1395
}
1402
1396
1397
+ #pragma warning disable VSTHRD100 // Avoid async void methods
1398
+
1403
1399
public async void Hide ( )
1404
1400
{
1405
1401
lastHistoryIndex = 1 ;
1406
1402
1407
1403
if ( ExternalPreviewVisible )
1404
+ {
1408
1405
CloseExternalPreview ( ) ;
1406
+ }
1409
1407
1410
1408
if ( ! SelectedIsFromQueryResults ( ) )
1411
1409
{
@@ -1476,6 +1474,8 @@ public async void Hide()
1476
1474
VisibilityChanged ? . Invoke ( this , new VisibilityChangedEventArgs { IsVisible = false } ) ;
1477
1475
}
1478
1476
1477
+ #pragma warning restore VSTHRD100 // Avoid async void methods
1478
+
1479
1479
/// <summary>
1480
1480
/// Checks if Flow Launcher should ignore any hotkeys
1481
1481
/// </summary>
0 commit comments