@@ -24,7 +24,6 @@ public class Main : ISettingProvider, IAsyncPlugin, IPluginI18n, IContextMenu, I
24
24
internal static UWP . Application [ ] _uwps { get ; set ; }
25
25
internal static Settings _settings { get ; set ; }
26
26
27
- private static bool IsStartupIndexProgramsRequired => _settings . LastIndexTime . AddDays ( 3 ) < DateTime . Today ;
28
27
29
28
internal static PluginInitContext Context { get ; private set ; }
30
29
@@ -51,29 +50,25 @@ public void Save()
51
50
52
51
public async Task < List < Result > > QueryAsync ( Query query , CancellationToken token )
53
52
{
54
-
55
- if ( IsStartupIndexProgramsRequired )
56
- _ = IndexPrograms ( ) ;
57
-
58
53
var result = await cache . GetOrCreateAsync ( query . Search , async entry =>
59
- {
60
- var resultList = await Task . Run ( ( ) =>
61
- _win32s . Cast < IProgram > ( )
62
- . Concat ( _uwps )
63
- . AsParallel ( )
64
- . WithCancellation ( token )
65
- . Where ( p => p . Enabled )
66
- . Select ( p => p . Result ( query . Search , Context . API ) )
67
- . Where ( r => r ? . Score > 0 )
68
- . ToList ( ) ) ;
69
-
70
- resultList = resultList . Any ( ) ? resultList : emptyResults ;
71
-
72
- entry . SetSize ( resultList . Count ) ;
73
- entry . SetSlidingExpiration ( TimeSpan . FromHours ( 8 ) ) ;
74
-
75
- return resultList ;
76
- } ) ;
54
+ {
55
+ var resultList = await Task . Run ( ( ) =>
56
+ _win32s . Cast < IProgram > ( )
57
+ . Concat ( _uwps )
58
+ . AsParallel ( )
59
+ . WithCancellation ( token )
60
+ . Where ( p => p . Enabled )
61
+ . Select ( p => p . Result ( query . Search , Context . API ) )
62
+ . Where ( r => r ? . Score > 0 )
63
+ . ToList ( ) ) ;
64
+
65
+ resultList = resultList . Any ( ) ? resultList : emptyResults ;
66
+
67
+ entry . SetSize ( resultList . Count ) ;
68
+ entry . SetSlidingExpiration ( TimeSpan . FromHours ( 8 ) ) ;
69
+
70
+ return resultList ;
71
+ } ) ;
77
72
78
73
return result ;
79
74
}
@@ -84,49 +79,35 @@ public async Task InitAsync(PluginInitContext context)
84
79
85
80
_settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
86
81
87
- await Task . Yield ( ) ;
88
-
89
82
Stopwatch . Normal ( "|Flow.Launcher.Plugin.Program.Main|Preload programs cost" , ( ) =>
90
83
{
91
84
_win32Storage = new BinaryStorage < Win32 [ ] > ( "Win32" ) ;
92
- _win32s = _win32Storage . TryLoad ( new Win32 [ ] { } ) ;
85
+ _win32s = _win32Storage . TryLoad ( new Win32 [ ]
86
+ {
87
+ } ) ;
93
88
_uwpStorage = new BinaryStorage < UWP . Application [ ] > ( "UWP" ) ;
94
- _uwps = _uwpStorage . TryLoad ( new UWP . Application [ ] { } ) ;
89
+ _uwps = _uwpStorage . TryLoad ( new UWP . Application [ ]
90
+ {
91
+ } ) ;
95
92
} ) ;
96
93
Log . Info ( $ "|Flow.Launcher.Plugin.Program.Main|Number of preload win32 programs <{ _win32s . Length } >") ;
97
94
Log . Info ( $ "|Flow.Launcher.Plugin.Program.Main|Number of preload uwps <{ _uwps . Length } >") ;
98
95
99
-
100
- bool indexedWinApps = false ;
101
- bool indexedUWPApps = false ;
96
+ bool cacheEmpty = ! _win32s . Any ( ) && ! _uwps . Any ( ) ;
102
97
103
98
var a = Task . Run ( ( ) =>
104
99
{
105
- if ( IsStartupIndexProgramsRequired || ! _win32s . Any ( ) )
106
- {
107
- Stopwatch . Normal ( "|Flow.Launcher.Plugin.Program.Main|Win32Program index cost" , IndexWin32Programs ) ;
108
- indexedWinApps = true ;
109
- }
100
+ Stopwatch . Normal ( "|Flow.Launcher.Plugin.Program.Main|Win32Program index cost" , IndexWin32Programs ) ;
110
101
} ) ;
111
102
112
103
var b = Task . Run ( ( ) =>
113
104
{
114
- if ( IsStartupIndexProgramsRequired || ! _uwps . Any ( ) )
115
- {
116
- Stopwatch . Normal ( "|Flow.Launcher.Plugin.Program.Main|Win32Program index cost" , IndexUwpPrograms ) ;
117
- indexedUWPApps = true ;
118
- }
105
+ Stopwatch . Normal ( "|Flow.Launcher.Plugin.Program.Main|Win32Program index cost" , IndexUwpPrograms ) ;
119
106
} ) ;
120
107
121
- var indexTask = Task . WhenAll ( a , b ) . ContinueWith ( t =>
122
- {
123
- if ( indexedWinApps && indexedUWPApps )
124
- _settings . LastIndexTime = DateTime . Today ;
125
- } ) ;
108
+ if ( cacheEmpty )
109
+ await Task . WhenAll ( a , b ) ;
126
110
127
- if ( ! ( _win32s . Any ( ) && _uwps . Any ( ) ) )
128
- await indexTask ;
129
-
130
111
Win32 . WatchProgramUpdate ( _settings ) ;
131
112
UWP . WatchPackageChange ( ) ;
132
113
}
@@ -141,7 +122,9 @@ public static void IndexUwpPrograms()
141
122
{
142
123
var windows10 = new Version ( 10 , 0 ) ;
143
124
var support = Environment . OSVersion . Version . Major >= windows10 . Major ;
144
- var applications = support ? UWP . All ( ) : new UWP . Application [ ] { } ;
125
+ var applications = support ? UWP . All ( ) : new UWP . Application [ ]
126
+ {
127
+ } ;
145
128
_uwps = applications ;
146
129
}
147
130
0 commit comments