Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static async Task InitializePluginsAsync()
}
catch (Exception e)
{
Log.Exception(nameof(PluginManager), $"Fail to Init plugin: {pair.Metadata.Name}", e);
Log.Exception(ClassName, $"Fail to Init plugin: {pair.Metadata.Name}", e);
pair.Metadata.Disabled = true;
failedPlugins.Enqueue(pair);
}
Expand Down
12 changes: 0 additions & 12 deletions Flow.Launcher.Core/Resource/InternationalizationManager.cs

This file was deleted.

9 changes: 3 additions & 6 deletions Flow.Launcher.Core/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Http;
Expand Down Expand Up @@ -131,7 +129,7 @@ private static async Task<UpdateManager> GitHubUpdateManagerAsync(string reposit

await using var jsonStream = await Http.GetStreamAsync(api).ConfigureAwait(false);

var releases = await System.Text.Json.JsonSerializer.DeserializeAsync<List<GithubRelease>>(jsonStream).ConfigureAwait(false);
var releases = await JsonSerializer.DeserializeAsync<List<GithubRelease>>(jsonStream).ConfigureAwait(false);
var latest = releases.Where(r => !r.Prerelease).OrderByDescending(r => r.PublishedAt).First();
var latestUrl = latest.HtmlUrl.Replace("/tag/", "/download/");

Expand All @@ -146,10 +144,9 @@ private static async Task<UpdateManager> GitHubUpdateManagerAsync(string reposit
return manager;
}

private static string NewVersionTips(string version)
private string NewVersionTips(string version)
{
var translator = Ioc.Default.GetRequiredService<Internationalization>();
var tips = string.Format(translator.GetTranslation("newVersionTips"), version);
var tips = string.Format(_api.GetTranslation("newVersionTips"), version);

return tips;
}
Expand Down
27 changes: 11 additions & 16 deletions Flow.Launcher/ActionKeywords.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
using System.Windows;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Plugin;
using Flow.Launcher.ViewModel;
using Flow.Launcher.Core;
using System.Linq;
using System.Collections.Generic;

namespace Flow.Launcher
{
public partial class ActionKeywords
{
private readonly PluginPair plugin;
private readonly Internationalization translater = InternationalizationManager.Instance;
private readonly PluginViewModel pluginViewModel;
private readonly PluginPair _plugin;
private readonly PluginViewModel _pluginViewModel;

public ActionKeywords(PluginViewModel pluginViewModel)
{
InitializeComponent();
plugin = pluginViewModel.PluginPair;
this.pluginViewModel = pluginViewModel;
_plugin = pluginViewModel.PluginPair;
_pluginViewModel = pluginViewModel;
}

private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
{
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, plugin.Metadata.ActionKeywords.ToArray());
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, _plugin.Metadata.ActionKeywords.ToArray());
tbAction.Focus();
}

Expand All @@ -34,7 +31,7 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)

