From 81c19db03ebad7a809fb4a11e5fa5cc361651b74 Mon Sep 17 00:00:00 2001 From: ywmoyue Date: Sun, 21 Jul 2024 17:19:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=95=E8=8E=B7=E5=AF=BC=E5=87=BA=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Settings/DevSettingsControl.xaml.cs | 78 +++++++++++++------ 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/src/BiliLite.UWP/Controls/Settings/DevSettingsControl.xaml.cs b/src/BiliLite.UWP/Controls/Settings/DevSettingsControl.xaml.cs index 0fe6adb9..7e39cb02 100644 --- a/src/BiliLite.UWP/Controls/Settings/DevSettingsControl.xaml.cs +++ b/src/BiliLite.UWP/Controls/Settings/DevSettingsControl.xaml.cs @@ -14,6 +14,8 @@ namespace BiliLite.Controls.Settings { public sealed partial class DevSettingsControl : UserControl { + private static readonly ILogger _logger = GlobalLogger.FromCurrentType(); + public DevSettingsControl() { this.InitializeComponent(); @@ -51,17 +53,20 @@ private void LoadDev() }; // 优先使用Grpc请求动态 - swFirstGrpcRequestDynamic.IsOn = SettingService.GetValue(SettingConstants.Other.FIRST_GRPC_REQUEST_DYNAMIC, true); + swFirstGrpcRequestDynamic.IsOn = + SettingService.GetValue(SettingConstants.Other.FIRST_GRPC_REQUEST_DYNAMIC, true); swFirstGrpcRequestDynamic.Toggled += ((e, args) => { - SettingService.SetValue(SettingConstants.Other.FIRST_GRPC_REQUEST_DYNAMIC, swFirstGrpcRequestDynamic.IsOn); + SettingService.SetValue(SettingConstants.Other.FIRST_GRPC_REQUEST_DYNAMIC, + swFirstGrpcRequestDynamic.IsOn); }); RequestBuildTextBox.Text = SettingService.GetValue(SettingConstants.Other.REQUEST_BUILD, SettingConstants.Other.DEFAULT_REQUEST_BUILD); // BiliLiteWebApi - BiliLiteWebApiTextBox.Text = SettingService.GetValue(SettingConstants.Other.BILI_LITE_WEB_API_BASE_URL, ApiConstants.BILI_LITE_WEB_API_DEFAULT_BASE_URL); + BiliLiteWebApiTextBox.Text = SettingService.GetValue(SettingConstants.Other.BILI_LITE_WEB_API_BASE_URL, + ApiConstants.BILI_LITE_WEB_API_DEFAULT_BASE_URL); BiliLiteWebApiTextBox.Loaded += (sender, e) => { BiliLiteWebApiTextBox.QuerySubmitted += (sender2, args) => @@ -73,12 +78,14 @@ private void LoadDev() SettingService.SetValue(SettingConstants.Other.BILI_LITE_WEB_API_BASE_URL, ""); return; } + if (!text.EndsWith("/")) text += "/"; if (!Uri.IsWellFormedUriString(text, UriKind.Absolute)) { Notify.ShowMessageToast("地址格式错误"); return; } + SettingService.SetValue(SettingConstants.Other.BILI_LITE_WEB_API_BASE_URL, text); sender2.Text = text; Notify.ShowMessageToast("保存成功"); @@ -86,7 +93,8 @@ private void LoadDev() }; // 更新json来源 - var selectedValue = SettingService.GetValue(SettingConstants.Other.UPDATE_JSON_ADDRESS, UpdateJsonAddressOptions.DEFAULT_UPDATE_JSON_ADDRESS); + var selectedValue = SettingService.GetValue(SettingConstants.Other.UPDATE_JSON_ADDRESS, + UpdateJsonAddressOptions.DEFAULT_UPDATE_JSON_ADDRESS); selectedValue = selectedValue.Replace("\"", ""); // 解决取出的值有奇怪的转义符 updateJsonAddress.SelectedItem = UpdateJsonAddressOptions.GetOption(selectedValue); mirrorComboboxSelectAction(selectedValue); @@ -94,7 +102,8 @@ private void LoadDev() { updateJsonAddress.SelectionChanged += (obj, args) => { - SettingService.SetValue(SettingConstants.Other.UPDATE_JSON_ADDRESS, updateJsonAddress.SelectedValue); + SettingService.SetValue(SettingConstants.Other.UPDATE_JSON_ADDRESS, + updateJsonAddress.SelectedValue); mirrorComboboxSelectAction(updateJsonAddress.SelectedValue); }; }; @@ -126,32 +135,42 @@ private void mirrorComboboxSelectAction(object selectedValue) switch (selectedValue) { case ApiHelper.GHPROXY_GIT_RAW_URL: - { - mirrorDonateText.Visibility = Visibility.Visible; - mirrorDonateUrl.NavigateUri = new Uri("https://mirror.ghproxy.com/donate"); - break; - } + { + mirrorDonateText.Visibility = Visibility.Visible; + mirrorDonateUrl.NavigateUri = new Uri("https://mirror.ghproxy.com/donate"); + break; + } case ApiHelper.KGITHUB_GIT_RAW_URL: - { - mirrorDonateText.Visibility = Visibility.Visible; - mirrorDonateUrl.NavigateUri = new Uri("https://help.kkgithub.com/donate"); - break; - } + { + mirrorDonateText.Visibility = Visibility.Visible; + mirrorDonateUrl.NavigateUri = new Uri("https://help.kkgithub.com/donate"); + break; + } case ApiHelper.GIT_RAW_URL: - { - mirrorDonateText.Visibility = Visibility.Collapsed; break; - } + { + mirrorDonateText.Visibility = Visibility.Collapsed; + break; + } default: - { - mirrorDonateText.Visibility = Visibility.Collapsed; break; - } + { + mirrorDonateText.Visibility = Visibility.Collapsed; + break; + } } } private async void BtnExportSettings_OnClick(object sender, RoutedEventArgs e) { - var exportService = App.ServiceProvider.GetRequiredService(); - await exportService.ExportSettings(); + try + { + var exportService = App.ServiceProvider.GetRequiredService(); + await exportService.ExportSettings(); + } + catch (Exception ex) + { + _logger.Error("导出失败", ex); + Notify.ShowMessageToast("导出失败,已记录错误"); + } } private async void BtnImportSettings_OnClick(object sender, RoutedEventArgs e) @@ -161,6 +180,7 @@ private async void BtnImportSettings_OnClick(object sender, RoutedEventArgs e) { return; } + Notify.ShowMessageToast("导入成功,正在重启应用"); // 等用户看提示 await Task.Delay(3000); @@ -174,8 +194,16 @@ private async void BtnImportSettings_OnClick(object sender, RoutedEventArgs e) private async void BtnExportSettingsWithAccount_OnClick(object sender, RoutedEventArgs e) { - var exportService = App.ServiceProvider.GetRequiredService(); - await exportService.ExportSettingsWithAccount(); + try + { + var exportService = App.ServiceProvider.GetRequiredService(); + await exportService.ExportSettingsWithAccount(); + } + catch (Exception ex) + { + _logger.Error("导出失败", ex); + Notify.ShowMessageToast("导出失败,已记录错误"); + } } private async void BtnOpenLogFolder_OnClick(object sender, RoutedEventArgs e)