diff --git a/YMCL.Main/Public/Classes/Setting.cs b/YMCL.Main/Public/Classes/Setting.cs index 0598e0c..bf8f50c 100644 --- a/YMCL.Main/Public/Classes/Setting.cs +++ b/YMCL.Main/Public/Classes/Setting.cs @@ -8,6 +8,8 @@ public class Setting { public string Language { get; set; } = "Unset"; public string MinecraftFolder { get; set; } + public string SkipUpdateVersion { get; set; } = string.Empty; + public bool EnableAutoCheckUpdate { get; set; } = true; public double MaximumDownloadThread { get; set; } = 64; public bool IsCompleteJavaInitialize { get; set; } public bool IsCompleteMinecraftFolderInitialize { get; set; } diff --git a/YMCL.Main/Public/Const.cs b/YMCL.Main/Public/Const.cs index e8b544c..6e66a74 100644 --- a/YMCL.Main/Public/Const.cs +++ b/YMCL.Main/Public/Const.cs @@ -44,6 +44,7 @@ public abstract class String public static string PluginDataPath { get; } = Path.Combine(UserDataRootPath, "YMCL.Plugin.DaiYu"); public static string PluginFolderPath { get; } = Path.Combine(UserDataRootPath, "Plugin"); public static string TempFolderPath { get; } = Path.Combine(UserDataRootPath, "Temp"); + public static string UpdateFolderPath { get; } = Path.Combine(UserDataRootPath, "Update"); public static string VersionSettingFileName { get; } = "YMCLSetting.DaiYu"; public static string GithubUpdateApiUrl { get; } = diff --git a/YMCL.Main/Public/Langs/MainLang.Designer.cs b/YMCL.Main/Public/Langs/MainLang.Designer.cs index 9fb8832..6db4ff6 100644 --- a/YMCL.Main/Public/Langs/MainLang.Designer.cs +++ b/YMCL.Main/Public/Langs/MainLang.Designer.cs @@ -302,6 +302,15 @@ public static string AutoScan { } } + /// + /// Looks up a localized string similar to 自动更新. + /// + public static string AutoUpdate { + get { + return ResourceManager.GetString("AutoUpdate", resourceCulture); + } + } + /// /// Looks up a localized string similar to 基岩版. /// @@ -2042,6 +2051,15 @@ public static string SkinModel { } } + /// + /// Looks up a localized string similar to 跳过此版本. + /// + public static string SkipThisVersion { + get { + return ResourceManager.GetString("SkipThisVersion", resourceCulture); + } + } + /// /// Looks up a localized string similar to 添加成功. /// diff --git a/YMCL.Main/Public/Langs/MainLang.resx b/YMCL.Main/Public/Langs/MainLang.resx index 467126e..3a1bbd3 100644 --- a/YMCL.Main/Public/Langs/MainLang.resx +++ b/YMCL.Main/Public/Langs/MainLang.resx @@ -905,4 +905,10 @@ sudo apt install vlc 桌面歌词大小 + + 自动更新 + + + 跳过此版本 + \ No newline at end of file diff --git a/YMCL.Main/Public/Method.cs b/YMCL.Main/Public/Method.cs index 2cc2f24..a9cf918 100644 --- a/YMCL.Main/Public/Method.cs +++ b/YMCL.Main/Public/Method.cs @@ -285,7 +285,7 @@ public static void RestartApp() Environment.Exit(0); } - public static async Task<(bool, string)> CheckUpdateAsync() + public static async Task<(bool, string, string)> CheckUpdateAsync() { try { @@ -303,12 +303,12 @@ public static void RestartApp() httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36 Edg/91.0.864.54"); var githubApiJson = JArray.Parse(await httpClient.GetStringAsync(Const.String.GithubUpdateApiUrl)); - var apiVersion = (string)githubApiJson[0]["name"]; - return (apiVersion != version, $"{apiVersion!}\n\n{(string)githubApiJson[0]["html_url"]}"); + var apiVersion = (string)githubApiJson[0]["name"]!; + return (apiVersion != version, apiVersion, $"{apiVersion!}\n\n{(string)githubApiJson[0]["html_url"]}"); } catch { - return (false, string.Empty); + return (false, string.Empty, string.Empty); } } diff --git a/YMCL.Main/Public/Styles/DarkTheme.axaml b/YMCL.Main/Public/Styles/DarkTheme.axaml index 16b555b..c97ee32 100644 --- a/YMCL.Main/Public/Styles/DarkTheme.axaml +++ b/YMCL.Main/Public/Styles/DarkTheme.axaml @@ -1,7 +1,8 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/YMCL.Main/Public/Styles/LightTheme.axaml b/YMCL.Main/Public/Styles/LightTheme.axaml index 491e2ae..3a19979 100644 --- a/YMCL.Main/Public/Styles/LightTheme.axaml +++ b/YMCL.Main/Public/Styles/LightTheme.axaml @@ -1,7 +1,8 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/YMCL.Main/Views/Initialize/InitializeWindow.axaml.cs b/YMCL.Main/Views/Initialize/InitializeWindow.axaml.cs index edba48c..231af9b 100644 --- a/YMCL.Main/Views/Initialize/InitializeWindow.axaml.cs +++ b/YMCL.Main/Views/Initialize/InitializeWindow.axaml.cs @@ -56,6 +56,7 @@ private void Init() Method.IO.TryCreateFolder(Const.String.UserDataRootPath); Method.IO.TryCreateFolder(Const.String.PluginFolderPath); Method.IO.TryCreateFolder(Const.String.TempFolderPath); + Method.IO.TryCreateFolder(Const.String.UpdateFolderPath); if (!File.Exists(Const.String.SettingDataPath)) File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(new Setting(), Formatting.Indented)); if (!File.Exists(Const.String.MinecraftFolderDataPath) || JsonConvert diff --git a/YMCL.Main/Views/Main/MainWindow.axaml.cs b/YMCL.Main/Views/Main/MainWindow.axaml.cs index 24f0117..1f50eb7 100644 --- a/YMCL.Main/Views/Main/MainWindow.axaml.cs +++ b/YMCL.Main/Views/Main/MainWindow.axaml.cs @@ -111,9 +111,13 @@ private void EventBinding() else if (Const.Data.Platform == Platform.Linux) { setting.IsAlreadyWrittenIntoTheUrlScheme = true; - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); } } + + await Task.Delay(200); + _ = Const.Window.main.settingPage.launcherSettingPage.AutoUpdate(); }; Activated += (_, _) => { @@ -188,7 +192,7 @@ private void EventBinding() public void LoadWindow() { Method.IO.ClearFolder(Const.String.TempFolderPath); - + SystemDecorations = SystemDecorations.Full; var setting = Const.Data.Setting; @@ -221,7 +225,8 @@ public void LoadWindow() if (setting.CustomHomePage == CustomHomePageWay.Local) try { - var c = (Control)AvaloniaRuntimeXamlLoader.Load(File.ReadAllText(Const.String.CustomHomePageXamlDataPath)); + var c = (Control)AvaloniaRuntimeXamlLoader.Load( + File.ReadAllText(Const.String.CustomHomePageXamlDataPath)); launchPage.CustomPageRoot.Child = c; } catch (Exception ex) diff --git a/YMCL.Main/Views/Main/Pages/Launch/LaunchPage.axaml.cs b/YMCL.Main/Views/Main/Pages/Launch/LaunchPage.axaml.cs index 4d54505..9dbe55f 100644 --- a/YMCL.Main/Views/Main/Pages/Launch/LaunchPage.axaml.cs +++ b/YMCL.Main/Views/Main/Pages/Launch/LaunchPage.axaml.cs @@ -31,6 +31,7 @@ public partial class LaunchPage : UserControl private bool _firstOpenVersionList = true; private bool _firstOpenVersionSetting = true; private bool _shouldCloseVersuionList; + private bool _isSelectioningVersionFolder = false; private List minecraftFolders = JsonConvert.DeserializeObject>(File.ReadAllText(Const.String.MinecraftFolderDataPath)); @@ -80,7 +81,8 @@ private void BindingEvent() } else { - LaunchConsoleRoot.Opacity = (double)Application.Current.Resources["Opacity"]!;; + LaunchConsoleRoot.Opacity = (double)Application.Current.Resources["Opacity"]!; + ; LaunchConsoleRoot.IsVisible = true; } }; @@ -103,6 +105,7 @@ private void BindingEvent() MinecraftFolderComboBox.SelectedItem.ToString() == setting.MinecraftFolder) return; setting.MinecraftFolder = MinecraftFolderComboBox.SelectedItem.ToString(); File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + _isSelectioningVersionFolder = true; _shouldCloseVersuionList = false; LoadVersions(); VersionListView.SelectedIndex = 0; @@ -165,7 +168,16 @@ private void BindingEvent() } }; CloseVersionListBtn.Click += (s, e) => { CloseVersionList(); }; - VersionListView.PointerEntered += (s, e) => { _shouldCloseVersuionList = true; }; + VersionListView.PointerEntered += async (s, e) => + { + if (_isSelectioningVersionFolder) + { + await Task.Delay(200); + _isSelectioningVersionFolder = false; + } + + _shouldCloseVersuionList = true; + }; VersionListView.SelectionChanged += async (s, e) => { if (VersionListView.SelectedItem != null) @@ -176,7 +188,8 @@ private void BindingEvent() setting.Version = "BedRock"; else setting.Version = (VersionListView.SelectedItem as GameEntry).Id; - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); } await Task.Delay(100); @@ -399,7 +412,8 @@ private void LoadAccounts() { AccountComboBox.SelectedItem = AccountComboBox.Items[0]; setting.AccountSelectionIndex = 0; - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); } } else diff --git a/YMCL.Main/Views/Main/Pages/Setting/Pages/Download/DownloadSettingPage.axaml b/YMCL.Main/Views/Main/Pages/Setting/Pages/Download/DownloadSettingPage.axaml index ed527de..1969081 100644 --- a/YMCL.Main/Views/Main/Pages/Setting/Pages/Download/DownloadSettingPage.axaml +++ b/YMCL.Main/Views/Main/Pages/Setting/Pages/Download/DownloadSettingPage.axaml @@ -114,7 +114,7 @@ + + + + + + diff --git a/YMCL.Main/Views/Main/Pages/Setting/Pages/Download/DownloadSettingPage.axaml.cs b/YMCL.Main/Views/Main/Pages/Setting/Pages/Download/DownloadSettingPage.axaml.cs index 5faeb60..038683b 100644 --- a/YMCL.Main/Views/Main/Pages/Setting/Pages/Download/DownloadSettingPage.axaml.cs +++ b/YMCL.Main/Views/Main/Pages/Setting/Pages/Download/DownloadSettingPage.axaml.cs @@ -45,13 +45,28 @@ private void BindingEvent() File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); Const.String.MusicApiUrl = MusicApiTextBox.Text; }; + AutoUpdateSwitch.Click += (s, e) => + { + var setting = Const.Data.Setting; + if (AutoUpdateSwitch.IsChecked != setting.ShowGameOutput) + { + setting.EnableAutoCheckUpdate = (bool)AutoUpdateSwitch.IsChecked!; + File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + } + }; SizeChanged += (_, _) => { - if (CustomUpdateUrlTextBox.IsVisible) - CustomUpdateUrlEnableComboBox.Width = 150; - else - CustomUpdateUrlEnableComboBox.Width = CustomUpdateUrlRoot.Bounds.Width - 2 * 6.5 - - CustomUpdateUrlLabel.Bounds.Width - 30; + try + { + if (CustomUpdateUrlTextBox.IsVisible) + CustomUpdateUrlEnableComboBox.Width = 150; + else + CustomUpdateUrlEnableComboBox.Width = CustomUpdateUrlRoot.Bounds.Width - 2 * 6.5 - + CustomUpdateUrlLabel.Bounds.Width - 30; + } + catch + { + } }; DownloadSourceComboBox.SelectionChanged += (s, e) => { @@ -101,6 +116,7 @@ private void ControlProperty() MaximumDownloadThreadSlider.Value = setting.MaximumDownloadThread; DownloadThreadWarning.IsVisible = MaximumDownloadThreadSlider.Value > 100; CustomUpdateUrlEnableComboBox.SelectedIndex = setting.EnableCustomUpdateUrl ? 1 : 0; + AutoUpdateSwitch.IsChecked = setting.EnableAutoCheckUpdate; CustomUpdateUrlTextBox.Text = setting.CustomUpdateUrl; Const.String.MusicApiUrl = setting.MusicApi; MusicApiTextBox.Text = setting.MusicApi; diff --git a/YMCL.Main/Views/Main/Pages/Setting/Pages/Launcher/LauncherSettingPage.axaml.cs b/YMCL.Main/Views/Main/Pages/Setting/Pages/Launcher/LauncherSettingPage.axaml.cs index 111c7cc..dec6534 100644 --- a/YMCL.Main/Views/Main/Pages/Setting/Pages/Launcher/LauncherSettingPage.axaml.cs +++ b/YMCL.Main/Views/Main/Pages/Setting/Pages/Launcher/LauncherSettingPage.axaml.cs @@ -1,21 +1,13 @@ using System; -using System.Diagnostics; using System.IO; -using System.Net; -using System.Net.Http; using System.Reflection; using System.Threading.Tasks; using Avalonia.Controls; -using Avalonia.Layout; -using Avalonia.Media; using Avalonia.Platform.Storage; using FluentAvalonia.UI.Controls; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using YMCL.Main.Public; -using YMCL.Main.Public.Controls.WindowTask; using YMCL.Main.Public.Langs; -using Application = Avalonia.Application; namespace YMCL.Main.Views.Main.Pages.Setting.Pages.Launcher; @@ -28,6 +20,28 @@ public LauncherSettingPage() BindingEvent(); } + public async Task AutoUpdate() + { + if (!Const.Data.Setting.EnableAutoCheckUpdate) return; + var updateAvailable = await Method.Ui.CheckUpdateAsync(); + if (!updateAvailable.Item1) return; + if (Const.Data.Setting.SkipUpdateVersion == updateAvailable.Item2) return; + var dialog = await Method.Ui.ShowDialogAsync(MainLang.FoundNewVersion, updateAvailable.Item3 + , b_cancel: MainLang.Cancel, b_secondary: MainLang.SkipThisVersion, + b_primary: MainLang.Ok); + if (dialog == ContentDialogResult.Primary) + { + var updateAppAsync = await Method.Ui.UpdateAppAsync(); + if (!updateAppAsync) Method.Ui.Toast(MainLang.UpdateFail); + } + else if (dialog == ContentDialogResult.Secondary) + { + Const.Data.Setting.SkipUpdateVersion = updateAvailable.Item2; + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(Const.Data.Setting, Formatting.Indented)); + } + } + private void BindingEvent() { Loaded += (s, e) => @@ -47,7 +61,7 @@ private void BindingEvent() CheckUpdateBtn.Content = ring; ring.Height = 17; ring.Width = 17; - var (checkUpdateAsyncStatus, checkUpdateAsyncMsg) = await Method.Ui.CheckUpdateAsync(); + var (checkUpdateAsyncStatus, _, checkUpdateAsyncMsg) = await Method.Ui.CheckUpdateAsync(); CheckUpdateBtn.IsEnabled = true; CheckUpdateBtn.Content = MainLang.CheckUpdate; if (!checkUpdateAsyncStatus) @@ -62,10 +76,7 @@ private void BindingEvent() if (dialog == ContentDialogResult.Primary) { var updateAppAsync = await Method.Ui.UpdateAppAsync(); - if (!updateAppAsync) - { - Method.Ui.Toast(MainLang.UpdateFail); - } + if (!updateAppAsync) Method.Ui.Toast(MainLang.UpdateFail); } }; } diff --git a/YMCL.Main/Views/Main/Pages/Setting/Pages/Personalize/PersonalizeSettingPage.axaml.cs b/YMCL.Main/Views/Main/Pages/Setting/Pages/Personalize/PersonalizeSettingPage.axaml.cs index aa7fb8d..629ebec 100644 --- a/YMCL.Main/Views/Main/Pages/Setting/Pages/Personalize/PersonalizeSettingPage.axaml.cs +++ b/YMCL.Main/Views/Main/Pages/Setting/Pages/Personalize/PersonalizeSettingPage.axaml.cs @@ -46,8 +46,14 @@ private void BindingEvent() }; SizeChanged += (s, e) => { - ColorPicker.Width = ColorPickerRoot.Bounds.Width - 2 * 6.5 - ColorPickerLabel.Bounds.Width - 30; - LyricColorPicker.Width = LyricRoot.Bounds.Width - 2 * 6.5 - LyricColorPickerLabel.Bounds.Width - 30; + try + { + ColorPicker.Width = ColorPickerRoot.Bounds.Width - 2 * 6.5 - ColorPickerLabel.Bounds.Width - 30; + LyricColorPicker.Width = LyricRoot.Bounds.Width - 2 * 6.5 - LyricColorPickerLabel.Bounds.Width - 30; + } + catch + { + } }; CustomHomePageComboBox.SelectionChanged += (s, e) => { @@ -56,7 +62,8 @@ private void BindingEvent() if (CustomHomePageComboBox.SelectedIndex != (int)setting.CustomHomePage) { setting.CustomHomePage = (CustomHomePageWay)CustomHomePageComboBox.SelectedIndex; - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); Method.Ui.RestartApp(); } }; @@ -84,7 +91,8 @@ private void BindingEvent() if (setting.AccentColor != color) { setting.AccentColor = color; - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); } Method.Ui.SetAccentColor(color); @@ -96,7 +104,8 @@ private void BindingEvent() if (setting.DeskLyricColor != color) { setting.DeskLyricColor = color; - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); } Const.Window.deskLyric.LyricText.Foreground = new SolidColorBrush(color); @@ -114,7 +123,8 @@ private void BindingEvent() if (setting.DeskLyricSize != Math.Round(LyricSizeSlider.Value)) { setting.DeskLyricSize = Math.Round(LyricSizeSlider.Value); - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); } Const.Window.deskLyric.LyricText.Transitions = null; @@ -218,7 +228,8 @@ private void BindingEvent() if (LanguageComboBox.SelectedItem.ToString().Split(' ')[0] != setting.Language) { setting.Language = LanguageComboBox.SelectedItem.ToString().Split(' ')[0]; - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); Method.Ui.RestartApp(); } }; @@ -228,7 +239,8 @@ private void BindingEvent() if (ThemeComboBox.SelectedIndex != (int)setting.Theme) { setting.Theme = (Theme)ThemeComboBox.SelectedIndex; - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); } Method.Ui.RestartApp(); @@ -239,7 +251,8 @@ private void BindingEvent() if (LauncherVisibilityComboBox.SelectedIndex != (int)setting.LauncherVisibility) { setting.LauncherVisibility = (LauncherVisibility)LauncherVisibilityComboBox.SelectedIndex; - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); } }; EditCustomBackGroundImgBtn.Click += async (_, _) => @@ -254,7 +267,8 @@ private void BindingEvent() var setting = Const.Data.Setting; setting.WindowBackGroundImgData = base64; - File.WriteAllText(Const.String.SettingDataPath, JsonConvert.SerializeObject(setting, Formatting.Indented)); + File.WriteAllText(Const.String.SettingDataPath, + JsonConvert.SerializeObject(setting, Formatting.Indented)); } Method.Ui.SetWindowBackGroundImg(); diff --git a/YMCL.Main/Views/Main/Pages/Setting/SettingPage.axaml b/YMCL.Main/Views/Main/Pages/Setting/SettingPage.axaml index c098b3d..ffa4e75 100644 --- a/YMCL.Main/Views/Main/Pages/Setting/SettingPage.axaml +++ b/YMCL.Main/Views/Main/Pages/Setting/SettingPage.axaml @@ -18,199 +18,206 @@ - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + CornerRadius="5" + DockPanel.Dock="Top" + Opacity="{DynamicResource Opacity}"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +