add notifyicon setting

This commit is contained in:
Lightczx
2024-05-21 15:27:10 +08:00
parent 8b9190d941
commit 1bf517f95d
10 changed files with 30 additions and 6 deletions

View File

@@ -59,7 +59,7 @@ public sealed partial class App : Application
public new void Exit()
{
XamlWindowLifetime.IsApplicationExiting = true;
XamlWindowLifetime.ApplicationExiting = true;
base.Exit();
}

View File

@@ -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>();
}

View File

@@ -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

View File

@@ -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();

View File

@@ -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; }
}

View File

@@ -96,7 +96,7 @@ internal sealed class XamlWindowSubclass : IDisposable
}
}
if (XamlWindowLifetime.IsApplicationExiting)
if (XamlWindowLifetime.ApplicationExiting)
{
return default;
}

View File

@@ -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";

View File

@@ -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>

View File

@@ -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);

View File

@@ -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=&#xE91C;}">
<ToggleSwitch IsOn="{Binding AppOptions.IsNotifyIconEnabled, Mode=TwoWay}"/>
</cwc:SettingsCard>
</StackPanel>
</Border>
</Border>