diff --git a/desktop/App.xaml.cs b/desktop/App.xaml.cs index ecaacbe..68bbec1 100644 --- a/desktop/App.xaml.cs +++ b/desktop/App.xaml.cs @@ -71,6 +71,7 @@ public partial class App : Application var version = GetType().Assembly.GetName().Version?.ToString() ?? "1.0.0"; _tray = new TrayIconService(_server.BaseUrl, version); _tray.ShowRequested += ShowAppWindow; + _tray.RestartRequested += RestartApplication; _tray.ExitRequested += ExitApplication; UpdateTrayStatus(); @@ -280,7 +281,6 @@ public partial class App : Application _main = new MainWindow(server, _settings, session); _main.LogoutRequested += OnLogoutRequested; _main.HiddenToTray += OnHiddenToTray; - _main.ServiceStateChanged += UpdateTrayStatus; } ShowAppWindow(); @@ -317,6 +317,37 @@ public partial class App : Application $"本机服务在 {_server?.BaseUrl} 继续提供,双击托盘图标可重新打开窗口。"); } + /// + /// 托盘菜单「重启软件」:先让本进程退出(释放单实例互斥体与 17300 端口),2 秒后再拉起自己。 + /// 直接用 Process.Start 会撞上单实例检测(新进程把参数转发给正在退出的旧进程后就没了)。 + /// + private void RestartApplication() + { + if (_exiting) return; + + var exe = Environment.ProcessPath; + AppLog.Write($"重启软件:{exe}"); + + if (!string.IsNullOrEmpty(exe)) + { + try + { + Process.Start(new ProcessStartInfo("cmd.exe", $"/c timeout /t 2 /nobreak >nul & start \"\" \"{exe}\"") + { + CreateNoWindow = true, + UseShellExecute = false, + WindowStyle = ProcessWindowStyle.Hidden, + }); + } + catch (Exception ex) + { + AppLog.Write($"启动新进程失败:{ex.Message}"); + } + } + + ExitApplication(); + } + // ---------------- 本机服务 ---------------- private void StartLocalServer() diff --git a/desktop/MainWindow.xaml b/desktop/MainWindow.xaml index 7ff4c1a..c7d99a0 100644 --- a/desktop/MainWindow.xaml +++ b/desktop/MainWindow.xaml @@ -48,13 +48,9 @@ - - -