From 80fdaa505bccef0aa1e3753d36ac5af314e5331a Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Tue, 2 Nov 2021 15:09:31 +0800 Subject: [PATCH] fix --- .../Application/Settings/SettingsHost.cs | 2 -- src/ST.Client.Android/UI/MainApplication.cs | 4 ---- .../Settings/GameLibrarySettings.Avalonia.cs | 8 +++---- .../Settings/GeneralSettings.Avalonia.cs | 12 +++++----- .../Settings/ProxySettings.Avalonia.cs | 6 ++--- .../Settings/SteamAccountSettings.cs | 2 +- src/ST.Client/Settings/UISettings.Avalonia.cs | 24 +++++++++---------- src/ST.Client/UI/IApplication.cs | 5 ++++ .../UI/ViewModels/Base/IViewModelBase.cs | 4 +++- .../UI/ViewModels/Base/IWindowViewModel.cs | 3 ++- 10 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/Common.CoreLib/Application/Settings/SettingsHost.cs b/src/Common.CoreLib/Application/Settings/SettingsHost.cs index 78f1f0844..31b971f08 100644 --- a/src/Common.CoreLib/Application/Settings/SettingsHost.cs +++ b/src/Common.CoreLib/Application/Settings/SettingsHost.cs @@ -6,8 +6,6 @@ namespace System.Application.Settings { public abstract class SettingsHostBase { - protected static readonly bool IsDesktopPlatform = OperatingSystem2.IsWindows || OperatingSystem2.IsMacOS || (OperatingSystem2.IsLinux && !OperatingSystem2.IsAndroid); - static readonly Dictionary instances = new(); public string CategoryName => GetCategoryName(); diff --git a/src/ST.Client.Android/UI/MainApplication.cs b/src/ST.Client.Android/UI/MainApplication.cs index 69d2871d7..2c59d4ee9 100644 --- a/src/ST.Client.Android/UI/MainApplication.cs +++ b/src/ST.Client.Android/UI/MainApplication.cs @@ -36,10 +36,6 @@ namespace System.Application.UI public MainApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { - IViewModelBase.IsInDesignMode = false; - IViewModelBase.IsMobileLayout = true; - IWindowViewModel.IsSupportedSizePosition = false; - // 此页面当前使用 Square.Picasso 库加载图片 AuthTradeWindowViewModel.IsLoadImage = false; } diff --git a/src/ST.Client/Settings/GameLibrarySettings.Avalonia.cs b/src/ST.Client/Settings/GameLibrarySettings.Avalonia.cs index b5590b36c..6d5b0b95d 100644 --- a/src/ST.Client/Settings/GameLibrarySettings.Avalonia.cs +++ b/src/ST.Client/Settings/GameLibrarySettings.Avalonia.cs @@ -13,7 +13,7 @@ namespace System.Application.Settings { partial class GameLibrarySettings { - static readonly SerializableProperty>? _HideGameList = IsDesktopPlatform ? GetProperty(defaultValue: new Dictionary(), autoSave: true) : null; + static readonly SerializableProperty>? _HideGameList = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: new Dictionary(), autoSave: true) : null; /// /// 隐藏的游戏列表 /// @@ -22,7 +22,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty> HideGameList => _HideGameList ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty>? _AFKAppList = IsDesktopPlatform ? GetProperty(defaultValue: new Dictionary(), autoSave: true) : null; + readonly static SerializableProperty>? _AFKAppList = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: new Dictionary(), autoSave: true) : null; /// /// 挂时长游戏列表 /// @@ -32,7 +32,7 @@ namespace System.Application.Settings public static SerializableProperty> AFKAppList => _AFKAppList ?? throw new PlatformNotSupportedException(); readonly static SerializableProperty? _IsAutoAFKApps - = IsDesktopPlatform ? GetProperty(defaultValue: true, autoSave: true) : null; + = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: true, autoSave: true) : null; /// /// 启用自动挂机 /// @@ -44,7 +44,7 @@ namespace System.Application.Settings // [SupportedOSPlatform("Windows")] // [SupportedOSPlatform("macOS")] // [SupportedOSPlatform("Linux")] - // public static readonly Lazy>? DefaultIgnoreList = IsDesktopPlatform ? new(new ReadOnlyCollection(new uint[] + // public static readonly Lazy>? DefaultIgnoreList = IApplication.IsDesktopPlatform ? new(new ReadOnlyCollection(new uint[] // { // 5, // 7, diff --git a/src/ST.Client/Settings/GeneralSettings.Avalonia.cs b/src/ST.Client/Settings/GeneralSettings.Avalonia.cs index 9b45a868c..e7d6408f7 100644 --- a/src/ST.Client/Settings/GeneralSettings.Avalonia.cs +++ b/src/ST.Client/Settings/GeneralSettings.Avalonia.cs @@ -17,7 +17,7 @@ namespace System.Application.Settings { partial class GeneralSettings { - readonly static SerializableProperty? _WindowsStartupAutoRun = IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; + readonly static SerializableProperty? _WindowsStartupAutoRun = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; /// /// 程序是否开机自启动 /// @@ -26,7 +26,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty WindowsStartupAutoRun => _WindowsStartupAutoRun ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _IsStartupAppMinimized = IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; + readonly static SerializableProperty? _IsStartupAppMinimized = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; /// /// 程序启动时最小化 /// @@ -36,7 +36,7 @@ namespace System.Application.Settings public static SerializableProperty? IsStartupAppMinimized => _IsStartupAppMinimized ?? throw new PlatformNotSupportedException(); readonly static SerializableProperty? _IsSteamAppListLocalCache - = IsDesktopPlatform ? GetProperty(defaultValue: true, autoSave: true) : null; + = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: true, autoSave: true) : null; /// /// 启用游戏列表本地缓存 /// @@ -45,7 +45,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty? IsSteamAppListLocalCache => _IsSteamAppListLocalCache ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty>? _TextReaderProvider = IsDesktopPlatform ? GetProperty(defaultValue: (IReadOnlyDictionary?)null, autoSave: true) : null; + readonly static SerializableProperty>? _TextReaderProvider = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: (IReadOnlyDictionary?)null, autoSave: true) : null; /// /// 用户设置的文本阅读器提供商,根据平台值不同,值格式为 枚举字符串 或 程序路径 /// @@ -54,7 +54,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty> TextReaderProvider => _TextReaderProvider ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _HostsEncodingType = IsDesktopPlatform ? GetProperty(defaultValue: default(IHostsFileService.EncodingType), autoSave: true) : null; + readonly static SerializableProperty? _HostsEncodingType = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: default(IHostsFileService.EncodingType), autoSave: true) : null; /// /// Hosts 文件编码类型 /// @@ -63,7 +63,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty HostsEncodingType => _HostsEncodingType ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _UseGPURendering = IsDesktopPlatform ? GetProperty(defaultValue: !OperatingSystem2.IsWindows7, autoSave: true) : null; + readonly static SerializableProperty? _UseGPURendering = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: !OperatingSystem2.IsWindows7, autoSave: true) : null; /// /// 使用硬件加速 /// diff --git a/src/ST.Client/Settings/ProxySettings.Avalonia.cs b/src/ST.Client/Settings/ProxySettings.Avalonia.cs index 92ecfa62d..585562168 100644 --- a/src/ST.Client/Settings/ProxySettings.Avalonia.cs +++ b/src/ST.Client/Settings/ProxySettings.Avalonia.cs @@ -14,7 +14,7 @@ namespace System.Application.Settings partial class ProxySettings { readonly static SerializableProperty? _IsProxyGOG - = IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; + = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; /// /// 启用GOG插件代理 /// @@ -24,7 +24,7 @@ namespace System.Application.Settings public static SerializableProperty IsProxyGOG => _IsProxyGOG ?? throw new PlatformNotSupportedException(); readonly static SerializableProperty? _EnableWindowsProxy - = IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; + = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; /// /// 启用系统代理模式 /// @@ -34,7 +34,7 @@ namespace System.Application.Settings public static SerializableProperty EnableWindowsProxy => _EnableWindowsProxy ?? throw new PlatformNotSupportedException(); readonly static SerializableProperty? _IsOnlyWorkSteamBrowser - = IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; + = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; /// /// 是否只针对Steam内置浏览器启用脚本 /// diff --git a/src/ST.Client/Settings/SteamAccountSettings.cs b/src/ST.Client/Settings/SteamAccountSettings.cs index 5bb31fe68..e24020bd3 100644 --- a/src/ST.Client/Settings/SteamAccountSettings.cs +++ b/src/ST.Client/Settings/SteamAccountSettings.cs @@ -16,7 +16,7 @@ namespace System.Application.Settings { #region Compat - readonly static SerializableProperty>? _AccountRemarks = IsDesktopPlatform ? Compat.GetProperty(defaultValue: new ConcurrentDictionary(), autoSave: false) : null; + readonly static SerializableProperty>? _AccountRemarks = IApplication.IsDesktopPlatform ? Compat.GetProperty(defaultValue: new ConcurrentDictionary(), autoSave: false) : null; /// /// Steam账号备注字典 /// diff --git a/src/ST.Client/Settings/UISettings.Avalonia.cs b/src/ST.Client/Settings/UISettings.Avalonia.cs index 6d4058402..71d827d1d 100644 --- a/src/ST.Client/Settings/UISettings.Avalonia.cs +++ b/src/ST.Client/Settings/UISettings.Avalonia.cs @@ -26,7 +26,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty> WindowSizePositions => _WindowSizePositions ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _FontName = IsDesktopPlatform ? GetProperty(defaultValue: "Default", autoSave: true) : null; + readonly static SerializableProperty? _FontName = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: "Default", autoSave: true) : null; /// /// 字体 /// @@ -35,7 +35,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty FontName => _FontName ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _AcrylicOpacity = IsDesktopPlatform ? GetProperty(defaultValue: .8, autoSave: true) : null; + readonly static SerializableProperty? _AcrylicOpacity = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: .8, autoSave: true) : null; /// /// 窗口背景透明度 /// @@ -44,7 +44,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty AcrylicOpacity => _AcrylicOpacity ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _WindowBackgroundMateria = IsDesktopPlatform ? GetProperty(defaultValue: OperatingSystem2.IsWindows11AtLeast ? 4 : 3, autoSave: true) : null; + readonly static SerializableProperty? _WindowBackgroundMateria = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: OperatingSystem2.IsWindows11AtLeast ? 4 : 3, autoSave: true) : null; /// /// 窗口背景材质 /// @@ -53,7 +53,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty WindowBackgroundMateria => _WindowBackgroundMateria ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _AppGridSize = IsDesktopPlatform ? GetProperty(defaultValue: 150, autoSave: true) : null; + readonly static SerializableProperty? _AppGridSize = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: 150, autoSave: true) : null; /// /// 库存游戏封面大小 /// @@ -62,7 +62,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty AppGridSize => _AppGridSize ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _SteamAccountRemarkReplaceName = IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; + readonly static SerializableProperty? _SteamAccountRemarkReplaceName = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; /// /// Steam账号备注替换名称显示 /// @@ -71,7 +71,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty SteamAccountRemarkReplaceName => _SteamAccountRemarkReplaceName ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _EnableFilletUI = IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; + readonly static SerializableProperty? _EnableFilletUI = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; /// /// 启用圆角界面 /// @@ -80,7 +80,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty EnableFilletUI => _EnableFilletUI ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _EnableDesktopBackground = IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; + readonly static SerializableProperty? _EnableDesktopBackground = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; /// /// 启用动态桌面背景 /// @@ -90,7 +90,7 @@ namespace System.Application.Settings public static SerializableProperty EnableDesktopBackground => _EnableDesktopBackground ?? throw new PlatformNotSupportedException(); readonly static SerializableProperty? _EnableCustomBackgroundImage - = IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; + = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; /// /// 启用自定义背景图片 /// @@ -99,7 +99,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty EnableCustomBackgroundImage => _EnableCustomBackgroundImage ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _BackgroundImagePath = IsDesktopPlatform ? GetProperty(defaultValue: "avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/Placeholders/0.png", autoSave: true) : null; + readonly static SerializableProperty? _BackgroundImagePath = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: "avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/Placeholders/0.png", autoSave: true) : null; /// /// 背景图片路径 /// @@ -108,7 +108,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty BackgroundImagePath => _BackgroundImagePath ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _ThemeAccent = IsDesktopPlatform ? GetProperty(defaultValue: "#FF0078D7", autoSave: true) : null; + readonly static SerializableProperty? _ThemeAccent = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: "#FF0078D7", autoSave: true) : null; /// /// 主题颜色(十六进制字符串) /// @@ -117,7 +117,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty ThemeAccent => _ThemeAccent ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _GetUserThemeAccent = IsDesktopPlatform ? GetProperty(defaultValue: true, autoSave: true) : null; + readonly static SerializableProperty? _GetUserThemeAccent = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: true, autoSave: true) : null; /// /// 主题颜色从系统获取 /// @@ -126,7 +126,7 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty GetUserThemeAccent => _GetUserThemeAccent ?? throw new PlatformNotSupportedException(); - readonly static SerializableProperty? _MainMenuExpandedState = IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; + readonly static SerializableProperty? _MainMenuExpandedState = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; /// /// 主菜单展开状态 /// diff --git a/src/ST.Client/UI/IApplication.cs b/src/ST.Client/UI/IApplication.cs index 38dd8784e..2010273d7 100644 --- a/src/ST.Client/UI/IApplication.cs +++ b/src/ST.Client/UI/IApplication.cs @@ -12,6 +12,11 @@ namespace System.Application.UI /// public partial interface IApplication { + /// + /// IsWindows or IsMacOS or (IsLinux and !IsAndroid) + /// + public static readonly bool IsDesktopPlatform = OperatingSystem2.IsWindows || OperatingSystem2.IsMacOS || (OperatingSystem2.IsLinux && !OperatingSystem2.IsAndroid); + static IApplication Instance => DI.Get(); /// diff --git a/src/ST.Client/UI/ViewModels/Base/IViewModelBase.cs b/src/ST.Client/UI/ViewModels/Base/IViewModelBase.cs index 3dcb7236a..afc9ef6f4 100644 --- a/src/ST.Client/UI/ViewModels/Base/IViewModelBase.cs +++ b/src/ST.Client/UI/ViewModels/Base/IViewModelBase.cs @@ -19,11 +19,13 @@ namespace System.Application.UI.ViewModels /// /// 是否在设计器的上下文中运行 /// - public static bool IsInDesignMode { protected get; set; } = true; + public static bool IsInDesignMode { protected get; set; } + = IApplication.IsDesktopPlatform; /// /// 是否使用移动端布局 /// public static bool IsMobileLayout { protected get; set; } + = !IApplication.IsDesktopPlatform; } } diff --git a/src/ST.Client/UI/ViewModels/Base/IWindowViewModel.cs b/src/ST.Client/UI/ViewModels/Base/IWindowViewModel.cs index af9fc8e43..67ffdca7a 100644 --- a/src/ST.Client/UI/ViewModels/Base/IWindowViewModel.cs +++ b/src/ST.Client/UI/ViewModels/Base/IWindowViewModel.cs @@ -10,6 +10,7 @@ namespace System.Application.UI.ViewModels /// /// 是否支持窗口大小与位置 /// - public static bool IsSupportedSizePosition { protected get; set; } = true; + public static bool IsSupportedSizePosition { protected get; set; } + = IApplication.IsDesktopPlatform; } }