Skip to content

Commit cc1e6dd

Browse files
committed
Fix theme select initialization issue
1 parent eeb9ea7 commit cc1e6dd

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,37 @@ public class ThemeSelector
99
{
1010
public const string Keyword = "fltheme";
1111

12-
private readonly Theme _theme;
1312
private readonly PluginInitContext _context;
1413

14+
// Do not initialize it in the constructor, because it will cause null reference in
15+
// var dicts = Application.Current.Resources.MergedDictionaries; line of Theme
16+
private Theme theme = null;
17+
private Theme Theme => theme ??= Ioc.Default.GetRequiredService<Theme>();
18+
1519
#region Theme Selection
1620

1721
// Theme select codes simplified from SettingsPaneThemeViewModel.cs
1822

1923
private Theme.ThemeData _selectedTheme;
2024
public Theme.ThemeData SelectedTheme
2125
{
22-
get => _selectedTheme ??= Themes.Find(v => v.FileNameWithoutExtension == _theme.GetCurrentTheme());
26+
get => _selectedTheme ??= Themes.Find(v => v.FileNameWithoutExtension == Theme.GetCurrentTheme());
2327
set
2428
{
2529
_selectedTheme = value;
26-
_theme.ChangeTheme(value.FileNameWithoutExtension);
30+
Theme.ChangeTheme(value.FileNameWithoutExtension);
2731

28-
_ = _theme.RefreshFrameAsync();
32+
_ = Theme.RefreshFrameAsync();
2933
}
3034
}
3135

32-
private List<Theme.ThemeData> Themes => _theme.LoadAvailableThemes();
36+
private List<Theme.ThemeData> Themes => Theme.LoadAvailableThemes();
3337

3438
#endregion
3539

3640
public ThemeSelector(PluginInitContext context)
3741
{
3842
_context = context;
39-
_theme = Ioc.Default.GetRequiredService<Theme>();
4043
}
4144

4245
public List<Result> Query(Query query)

0 commit comments

Comments
 (0)