mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
add notifyicon setting
This commit is contained in:
@@ -59,7 +59,7 @@ public sealed partial class App : Application
|
||||
|
||||
public new void Exit()
|
||||
{
|
||||
XamlWindowLifetime.IsApplicationExiting = true;
|
||||
XamlWindowLifetime.ApplicationExiting = true;
|
||||
base.Exit();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Core.LifeCycle.InterProcess;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Core.Shell;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.Core.Windowing.HotKey;
|
||||
using Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
using Snap.Hutao.Service;
|
||||
using Snap.Hutao.Service.DailyNote;
|
||||
using Snap.Hutao.Service.Discord;
|
||||
using Snap.Hutao.Service.Hutao;
|
||||
@@ -64,8 +66,9 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
|
||||
ToastNotificationManagerCompat.OnActivated += NotificationActivate;
|
||||
|
||||
serviceProvider.GetRequiredService<HotKeyOptions>().RegisterAll();
|
||||
if (LocalSetting.Get(SettingKeys.IsNotifyIconEnabled, true))
|
||||
if (serviceProvider.GetRequiredService<AppOptions>().IsNotifyIconEnabled)
|
||||
{
|
||||
XamlWindowLifetime.ApplicationLaunchedWithNotifyIcon = true;
|
||||
serviceProvider.GetRequiredService<App>().DispatcherShutdownMode = DispatcherShutdownMode.OnExplicitShutdown;
|
||||
_ = serviceProvider.GetRequiredService<NotifyIconController>();
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ internal static class SettingKeys
|
||||
public const string StaticResourceImageArchive = "StaticResourceImageArchive";
|
||||
public const string HotKeyMouseClickRepeatForever = "HotKeyMouseClickRepeatForever";
|
||||
public const string IsAllocConsoleDebugModeEnabled = "IsAllocConsoleDebugModeEnabled2";
|
||||
public const string IsNotifyIconEnabled = "IsNotifyIconEnabled";
|
||||
#endregion
|
||||
|
||||
#region Passport
|
||||
|
||||
@@ -97,7 +97,7 @@ internal sealed class XamlWindowController
|
||||
|
||||
private void OnWindowClosed(object sender, WindowEventArgs args)
|
||||
{
|
||||
if (LocalSetting.Get(SettingKeys.IsNotifyIconEnabled, true) && !XamlWindowLifetime.IsApplicationExiting)
|
||||
if (XamlWindowLifetime.ApplicationLaunchedWithNotifyIcon && !XamlWindowLifetime.ApplicationExiting)
|
||||
{
|
||||
args.Handled = true;
|
||||
window.Hide();
|
||||
|
||||
@@ -5,5 +5,7 @@ namespace Snap.Hutao.Core.Windowing;
|
||||
|
||||
internal static class XamlWindowLifetime
|
||||
{
|
||||
public static bool IsApplicationExiting { get; set; }
|
||||
public static bool ApplicationLaunchedWithNotifyIcon { get; set; }
|
||||
|
||||
public static bool ApplicationExiting { get; set; }
|
||||
}
|
||||
@@ -96,7 +96,7 @@ internal sealed class XamlWindowSubclass : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
if (XamlWindowLifetime.IsApplicationExiting)
|
||||
if (XamlWindowLifetime.ApplicationExiting)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ internal sealed partial class SettingEntry
|
||||
public const string GamePathEntries = "GamePathEntries";
|
||||
public const string Culture = "Culture";
|
||||
|
||||
public const string IsNotifyIconEnabled = "IsNotifyIconEnabled";
|
||||
public const string SystemBackdropType = "SystemBackdropType";
|
||||
public const string ElementTheme = "ElementTheme";
|
||||
public const string BackgroundImageType = "BackgroundImageType";
|
||||
|
||||
@@ -2663,6 +2663,12 @@
|
||||
<data name="ViewPageSettingKeyShortcutHeader" xml:space="preserve">
|
||||
<value>快捷键</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingNotifyIconDescription" xml:space="preserve">
|
||||
<value>在通知区域显示图标,以允许执行后台任务,重启后生效</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingNotifyIconHeader" xml:space="preserve">
|
||||
<value>通知区域图标</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingOfficialSiteNavigate" xml:space="preserve">
|
||||
<value>前往官网</value>
|
||||
</data>
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Snap.Hutao.Service;
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class AppOptions : DbStoreOptions
|
||||
{
|
||||
private bool? isNotifyIconEnabled;
|
||||
private bool? isEmptyHistoryWishVisible;
|
||||
private bool? isUnobtainedWishItemVisible;
|
||||
private BackdropType? backdropType;
|
||||
@@ -23,6 +24,12 @@ internal sealed partial class AppOptions : DbStoreOptions
|
||||
private Region? region;
|
||||
private string? geetestCustomCompositeUrl;
|
||||
|
||||
public bool IsNotifyIconEnabled
|
||||
{
|
||||
get => GetOption(ref isNotifyIconEnabled, SettingEntry.IsNotifyIconEnabled, true);
|
||||
set => SetOption(ref isNotifyIconEnabled, SettingEntry.IsNotifyIconEnabled, value);
|
||||
}
|
||||
|
||||
public bool IsEmptyHistoryWishVisible
|
||||
{
|
||||
get => GetOption(ref isEmptyHistoryWishVisible, SettingEntry.IsEmptyHistoryWishVisible, false);
|
||||
|
||||
@@ -348,6 +348,12 @@
|
||||
<cwc:SettingsCard Header="{shcm:ResourceString Name=ViewPageSettingBackgroundImageLocalFolderCopyrightHeader}" Visibility="{Binding BackgroundImageOptions.Wallpaper, Converter={StaticResource EmptyObjectToBoolRevertConverter}}"/>
|
||||
</cwc:SettingsExpander.Items>
|
||||
</cwc:SettingsExpander>
|
||||
<cwc:SettingsCard
|
||||
Description="{shcm:ResourceString Name=ViewPageSettingNotifyIconDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageSettingNotifyIconHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
<ToggleSwitch IsOn="{Binding AppOptions.IsNotifyIconEnabled, Mode=TwoWay}"/>
|
||||
</cwc:SettingsCard>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Border>
|
||||
|
||||
Reference in New Issue
Block a user