-
-
Notifications
You must be signed in to change notification settings - Fork 374
New API Function from Theme & Improve Theme Model #3420
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
Changes from 13 commits
358b1fd
9b9704e
1611ad3
514fa00
28d92c7
2e885ea
0c0461d
ecd019d
91b6427
6c45882
9052f7b
537c03f
b3aa897
a2d9957
bac14fa
dd210ad
a3c7be9
a4c8343
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
|
||
namespace Flow.Launcher.Plugin.SharedModels; | ||
|
||
/// <summary> | ||
/// Theme data model | ||
/// </summary> | ||
public class ThemeData | ||
{ | ||
/// <summary> | ||
/// Theme file name without extension | ||
/// </summary> | ||
public string FileNameWithoutExtension { get; private init; } | ||
|
||
/// <summary> | ||
/// Theme name | ||
/// </summary> | ||
public string Name { get; private init; } | ||
|
||
/// <summary> | ||
/// Indicates whether the theme supports dark mode | ||
/// </summary> | ||
public bool? IsDark { get; private init; } | ||
|
||
/// <summary> | ||
/// Indicates whether the theme supports blur effects | ||
/// </summary> | ||
public bool? HasBlur { get; private init; } | ||
|
||
/// <summary> | ||
/// Theme data constructor | ||
/// </summary> | ||
public ThemeData(string fileNameWithoutExtension, string name, bool? isDark = null, bool? hasBlur = null) | ||
{ | ||
FileNameWithoutExtension = fileNameWithoutExtension; | ||
Name = name; | ||
IsDark = isDark; | ||
HasBlur = hasBlur; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public static bool operator ==(ThemeData left, ThemeData right) | ||
{ | ||
if (left is null && right is null) | ||
return true; | ||
if (left is null || right is null) | ||
return false; | ||
return left.Equals(right); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public static bool operator !=(ThemeData left, ThemeData right) | ||
{ | ||
return !(left == right); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object obj) | ||
{ | ||
if (obj is not ThemeData other) | ||
return false; | ||
return FileNameWithoutExtension == other.FileNameWithoutExtension && | ||
Name == other.Name; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() | ||
{ | ||
return HashCode.Combine(FileNameWithoutExtension, Name); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
return Name; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -39,6 +39,9 @@ public class PublicAPIInstance : IPublicAPI | |||||||||||||||||||||
private readonly Internationalization _translater; | ||||||||||||||||||||||
private readonly MainViewModel _mainVM; | ||||||||||||||||||||||
|
||||||||||||||||||||||
private Theme _theme; | ||||||||||||||||||||||
private Theme Theme => _theme ??= Ioc.Default.GetRequiredService<Theme>(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
private readonly object _saveSettingsLock = new(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
#region Constructor | ||||||||||||||||||||||
|
@@ -356,6 +359,16 @@ public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", M | |||||||||||||||||||||
|
||||||||||||||||||||||
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, cancelProgress); | ||||||||||||||||||||||
|
||||||||||||||||||||||
public List<ThemeData> GetAvailableThemes() => Theme.GetAvailableThemes(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
public ThemeData GetCurrentTheme() => Theme.GetCurrentTheme(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
public void SetCurrentTheme(ThemeData theme) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
Theme.ChangeTheme(theme.FileNameWithoutExtension); | ||||||||||||||||||||||
_ = _theme.RefreshFrameAsync(); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider awaiting RefreshFrameAsync() or properly handling its exceptions to prevent silent failures in theme refresh.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Jack251970 is this applicable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jjw24 I think we can remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me, changing theme from |
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
public ValueTask<ImageSource> LoadImageAsync(string path, bool loadFullImage = false, bool cacheImage = true) => | ||||||||||||||||||||||
ImageLoader.LoadAsync(path, loadFullImage, cacheImage); | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.