private void btnDone_OnClick(object sender, RoutedEventArgs _)
{
var oldActionKeywords = plugin.Metadata.ActionKeywords;
var oldActionKeywords = _plugin.Metadata.ActionKeywords;

var newActionKeywords = tbAction.Text.Split(Query.ActionKeywordSeparator).ToList();
newActionKeywords.RemoveAll(string.IsNullOrEmpty);
Expand All @@ -48,7 +45,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
{
if (oldActionKeywords.Count != newActionKeywords.Count)
{
ReplaceActionKeyword(plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
ReplaceActionKeyword(_plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
return;
}

Expand All @@ -58,18 +55,16 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
if (sortedOldActionKeywords.SequenceEqual(sortedNewActionKeywords))
{
// User just changes the sequence of action keywords
var msg = translater.GetTranslation("newActionKeywordsSameAsOld");
MessageBoxEx.Show(msg);
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsSameAsOld"));
}
else
{
ReplaceActionKeyword(plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
ReplaceActionKeyword(_plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
}
}
else
{
string msg = translater.GetTranslation("newActionKeywordsHasBeenAssigned");
App.API.ShowMsgBox(msg);
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
}
}

Expand All @@ -85,7 +80,7 @@ private void ReplaceActionKeyword(string id, IReadOnlyList<string> removedAction
}

// Update action keywords text and close window
pluginViewModel.OnActionKeywordsChanged();
_pluginViewModel.OnActionKeywordsChanged();
Close();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public void Dispose()

public void OnSecondAppStarted()
{
Ioc.Default.GetRequiredService<MainViewModel>().Show();
API.ShowMainWindow();
}

#endregion
Expand Down
3 changes: 1 addition & 2 deletions Flow.Launcher/Converters/TextConverter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.ViewModel;

namespace Flow.Launcher.Converters;
Expand All @@ -23,7 +22,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
if (translationKey is null)
return id;

return InternationalizationManager.Instance.GetTranslation(translationKey);
return App.API.GetTranslation(translationKey);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new InvalidOperationException();
Expand Down
8 changes: 3 additions & 5 deletions Flow.Launcher/CustomQueryHotkeySetting.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Helper;
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.UserSettings;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down Expand Up @@ -53,22 +52,21 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
Close();
}


public void UpdateItem(CustomPluginHotkey item)
{
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (updateCustomHotkey == null)
{
App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("invalidPluginHotkey"));
App.API.ShowMsgBox(App.API.GetTranslation("invalidPluginHotkey"));
Close();
return;
}

tbAction.Text = updateCustomHotkey.ActionKeyword;
HotkeyControl.SetHotkey(updateCustomHotkey.Hotkey, false);
update = true;
lblAdd.Text = InternationalizationManager.Instance.GetTranslation("update");
lblAdd.Text = App.API.GetTranslation("update");
}

private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)
Expand Down
10 changes: 4 additions & 6 deletions Flow.Launcher/CustomShortcutSetting.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Flow.Launcher.Core.Resource;
using System;
using System;
using System.Windows;
using System.Windows.Input;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.Core;

namespace Flow.Launcher
{
Expand Down Expand Up @@ -41,15 +39,15 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)

private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{
if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value))
if (string.IsNullOrEmpty(Key) || string.IsNullOrEmpty(Value))
{
App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("emptyShortcut"));
App.API.ShowMsgBox(App.API.GetTranslation("emptyShortcut"));
return;
}
// Check if key is modified or adding a new one
if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key))
{
App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("duplicateShortcut"));
App.API.ShowMsgBox(App.API.GetTranslation("duplicateShortcut"));
return;
}
DialogResult = !update || originalKey != Key || originalValue != Value;
Expand Down
15 changes: 7 additions & 8 deletions Flow.Launcher/Helper/HotKeyMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using NHotkey;
using NHotkey.Wpf;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.ViewModel;
using ChefKeys;
using Flow.Launcher.Infrastructure.Logger;
Expand Down Expand Up @@ -56,8 +55,8 @@ private static void SetWithChefKeys(string hotkeyStr)
string.Format("|HotkeyMapper.SetWithChefKeys|Error registering hotkey: {0} \nStackTrace:{1}",
e.Message,
e.StackTrace));
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle");
string errorMsg = string.Format(App.API.GetTranslation("registerHotkeyFailed"), hotkeyStr);
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
MessageBoxEx.Show(errorMsg, errorMsgTitle);
}
}
Expand All @@ -82,8 +81,8 @@ internal static void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs>
e.Message,
e.StackTrace,
hotkeyStr));
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle");
string errorMsg = string.Format(App.API.GetTranslation("registerHotkeyFailed"), hotkeyStr);
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
App.API.ShowMsgBox(errorMsg, errorMsgTitle);
}
}
Expand All @@ -107,8 +106,8 @@ internal static void RemoveHotkey(string hotkeyStr)
string.Format("|HotkeyMapper.RemoveHotkey|Error removing hotkey: {0} \nStackTrace:{1}",
e.Message,
e.StackTrace));
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("unregisterHotkeyFailed"), hotkeyStr);
string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle");
string errorMsg = string.Format(App.API.GetTranslation("unregisterHotkeyFailed"), hotkeyStr);
string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle");
MessageBoxEx.Show(errorMsg, errorMsgTitle);
}
}
Expand Down Expand Up @@ -137,7 +136,7 @@ internal static void SetCustomQueryHotkey(CustomPluginHotkey hotkey)
if (_mainViewModel.ShouldIgnoreHotkeys())
return;

_mainViewModel.Show();
App.API.ShowMainWindow();
_mainViewModel.ChangeQueryText(hotkey.ActionKeyword, true);
});
}
Expand Down
13 changes: 4 additions & 9 deletions Flow.Launcher/HotkeyControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Windows;
using System.Windows.Input;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.UserSettings;
Expand Down Expand Up @@ -65,7 +64,6 @@ private static void OnHotkeyChanged(DependencyObject d, DependencyPropertyChange
hotkeyControl.RefreshHotkeyInterface(hotkeyControl.Hotkey);
}


