Skip to content

Commit

Permalink
Improve code quality for field names
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack251970 committed Feb 23, 2025
1 parent 8496cfc commit ad63b0e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
48 changes: 24 additions & 24 deletions Flow.Launcher.Core/Resource/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class Theme

private const int ShadowExtraMargin = 32;

private readonly IPublicAPI API;
private readonly Settings Settings;
private readonly List<string> _themeDirectories = new List<string>();
private readonly IPublicAPI _api;
private readonly Settings _settings;
private readonly List<string> _themeDirectories = new();
private ResourceDictionary _oldResource;
private string _oldTheme;
private const string Folder = Constant.Themes;
Expand All @@ -41,8 +41,8 @@ public class Theme

public Theme(IPublicAPI publicAPI, Settings settings)
{
API = publicAPI;
Settings = settings;
_api = publicAPI;
_settings = settings;

_themeDirectories.Add(DirectoryPath);
_themeDirectories.Add(UserDirectoryPath);
Expand Down Expand Up @@ -94,7 +94,7 @@ public bool ChangeTheme(string theme)
// to things like fonts
UpdateResourceDictionary(GetResourceDictionary(theme));

Settings.Theme = theme;
_settings.Theme = theme;


//always allow re-loading default theme, in case of failure of switching to a new theme from default theme
Expand All @@ -105,7 +105,7 @@ public bool ChangeTheme(string theme)

BlurEnabled = Win32Helper.IsBlurTheme();

if (Settings.UseDropShadowEffect && !BlurEnabled)
if (_settings.UseDropShadowEffect && !BlurEnabled)
AddDropShadowEffectToCurrentTheme();

Win32Helper.SetBlurForWindow(Application.Current.MainWindow, BlurEnabled);
Expand All @@ -115,7 +115,7 @@ public bool ChangeTheme(string theme)
Log.Error($"|Theme.ChangeTheme|Theme <{theme}> path can't be found");
if (theme != defaultTheme)
{
API.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_path_not_exists"), theme));
_api.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_path_not_exists"), theme));
ChangeTheme(defaultTheme);
}
return false;
Expand All @@ -125,7 +125,7 @@ public bool ChangeTheme(string theme)
Log.Error($"|Theme.ChangeTheme|Theme <{theme}> fail to parse");
if (theme != defaultTheme)
{
API.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_parse_error"), theme));
_api.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_parse_error"), theme));
ChangeTheme(defaultTheme);
}
return false;
Expand Down Expand Up @@ -153,7 +153,7 @@ private ResourceDictionary GetThemeResourceDictionary(string theme)
return dict;
}

private ResourceDictionary CurrentThemeResourceDictionary() => GetThemeResourceDictionary(Settings.Theme);
private ResourceDictionary CurrentThemeResourceDictionary() => GetThemeResourceDictionary(_settings.Theme);

public ResourceDictionary GetResourceDictionary(string theme)
{
Expand All @@ -162,10 +162,10 @@ public ResourceDictionary GetResourceDictionary(string theme)
if (dict["QueryBoxStyle"] is Style queryBoxStyle &&
dict["QuerySuggestionBoxStyle"] is Style querySuggestionBoxStyle)
{
var fontFamily = new FontFamily(Settings.QueryBoxFont);
var fontStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle);
var fontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight);
var fontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch);
var fontFamily = new FontFamily(_settings.QueryBoxFont);
var fontStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.QueryBoxFontStyle);
var fontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.QueryBoxFontWeight);
var fontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.QueryBoxFontStretch);

queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, fontFamily));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, fontStyle));
Expand All @@ -190,10 +190,10 @@ public ResourceDictionary GetResourceDictionary(string theme)
dict["ItemHotkeyStyle"] is Style resultHotkeyItemStyle &&
dict["ItemHotkeySelectedStyle"] is Style resultHotkeyItemSelectedStyle)
{
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(Settings.ResultFont));
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.ResultFontStyle));
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.ResultFontWeight));
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.ResultFontStretch));
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(_settings.ResultFont));
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.ResultFontStyle));
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.ResultFontWeight));
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.ResultFontStretch));

Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch };
Array.ForEach(
Expand All @@ -205,10 +205,10 @@ public ResourceDictionary GetResourceDictionary(string theme)
dict["ItemSubTitleStyle"] is Style resultSubItemStyle &&
dict["ItemSubTitleSelectedStyle"] is Style resultSubItemSelectedStyle)
{
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(Settings.ResultSubFont));
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.ResultSubFontStyle));
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.ResultSubFontWeight));
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.ResultSubFontStretch));
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(_settings.ResultSubFont));
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.ResultSubFontStyle));
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.ResultSubFontWeight));
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.ResultSubFontStretch));

Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch };
Array.ForEach(
Expand All @@ -218,15 +218,15 @@ public ResourceDictionary GetResourceDictionary(string theme)

/* Ignore Theme Window Width and use setting */
var windowStyle = dict["WindowStyle"] as Style;
var width = Settings.WindowSize;
var width = _settings.WindowSize;
windowStyle.Setters.Add(new Setter(Window.WidthProperty, width));
mainWindowWidth = (double)width;
return dict;
}

