diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia.App/App.axaml.cs b/System.Application.SteamTools.Client.Desktop.Avalonia.App/App.axaml.cs index 31636f886..a55b039b8 100644 --- a/System.Application.SteamTools.Client.Desktop.Avalonia.App/App.axaml.cs +++ b/System.Application.SteamTools.Client.Desktop.Avalonia.App/App.axaml.cs @@ -16,7 +16,9 @@ using Window = Avalonia.Controls.Window; using WindowState = Avalonia.Controls.WindowState; using Avalonia.Themes.Fluent; using Avalonia.Markup.Xaml.Styling; - +using System.Application.Services; +using System.Windows.Input; +using System.Linq; #if WINDOWS using System.Windows.Shell; using WpfApplication = System.Windows.Application; @@ -24,18 +26,50 @@ using WpfApplication = System.Windows.Application; namespace System.Application.UI { - public partial class App : AvaloniaApplication, IDisposableHolder + public partial class App : AvaloniaApplication, IDisposableHolder, IDesktopAppService { public static App Instance => Current is App app ? app : throw new Exception("Impossible"); - [Obsolete("use IOPath.AppDataDirectory", true)] - public DirectoryInfo LocalAppData => new DirectoryInfo(IOPath.AppDataDirectory); - public static DirectoryInfo RootDirectory => new DirectoryInfo(AppContext.BaseDirectory); + [Obsolete("use IOPath.AppDataDirectory", true)] + public DirectoryInfo LocalAppData => new(IOPath.AppDataDirectory); + + public static DirectoryInfo RootDirectory => new(AppContext.BaseDirectory); [Obsolete("use AppHelper.ProgramName", true)] public string ProgramName => AppHelper.ProgramName; - public FluentTheme? fluentTheme; + bool mTheme; + + public bool Theme + { + get + { + return mTheme; + } + set + { + if (value == mTheme) return; + + var mode = value ? FluentThemeMode.Light : FluentThemeMode.Dark; + var uri_0 = new Uri($"avares://Avalonia.Themes.Fluent/Fluent{(value ? "Light" : "Dark")}.xaml"); + var uri_1 = new Uri($"avares://System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/Styles/Theme{(value ? "Light" : "Dark")}.xaml"); + + Styles[0] = new FluentTheme(uri_0) + { + Mode = mode + }; + Styles[1] = new StyleInclude(uri_1) + { + Source = uri_1, + }; + + mTheme = value; + } + } + + readonly Dictionary mNotifyIconMenus = new(); + + public IReadOnlyDictionary NotifyIconMenus => mNotifyIconMenus; public override void Initialize() { @@ -90,39 +124,25 @@ namespace System.Application.UI }; NotifyIconContextMenu = new ContextMenu(); - var menuItems = new List + + mNotifyIconMenus.Add("Light", ReactiveCommand.Create(() => { - new MenuItem() - { - Header = "Light", - Command = ReactiveCommand.Create(()=>{ - Styles[0] = new FluentTheme(new Uri("avares://Avalonia.Themes.Fluent/FluentLight.xaml")) - { Mode= FluentThemeMode.Light }; - var uri = new Uri("avares://System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/Styles/ThemeLight.xaml"); - Styles[1] = new StyleInclude(uri){ Source = uri }; - }) - }, - new MenuItem() - { - Header = "Dark", - Command = ReactiveCommand.Create(()=>{ - Styles[0] = new FluentTheme(new Uri("avares://Avalonia.Themes.Fluent/FluentDark.xaml")){ Mode= FluentThemeMode.Dark }; - var uri = new Uri("avares://System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/Styles/ThemeDark.xaml"); - Styles[1] = new StyleInclude(uri){ Source = uri }; - }) - }, - new MenuItem() - { - Header = "NotifyIconContextMenuItemHeaderRestore", - Command = ReactiveCommand.Create(RestoreMainWindow) - }, - new MenuItem() - { - Header = "NotifyIconContextMenuItemHeaderExit", - Command = ReactiveCommand.Create(Shutdown) - } - }; - NotifyIconContextMenu.Items = menuItems; + Theme = true; + })); + + mNotifyIconMenus.Add("Dark", ReactiveCommand.Create(() => + { + Theme = false; + })); + + mNotifyIconMenus.Add("Show", + ReactiveCommand.Create(RestoreMainWindow)); + + mNotifyIconMenus.Add("Exit", + ReactiveCommand.Create(Shutdown)); + + NotifyIconContextMenu.Items = mNotifyIconMenus + .Select(x => new MenuItem { Header = x.Key, Command = x.Value }).ToList(); notifyIcon.ContextMenu = NotifyIconContextMenu; notifyIcon.Visible = true; notifyIcon.Click += NotifyIcon_Click; @@ -168,7 +188,6 @@ namespace System.Application.UI public Window? MainWindow { get; set; } - /// /// Restores the app's main window by setting its WindowState to /// WindowState.Normal and showing the window. @@ -209,9 +228,11 @@ namespace System.Application.UI } } + void IDesktopAppService.Shutdown() => Shutdown(); + #region IDisposable members - public readonly CompositeDisposable compositeDisposable = new CompositeDisposable(); + public readonly CompositeDisposable compositeDisposable = new(); ICollection IDisposableHolder.CompositeDisposable => compositeDisposable; diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Migrations.cs b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Migrations.cs new file mode 100644 index 000000000..f6bf882b3 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Migrations.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace System.Application.UI +{ + /// + /// 迁移 + /// + public static class Migrations + { + /// + /// 从 V1 版本 迁移配置文件等信息 + /// + public static void FromV1() + { + // 将以前的配置读取,存储到新的格式 + // 删除以前的配置文件 + } + } +} diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Program.cs b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Program.cs index 2ca64db37..550d89773 100644 --- a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Program.cs +++ b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Program.cs @@ -26,6 +26,7 @@ namespace System.Application.UI var logger = LogManager.GetCurrentClassLogger(); try { + Migrations.FromV1(); Startup.Init(); #if WINDOWS var app = new WpfApp(); diff --git a/System.Application.SteamTools.Client.Desktop/Migrations.cs b/System.Application.SteamTools.Client.Desktop/Migrations.cs new file mode 100644 index 000000000..f653a0cb0 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop/Migrations.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace System.Application +{ + /// + /// 迁移 + /// + public static class Migrations + { + /// + /// 从 V1 版本 迁移配置文件等信息 + /// + public static void FromV1() + { + // 将以前的配置读取,存储到新的格式 + // 删除以前的配置文件 + } + } +} diff --git a/System.Application.SteamTools.Client.Desktop/Services/IDesktopAppService.cs b/System.Application.SteamTools.Client.Desktop/Services/IDesktopAppService.cs new file mode 100644 index 000000000..09396f91f --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop/Services/IDesktopAppService.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.Windows.Input; + +namespace System.Application.Services +{ + public interface IDesktopAppService + { + /// + /// 当前桌面应用的主题 + /// Light + /// Dark + /// + bool Theme { get; set; } + + /// + /// 退出整个程序 + /// + void Shutdown(); + + /// + /// 主窗口恢复显示 + /// + void RestoreMainWindow(); + + /// + /// 托盘菜单 + /// + IReadOnlyDictionary NotifyIconMenus { get; } + } +} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop/UI/AppHelper.cs b/System.Application.SteamTools.Client.Desktop/UI/AppHelper.cs index c72b1b2cb..264f31684 100644 --- a/System.Application.SteamTools.Client.Desktop/UI/AppHelper.cs +++ b/System.Application.SteamTools.Client.Desktop/UI/AppHelper.cs @@ -146,6 +146,8 @@ namespace System.Application.UI } } + public static IDesktopAppService Current => DI.Get(); + #if DEBUG [Obsolete("use EnableLogger", true)] diff --git a/System.Application.SteamTools.Services.CloudService.Models/Models/ApiResponseCode.cs b/System.Application.SteamTools.Services.CloudService.Models/Models/ApiResponseCode.cs index 1f0436fb1..156e26588 100644 --- a/System.Application.SteamTools.Services.CloudService.Models/Models/ApiResponseCode.cs +++ b/System.Application.SteamTools.Services.CloudService.Models/Models/ApiResponseCode.cs @@ -21,6 +21,8 @@ namespace System.Application.Models BadRequest = HttpStatusCode.BadRequest, + InternalServerError = HttpStatusCode.InternalServerError, + #endregion #region CustomCode 自定义响应码,1000~? diff --git a/System.Application.SteamTools/ModelValidatorProvider.cs b/System.Application.SteamTools/ModelValidatorProvider.cs index 364e19628..cef3aa442 100644 --- a/System.Application.SteamTools/ModelValidatorProvider.cs +++ b/System.Application.SteamTools/ModelValidatorProvider.cs @@ -171,6 +171,10 @@ namespace System.Application public const string 当前手机号今日发送短信数量超过最大上限 = "验证码获取次数达到今日上限了哦,明天再试试吧"; public const string 短信服务故障 = "服务器错误【5001】"; + + public const string 验证码已过期或不存在 = "验证码已过期或不存在"; + + public const string 验证码不正确 = "验证码不正确"; } public static class Lengths diff --git a/System.Application.SteamTools/SmsCodeType.cs b/System.Application.SteamTools/SmsCodeType.cs index 87a46c111..b0d34753f 100644 --- a/System.Application.SteamTools/SmsCodeType.cs +++ b/System.Application.SteamTools/SmsCodeType.cs @@ -8,13 +8,11 @@ /// /// [通过手机号码注册账号]用于注册 /// - [Obsolete("register has been deprecated")] Register = 200, /// /// [通过手机号码重设密码]找回密码 /// - [Obsolete("password has been deprecated")] ForgotPassword = 201, /// @@ -35,7 +33,6 @@ /// /// [通过手机号码]登录 /// - [Obsolete("login has been deprecated")] Login = 205, } } \ No newline at end of file