public static readonly DependencyProperty ChangeHotkeyProperty = DependencyProperty.Register(
nameof(ChangeHotkey),
typeof(ICommand),
Expand All @@ -79,7 +77,6 @@ public ICommand? ChangeHotkey
set { SetValue(ChangeHotkeyProperty, value); }
}


public static readonly DependencyProperty TypeProperty = DependencyProperty.Register(
nameof(Type),
typeof(HotkeyType),
Expand Down Expand Up @@ -227,19 +224,18 @@ private void RefreshHotkeyInterface(string hotkey)
private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) =>
hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey);

public string EmptyHotkey => InternationalizationManager.Instance.GetTranslation("none");
public string EmptyHotkey => App.API.GetTranslation("none");

public ObservableCollection<string> KeysToDisplay { get; set; } = new();

public HotkeyModel CurrentHotkey { get; private set; } = new(false, false, false, false, Key.None);


public void GetNewHotkey(object sender, RoutedEventArgs e)
{
OpenHotkeyDialog();
_ = OpenHotkeyDialogAsync();
}

private async Task OpenHotkeyDialog()
private async Task OpenHotkeyDialogAsync()
{
if (!string.IsNullOrEmpty(Hotkey))
{
Expand All @@ -262,12 +258,11 @@ private async Task OpenHotkeyDialog()
}
}


private void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true)
{
if (triggerValidate)
{
bool hotkeyAvailable = false;
bool hotkeyAvailable;
// TODO: This is a temporary way to enforce changing only the open flow hotkey to Win, and will be removed by PR #3157
if (keyModel.ToString() == "LWin" || keyModel.ToString() == "RWin")
{
Expand Down
13 changes: 6 additions & 7 deletions Flow.Launcher/HotkeyControlDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Windows.Input;
using ChefKeys;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.UserSettings;
Expand Down Expand Up @@ -34,15 +33,15 @@ public enum EResultType

public EResultType ResultType { get; private set; } = EResultType.Cancel;
public string ResultValue { get; private set; } = string.Empty;
public static string EmptyHotkey => InternationalizationManager.Instance.GetTranslation("none");
public static string EmptyHotkey => App.API.GetTranslation("none");

private static bool isOpenFlowHotkey;

public HotkeyControlDialog(string hotkey, string defaultHotkey, string windowTitle = "")
{
WindowTitle = windowTitle switch
{
"" or null => InternationalizationManager.Instance.GetTranslation("hotkeyRegTitle"),
"" or null => App.API.GetTranslation("hotkeyRegTitle"),
_ => windowTitle
};
DefaultHotkey = defaultHotkey;
Expand Down Expand Up @@ -141,14 +140,14 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
if (_hotkeySettings.RegisteredHotkeys.FirstOrDefault(v => v.Hotkey == hotkey) is { } registeredHotkeyData)
{
var description = string.Format(
InternationalizationManager.Instance.GetTranslation(registeredHotkeyData.DescriptionResourceKey),
App.API.GetTranslation(registeredHotkeyData.DescriptionResourceKey),
registeredHotkeyData.DescriptionFormatVariables
);
Alert.Visibility = Visibility.Visible;
if (registeredHotkeyData.RemoveHotkey is not null)
{
tbMsg.Text = string.Format(
InternationalizationManager.Instance.GetTranslation("hotkeyUnavailableEditable"),
App.API.GetTranslation("hotkeyUnavailableEditable"),
description
);
SaveBtn.IsEnabled = false;
Expand All @@ -160,7 +159,7 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
else
{
tbMsg.Text = string.Format(
InternationalizationManager.Instance.GetTranslation("hotkeyUnavailableUneditable"),
App.API.GetTranslation("hotkeyUnavailableUneditable"),
description
);
SaveBtn.IsEnabled = false;
Expand All @@ -176,7 +175,7 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)

if (!CheckHotkeyAvailability(hotkey.Value, true))
{
tbMsg.Text = InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable");
tbMsg.Text = App.API.GetTranslation("hotkeyUnavailable");
Alert.Visibility = Visibility.Visible;
SaveBtn.IsEnabled = false;
SaveBtn.Visibility = Visibility.Visible;
Expand Down
Loading
Loading