mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -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;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -13,6 +14,7 @@ namespace SourceGit {
|
||||||
/// 程序入口.
|
/// 程序入口.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App : Application {
|
public partial class App : Application {
|
||||||
|
private static bool restart = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 读取本地化字串
|
/// 读取本地化字串
|
||||||
|
@ -26,6 +28,15 @@ namespace SourceGit {
|
||||||
return string.Format(data, args);
|
return string.Format(data, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重启程序
|
||||||
|
/// </summary>
|
||||||
|
public static void Restart() {
|
||||||
|
restart = true;
|
||||||
|
Process.Start(Process.GetCurrentProcess().MainModule.FileName);
|
||||||
|
Current.Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 启动.
|
/// 启动.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -109,7 +120,7 @@ namespace SourceGit {
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void OnAppDeactivated(object sender, EventArgs e) {
|
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 CRLF { get; set; }
|
||||||
public string MergeCmd { get; set; }
|
public string MergeCmd { get; set; }
|
||||||
|
|
||||||
|
private string locale;
|
||||||
|
private string avatarServer;
|
||||||
|
private bool useDarkTheme;
|
||||||
|
private bool checkUpdate;
|
||||||
|
private bool autoFetch;
|
||||||
|
|
||||||
public Preference() {
|
public Preference() {
|
||||||
if (Models.Preference.Instance.IsReady) {
|
if (Models.Preference.Instance.IsReady) {
|
||||||
User = new Commands.Config().Get("user.name");
|
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);
|
var merger = Models.MergeTool.Supported.Find(x => x.Type == Models.Preference.Instance.MergeTool.Type);
|
||||||
if (merger != null) MergeCmd = merger.Cmd;
|
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();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +114,17 @@ namespace SourceGit.Views {
|
||||||
}
|
}
|
||||||
|
|
||||||
Models.Preference.Save();
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue