mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 01:08:18 +08:00
Support for Sys Tray Icon
This commit is contained in:
parent
df85543337
commit
2d4d7b80c1
@ -45,12 +45,13 @@ namespace Wox
|
||||
RegisterUnhandledException();
|
||||
ThreadPool.QueueUserWorkItem(o => { ImageLoader.ImageLoader.PreloadImages(); });
|
||||
|
||||
|
||||
MainViewModel mainVM = new MainViewModel();
|
||||
API = new PublicAPIInstance(mainVM);
|
||||
Window = new MainWindow();
|
||||
Window.DataContext = mainVM;
|
||||
|
||||
NotifyIconManager notifyIconManager = new NotifyIconManager(API);
|
||||
|
||||
PluginManager.Init(API);
|
||||
CommandArgsFactory.Execute(e.Args.ToList());
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ namespace Wox.Helper
|
||||
{
|
||||
var window = Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.GetType() == typeof(T))
|
||||
?? (T)Activator.CreateInstance(typeof(T), args);
|
||||
Application.Current.MainWindow.Hide();
|
||||
App.API.HideApp();
|
||||
window.Show();
|
||||
window.Focus();
|
||||
|
||||
|
@ -24,20 +24,14 @@ namespace Wox
|
||||
|
||||
#region Properties
|
||||
|
||||
private readonly Storyboard progressBarStoryboard = new Storyboard();
|
||||
private NotifyIcon notifyIcon;
|
||||
|
||||
|
||||
private readonly Storyboard progressBarStoryboard = new Storyboard();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
InitialTray();
|
||||
|
||||
//pnlResult.ItemDropEvent += pnlResult_ItemDropEvent;
|
||||
Closing += MainWindow_Closing;
|
||||
}
|
||||
@ -132,22 +126,6 @@ namespace Wox
|
||||
progressBar.BeginStoryboard(progressBarStoryboard);
|
||||
}
|
||||
|
||||
private void InitialTray()
|
||||
{
|
||||
//notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true };
|
||||
//notifyIcon.Click += (o, e) => ShowWox();
|
||||
//var open = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayOpen"));
|
||||
//open.Click += (o, e) => ShowWox();
|
||||
//var setting = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTraySettings"));
|
||||
//setting.Click += (o, e) => OpenSettingDialog();
|
||||
//var about = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayAbout"));
|
||||
//about.Click += (o, e) => OpenSettingDialog("about");
|
||||
//var exit = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayExit"));
|
||||
//exit.Click += (o, e) => CloseApp();
|
||||
//MenuItem[] childen = { open, setting, about, exit };
|
||||
//notifyIcon.ContextMenu = new ContextMenu(childen);
|
||||
}
|
||||
|
||||
private void Border_OnMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left) DragMove();
|
||||
|
40
Wox/NotifyIconManager.cs
Normal file
40
Wox/NotifyIconManager.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox
|
||||
{
|
||||
public class NotifyIconManager
|
||||
{
|
||||
|
||||
private NotifyIcon notifyIcon;
|
||||
private IPublicAPI _api;
|
||||
|
||||
public NotifyIconManager(IPublicAPI api)
|
||||
{
|
||||
this.InitialTray();
|
||||
this._api = api;
|
||||
}
|
||||
|
||||
private void InitialTray()
|
||||
{
|
||||
notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true };
|
||||
notifyIcon.Click += (o, e) => this._api.ShowApp();
|
||||
var open = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayOpen"));
|
||||
open.Click += (o, e) => this._api.ShowApp();
|
||||
var setting = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTraySettings"));
|
||||
setting.Click += (o, e) => this._api.OpenSettingDialog();
|
||||
var about = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayAbout"));
|
||||
about.Click += (o, e) => this._api.OpenSettingDialog("about");
|
||||
var exit = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayExit"));
|
||||
exit.Click += (o, e) => this._api.HideApp();
|
||||
MenuItem[] childen = { open, setting, about, exit };
|
||||
notifyIcon.ContextMenu = new ContextMenu(childen);
|
||||
}
|
||||
}
|
||||
}
|
@ -19,19 +19,22 @@ using Wox.Helper;
|
||||
using Wox.Plugin;
|
||||
using Application = System.Windows.Forms.Application;
|
||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using NHotkey.Wpf;
|
||||
using NHotkey;
|
||||
|
||||
namespace Wox
|
||||
{
|
||||
public partial class SettingWindow : Window
|
||||
{
|
||||
public readonly MainWindow MainWindow;
|
||||
public readonly IPublicAPI _api;
|
||||
bool settingsLoaded;
|
||||
private Dictionary<ISettingProvider, Control> featureControls = new Dictionary<ISettingProvider, Control>();
|
||||
private bool themeTabLoaded;
|
||||
|
||||
public SettingWindow(MainWindow mainWindow)
|
||||
public SettingWindow(IPublicAPI api)
|
||||
{
|
||||
MainWindow = mainWindow;
|
||||
this._api = api;
|
||||
InitializeComponent();
|
||||
Loaded += Setting_Loaded;
|
||||
}
|
||||
@ -250,23 +253,45 @@ namespace Wox
|
||||
{
|
||||
if (ctlHotkey.CurrentHotkeyAvailable)
|
||||
{
|
||||
//MainWindow.SetHotkey(ctlHotkey.CurrentHotkey, delegate
|
||||
//{
|
||||
// if (!MainWindow.IsVisible)
|
||||
// {
|
||||
// MainWindow.ShowApp();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// MainWindow.HideApp();
|
||||
// }
|
||||
//});
|
||||
//MainWindow.RemoveHotkey(UserSettingStorage.Instance.Hotkey);
|
||||
SetHotkey(ctlHotkey.CurrentHotkey, delegate
|
||||
{
|
||||
if (!App.Window.IsVisible)
|
||||
{
|
||||
this._api.ShowApp();
|
||||
}
|
||||
else
|
||||
{
|
||||
this._api.HideApp();
|
||||
}
|
||||
});
|
||||
RemoveHotkey(UserSettingStorage.Instance.Hotkey);
|
||||
UserSettingStorage.Instance.Hotkey = ctlHotkey.CurrentHotkey.ToString();
|
||||
UserSettingStorage.Instance.Save();
|
||||
}
|
||||
}
|
||||
|
||||
void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs> action)
|
||||
{
|
||||
string hotkeyStr = hotkey.ToString();
|
||||
try
|
||||
{
|
||||
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
|
||||
MessageBox.Show(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveHotkey(string hotkeyStr)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(hotkeyStr))
|
||||
{
|
||||
HotkeyManager.Current.Remove(hotkeyStr);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHotkeyTabSelected()
|
||||
{
|
||||
ctlHotkey.HotkeyChanged += ctlHotkey_OnHotkeyChanged;
|
||||
@ -289,7 +314,7 @@ namespace Wox
|
||||
UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item);
|
||||
lvCustomHotkey.Items.Refresh();
|
||||
UserSettingStorage.Instance.Save();
|
||||
//MainWindow.RemoveHotkey(item.Hotkey);
|
||||
RemoveHotkey(item.Hotkey);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,6 +126,7 @@
|
||||
<Compile Include="Converters\VisibilityConverter.cs" />
|
||||
<Compile Include="Helper\SingletonWindowOpener.cs" />
|
||||
<Compile Include="ImageLoader\ImageCacheStroage.cs" />
|
||||
<Compile Include="NotifyIconManager.cs" />
|
||||
<Compile Include="PublicAPIInstance.cs" />
|
||||
<Compile Include="Storage\QueryHistoryStorage.cs" />
|
||||
<Compile Include="Storage\TopMostRecordStorage.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user