From 58e690e1dc5ebfe7668bf9a482e106c40b8860e8 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 25 May 2021 10:21:29 +0800 Subject: [PATCH] feature: auto restart application when general setting changed --- src/App.xaml.cs | 13 ++++++++++++- src/Views/Preference.xaml.cs | 24 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/App.xaml.cs b/src/App.xaml.cs index 94a8780b..dadd88be 100644 --- a/src/App.xaml.cs +++ b/src/App.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Net; using System.Reflection; @@ -13,6 +14,7 @@ namespace SourceGit { /// 程序入口. /// public partial class App : Application { + private static bool restart = false; /// /// 读取本地化字串 @@ -26,6 +28,15 @@ namespace SourceGit { return string.Format(data, args); } + /// + /// 重启程序 + /// + public static void Restart() { + restart = true; + Process.Start(Process.GetCurrentProcess().MainModule.FileName); + Current.Shutdown(); + } + /// /// 启动. /// @@ -109,7 +120,7 @@ namespace SourceGit { /// /// private void OnAppDeactivated(object sender, EventArgs e) { - Models.Preference.Save(); + if (!restart) Models.Preference.Save(); } } } diff --git a/src/Views/Preference.xaml.cs b/src/Views/Preference.xaml.cs index 6382da32..e975324b 100644 --- a/src/Views/Preference.xaml.cs +++ b/src/Views/Preference.xaml.cs @@ -15,6 +15,12 @@ namespace SourceGit.Views { public string CRLF { get; set; } public string MergeCmd { get; set; } + private string locale; + private string avatarServer; + private bool useDarkTheme; + private bool checkUpdate; + private bool autoFetch; + public Preference() { if (Models.Preference.Instance.IsReady) { User = new Commands.Config().Get("user.name"); @@ -30,6 +36,12 @@ namespace SourceGit.Views { var merger = Models.MergeTool.Supported.Find(x => x.Type == Models.Preference.Instance.MergeTool.Type); if (merger != null) MergeCmd = merger.Cmd; + locale = Models.Preference.Instance.General.Locale; + avatarServer = Models.Preference.Instance.General.AvatarServer; + useDarkTheme = Models.Preference.Instance.General.UseDarkTheme; + checkUpdate = Models.Preference.Instance.General.CheckForUpdate; + autoFetch = Models.Preference.Instance.General.AutoFetchRemotes; + InitializeComponent(); } @@ -102,7 +114,17 @@ namespace SourceGit.Views { } Models.Preference.Save(); - Close(); + + var general = Models.Preference.Instance.General; + if (locale != general.Locale || + avatarServer != general.AvatarServer || + useDarkTheme != general.UseDarkTheme || + checkUpdate != general.CheckForUpdate || + autoFetch != general.AutoFetchRemotes) { + App.Restart(); + } else { + Close(); + } } #endregion }