1
- using System ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
3
2
using System . Linq ;
4
3
using CommunityToolkit . Mvvm . DependencyInjection ;
5
4
using Flow . Launcher . Core . Resource ;
6
5
7
6
namespace Flow . Launcher . Plugin . Sys
8
7
{
9
- public class ThemeSelector : IDisposable
8
+ public class ThemeSelector
10
9
{
11
10
public const string Keyword = "fltheme" ;
12
11
13
12
private readonly Theme _theme ;
14
13
private readonly PluginInitContext _context ;
15
14
16
- private IEnumerable < string > themes ;
17
-
18
15
public ThemeSelector ( PluginInitContext context )
19
16
{
20
17
_context = context ;
21
18
_theme = Ioc . Default . GetRequiredService < Theme > ( ) ;
22
- context . API . VisibilityChanged += OnVisibilityChanged ;
23
- }
24
-
25
- ~ ThemeSelector ( )
26
- {
27
- Dispose ( false ) ;
28
19
}
29
20
30
21
public List < Result > Query ( Query query )
31
22
{
32
- if ( query . IsReQuery )
33
- {
34
- LoadThemes ( ) ;
35
- }
23
+ var themes = _theme . LoadAvailableThemes ( ) . Select ( x => x . FileNameWithoutExtension ) ;
36
24
37
25
string search = query . SecondToEndSearch ;
38
26
@@ -50,17 +38,6 @@ public List<Result> Query(Query query)
50
38
. ToList ( ) ;
51
39
}
52
40
53
- private void OnVisibilityChanged ( object sender , VisibilityChangedEventArgs args )
54
- {
55
- if ( args . IsVisible && ! _context . CurrentPluginMetadata . Disabled )
56
- {
57
- LoadThemes ( ) ;
58
- }
59
- }
60
-
61
- private void LoadThemes ( )
62
- => themes = _theme . LoadAvailableThemes ( ) . Select ( x => x . FileNameWithoutExtension ) ;
63
-
64
41
private Result CreateThemeResult ( string theme ) => CreateThemeResult ( theme , 0 , null ) ;
65
42
66
43
private Result CreateThemeResult ( string theme , int score , IList < int > highlightData )
@@ -69,6 +46,7 @@ private Result CreateThemeResult(string theme, int score, IList<int> highlightDa
69
46
if ( theme == _theme . CurrentTheme )
70
47
{
71
48
title = $ "{ theme } ★";
49
+ // Set current theme to the top
72
50
score = 2000 ;
73
51
}
74
52
else
@@ -92,29 +70,5 @@ private Result CreateThemeResult(string theme, int score, IList<int> highlightDa
92
70
}
93
71
} ;
94
72
}
95
-
96
- private bool disposed ;
97
- protected virtual void Dispose ( bool disposing )
98
- {
99
- if ( ! disposed )
100
- {
101
- if ( disposing )
102
- {
103
- // Dispose managed resources
104
- if ( _context ? . API != null )
105
- {
106
- _context . API . VisibilityChanged -= OnVisibilityChanged ;
107
- }
108
- }
109
- // Free unmanaged resources
110
- disposed = true ;
111
- }
112
- }
113
-
114
- public void Dispose ( )
115
- {
116
- Dispose ( true ) ;
117
- GC . SuppressFinalize ( this ) ;
118
- }
119
73
}
120
74
}
0 commit comments