private ResourceDictionary GetCurrentResourceDictionary( )
{
return GetResourceDictionary(Settings.Theme);
return GetResourceDictionary(_settings.Theme);
}

public List<ThemeData> LoadAvailableThemes()
Expand Down
28 changes: 14 additions & 14 deletions Flow.Launcher.Core/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ namespace Flow.Launcher.Core
{
public class Updater
{
private readonly IPublicAPI API;

public string GitHubRepository { get; init; }

private readonly IPublicAPI _api;

public Updater(IPublicAPI publicAPI, string gitHubRepository)
{
API = publicAPI;
_api = publicAPI;
GitHubRepository = gitHubRepository;
}

Expand All @@ -40,8 +40,8 @@ public async Task UpdateAppAsync(bool silentUpdate = true)
try
{
if (!silentUpdate)
API.ShowMsg(API.GetTranslation("pleaseWait"),
API.GetTranslation("update_flowlauncher_update_check"));
_api.ShowMsg(_api.GetTranslation("pleaseWait"),
_api.GetTranslation("update_flowlauncher_update_check"));

using var updateManager = await GitHubUpdateManagerAsync(GitHubRepository).ConfigureAwait(false);

Expand All @@ -56,13 +56,13 @@ public async Task UpdateAppAsync(bool silentUpdate = true)
if (newReleaseVersion <= currentVersion)
{
if (!silentUpdate)
API.ShowMsgBox(API.GetTranslation("update_flowlauncher_already_on_latest"));
_api.ShowMsgBox(_api.GetTranslation("update_flowlauncher_already_on_latest"));
return;
}

if (!silentUpdate)
API.ShowMsg(API.GetTranslation("update_flowlauncher_update_found"),
API.GetTranslation("update_flowlauncher_updating"));
_api.ShowMsg(_api.GetTranslation("update_flowlauncher_update_found"),
_api.GetTranslation("update_flowlauncher_updating"));

await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply).ConfigureAwait(false);

Expand All @@ -71,9 +71,9 @@ public async Task UpdateAppAsync(bool silentUpdate = true)
if (DataLocation.PortableDataLocationInUse())
{
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}";
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination, (s) => API.ShowMsgBox(s));
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination, (s) => API.ShowMsgBox(s)))
API.ShowMsgBox(string.Format(API.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"),
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination, (s) => _api.ShowMsgBox(s));
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination, (s) => _api.ShowMsgBox(s)))
_api.ShowMsgBox(string.Format(_api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"),
DataLocation.PortableDataPath,
targetDestination));
}
Expand All @@ -86,7 +86,7 @@ public async Task UpdateAppAsync(bool silentUpdate = true)

Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");

if (API.ShowMsgBox(newVersionTips, API.GetTranslation("update_flowlauncher_new_update"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
if (_api.ShowMsgBox(newVersionTips, _api.GetTranslation("update_flowlauncher_new_update"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
UpdateManager.RestartApp(Constant.ApplicationFileName);
}
Expand All @@ -99,8 +99,8 @@ public async Task UpdateAppAsync(bool silentUpdate = true)
Log.Exception($"|Updater.UpdateApp|Error Occurred", e);

if (!silentUpdate)
API.ShowMsg(API.GetTranslation("update_flowlauncher_fail"),
API.GetTranslation("update_flowlauncher_check_connection"));
_api.ShowMsg(_api.GetTranslation("update_flowlauncher_fail"),
_api.GetTranslation("update_flowlauncher_check_connection"));
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public bool KeywordEnabled
}

private string actionKeyword;
private readonly IPublicAPI api;
private readonly IPublicAPI _api;
private bool _keywordEnabled;

public ActionKeywordSetting(ActionKeywordModel selectedActionKeyword, IPublicAPI api)
{
CurrentActionKeyword = selectedActionKeyword;
this.api = api;
_api = api;
ActionKeyword = selectedActionKeyword.Keyword;
KeywordEnabled = selectedActionKeyword.Enabled;

Expand All @@ -62,22 +62,22 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
switch (CurrentActionKeyword.KeywordProperty, KeywordEnabled)
{
case (Settings.ActionKeyword.FileContentSearchActionKeyword, true):
api.ShowMsgBox(api.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
_api.ShowMsgBox(_api.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
return;
case (Settings.ActionKeyword.QuickAccessActionKeyword, true):
api.ShowMsgBox(api.GetTranslation("plugin_explorer_quickaccess_globalActionKeywordInvalid"));
_api.ShowMsgBox(_api.GetTranslation("plugin_explorer_quickaccess_globalActionKeywordInvalid"));
return;
}

if (!KeywordEnabled || !api.ActionKeywordAssigned(ActionKeyword))
if (!KeywordEnabled || !_api.ActionKeywordAssigned(ActionKeyword))
{
DialogResult = true;
Close();
return;
}

// The keyword is not valid, so show message
api.ShowMsgBox(api.GetTranslation("newActionKeywordsHasBeenAssigned"));
_api.ShowMsgBox(_api.GetTranslation("newActionKeywordsHasBeenAssigned"));
}

private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit ad63b0e

Please sign in to comment.