This commit is contained in:
Aigio Liu
2021-03-06 10:16:25 +08:00
parent df776eff06
commit 3cbcabeedf
9 changed files with 146 additions and 43 deletions
@@ -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<string, ICommand> mNotifyIconMenus = new();
public IReadOnlyDictionary<string, ICommand> NotifyIconMenus => mNotifyIconMenus;
public override void Initialize()
{
@@ -90,39 +124,25 @@ namespace System.Application.UI
};
NotifyIconContextMenu = new ContextMenu();
var menuItems = new List<MenuItem>
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; }
/// <summary>
/// Restores the app's main window by setting its <c>WindowState</c> to
/// <c>WindowState.Normal</c> 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<IDisposable> IDisposableHolder.CompositeDisposable => compositeDisposable;
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Application.UI
{
/// <summary>
/// 迁移
/// </summary>
public static class Migrations
{
/// <summary>
/// 从 V1 版本 迁移配置文件等信息
/// </summary>
public static void FromV1()
{
// 将以前的配置读取,存储到新的格式
// 删除以前的配置文件
}
}
}
@@ -26,6 +26,7 @@ namespace System.Application.UI
var logger = LogManager.GetCurrentClassLogger();
try
{
Migrations.FromV1();
Startup.Init();
#if WINDOWS
var app = new WpfApp();
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Application
{
/// <summary>
/// 迁移
/// </summary>
public static class Migrations
{
/// <summary>
/// 从 V1 版本 迁移配置文件等信息
/// </summary>
public static void FromV1()
{
// 将以前的配置读取,存储到新的格式
// 删除以前的配置文件
}
}
}
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Windows.Input;
namespace System.Application.Services
{
public interface IDesktopAppService
{
/// <summary>
/// 当前桌面应用的主题
/// <para><see langword="true"/> Light</para>
/// <para><see langword="false"/> Dark</para>
/// </summary>
bool Theme { get; set; }
/// <summary>
/// 退出整个程序
/// </summary>
void Shutdown();
/// <summary>
/// 主窗口恢复显示
/// </summary>
void RestoreMainWindow();
/// <summary>
/// 托盘菜单
/// </summary>
IReadOnlyDictionary<string, ICommand> NotifyIconMenus { get; }
}
}
@@ -146,6 +146,8 @@ namespace System.Application.UI
}
}
public static IDesktopAppService Current => DI.Get<IDesktopAppService>();
#if DEBUG
[Obsolete("use EnableLogger", true)]
@@ -21,6 +21,8 @@ namespace System.Application.Models
BadRequest = HttpStatusCode.BadRequest,
InternalServerError = HttpStatusCode.InternalServerError,
#endregion
#region CustomCode 自定义响应码,1000~?
@@ -171,6 +171,10 @@ namespace System.Application
public const string 当前手机号今日发送短信数量超过最大上限 = "验证码获取次数达到今日上限了哦,明天再试试吧";
public const string 短信服务故障 = "服务器错误【5001】";
public const string 验证码已过期或不存在 = "验证码已过期或不存在";
public const string 验证码不正确 = "验证码不正确";
}
public static class Lengths
@@ -8,13 +8,11 @@
/// <summary>
/// [通过手机号码注册账号]用于注册
/// </summary>
[Obsolete("register has been deprecated")]
Register = 200,
/// <summary>
/// [通过手机号码重设密码]找回密码
/// </summary>
[Obsolete("password has been deprecated")]
ForgotPassword = 201,
/// <summary>
@@ -35,7 +33,6 @@
/// <summary>
/// [通过手机号码]登录
/// </summary>
[Obsolete("login has been deprecated")]
Login = 205,
}
}