From 9e6f8dee1b9035b2e9bea95fc5e95e1c9e09d0ad Mon Sep 17 00:00:00 2001 From: leiurayer <1432593898@qq.com> Date: Wed, 7 Aug 2024 15:56:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96SettingsManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Downkyi.Core/Bili/Web/Login.cs | 6 +- src/Downkyi.Core/Bili/Web/LoginHelper.cs | 2 +- src/Downkyi.Core/Settings/SettingsManager.cs | 34 ++++++-- src/Downkyi.UI/Services/MainSearchService.cs | 2 +- src/Downkyi.UI/ViewModels/IndexViewModel.cs | 6 +- .../ViewModels/Login/CookiesViewModel.cs | 1 - .../ViewModels/Settings/AboutViewModel.cs | 8 +- .../ViewModels/Settings/BasicViewModel.cs | 20 ++--- .../ViewModels/Settings/DanmakuViewModel.cs | 54 ++++++------ .../ViewModels/Settings/NetworkViewModel.cs | 82 +++++++++---------- .../ViewModels/Settings/VideoViewModel.cs | 44 +++++----- .../ViewModels/Video/VideoDetailViewModel.cs | 4 +- src/Downkyi/ViewModels/MainWindowViewModel.cs | 2 +- 13 files changed, 138 insertions(+), 127 deletions(-) diff --git a/src/Downkyi.Core/Bili/Web/Login.cs b/src/Downkyi.Core/Bili/Web/Login.cs index 682302b..360cbaf 100644 --- a/src/Downkyi.Core/Bili/Web/Login.cs +++ b/src/Downkyi.Core/Bili/Web/Login.cs @@ -13,7 +13,7 @@ internal class Login : ILogin /// (url, key) public Tuple? GetQRCodeUrl() { - string userAgent = SettingsManager.GetInstance().GetUserAgent(); + string userAgent = SettingsManager.Instance.GetUserAgent(); BiliManager.Instance().SetUserAgent(userAgent); var qrcode = LoginQR.GenerateQRCode(); @@ -28,7 +28,7 @@ internal class Login : ILogin /// public QRCodeStatus? PollQRCode(string qrcodeKey) { - string userAgent = SettingsManager.GetInstance().GetUserAgent(); + string userAgent = SettingsManager.Instance.GetUserAgent(); BiliManager.Instance().SetUserAgent(userAgent); var qrcode = LoginQR.PollQRCode(qrcodeKey); @@ -50,7 +50,7 @@ internal class Login : ILogin /// public NavigationInfo? GetNavigationInfo() { - string userAgent = SettingsManager.GetInstance().GetUserAgent(); + string userAgent = SettingsManager.Instance.GetUserAgent(); BiliManager.Instance().SetUserAgent(userAgent); BiliManager.Instance().SetCookies(LoginHelper.GetLoginInfoCookies()); diff --git a/src/Downkyi.Core/Bili/Web/LoginHelper.cs b/src/Downkyi.Core/Bili/Web/LoginHelper.cs index 300e4bd..8d66208 100644 --- a/src/Downkyi.Core/Bili/Web/LoginHelper.cs +++ b/src/Downkyi.Core/Bili/Web/LoginHelper.cs @@ -116,7 +116,7 @@ public static class LoginHelper { File.Delete(LOCAL_LOGIN_INFO); - SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings + SettingsManager.Instance.SetUserInfo(new UserInfoSettings { Mid = -1, Name = "", diff --git a/src/Downkyi.Core/Settings/SettingsManager.cs b/src/Downkyi.Core/Settings/SettingsManager.cs index 229c5f7..ee307d4 100644 --- a/src/Downkyi.Core/Settings/SettingsManager.cs +++ b/src/Downkyi.Core/Settings/SettingsManager.cs @@ -10,8 +10,6 @@ namespace Downkyi.Core.Settings; public partial class SettingsManager { - private static SettingsManager? instance; - // 内存中保存一份配置 private AppSettings appSettings; @@ -26,16 +24,38 @@ public partial class SettingsManager private readonly string password = "YO1J$4#p"; #endif + // 单例模式 + private static SettingsManager? _instance; + private static readonly object _lock = new(); /// - /// 获取SettingsManager实例 + /// 获取SettingsManager唯一实例 /// - /// - public static SettingsManager GetInstance() + public static SettingsManager Instance { - instance ??= new SettingsManager(); - return instance; + get + { + // 双重检查锁定 + if (_instance == null) + { + lock (_lock) + { + _instance ??= new SettingsManager(); + } + } + return _instance; + } } + /// + /// 获取SettingsManager实例 + /// + /// + //public static SettingsManager GetInstance() + //{ + // instance ??= new SettingsManager(); + // return instance; + //} + /// /// 隐藏Settings()方法,必须使用单例模式 /// diff --git a/src/Downkyi.UI/Services/MainSearchService.cs b/src/Downkyi.UI/Services/MainSearchService.cs index 8a9ca3c..f31bfcf 100644 --- a/src/Downkyi.UI/Services/MainSearchService.cs +++ b/src/Downkyi.UI/Services/MainSearchService.cs @@ -126,7 +126,7 @@ public class MainSearchService : IMainSearchService { "value", mid }, }; - UserInfoSettings userInfo = SettingsManager.GetInstance().GetUserInfo(); + UserInfoSettings userInfo = SettingsManager.Instance.GetUserInfo(); if (userInfo != null && userInfo.Mid == mid) { NavigationService.ForwardAsync(MySpaceViewModel.Key, parameter); diff --git a/src/Downkyi.UI/ViewModels/IndexViewModel.cs b/src/Downkyi.UI/ViewModels/IndexViewModel.cs index ca7c9c5..6002379 100644 --- a/src/Downkyi.UI/ViewModels/IndexViewModel.cs +++ b/src/Downkyi.UI/ViewModels/IndexViewModel.cs @@ -70,7 +70,7 @@ public partial class IndexViewModel : ViewModelBase else { // 进入用户空间 - var userInfo = SettingsManager.GetInstance().GetUserInfo(); + var userInfo = SettingsManager.Instance.GetUserInfo(); if (userInfo != null && userInfo.Mid != -1) { Dictionary parameter = new() @@ -161,7 +161,7 @@ public partial class IndexViewModel : ViewModelBase var userInfo = BiliLocator.Login.GetNavigationInfo(); if (userInfo != null) { - SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings + SettingsManager.Instance.SetUserInfo(new UserInfoSettings { Mid = userInfo.Mid, Name = userInfo.Name, @@ -171,7 +171,7 @@ public partial class IndexViewModel : ViewModelBase } else { - SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings + SettingsManager.Instance.SetUserInfo(new UserInfoSettings { Mid = -1, Name = "", diff --git a/src/Downkyi.UI/ViewModels/Login/CookiesViewModel.cs b/src/Downkyi.UI/ViewModels/Login/CookiesViewModel.cs index 0e41bdf..a295959 100644 --- a/src/Downkyi.UI/ViewModels/Login/CookiesViewModel.cs +++ b/src/Downkyi.UI/ViewModels/Login/CookiesViewModel.cs @@ -62,7 +62,6 @@ public partial class CookiesViewModel : ViewModelBase return Task.CompletedTask; } - [RelayCommand(FlowExceptionsToTaskScheduler = true)] private Task SaveCookiesAsync() { diff --git a/src/Downkyi.UI/ViewModels/Settings/AboutViewModel.cs b/src/Downkyi.UI/ViewModels/Settings/AboutViewModel.cs index 309e455..1e246aa 100644 --- a/src/Downkyi.UI/ViewModels/Settings/AboutViewModel.cs +++ b/src/Downkyi.UI/ViewModels/Settings/AboutViewModel.cs @@ -48,11 +48,11 @@ public partial class AboutViewModel : BaseSettingsViewModel IsOnNavigatedTo = true; // 是否接收测试版更新 - var isReceiveBetaVersion = SettingsManager.GetInstance().IsReceiveBetaVersion(); + var isReceiveBetaVersion = SettingsManager.Instance.IsReceiveBetaVersion(); IsReceiveBetaVersion = isReceiveBetaVersion == AllowStatus.YES; // 是否在启动时自动检查更新 - var isAutoUpdateWhenLaunch = SettingsManager.GetInstance().GetAutoUpdateWhenLaunch(); + var isAutoUpdateWhenLaunch = SettingsManager.Instance.GetAutoUpdateWhenLaunch(); IsAutoUpdateWhenLaunch = isAutoUpdateWhenLaunch == AllowStatus.YES; IsOnNavigatedTo = false; @@ -94,7 +94,7 @@ public partial class AboutViewModel : BaseSettingsViewModel { AllowStatus isReceiveBetaVersion = IsReceiveBetaVersion ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().IsReceiveBetaVersion(isReceiveBetaVersion); + bool isSucceed = SettingsManager.Instance.IsReceiveBetaVersion(isReceiveBetaVersion); PublishTip(Key, isSucceed); } @@ -106,7 +106,7 @@ public partial class AboutViewModel : BaseSettingsViewModel { AllowStatus isAutoUpdateWhenLaunch = IsAutoUpdateWhenLaunch ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().SetAutoUpdateWhenLaunch(isAutoUpdateWhenLaunch); + bool isSucceed = SettingsManager.Instance.SetAutoUpdateWhenLaunch(isAutoUpdateWhenLaunch); PublishTip(Key, isSucceed); } diff --git a/src/Downkyi.UI/ViewModels/Settings/BasicViewModel.cs b/src/Downkyi.UI/ViewModels/Settings/BasicViewModel.cs index 05646ef..4d212e7 100644 --- a/src/Downkyi.UI/ViewModels/Settings/BasicViewModel.cs +++ b/src/Downkyi.UI/ViewModels/Settings/BasicViewModel.cs @@ -66,23 +66,23 @@ public partial class BasicViewModel : BaseSettingsViewModel IsOnNavigatedTo = true; // 下载完成后的操作 - AfterDownloadOperation afterDownload = SettingsManager.GetInstance().GetAfterDownloadOperation(); + AfterDownloadOperation afterDownload = SettingsManager.Instance.GetAfterDownloadOperation(); SetAfterDownloadOperation(afterDownload); // 是否监听剪贴板 - AllowStatus isListenClipboard = SettingsManager.GetInstance().IsListenClipboard(); + AllowStatus isListenClipboard = SettingsManager.Instance.IsListenClipboard(); IsListenClipboard = isListenClipboard == AllowStatus.YES; // 是否自动解析视频 - AllowStatus isAutoParseVideo = SettingsManager.GetInstance().IsAutoParseVideo(); + AllowStatus isAutoParseVideo = SettingsManager.Instance.IsAutoParseVideo(); IsAutoParseVideo = isAutoParseVideo == AllowStatus.YES; // 解析范围 - ParseScope parseScope = SettingsManager.GetInstance().GetParseScope(); + ParseScope parseScope = SettingsManager.Instance.GetParseScope(); SelectedParseScope = ParseScopes.FirstOrDefault(t => { return t.ParseScope == parseScope; }); // 解析后是否自动下载解析视频 - AllowStatus isAutoDownloadAll = SettingsManager.GetInstance().IsAutoDownloadAll(); + AllowStatus isAutoDownloadAll = SettingsManager.Instance.IsAutoDownloadAll(); IsAutoDownloadAll = isAutoDownloadAll == AllowStatus.YES; IsOnNavigatedTo = false; @@ -104,7 +104,7 @@ public partial class BasicViewModel : BaseSettingsViewModel "CloseSystem" => AfterDownloadOperation.CLOSE_SYSTEM, _ => AfterDownloadOperation.NONE, }; - bool isSucceed = SettingsManager.GetInstance().SetAfterDownloadOperation(afterDownload); + bool isSucceed = SettingsManager.Instance.SetAfterDownloadOperation(afterDownload); PublishTip(Key, isSucceed); } @@ -116,7 +116,7 @@ public partial class BasicViewModel : BaseSettingsViewModel { AllowStatus isListenClipboard = IsListenClipboard ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().IsListenClipboard(isListenClipboard); + bool isSucceed = SettingsManager.Instance.IsListenClipboard(isListenClipboard); PublishTip(Key, isSucceed); } @@ -128,7 +128,7 @@ public partial class BasicViewModel : BaseSettingsViewModel { AllowStatus isAutoParseVideo = IsAutoParseVideo ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().IsAutoParseVideo(isAutoParseVideo); + bool isSucceed = SettingsManager.Instance.IsAutoParseVideo(isAutoParseVideo); PublishTip(Key, isSucceed); } @@ -141,7 +141,7 @@ public partial class BasicViewModel : BaseSettingsViewModel { //if (parameter is not ParseScopeDisplay parseScope) { return; } - bool isSucceed = SettingsManager.GetInstance().SetParseScope(SelectedParseScope!.ParseScope); + bool isSucceed = SettingsManager.Instance.SetParseScope(SelectedParseScope!.ParseScope); PublishTip(Key, isSucceed); } @@ -153,7 +153,7 @@ public partial class BasicViewModel : BaseSettingsViewModel { AllowStatus isAutoDownloadAll = IsAutoDownloadAll ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().IsAutoDownloadAll(isAutoDownloadAll); + bool isSucceed = SettingsManager.Instance.IsAutoDownloadAll(isAutoDownloadAll); PublishTip(Key, isSucceed); } diff --git a/src/Downkyi.UI/ViewModels/Settings/DanmakuViewModel.cs b/src/Downkyi.UI/ViewModels/Settings/DanmakuViewModel.cs index 7ddd10b..ba0b4d0 100644 --- a/src/Downkyi.UI/ViewModels/Settings/DanmakuViewModel.cs +++ b/src/Downkyi.UI/ViewModels/Settings/DanmakuViewModel.cs @@ -65,25 +65,25 @@ public partial class DanmakuViewModel : BaseSettingsViewModel IsOnNavigatedTo = true; // 屏蔽顶部弹幕 - AllowStatus danmakuTopFilter = SettingsManager.GetInstance().GetDanmakuTopFilter(); + AllowStatus danmakuTopFilter = SettingsManager.Instance.GetDanmakuTopFilter(); TopFilter = danmakuTopFilter == AllowStatus.YES; // 屏蔽底部弹幕 - AllowStatus danmakuBottomFilter = SettingsManager.GetInstance().GetDanmakuBottomFilter(); + AllowStatus danmakuBottomFilter = SettingsManager.Instance.GetDanmakuBottomFilter(); BottomFilter = danmakuBottomFilter == AllowStatus.YES; // 屏蔽滚动弹幕 - AllowStatus danmakuScrollFilter = SettingsManager.GetInstance().GetDanmakuScrollFilter(); + AllowStatus danmakuScrollFilter = SettingsManager.Instance.GetDanmakuScrollFilter(); ScrollFilter = danmakuScrollFilter == AllowStatus.YES; // 分辨率-宽 - ScreenWidth = SettingsManager.GetInstance().GetDanmakuScreenWidth(); + ScreenWidth = SettingsManager.Instance.GetDanmakuScreenWidth(); // 分辨率-高 - ScreenHeight = SettingsManager.GetInstance().GetDanmakuScreenHeight(); + ScreenHeight = SettingsManager.Instance.GetDanmakuScreenHeight(); // 弹幕字体 - string danmakuFont = SettingsManager.GetInstance().GetDanmakuFontName(); + string danmakuFont = SettingsManager.Instance.GetDanmakuFontName(); if (danmakuFont != null && Fonts.Contains(danmakuFont)) { // 只有系统中存在当前设置的字体,才能显示 @@ -91,13 +91,13 @@ public partial class DanmakuViewModel : BaseSettingsViewModel } // 弹幕字体大小 - FontSize = SettingsManager.GetInstance().GetDanmakuFontSize(); + FontSize = SettingsManager.Instance.GetDanmakuFontSize(); // 弹幕限制行数 - LineCount = SettingsManager.GetInstance().GetDanmakuLineCount(); + LineCount = SettingsManager.Instance.GetDanmakuLineCount(); // 弹幕布局算法 - DanmakuLayoutAlgorithm layoutAlgorithm = SettingsManager.GetInstance().GetDanmakuLayoutAlgorithm(); + DanmakuLayoutAlgorithm layoutAlgorithm = SettingsManager.Instance.GetDanmakuLayoutAlgorithm(); SetLayoutAlgorithm(layoutAlgorithm); IsOnNavigatedTo = false; @@ -111,7 +111,7 @@ public partial class DanmakuViewModel : BaseSettingsViewModel { AllowStatus isTopFilter = TopFilter ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().SetDanmakuTopFilter(isTopFilter); + bool isSucceed = SettingsManager.Instance.SetDanmakuTopFilter(isTopFilter); PublishTip(Key, isSucceed); } @@ -123,7 +123,7 @@ public partial class DanmakuViewModel : BaseSettingsViewModel { AllowStatus isBottomFilter = BottomFilter ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().SetDanmakuBottomFilter(isBottomFilter); + bool isSucceed = SettingsManager.Instance.SetDanmakuBottomFilter(isBottomFilter); PublishTip(Key, isSucceed); } @@ -135,7 +135,7 @@ public partial class DanmakuViewModel : BaseSettingsViewModel { AllowStatus isScrollFilter = ScrollFilter ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().SetDanmakuScrollFilter(isScrollFilter); + bool isSucceed = SettingsManager.Instance.SetDanmakuScrollFilter(isScrollFilter); PublishTip(Key, isSucceed); } @@ -149,7 +149,7 @@ public partial class DanmakuViewModel : BaseSettingsViewModel int width = (int)Number.GetInt(parameter); ScreenWidth = width; - bool isSucceed = SettingsManager.GetInstance().SetDanmakuScreenWidth(ScreenWidth); + bool isSucceed = SettingsManager.Instance.SetDanmakuScreenWidth(ScreenWidth); PublishTip(Key, isSucceed); } @@ -163,7 +163,7 @@ public partial class DanmakuViewModel : BaseSettingsViewModel int height = (int)Number.GetInt(parameter); ScreenHeight = height; - bool isSucceed = SettingsManager.GetInstance().SetDanmakuScreenHeight(ScreenHeight); + bool isSucceed = SettingsManager.Instance.SetDanmakuScreenHeight(ScreenHeight); PublishTip(Key, isSucceed); } @@ -174,7 +174,7 @@ public partial class DanmakuViewModel : BaseSettingsViewModel [RelayCommand] private void FontSelected(string parameter) { - bool isSucceed = SettingsManager.GetInstance().SetDanmakuFontName(parameter); + bool isSucceed = SettingsManager.Instance.SetDanmakuFontName(parameter); PublishTip(Key, isSucceed); } @@ -188,7 +188,7 @@ public partial class DanmakuViewModel : BaseSettingsViewModel int fontSize = (int)Number.GetInt(parameter); FontSize = fontSize; - bool isSucceed = SettingsManager.GetInstance().SetDanmakuFontSize(FontSize); + bool isSucceed = SettingsManager.Instance.SetDanmakuFontSize(FontSize); PublishTip(Key, isSucceed); } @@ -202,7 +202,7 @@ public partial class DanmakuViewModel : BaseSettingsViewModel int lineCount = (int)Number.GetInt(parameter); LineCount = lineCount; - bool isSucceed = SettingsManager.GetInstance().SetDanmakuLineCount(LineCount); + bool isSucceed = SettingsManager.Instance.SetDanmakuLineCount(LineCount); PublishTip(Key, isSucceed); } @@ -213,21 +213,13 @@ public partial class DanmakuViewModel : BaseSettingsViewModel [RelayCommand] private void SetLayoutAlgorithm(string parameter) { - DanmakuLayoutAlgorithm layoutAlgorithm; - switch (parameter) + var layoutAlgorithm = parameter switch { - case "Sync": - layoutAlgorithm = DanmakuLayoutAlgorithm.SYNC; - break; - case "Async": - layoutAlgorithm = DanmakuLayoutAlgorithm.ASYNC; - break; - default: - layoutAlgorithm = DanmakuLayoutAlgorithm.SYNC; - break; - } - - bool isSucceed = SettingsManager.GetInstance().SetDanmakuLayoutAlgorithm(layoutAlgorithm); + "Sync" => DanmakuLayoutAlgorithm.SYNC, + "Async" => DanmakuLayoutAlgorithm.ASYNC, + _ => DanmakuLayoutAlgorithm.SYNC, + }; + bool isSucceed = SettingsManager.Instance.SetDanmakuLayoutAlgorithm(layoutAlgorithm); PublishTip(Key, isSucceed); if (isSucceed) diff --git a/src/Downkyi.UI/ViewModels/Settings/NetworkViewModel.cs b/src/Downkyi.UI/ViewModels/Settings/NetworkViewModel.cs index a85f179..17cf79f 100644 --- a/src/Downkyi.UI/ViewModels/Settings/NetworkViewModel.cs +++ b/src/Downkyi.UI/ViewModels/Settings/NetworkViewModel.cs @@ -145,14 +145,14 @@ public partial class NetworkViewModel : BaseSettingsViewModel IsOnNavigatedTo = true; // 启用https - AllowStatus useSSL = SettingsManager.GetInstance().UseSSL(); + AllowStatus useSSL = SettingsManager.Instance.UseSSL(); UseSSL = useSSL == AllowStatus.YES; // UserAgent - UserAgent = SettingsManager.GetInstance().GetUserAgent(); + UserAgent = SettingsManager.Instance.GetUserAgent(); // 选择下载器 - var downloader = SettingsManager.GetInstance().GetDownloader(); + var downloader = SettingsManager.Instance.GetDownloader(); switch (downloader) { case Downloader.NOT_SET: @@ -169,58 +169,58 @@ public partial class NetworkViewModel : BaseSettingsViewModel } // builtin同时下载数 - SelectedMaxCurrentDownload = SettingsManager.GetInstance().GetMaxCurrentDownloads(); + SelectedMaxCurrentDownload = SettingsManager.Instance.GetMaxCurrentDownloads(); // builtin最大线程数 - SelectedSplit = SettingsManager.GetInstance().GetSplit(); + SelectedSplit = SettingsManager.Instance.GetSplit(); // 是否开启builtin http代理 - AllowStatus isHttpProxy = SettingsManager.GetInstance().IsHttpProxy(); + AllowStatus isHttpProxy = SettingsManager.Instance.IsHttpProxy(); IsHttpProxy = isHttpProxy == AllowStatus.YES; // builtin的http代理的地址 - HttpProxy = SettingsManager.GetInstance().GetHttpProxy(); + HttpProxy = SettingsManager.Instance.GetHttpProxy(); // builtin的http代理的端口 - HttpProxyPort = SettingsManager.GetInstance().GetHttpProxyListenPort(); + HttpProxyPort = SettingsManager.Instance.GetHttpProxyListenPort(); // Aria服务器host - AriaHost = SettingsManager.GetInstance().GetAriaHost(); + AriaHost = SettingsManager.Instance.GetAriaHost(); // Aria服务器端口 - AriaListenPort = SettingsManager.GetInstance().GetAriaListenPort(); + AriaListenPort = SettingsManager.Instance.GetAriaListenPort(); // Aria服务器Token - AriaToken = SettingsManager.GetInstance().GetAriaToken(); + AriaToken = SettingsManager.Instance.GetAriaToken(); // Aria的日志等级 - AriaConfigLogLevel ariaLogLevel = SettingsManager.GetInstance().GetAriaLogLevel(); + AriaConfigLogLevel ariaLogLevel = SettingsManager.Instance.GetAriaLogLevel(); SelectedAriaLogLevel = ariaLogLevel.ToString("G"); // Aria同时下载数 - SelectedAriaMaxConcurrentDownload = SettingsManager.GetInstance().GetMaxCurrentDownloads(); + SelectedAriaMaxConcurrentDownload = SettingsManager.Instance.GetMaxCurrentDownloads(); // Aria最大线程数 - SelectedAriaSplit = SettingsManager.GetInstance().GetAriaSplit(); + SelectedAriaSplit = SettingsManager.Instance.GetAriaSplit(); // Aria下载速度限制 - AriaMaxOverallDownloadLimit = SettingsManager.GetInstance().GetAriaMaxOverallDownloadLimit(); + AriaMaxOverallDownloadLimit = SettingsManager.Instance.GetAriaMaxOverallDownloadLimit(); // Aria下载单文件速度限制 - AriaMaxDownloadLimit = SettingsManager.GetInstance().GetAriaMaxDownloadLimit(); + AriaMaxDownloadLimit = SettingsManager.Instance.GetAriaMaxDownloadLimit(); // 是否开启Aria http代理 - AllowStatus isAriaHttpProxy = SettingsManager.GetInstance().IsAriaHttpProxy(); + AllowStatus isAriaHttpProxy = SettingsManager.Instance.IsAriaHttpProxy(); IsAriaHttpProxy = isAriaHttpProxy == AllowStatus.YES; // Aria的http代理的地址 - AriaHttpProxy = SettingsManager.GetInstance().GetAriaHttpProxy(); + AriaHttpProxy = SettingsManager.Instance.GetAriaHttpProxy(); // Aria的http代理的端口 - AriaHttpProxyPort = SettingsManager.GetInstance().GetAriaHttpProxyListenPort(); + AriaHttpProxyPort = SettingsManager.Instance.GetAriaHttpProxyListenPort(); // Aria文件预分配 - AriaConfigFileAllocation ariaFileAllocation = SettingsManager.GetInstance().GetAriaFileAllocation(); + AriaConfigFileAllocation ariaFileAllocation = SettingsManager.Instance.GetAriaFileAllocation(); SelectedAriaFileAllocation = ariaFileAllocation.ToString("G"); IsOnNavigatedTo = false; @@ -234,7 +234,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel { AllowStatus useSSL = UseSSL ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().UseSSL(useSSL); + bool isSucceed = SettingsManager.Instance.UseSSL(useSSL); PublishTip(Key, isSucceed); } @@ -244,7 +244,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel [RelayCommand] private void SetUserAgent() { - bool isSucceed = SettingsManager.GetInstance().SetUserAgent(UserAgent); + bool isSucceed = SettingsManager.Instance.SetUserAgent(UserAgent); PublishTip(Key, isSucceed); } @@ -260,9 +260,9 @@ public partial class NetworkViewModel : BaseSettingsViewModel "Builtin" => Downloader.BUILT_IN, "Aria2c" => Downloader.ARIA, "CustomAria2c" => Downloader.CUSTOM_ARIA, - _ => SettingsManager.GetInstance().GetDownloader(), + _ => SettingsManager.Instance.GetDownloader(), }; - bool isSucceed = SettingsManager.GetInstance().SetDownloader(downloader); + bool isSucceed = SettingsManager.Instance.SetDownloader(downloader); PublishTip(Key, isSucceed); // 弹窗提示是否重启程序 @@ -284,7 +284,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel [RelayCommand] private void SetMaxCurrentDownloads() { - bool isSucceed = SettingsManager.GetInstance().SetMaxCurrentDownloads(SelectedMaxCurrentDownload); + bool isSucceed = SettingsManager.Instance.SetMaxCurrentDownloads(SelectedMaxCurrentDownload); PublishTip(Key, isSucceed); } @@ -295,7 +295,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel [RelayCommand] private void SetSplits() { - bool isSucceed = SettingsManager.GetInstance().SetSplit(SelectedSplit); + bool isSucceed = SettingsManager.Instance.SetSplit(SelectedSplit); PublishTip(Key, isSucceed); } @@ -307,7 +307,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel { AllowStatus isHttpProxy = IsHttpProxy ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().IsHttpProxy(isHttpProxy); + bool isSucceed = SettingsManager.Instance.IsHttpProxy(isHttpProxy); PublishTip(Key, isSucceed); } @@ -318,7 +318,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel [RelayCommand] private void SetHttpProxy(string parameter) { - bool isSucceed = SettingsManager.GetInstance().SetHttpProxy(parameter); + bool isSucceed = SettingsManager.Instance.SetHttpProxy(parameter); PublishTip(Key, isSucceed); } @@ -332,7 +332,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel int httpProxyPort = (int)Number.GetInt(parameter); HttpProxyPort = httpProxyPort; - bool isSucceed = SettingsManager.GetInstance().SetHttpProxyListenPort(HttpProxyPort); + bool isSucceed = SettingsManager.Instance.SetHttpProxyListenPort(HttpProxyPort); PublishTip(Key, isSucceed); } @@ -344,7 +344,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel private void SetAriaHost(string parameter) { AriaHost = parameter; - bool isSucceed = SettingsManager.GetInstance().SetAriaHost(AriaHost); + bool isSucceed = SettingsManager.Instance.SetAriaHost(AriaHost); PublishTip(Key, isSucceed); } @@ -358,7 +358,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel int listenPort = (int)Number.GetInt(parameter); AriaListenPort = listenPort; - bool isSucceed = SettingsManager.GetInstance().SetAriaListenPort(AriaListenPort); + bool isSucceed = SettingsManager.Instance.SetAriaListenPort(AriaListenPort); PublishTip(Key, isSucceed); } @@ -370,7 +370,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel private void SetAriaToken(string parameter) { AriaToken = parameter; - bool isSucceed = SettingsManager.GetInstance().SetAriaToken(AriaToken); + bool isSucceed = SettingsManager.Instance.SetAriaToken(AriaToken); PublishTip(Key, isSucceed); } @@ -390,7 +390,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel "ERROR" => AriaConfigLogLevel.ERROR, _ => AriaConfigLogLevel.INFO, }; - bool isSucceed = SettingsManager.GetInstance().SetAriaLogLevel(ariaLogLevel); + bool isSucceed = SettingsManager.Instance.SetAriaLogLevel(ariaLogLevel); PublishTip(Key, isSucceed); } @@ -401,7 +401,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel [RelayCommand] private void SetAriaMaxConcurrentDownloads() { - bool isSucceed = SettingsManager.GetInstance().SetMaxCurrentDownloads(SelectedAriaMaxConcurrentDownload); + bool isSucceed = SettingsManager.Instance.SetMaxCurrentDownloads(SelectedAriaMaxConcurrentDownload); PublishTip(Key, isSucceed); } @@ -412,7 +412,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel [RelayCommand] private void SetAriaSplits() { - bool isSucceed = SettingsManager.GetInstance().SetAriaSplit(SelectedAriaSplit); + bool isSucceed = SettingsManager.Instance.SetAriaSplit(SelectedAriaSplit); PublishTip(Key, isSucceed); } @@ -426,7 +426,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel int downloadLimit = (int)Number.GetInt(parameter); AriaMaxOverallDownloadLimit = downloadLimit; - bool isSucceed = SettingsManager.GetInstance().SetAriaMaxOverallDownloadLimit(AriaMaxOverallDownloadLimit); + bool isSucceed = SettingsManager.Instance.SetAriaMaxOverallDownloadLimit(AriaMaxOverallDownloadLimit); PublishTip(Key, isSucceed); } @@ -440,7 +440,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel int downloadLimit = (int)Number.GetInt(parameter); AriaMaxDownloadLimit = downloadLimit; - bool isSucceed = SettingsManager.GetInstance().SetAriaMaxDownloadLimit(AriaMaxDownloadLimit); + bool isSucceed = SettingsManager.Instance.SetAriaMaxDownloadLimit(AriaMaxDownloadLimit); PublishTip(Key, isSucceed); } @@ -452,7 +452,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel { AllowStatus isAriaHttpProxy = IsAriaHttpProxy ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().IsAriaHttpProxy(isAriaHttpProxy); + bool isSucceed = SettingsManager.Instance.IsAriaHttpProxy(isAriaHttpProxy); PublishTip(Key, isSucceed); } @@ -463,7 +463,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel [RelayCommand] private void SetAriaHttpProxy(string parameter) { - bool isSucceed = SettingsManager.GetInstance().SetAriaHttpProxy(parameter); + bool isSucceed = SettingsManager.Instance.SetAriaHttpProxy(parameter); PublishTip(Key, isSucceed); } @@ -477,7 +477,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel int httpProxyPort = (int)Number.GetInt(parameter); AriaHttpProxyPort = httpProxyPort; - bool isSucceed = SettingsManager.GetInstance().SetAriaHttpProxyListenPort(AriaHttpProxyPort); + bool isSucceed = SettingsManager.Instance.SetAriaHttpProxyListenPort(AriaHttpProxyPort); PublishTip(Key, isSucceed); } @@ -494,7 +494,7 @@ public partial class NetworkViewModel : BaseSettingsViewModel "FALLOC" => AriaConfigFileAllocation.FALLOC, _ => AriaConfigFileAllocation.PREALLOC, }; - bool isSucceed = SettingsManager.GetInstance().SetAriaFileAllocation(ariaFileAllocation); + bool isSucceed = SettingsManager.Instance.SetAriaFileAllocation(ariaFileAllocation); PublishTip(Key, isSucceed); } diff --git a/src/Downkyi.UI/ViewModels/Settings/VideoViewModel.cs b/src/Downkyi.UI/ViewModels/Settings/VideoViewModel.cs index 6a41779..e2b637e 100644 --- a/src/Downkyi.UI/ViewModels/Settings/VideoViewModel.cs +++ b/src/Downkyi.UI/ViewModels/Settings/VideoViewModel.cs @@ -119,7 +119,7 @@ public partial class VideoViewModel : BaseSettingsViewModel fileName.Add(item.Id); } - bool isSucceed = SettingsManager.GetInstance().SetFileNameParts(fileName); + bool isSucceed = SettingsManager.Instance.SetFileNameParts(fileName); PublishTip(Key, isSucceed); }); @@ -149,30 +149,30 @@ public partial class VideoViewModel : BaseSettingsViewModel IsOnNavigatedTo = true; // 优先下载的视频编码 - int videoCodecs = SettingsManager.GetInstance().GetVideoCodecs(); + int videoCodecs = SettingsManager.Instance.GetVideoCodecs(); SelectedVideoCodec = VideoCodecs.FirstOrDefault(t => { return t.Id == videoCodecs; }); // 优先下载画质 - int quality = SettingsManager.GetInstance().GetQuality(); + int quality = SettingsManager.Instance.GetQuality(); SelectedVideoQuality = VideoQualityList.FirstOrDefault(t => { return t.Id == quality; }); // 优先下载音质 - int audioQuality = SettingsManager.GetInstance().GetAudioQuality(); + int audioQuality = SettingsManager.Instance.GetAudioQuality(); SelectedAudioQuality = AudioQualityList.FirstOrDefault(t => { return t.Id == audioQuality; }); // 是否下载flv视频后转码为mp4 - AllowStatus isTranscodingFlvToMp4 = SettingsManager.GetInstance().IsTranscodingFlvToMp4(); + AllowStatus isTranscodingFlvToMp4 = SettingsManager.Instance.IsTranscodingFlvToMp4(); IsTranscodingFlvToMp4 = isTranscodingFlvToMp4 == AllowStatus.YES; // 是否使用默认下载目录 - AllowStatus isUseSaveVideoRootPath = SettingsManager.GetInstance().IsUseSaveVideoRootPath(); + AllowStatus isUseSaveVideoRootPath = SettingsManager.Instance.IsUseSaveVideoRootPath(); IsUseDefaultDirectory = isUseSaveVideoRootPath == AllowStatus.YES; // 默认下载目录 - SaveVideoDirectory = SettingsManager.GetInstance().GetSaveVideoRootPath(); + SaveVideoDirectory = SettingsManager.Instance.GetSaveVideoRootPath(); // 下载内容 - VideoContentSettings videoContent = SettingsManager.GetInstance().GetVideoContent(); + VideoContentSettings videoContent = SettingsManager.Instance.GetVideoContent(); DownloadAudio = videoContent.DownloadAudio; DownloadVideo = videoContent.DownloadVideo; @@ -190,7 +190,7 @@ public partial class VideoViewModel : BaseSettingsViewModel } // 文件命名格式 - List fileNameParts = SettingsManager.GetInstance().GetFileNameParts(); + List fileNameParts = SettingsManager.Instance.GetFileNameParts(); SelectedFileName.Clear(); foreach (FileNamePart item in fileNameParts) { @@ -208,10 +208,10 @@ public partial class VideoViewModel : BaseSettingsViewModel } // 文件命名中的时间格式 - SelectedTimeFormat = SettingsManager.GetInstance().GetFileNamePartTimeFormat(); + SelectedTimeFormat = SettingsManager.Instance.GetFileNamePartTimeFormat(); // 文件命名中的序号格式 - OrderFormat orderFormat = SettingsManager.GetInstance().GetOrderFormat(); + OrderFormat orderFormat = SettingsManager.Instance.GetOrderFormat(); SelectedOrderFormat = OrderFormatList.FirstOrDefault(t => { return t.Id == orderFormat; }); IsOnNavigatedTo = false; @@ -224,7 +224,7 @@ public partial class VideoViewModel : BaseSettingsViewModel [RelayCommand] private void SetVideoCodecs() { - bool isSucceed = SettingsManager.GetInstance().SetVideoCodecs(SelectedVideoCodec!.Id); + bool isSucceed = SettingsManager.Instance.SetVideoCodecs(SelectedVideoCodec!.Id); PublishTip(Key, isSucceed); } @@ -235,7 +235,7 @@ public partial class VideoViewModel : BaseSettingsViewModel [RelayCommand] private void SetVideoQuality() { - bool isSucceed = SettingsManager.GetInstance().SetQuality(SelectedVideoQuality!.Id); + bool isSucceed = SettingsManager.Instance.SetQuality(SelectedVideoQuality!.Id); PublishTip(Key, isSucceed); } @@ -246,7 +246,7 @@ public partial class VideoViewModel : BaseSettingsViewModel [RelayCommand] private void SetAudioQuality() { - bool isSucceed = SettingsManager.GetInstance().SetAudioQuality(SelectedAudioQuality!.Id); + bool isSucceed = SettingsManager.Instance.SetAudioQuality(SelectedAudioQuality!.Id); PublishTip(Key, isSucceed); } @@ -258,7 +258,7 @@ public partial class VideoViewModel : BaseSettingsViewModel { AllowStatus isTranscodingFlvToMp4 = IsTranscodingFlvToMp4 ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().IsTranscodingFlvToMp4(isTranscodingFlvToMp4); + bool isSucceed = SettingsManager.Instance.IsTranscodingFlvToMp4(isTranscodingFlvToMp4); PublishTip(Key, isSucceed); } @@ -270,7 +270,7 @@ public partial class VideoViewModel : BaseSettingsViewModel { AllowStatus isUseDefaultDirectory = IsUseDefaultDirectory ? AllowStatus.YES : AllowStatus.NO; - bool isSucceed = SettingsManager.GetInstance().IsUseSaveVideoRootPath(isUseDefaultDirectory); + bool isSucceed = SettingsManager.Instance.IsUseSaveVideoRootPath(isUseDefaultDirectory); PublishTip(Key, isSucceed); } @@ -283,7 +283,7 @@ public partial class VideoViewModel : BaseSettingsViewModel string directory = await StoragePicker.FolderPicker(SaveVideoDirectory); if (directory == "") { return; } - bool isSucceed = SettingsManager.GetInstance().SetSaveVideoRootPath(directory); + bool isSucceed = SettingsManager.Instance.SetSaveVideoRootPath(directory); PublishTip(Key, isSucceed); if (isSucceed) @@ -420,7 +420,7 @@ public partial class VideoViewModel : BaseSettingsViewModel [RelayCommand] private void TimeFormat() { - bool isSucceed = SettingsManager.GetInstance().SetFileNamePartTimeFormat(SelectedTimeFormat); + bool isSucceed = SettingsManager.Instance.SetFileNamePartTimeFormat(SelectedTimeFormat); PublishTip(Key, isSucceed); } @@ -431,7 +431,7 @@ public partial class VideoViewModel : BaseSettingsViewModel [RelayCommand] private void OrderFormat() { - bool isSucceed = SettingsManager.GetInstance().SetOrderFormat(SelectedOrderFormat!.Id); + bool isSucceed = SettingsManager.Instance.SetOrderFormat(SelectedOrderFormat!.Id); PublishTip(Key, isSucceed); } @@ -441,10 +441,10 @@ public partial class VideoViewModel : BaseSettingsViewModel [RelayCommand] private void Reset() { - bool isSucceed = SettingsManager.GetInstance().SetFileNameParts(null); + bool isSucceed = SettingsManager.Instance.SetFileNameParts(null); PublishTip(Key, isSucceed); - List fileNameParts = SettingsManager.GetInstance().GetFileNameParts(); + List fileNameParts = SettingsManager.Instance.GetFileNameParts(); SelectedFileName.Clear(); foreach (FileNamePart item in fileNameParts) { @@ -480,7 +480,7 @@ public partial class VideoViewModel : BaseSettingsViewModel DownloadCover = DownloadCover }; - bool isSucceed = SettingsManager.GetInstance().SetVideoContent(videoContent); + bool isSucceed = SettingsManager.Instance.SetVideoContent(videoContent); PublishTip(Key, isSucceed); } diff --git a/src/Downkyi.UI/ViewModels/Video/VideoDetailViewModel.cs b/src/Downkyi.UI/ViewModels/Video/VideoDetailViewModel.cs index 92dc01a..109cda6 100644 --- a/src/Downkyi.UI/ViewModels/Video/VideoDetailViewModel.cs +++ b/src/Downkyi.UI/ViewModels/Video/VideoDetailViewModel.cs @@ -90,7 +90,7 @@ public partial class VideoDetailViewModel : ViewModelBase var tryVideoInfoView = service.GetVideoView(_input); // 是否自动解析视频 - if (SettingsManager.GetInstance().IsAutoParseVideo() == AllowStatus.YES) + if (SettingsManager.Instance.IsAutoParseVideo() == AllowStatus.YES) { // TODO } @@ -136,7 +136,7 @@ public partial class VideoDetailViewModel : ViewModelBase { "value", mid }, }; - UserInfoSettings userInfo = SettingsManager.GetInstance().GetUserInfo(); + UserInfoSettings userInfo = SettingsManager.Instance.GetUserInfo(); if (userInfo != null && userInfo.Mid == mid) { await NavigationService.ForwardAsync(MySpaceViewModel.Key, parameter); diff --git a/src/Downkyi/ViewModels/MainWindowViewModel.cs b/src/Downkyi/ViewModels/MainWindowViewModel.cs index 1fafadb..c9a0712 100644 --- a/src/Downkyi/ViewModels/MainWindowViewModel.cs +++ b/src/Downkyi/ViewModels/MainWindowViewModel.cs @@ -78,7 +78,7 @@ public partial class MainWindowViewModel : ViewModelBase while (true) { - AllowStatus isListenClipboard = SettingsManager.GetInstance().IsListenClipboard(); + AllowStatus isListenClipboard = SettingsManager.Instance.IsListenClipboard(); if (isListenClipboard != AllowStatus.YES) { continue;