Skip to content

Commit

Permalink
Add SystemTrayService
Browse files Browse the repository at this point in the history
1.Add SystemTrayService to manage shell notifyicon
2.Update Readme.md
  • Loading branch information
Gaoyifei1011 committed Apr 13, 2024
1 parent 0ff7f59 commit 95e5aa9
Show file tree
Hide file tree
Showing 37 changed files with 1,441 additions and 51 deletions.
1 change: 0 additions & 1 deletion Description/README_EN-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,5 @@ Unpackaged version

### Other content

> * The project began on March 20, 2023, and ended on July 29, 2023, lasting a total of 4 months and 9 days.
> * This project is an open source project licensed under the MIT license, and you may modify, distribute, or merge copies with new copies. If you use the project, please do not use it for illegal purposes, and the developer will not be held responsible.
> * [Tool prototype](https://github.com/Gaoyifei1011/WindowsToolbox/blob/main/Description/RawApplicationDescription.md) 
1 change: 0 additions & 1 deletion Description/README_ZH-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,5 @@

### 其他内容

> * 该项目自2023年3月20日起,到2023年7月29日结束,共历时4个月零9天。
> * 该项目是基于MIT协议许可的开源项目,您可以修改、分发该项目或将副本与新副本合并。如果您使用了该项目,请勿用于非法用途,本开发者不会承担任何责任。
> * [工具原型](https://github.com/Gaoyifei1011/WindowsToolbox/blob/main/Description/RawApplicationDescription.md) 
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@

### 其他内容

> * 该项目自2023年3月20日起,到2023年7月29日结束,共历时4个月零9天。
> * 该项目是基于MIT协议许可的开源项目,您可以修改、分发该项目或将副本与新副本合并。如果您使用了该项目,请勿用于非法用途,本开发者不会承担任何责任。
> * [工具原型](https://github.com/Gaoyifei1011/WindowsToolbox/blob/main/Description/RawApplicationDescription.md) 
10 changes: 5 additions & 5 deletions WindowsTools/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Mile.Xaml.Interop;
using Mile.Xaml;
using System;
using System.Diagnostics.Tracing;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Hosting;
using WindowsTools.Services.Root;
using WindowsTools.Views.Windows;

Expand All @@ -17,8 +16,7 @@ public partial class App : Application, IDisposable

public App()
{
WindowsXamlManager.InitializeForCurrentThread();
Window.Current.GetInterop().TransparentBackground = true;
this.ThreadInitialize();
InitializeComponent();
UnhandledException += OnUnhandledException;
}
Expand Down Expand Up @@ -55,7 +53,9 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
MainWindow.Current.Close();
this.ThreadUninitialize();
MainWindow.Current?.Close();
//SystemTrayService.CloseSystemTray();
System.Windows.Forms.Application.Exit();
}

Expand Down
Binary file modified WindowsTools/Assets/ControlIcon/ShellMenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions WindowsTools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,13 @@ public static void Main(string[] args)

Application.SetCompatibleTextRenderingDefault(false);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ApplicationExit += OnApplicationExit;
Application.ThreadException += OnThreadException;
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

new App();
Application.Run(new MainWindow());
}

/// <summary>
/// 在应用程序即将关闭时发生
/// </summary>
private static void OnApplicationExit(object sender, EventArgs args)
{
(Windows.UI.Xaml.Application.Current as App).Dispose();
}

/// <summary>
/// 处理 Windows 窗体 UI 线程异常
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions WindowsTools/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
[assembly: AssemblyCompany("高怡飞")]
[assembly: AssemblyCopyright("Copyright ©2024 高怡飞, All Rights Reserved.")]
[assembly: AssemblyDescription("Windows 工具箱")]
[assembly: AssemblyFileVersion("2.2.410.0")]
[assembly: AssemblyInformationalVersion("2.2.410.0")]
[assembly: AssemblyFileVersion("2.3.413.0")]
[assembly: AssemblyInformationalVersion("2.3.413.0")]
[assembly: AssemblyProduct("Windows 工具箱")]
[assembly: AssemblyTitle("Windows 工具箱")]
[assembly: AssemblyVersion("2.2.410.0")]
[assembly: AssemblyVersion("2.3.413.0")]

// 设置程序集对 COM 组件的访问权限
[assembly: ComVisible(false)]
Expand Down
63 changes: 63 additions & 0 deletions WindowsTools/Services/Root/SystemTrayService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Drawing;
using System.Windows.Forms;

namespace WindowsTools.Services.Root
{
/// <summary>
/// 系统托盘菜单服务
/// </summary>
public static class SystemTrayService
{
private static NotifyIcon notifyIcon;

public static event MouseEventHandler MouseClick;

public static event MouseEventHandler MouseDoubleClick;

/// <summary>
/// 初始化系统托盘
/// </summary>
public static void InitializeSystemTray(string content, string iconPath)
{
if (notifyIcon is null)
{
notifyIcon = new NotifyIcon();
notifyIcon.Text = content;
notifyIcon.Icon = Icon.ExtractAssociatedIcon(iconPath);
notifyIcon.Visible = true;
notifyIcon.MouseClick += OnMouseClick;
notifyIcon.MouseDoubleClick += OnMouseDoubleClick;
}
}

/// <summary>
/// 关闭托盘菜单
/// </summary>
public static void CloseSystemTray()
{
if (notifyIcon is not null)
{
notifyIcon.Visible = false;
notifyIcon.MouseClick -= OnMouseClick;
notifyIcon.Dispose();
notifyIcon = null;
}
}

/// <summary>
/// 处理托盘菜单鼠标点击事件
/// </summary>
private static void OnMouseClick(object sender, MouseEventArgs args)
{
MouseClick?.Invoke(sender, args);
}

/// <summary>
/// 处理托盘菜单鼠标双击事件
/// </summary>
private static void OnMouseDoubleClick(object sender, MouseEventArgs args)
{
MouseDoubleClick?.Invoke(sender, args);
}
}
}
90 changes: 90 additions & 0 deletions WindowsTools/Strings/ShellMenu.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions WindowsTools/Strings/ShellMenu.en-us.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,36 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AddMenu" xml:space="preserve">
<value>Add menu</value>
</data>
<data name="Apply" xml:space="preserve">
<value>Apply</value>
</data>
<data name="ApplyModify" xml:space="preserve">
<value>Apply modify</value>
</data>
<data name="MenuList" xml:space="preserve">
<value>Menu list</value>
</data>
<data name="Modify" xml:space="preserve">
<value>Modify</value>
</data>
<data name="Refresh" xml:space="preserve">
<value>Refresh</value>
</data>
<data name="ReturnDefault" xml:space="preserve">
<value>Return default</value>
</data>
<data name="RootMenuIcon" xml:space="preserve">
<value>Root menu icon</value>
</data>
<data name="RootMenuName" xml:space="preserve">
<value>Root menu name</value>
</data>
<data name="RootMenuSettings" xml:space="preserve">
<value>Root menu settings</value>
</data>
<data name="Title" xml:space="preserve">
<value>Custom shell menu</value>
</data>
Expand Down
30 changes: 30 additions & 0 deletions WindowsTools/Strings/ShellMenu.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,36 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AddMenu" xml:space="preserve">
<value>Add menu</value>
</data>
<data name="Apply" xml:space="preserve">
<value>Apply</value>
</data>
<data name="ApplyModify" xml:space="preserve">
<value>Apply modify</value>
</data>
<data name="MenuList" xml:space="preserve">
<value>Menu list</value>
</data>
<data name="Modify" xml:space="preserve">
<value>Modify</value>
</data>
<data name="Refresh" xml:space="preserve">
<value>Refresh</value>
</data>
<data name="ReturnDefault" xml:space="preserve">
<value>Return default</value>
</data>
<data name="RootMenuIcon" xml:space="preserve">
<value>Root menu icon</value>
</data>
<data name="RootMenuName" xml:space="preserve">
<value>Root menu name</value>
</data>
<data name="RootMenuSettings" xml:space="preserve">
<value>Root menu settings</value>
</data>
<data name="Title" xml:space="preserve">
<value>Custom shell menu</value>
</data>
Expand Down
30 changes: 30 additions & 0 deletions WindowsTools/Strings/ShellMenu.zh-hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,36 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AddMenu" xml:space="preserve">
<value>添加菜单</value>
</data>
<data name="Apply" xml:space="preserve">
<value>应用</value>
</data>
<data name="ApplyModify" xml:space="preserve">
<value>应用更改</value>
</data>
<data name="MenuList" xml:space="preserve">
<value>菜单列表</value>
</data>
<data name="Modify" xml:space="preserve">
<value>修改</value>
</data>
<data name="Refresh" xml:space="preserve">
<value>刷新</value>
</data>
<data name="ReturnDefault" xml:space="preserve">
<value>还原默认</value>
</data>
<data name="RootMenuIcon" xml:space="preserve">
<value>根菜单图标</value>
</data>
<data name="RootMenuName" xml:space="preserve">
<value>根菜单名称</value>
</data>
<data name="RootMenuSettings" xml:space="preserve">
<value>根菜单设置</value>
</data>
<data name="Title" xml:space="preserve">
<value>自定义扩展菜单</value>
</data>
Expand Down
Loading

0 comments on commit 95e5aa9

Please sign in to comment.