diff --git a/assets/translations/en-US.json b/assets/translations/en-US.json index 1445db5..5b93532 100644 --- a/assets/translations/en-US.json +++ b/assets/translations/en-US.json @@ -719,6 +719,7 @@ "stickersNewDescription": "Create a new sticker belongs to this pack.", "stickersPackNew": "New Sticker Pack", "trayMenuShow": "Show", + "trayMenuMuteNotification": "Do Not Disturb", "update": "Update", "forceUpdate": "Force Update", "forceUpdateDescription": "Force to show the application update popup, even the new version is not available." diff --git a/assets/translations/zh-CN.json b/assets/translations/zh-CN.json index e15adaf..842807d 100644 --- a/assets/translations/zh-CN.json +++ b/assets/translations/zh-CN.json @@ -717,6 +717,7 @@ "stickersNewDescription": "创建一个新的贴图。", "stickersPackNew": "新建贴图包", "trayMenuShow": "显示", + "trayMenuMuteNotification": "静音通知", "update": "更新", "forceUpdate": "强制更新", "forceUpdateDescription": "强制更新应用程序,即使有更新的版本可能不可用。" diff --git a/assets/translations/zh-HK.json b/assets/translations/zh-HK.json index cf2c494..8e16d03 100644 --- a/assets/translations/zh-HK.json +++ b/assets/translations/zh-HK.json @@ -717,6 +717,7 @@ "stickersNewDescription": "創建一個新的貼圖。", "stickersPackNew": "新建貼圖包", "trayMenuShow": "顯示", + "trayMenuMuteNotification": "靜音通知", "update": "更新", "forceUpdate": "強制更新", "forceUpdateDescription": "強制更新應用程序,即使有更新的版本可能不可用。" diff --git a/assets/translations/zh-TW.json b/assets/translations/zh-TW.json index b3e8ccf..7ac3e25 100644 --- a/assets/translations/zh-TW.json +++ b/assets/translations/zh-TW.json @@ -717,6 +717,7 @@ "stickersNewDescription": "創建一個新的貼圖。", "stickersPackNew": "新建貼圖包", "trayMenuShow": "顯示", + "trayMenuMuteNotification": "靜音通知", "update": "更新", "forceUpdate": "強制更新", "forceUpdateDescription": "強制更新應用程序,即使有更新的版本可能不可用。" diff --git a/lib/main.dart b/lib/main.dart index e025f6a..0a5467c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -333,6 +333,31 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { } } + final Menu _appTrayMenu = Menu( + items: [ + MenuItem( + key: 'version_label', + label: 'Solian', + disabled: true, + ), + MenuItem.separator(), + MenuItem.checkbox( + checked: false, + key: 'mute_notification', + label: 'trayMenuMuteNotification'.tr(), + ), + MenuItem.separator(), + MenuItem( + key: 'window_show', + label: 'trayMenuShow'.tr(), + ), + MenuItem( + key: 'exit', + label: 'trayMenuExit'.tr(), + ), + ], + ); + Future _trayInitialization() async { if (kIsWeb || Platform.isAndroid || Platform.isIOS) return; @@ -344,25 +369,13 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { trayManager.addListener(this); await trayManager.setIcon(icon); - Menu menu = Menu( - items: [ - MenuItem( - key: 'version_label', - label: 'Solian ${appVersion.version}+${appVersion.buildNumber}', - disabled: true, - ), - MenuItem.separator(), - MenuItem( - key: 'window_show', - label: 'trayMenuShow'.tr(), - ), - MenuItem( - key: 'exit', - label: 'trayMenuExit'.tr(), - ), - ], + _appTrayMenu.items![0] = MenuItem( + key: 'version_label', + label: 'Solian ${appVersion.version}+${appVersion.buildNumber}', + disabled: true, ); - await trayManager.setContextMenu(menu); + + await trayManager.setContextMenu(_appTrayMenu); } Future _notifyInitialization() async { @@ -424,8 +437,15 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { @override void onTrayMenuItemClick(MenuItem menuItem) { switch (menuItem.key) { + case 'mute_notification': + final nty = context.read(); + nty.isMuted = !nty.isMuted; + _appTrayMenu.items![2].checked = nty.isMuted; + trayManager.setContextMenu(_appTrayMenu); + break; case 'window_show': - appWindow.show(); + // To prevent the window from being hide after just show on macOS + Timer(const Duration(milliseconds: 100), () => appWindow.show()); break; case 'exit': _appLifecycleListener?.dispose(); diff --git a/lib/providers/notification.dart b/lib/providers/notification.dart index 0dbe561..fa003d2 100644 --- a/lib/providers/notification.dart +++ b/lib/providers/notification.dart @@ -79,6 +79,7 @@ class NotificationProvider extends ChangeNotifier { List notifications = List.empty(growable: true); int? skippableNotifyChannel; + bool isMuted = false; void listen() { _ws.pk.stream.listen((event) { @@ -107,7 +108,7 @@ class NotificationProvider extends ChangeNotifier { notifyListeners(); updateTray(); - if (!kIsWeb) { + if (!kIsWeb && !isMuted) { if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { LocalNotification notify = LocalNotification( title: notification.title,