UI字样标题

This commit is contained in:
老九 2021-11-05 22:16:27 +08:00
parent 4f305ef7c8
commit 5adb329655
2 changed files with 14 additions and 14 deletions

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.Reflection;
using System.Windows; using System.Windows;
using System.Windows.Interop; using System.Windows.Interop;
@ -12,7 +12,7 @@ namespace FastGithub.UI
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
private readonly System.Windows.Forms.NotifyIcon notifyIcon; 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"; private const string PROJECT_URI = "https://github.com/dotnetcore/FastGithub";
public MainWindow() public MainWindow()
@ -25,10 +25,13 @@ namespace FastGithub.UI
var exit = new System.Windows.Forms.MenuItem("退出(&C)"); var exit = new System.Windows.Forms.MenuItem("退出(&C)");
exit.Click += (s, e) => this.Close(); exit.Click += (s, e) => this.Close();
var version = this.GetType().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
this.Title = $"{FASTGITHUB_UI} v{version}";
this.notifyIcon = new System.Windows.Forms.NotifyIcon this.notifyIcon = new System.Windows.Forms.NotifyIcon
{ {
Visible = true, Visible = true,
Text = FAST_GITHUB, Text = FASTGITHUB_UI,
ContextMenu = new System.Windows.Forms.ContextMenu(new[] { about, exit }), ContextMenu = new System.Windows.Forms.ContextMenu(new[] { about, exit }),
Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath) Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath)
}; };
@ -42,15 +45,8 @@ namespace FastGithub.UI
this.WindowState = WindowState.Normal; 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}";
}
}
/// <summary> /// <summary>
/// 拦截最小化事件 /// 拦截最小化事件

View File

@ -10,11 +10,15 @@ namespace FastGithub.UI
{ {
class Program 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] [STAThread]
static void Main(string[] args) static void Main(string[] args)
{ {
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve; 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) if (isFirstInstance == false)
{ {
return; return;
@ -24,7 +28,7 @@ namespace FastGithub.UI
SetWebBrowserVersion(); SetWebBrowserVersion();
var app = new Application(); var app = new Application();
app.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative); app.StartupUri = new Uri(MAIN_WINDOWS, UriKind.Relative);
app.Run(); app.Run();
} }
@ -71,7 +75,7 @@ namespace FastGithub.UI
/// <returns></returns> /// <returns></returns>
private static void StartFastGithub() private static void StartFastGithub()
{ {
const string fileName = "fastgithub.exe"; const string fileName = FASTGITHUB_PATH;
if (File.Exists(fileName) == false) if (File.Exists(fileName) == false)
{ {
return; return;