From 112a06f92a95164d9062120ad4de7804435fc6e9 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Wed, 15 Oct 2025 19:16:20 +0800 Subject: [PATCH] custom show tray icon Closes #1569 Signed-off-by: bggRGjQaUbCoE --- lib/pages/main/controller.dart | 1 + lib/pages/main/view.dart | 8 +++++--- lib/pages/setting/models/style_settings.dart | 11 ++++++++++- lib/utils/storage_key.dart | 3 ++- lib/utils/storage_pref.dart | 3 +++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/pages/main/controller.dart b/lib/pages/main/controller.dart index a677d95b..bc6cc4f6 100644 --- a/lib/pages/main/controller.dart +++ b/lib/pages/main/controller.dart @@ -58,6 +58,7 @@ class MainController extends GetxController late final optTabletNav = Pref.optTabletNav; late bool directExitOnBack = Pref.directExitOnBack; + late bool showTrayIcon = Pref.showTrayIcon; late bool minimizeOnExit = Pref.minimizeOnExit; late bool pauseOnMinimize = Pref.pauseOnMinimize; late bool isPlaying = false; diff --git a/lib/pages/main/view.dart b/lib/pages/main/view.dart index 146672f0..c61dd213 100644 --- a/lib/pages/main/view.dart +++ b/lib/pages/main/view.dart @@ -45,8 +45,10 @@ class _MainAppState extends State windowManager ..addListener(this) ..setPreventClose(true); - trayManager.addListener(this); - _handleTray(); + if (_mainController.showTrayIcon) { + trayManager.addListener(this); + _handleTray(); + } } } @@ -131,7 +133,7 @@ class _MainAppState extends State @override void onWindowClose() { - if (_mainController.minimizeOnExit) { + if (_mainController.showTrayIcon && _mainController.minimizeOnExit) { windowManager.hide(); _onHideWindow(); } else { diff --git a/lib/pages/setting/models/style_settings.dart b/lib/pages/setting/models/style_settings.dart index 69c2b1ac..ebe5e5e5 100644 --- a/lib/pages/setting/models/style_settings.dart +++ b/lib/pages/setting/models/style_settings.dart @@ -36,7 +36,7 @@ import 'package:get/get.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; List get styleSettings => [ - if (Utils.isDesktop) + if (Utils.isDesktop) ...[ const SettingsModel( settingsType: SettingsType.sw1tch, title: '显示窗口标题栏', @@ -45,6 +45,15 @@ List get styleSettings => [ defaultVal: true, needReboot: true, ), + const SettingsModel( + settingsType: SettingsType.sw1tch, + title: '显示托盘图标', + leading: Icon(Icons.donut_large_rounded), + setKey: SettingBoxKey.showTrayIcon, + defaultVal: true, + needReboot: true, + ), + ], SettingsModel( settingsType: SettingsType.sw1tch, title: '横屏适配', diff --git a/lib/utils/storage_key.dart b/lib/utils/storage_key.dart index 483d0d14..cfefad93 100644 --- a/lib/utils/storage_key.dart +++ b/lib/utils/storage_key.dart @@ -149,7 +149,8 @@ abstract class SettingBoxKey { windowPosition = 'windowPosition', isWindowMaximized = 'isWindowMaximized', showWindowTitleBar = 'showWindowTitleBar', - desktopVolume = 'desktopVolume'; + desktopVolume = 'desktopVolume', + showTrayIcon = 'showTrayIcon'; static const String subtitlePreferenceV2 = 'subtitlePreferenceV2', enableDragSubtitle = 'enableDragSubtitle', diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index dbf9f1e2..5d11c93c 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -861,4 +861,7 @@ abstract class Pref { static bool get enableTapDm => _setting.get(SettingBoxKey.enableTapDm, defaultValue: true); + + static bool get showTrayIcon => + _setting.get(SettingBoxKey.showTrayIcon, defaultValue: true); }