-
-
Notifications
You must be signed in to change notification settings - Fork 456
Add Flow Launcher Theme Selector to Sys plugin #2448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Jack251970
merged 19 commits into
Flow-Launcher:dev
from
Odotocodot:flow-theme-selector-plugin
Mar 13, 2025
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1b31e9c
Create Flow Launcher Theme Selector plugin
Odotocodot 5e69bd7
Merge branch 'dev' into flow-theme-selector-plugin
taooceros 49a71d7
Move Theme Selector into Sys plugin
Odotocodot 7a0be2c
Remove Reloadable from theme selector
Odotocodot 874a785
cache keywordIndex
jjw24 4005054
implement the complete IDisposable pattern
jjw24 fe8bb6b
Merge branch 'dev' into flow-theme-selector-plugin
jjw24 fce3b3a
Fix crash on theme search
Odotocodot a2372d8
Merge branch 'dev' into flow-theme-selector-plugin
Jack251970 b2dc128
Use dependency injection to fix issue
Jack251970 59fbef1
Use public current theme
Jack251970 9395b89
Make default score larger
Jack251970 468c0b2
Change ico & glyph
Jack251970 bad304b
Query themes every time
Jack251970 94774b2
Requery and do not close window
Jack251970 d099a39
Fix theme change drop shadow effect issue & Add theme description
Jack251970 b2f8ad9
Fix null exception
Odotocodot 84cd1a8
Remove extra code
Odotocodot f503e41
Merge branch 'dev' into flow-theme-selector-plugin
Odotocodot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using CommunityToolkit.Mvvm.DependencyInjection; | ||
| using Flow.Launcher.Core.Resource; | ||
| using Flow.Launcher.Infrastructure.UserSettings; | ||
|
|
||
| namespace Flow.Launcher.Plugin.Sys | ||
| { | ||
| public class ThemeSelector | ||
| { | ||
| public const string Keyword = "fltheme"; | ||
|
|
||
| private readonly Settings _settings; | ||
| private readonly Theme _theme; | ||
| private readonly PluginInitContext _context; | ||
|
|
||
| #region Theme Selection | ||
|
|
||
| // Theme select codes from SettingsPaneThemeViewModel.cs | ||
|
|
||
| private Theme.ThemeData _selectedTheme; | ||
| private Theme.ThemeData SelectedTheme | ||
| { | ||
| get => _selectedTheme ??= Themes.Find(v => v.FileNameWithoutExtension == _theme.CurrentTheme); | ||
Odotocodot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| set | ||
| { | ||
| _selectedTheme = value; | ||
| _theme.ChangeTheme(value.FileNameWithoutExtension); | ||
|
|
||
| if (_theme.BlurEnabled && _settings.UseDropShadowEffect) | ||
| DropShadowEffect = false; | ||
| } | ||
| } | ||
|
|
||
| private List<Theme.ThemeData> Themes => _theme.LoadAvailableThemes(); | ||
|
|
||
| private bool DropShadowEffect | ||
| { | ||
| get => _settings.UseDropShadowEffect; | ||
| set | ||
| { | ||
| if (_theme.BlurEnabled && value) | ||
| { | ||
| _context.API.ShowMsgBox(_context.API.GetTranslation("shadowEffectNotAllowed")); | ||
| return; | ||
| } | ||
|
|
||
| if (value) | ||
| { | ||
| _theme.AddDropShadowEffectToCurrentTheme(); | ||
| } | ||
| else | ||
| { | ||
| _theme.RemoveDropShadowEffectFromCurrentTheme(); | ||
| } | ||
|
|
||
| _settings.UseDropShadowEffect = value; | ||
| } | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| public ThemeSelector(PluginInitContext context) | ||
| { | ||
| _context = context; | ||
| _theme = Ioc.Default.GetRequiredService<Theme>(); | ||
| } | ||
|
|
||
| public List<Result> Query(Query query) | ||
| { | ||
| var search = query.SecondToEndSearch; | ||
| if (string.IsNullOrWhiteSpace(search)) | ||
| { | ||
| return Themes.Select(CreateThemeResult) | ||
| .OrderBy(x => x.Title) | ||
| .ToList(); | ||
| } | ||
|
|
||
| return Themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme.Name))) | ||
| .Where(x => x.matchResult.IsSearchPrecisionScoreMet()) | ||
| .Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData)) | ||
| .OrderBy(x => x.Title) | ||
| .ToList(); | ||
| } | ||
|
|
||
| private Result CreateThemeResult(Theme.ThemeData theme) => CreateThemeResult(theme, 0, null); | ||
|
|
||
| private Result CreateThemeResult(Theme.ThemeData theme, int score, IList<int> highlightData) | ||
| { | ||
| string themeName = theme.Name; | ||
| string title; | ||
| if (theme == SelectedTheme) | ||
| { | ||
| title = $"{theme.Name} ★"; | ||
| // Set current theme to the top | ||
| score = 2000; | ||
| } | ||
| else | ||
| { | ||
| title = theme.Name; | ||
| // Set them to 1000 so that they are higher than other non-theme records | ||
| score = 1000; | ||
| } | ||
|
|
||
| string description = string.Empty; | ||
| if (theme.IsDark == true) | ||
| { | ||
| description += _context.API.GetTranslation("TypeIsDarkToolTip"); | ||
| if (theme.HasBlur == true) | ||
| { | ||
| description += ""; | ||
| description += _context.API.GetTranslation("TypeHasBlurToolTip"); | ||
| } | ||
| } | ||
| else if (theme.HasBlur == true) | ||
| { | ||
| description += _context.API.GetTranslation("TypeHasBlurToolTip"); | ||
| } | ||
|
|
||
| return new Result | ||
| { | ||
| Title = title, | ||
| TitleHighlightData = highlightData, | ||
| SubTitle = description, | ||
| IcoPath = "Images\\theme_selector.png", | ||
| Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue790"), | ||
| Score = score, | ||
| Action = c => | ||
| { | ||
| SelectedTheme = theme; | ||
| _context.API.ReQuery(); | ||
| return false; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.