Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

右下角图标菜单增加重启功能 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zhupengfeivip wants to merge 1 commit into creazyboyone:master
base: master
Choose a base branch
Loading
from zhupengfeivip:master
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion FastGithub.UI/MainWindow.xaml.cs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;

Expand All @@ -25,13 +26,16 @@ public MainWindow()
var exit = new System.Windows.Forms.MenuItem("关闭应用(&C)");
exit.Click += (s, e) => this.Close();

var restart = new System.Windows.Forms.MenuItem("重启应用(&R)");
restart.Click += (s, e) => RestartApplication();

var version = this.GetType().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
this.Title = $"{FASTGITHUB_UI} v{version}";
this.notifyIcon = new System.Windows.Forms.NotifyIcon
{
Visible = true,
Text = FASTGITHUB_UI,
ContextMenu = new System.Windows.Forms.ContextMenu(new[] { upgrade, exit }),
ContextMenu = new System.Windows.Forms.ContextMenu(new[] { restart, upgrade, exit }),
Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath)
};

Expand All @@ -46,6 +50,35 @@ public MainWindow()
};
}

/// <summary>
/// 管理员权限程序 安全重启
/// </summary>
private void RestartApplication()
{
try
{
// 获取当前程序路径
string exePath = Process.GetCurrentProcess().MainModule.FileName;

// 重点:用 cmd /c start 异步启动,不等待,不阻塞
Process.Start(new ProcessStartInfo()
{
FileName = "cmd.exe",
Arguments = $"/c start \"\" \"{exePath}\"",
Verb = "runas", // 管理员权限
UseShellExecute = true,
CreateNoWindow = true // 不显示黑窗口
});

// 立刻关闭当前程序
Application.Current.Shutdown();
}
catch
{
// 用户取消UAC时,不报错
}
}


/// <summary>
/// 拦截最小化事件
Expand Down

AltStyle によって変換されたページ (->オリジナル) /