mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Refactoring CustomizedPluginConfig
1. Reorder the sequence of initialization of UserSettings. 2. Use dictionary for CustomizedPluginConfigs, so code logic like `.FirstOrDefault(o => o.ID == id);` are removed 3. part of #389
This commit is contained in:
@@ -8,9 +8,9 @@ using System.Threading;
|
||||
using System.Windows;
|
||||
using Wox.CommandArgs;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin;
|
||||
using Wox.ViewModel;
|
||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Wox
|
||||
private const string Unique = "Wox_Unique_Application_Mutex";
|
||||
public static MainWindow Window { get; private set; }
|
||||
|
||||
public static IPublicAPI API { get; private set; }
|
||||
public static PublicAPIInstance API { get; private set; }
|
||||
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
@@ -50,11 +50,13 @@ namespace Wox
|
||||
MainViewModel mainVM = new MainViewModel();
|
||||
API = new PublicAPIInstance(mainVM);
|
||||
Window = new MainWindow {DataContext = mainVM};
|
||||
|
||||
NotifyIconManager notifyIconManager = new NotifyIconManager(API);
|
||||
|
||||
PluginManager.Init(API);
|
||||
CommandArgsFactory.Execute(e.Args.ToList());
|
||||
|
||||
// happlebao todo: the whole setting releated initialization should be put into seperate class/method
|
||||
API.SetHotkey(UserSettingStorage.Instance.Hotkey, API.OnHotkey);
|
||||
API.SetCustomPluginHotkey();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -30,9 +30,6 @@ namespace Wox
|
||||
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
||||
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
|
||||
|
||||
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
|
||||
SetCustomPluginHotkey();
|
||||
|
||||
MainVM.ListeningKeyPressed += (o, e) => {
|
||||
|
||||
if(e.KeyEventArgs.Key == Key.Back)
|
||||
@@ -98,7 +95,7 @@ namespace Wox
|
||||
ShowWox();
|
||||
}
|
||||
|
||||
public void ShowMsg(string title, string subTitle, string iconPath)
|
||||
public void ShowMsg(string title, string subTitle = "", string iconPath = "")
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
@@ -202,7 +199,7 @@ namespace Wox
|
||||
MainVM.OnTextBoxSelected();
|
||||
}
|
||||
|
||||
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
|
||||
internal void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
|
||||
{
|
||||
var hotkey = new HotkeyModel(hotkeyStr);
|
||||
SetHotkey(hotkey, action);
|
||||
@@ -244,7 +241,7 @@ namespace Wox
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SetCustomPluginHotkey()
|
||||
internal void SetCustomPluginHotkey()
|
||||
{
|
||||
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
|
||||
foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys)
|
||||
@@ -259,7 +256,7 @@ namespace Wox
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHotkey(object sender, HotkeyEventArgs e)
|
||||
protected internal void OnHotkey(object sender, HotkeyEventArgs e)
|
||||
{
|
||||
if (ShouldIgnoreHotkeys()) return;
|
||||
ToggleWox();
|
||||
|
||||
@@ -567,7 +567,7 @@ namespace Wox
|
||||
pluginId = pair.Metadata.ID;
|
||||
pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath);
|
||||
|
||||
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginId);
|
||||
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs[pluginId];
|
||||
cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled;
|
||||
|
||||
PluginContentPanel.Content = null;
|
||||
@@ -615,17 +615,17 @@ namespace Wox
|
||||
id = pair.Metadata.ID;
|
||||
name = pair.Metadata.Name;
|
||||
}
|
||||
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == id);
|
||||
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs[id];
|
||||
if (customizedPluginConfig == null)
|
||||
{
|
||||
// todo when this part will be invoked
|
||||
UserSettingStorage.Instance.CustomizedPluginConfigs.Add(new CustomizedPluginConfig
|
||||
UserSettingStorage.Instance.CustomizedPluginConfigs[id] = new CustomizedPluginConfig
|
||||
{
|
||||
Disabled = cbDisabled.IsChecked ?? true,
|
||||
ID = id,
|
||||
Name = name,
|
||||
ActionKeywords = null
|
||||
});
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user