mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
feature<Preference>: auto restart application when general setting changed
This commit is contained in:
parent
e3a5b0b62a
commit
58e690e1dc
2 changed files with 35 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
|
@ -13,6 +14,7 @@ namespace SourceGit {
|
|||
/// 程序入口.
|
||||
/// </summary>
|
||||
public partial class App : Application {
|
||||
private static bool restart = false;
|
||||
|
||||
/// <summary>
|
||||
/// 读取本地化字串
|
||||
|
@ -26,6 +28,15 @@ namespace SourceGit {
|
|||
return string.Format(data, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重启程序
|
||||
/// </summary>
|
||||
public static void Restart() {
|
||||
restart = true;
|
||||
Process.Start(Process.GetCurrentProcess().MainModule.FileName);
|
||||
Current.Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动.
|
||||
/// </summary>
|
||||
|
@ -109,7 +120,7 @@ namespace SourceGit {
|
|||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnAppDeactivated(object sender, EventArgs e) {
|
||||
Models.Preference.Save();
|
||||
if (!restart) Models.Preference.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue