mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 12:45:00 +00:00
refactor<*>: use DynamicResource instead of StaticResource for brushes and locales
This commit is contained in:
parent
4a56b47265
commit
afc4eafb6f
73 changed files with 630 additions and 601 deletions
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SourceGit.Models {
|
||||
|
@ -18,5 +19,15 @@ namespace SourceGit.Models {
|
|||
Name = name;
|
||||
Resource = res;
|
||||
}
|
||||
|
||||
public static void Change() {
|
||||
var lang = Preference.Instance.General.Locale;
|
||||
foreach (var rs in App.Current.Resources.MergedDictionaries) {
|
||||
if (rs.Source != null && rs.Source.OriginalString.StartsWith("pack://application:,,,/Resources/Locales/", StringComparison.Ordinal)) {
|
||||
rs.Source = new Uri($"pack://application:,,,/Resources/Locales/{lang}.xaml", UriKind.Absolute);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
38
src/Models/Theme.cs
Normal file
38
src/Models/Theme.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace SourceGit.Models {
|
||||
/// <summary>
|
||||
/// 主题
|
||||
/// </summary>
|
||||
public static class Theme {
|
||||
/// <summary>
|
||||
/// 主题切换事件
|
||||
/// </summary>
|
||||
public static event Action Changed;
|
||||
|
||||
/// <summary>
|
||||
/// 启用主题变化监听
|
||||
/// </summary>
|
||||
/// <param name="elem"></param>
|
||||
public static void AddListener(FrameworkElement elem, Action callback) {
|
||||
elem.Loaded += (_, __) => Changed += callback;
|
||||
elem.Unloaded += (_, __) => Changed -= callback;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换主题
|
||||
/// </summary>
|
||||
public static void Change() {
|
||||
var theme = Preference.Instance.General.UseDarkTheme ? "Dark" : "Light";
|
||||
foreach (var rs in App.Current.Resources.MergedDictionaries) {
|
||||
if (rs.Source != null && rs.Source.OriginalString.StartsWith("pack://application:,,,/Resources/Themes/", StringComparison.Ordinal)) {
|
||||
rs.Source = new Uri($"pack://application:,,,/Resources/Themes/{theme}.xaml", UriKind.Absolute);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Changed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,9 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#if NET48
|
||||
using Newtonsoft.Json;
|
||||
|
@ -52,12 +57,36 @@ namespace SourceGit.Models {
|
|||
get { return PreRelease ? "YES" : "NO"; }
|
||||
}
|
||||
|
||||
public static Version Load(string data) {
|
||||
public static void Check(Action<Version> onUpgradable) {
|
||||
if (!Preference.Instance.General.CheckForUpdate) return;
|
||||
|
||||
var curDayOfYear = DateTime.Now.DayOfYear;
|
||||
var lastDayOfYear = Preference.Instance.General.LastCheckDay;
|
||||
if (lastDayOfYear != curDayOfYear) {
|
||||
Preference.Instance.General.LastCheckDay = curDayOfYear;
|
||||
Task.Run(() => {
|
||||
try {
|
||||
var web = new WebClient() { Encoding = Encoding.UTF8 };
|
||||
var raw = web.DownloadString("https://gitee.com/api/v5/repos/sourcegit/sourcegit/releases/latest");
|
||||
#if NET48
|
||||
return JsonConvert.DeserializeObject<Version>(data);
|
||||
var ver = JsonConvert.DeserializeObject<Version>(raw);
|
||||
#else
|
||||
return JsonSerializer.Deserialize<Version>(data);
|
||||
var ver = JsonSerializer.Deserialize<Version>(raw);
|
||||
#endif
|
||||
var cur = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
|
||||
var matches = Regex.Match(ver.TagName, @"^v(\d+)\.(\d+).*");
|
||||
if (!matches.Success) return;
|
||||
|
||||
var major = int.Parse(matches.Groups[1].Value);
|
||||
var minor = int.Parse(matches.Groups[2].Value);
|
||||
if (major > cur.Major || (major == cur.Major && minor > cur.Minor)) {
|
||||
onUpgradable?.Invoke(ver);
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue