From 5adb329655193a3a8848a6a733f05977bede5042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E4=B9=9D?= <366193849@qq.com> Date: Fri, 5 Nov 2021 22:16:27 +0800 Subject: [PATCH] =?UTF-8?q?UI=E5=AD=97=E6=A0=B7=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.UI/MainWindow.xaml.cs | 18 +++++++----------- FastGithub.UI/Program.cs | 10 +++++++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/FastGithub.UI/MainWindow.xaml.cs b/FastGithub.UI/MainWindow.xaml.cs index 709299b..ef6ddee 100644 --- a/FastGithub.UI/MainWindow.xaml.cs +++ b/FastGithub.UI/MainWindow.xaml.cs @@ -1,6 +1,6 @@ using System; using System.Diagnostics; -using System.IO; +using System.Reflection; using System.Windows; using System.Windows.Interop; @@ -12,7 +12,7 @@ namespace FastGithub.UI public partial class MainWindow : Window { private readonly System.Windows.Forms.NotifyIcon notifyIcon; - private const string FAST_GITHUB = "FastGithub"; + private const string FASTGITHUB_UI = "FastGithub.UI"; private const string PROJECT_URI = "https://github.com/dotnetcore/FastGithub"; public MainWindow() @@ -25,10 +25,13 @@ namespace FastGithub.UI var exit = new System.Windows.Forms.MenuItem("退出(&C)"); exit.Click += (s, e) => this.Close(); + var version = this.GetType().Assembly.GetCustomAttribute()?.InformationalVersion; + + this.Title = $"{FASTGITHUB_UI} v{version}"; this.notifyIcon = new System.Windows.Forms.NotifyIcon { Visible = true, - Text = FAST_GITHUB, + Text = FASTGITHUB_UI, ContextMenu = new System.Windows.Forms.ContextMenu(new[] { about, exit }), Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath) }; @@ -42,15 +45,8 @@ namespace FastGithub.UI this.WindowState = WindowState.Normal; } }; + } - var fileName = $"{FAST_GITHUB}.exe"; - if (File.Exists(fileName) == true) - { - var version = FileVersionInfo.GetVersionInfo(fileName); - this.Title = $"{FAST_GITHUB} v{version.ProductVersion}"; - } - } - /// /// 拦截最小化事件 diff --git a/FastGithub.UI/Program.cs b/FastGithub.UI/Program.cs index 09ebcd1..f7d95ed 100644 --- a/FastGithub.UI/Program.cs +++ b/FastGithub.UI/Program.cs @@ -10,11 +10,15 @@ namespace FastGithub.UI { class Program { + private const string MUTEX_NAME = "Global\\FastGithub.UI"; + private const string MAIN_WINDOWS = "MainWindow.xaml"; + private const string FASTGITHUB_PATH = "fastgithub.exe"; + [STAThread] static void Main(string[] args) { AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve; - using var mutex = new Mutex(true, "Global\\FastGithub.UI", out var isFirstInstance); + using var mutex = new Mutex(true, MUTEX_NAME, out var isFirstInstance); if (isFirstInstance == false) { return; @@ -24,7 +28,7 @@ namespace FastGithub.UI SetWebBrowserVersion(); var app = new Application(); - app.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative); + app.StartupUri = new Uri(MAIN_WINDOWS, UriKind.Relative); app.Run(); } @@ -71,7 +75,7 @@ namespace FastGithub.UI /// private static void StartFastGithub() { - const string fileName = "fastgithub.exe"; + const string fileName = FASTGITHUB_PATH; if (File.Exists(fileName) == false) { return;