Skip to content

Commit

Permalink
feat(desktop): show minimized to system tray notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingkor Roy Tirtho committed Apr 27, 2023
1 parent 5536b95 commit 296f96c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 44 deletions.
13 changes: 10 additions & 3 deletions lib/components/shared/page_window_title_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import 'package:window_manager/window_manager.dart';
import 'dart:math';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'dart:io' show Platform;
import 'package:flutter_desktop_tools/flutter_desktop_tools.dart';

final closeNotification = DesktopTools.createNotification(
title: 'Spotube',
message: 'Running in background. Minimized to System Tray',
);

class PageWindowTitleBar extends StatefulHookWidget
implements PreferredSizeWidget {
Expand Down Expand Up @@ -101,11 +107,12 @@ class WindowTitleBarButtons extends HookConsumerWidget {
final isMaximized = useState<bool?>(null);
const type = ThemeType.auto;

void onClose() {
Future<void> onClose() async {
if (closeBehavior == CloseBehavior.close) {
windowManager.close();
await windowManager.close();
} else {
windowManager.hide();
await windowManager.hide();
await closeNotification?.show();
}
}

Expand Down
12 changes: 4 additions & 8 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

#include <audioplayers_linux/audioplayers_linux_plugin.h>
#include <catcher/catcher_plugin.h>
#include <desktop_multi_window/desktop_multi_window_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <native_context_menu/native_context_menu_plugin.h>
#include <local_notifier/local_notifier_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <system_theme/system_theme_plugin.h>
#include <system_tray/system_tray_plugin.h>
Expand All @@ -25,15 +24,12 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) catcher_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "CatcherPlugin");
catcher_plugin_register_with_registrar(catcher_registrar);
g_autoptr(FlPluginRegistrar) desktop_multi_window_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopMultiWindowPlugin");
desktop_multi_window_plugin_register_with_registrar(desktop_multi_window_registrar);
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
g_autoptr(FlPluginRegistrar) native_context_menu_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "NativeContextMenuPlugin");
native_context_menu_plugin_register_with_registrar(native_context_menu_registrar);
g_autoptr(FlPluginRegistrar) local_notifier_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "LocalNotifierPlugin");
local_notifier_plugin_register_with_registrar(local_notifier_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
Expand Down
3 changes: 1 addition & 2 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_linux
catcher
desktop_multi_window
flutter_secure_storage_linux
native_context_menu
local_notifier
screen_retriever
system_theme
system_tray
Expand Down
6 changes: 2 additions & 4 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import audio_service
import audio_session
import audioplayers_darwin
import catcher
import desktop_multi_window
import device_info_plus
import flutter_secure_storage_macos
import native_context_menu
import local_notifier
import package_info_plus
import path_provider_foundation
import screen_retriever
Expand All @@ -29,10 +28,9 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin"))
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
CatcherPlugin.register(with: registry.registrar(forPlugin: "CatcherPlugin"))
FlutterMultiWindowPlugin.register(with: registry.registrar(forPlugin: "FlutterMultiWindowPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
NativeContextMenuPlugin.register(with: registry.registrar(forPlugin: "NativeContextMenuPlugin"))
LocalNotifierPlugin.register(with: registry.registrar(forPlugin: "LocalNotifierPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
Expand Down
28 changes: 10 additions & 18 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -466,14 +466,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.8"
desktop_multi_window:
dependency: transitive
description:
name: desktop_multi_window
sha256: "29971186ae0790e32b156f127f9c22c5ee77bdb94b14f7cea23f2356d0c76cfc"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
device_info_plus:
dependency: transitive
description:
Expand Down Expand Up @@ -627,8 +619,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "3c07755ad33fb28a042da0ed26e31086ca318e21"
resolved-ref: "3c07755ad33fb28a042da0ed26e31086ca318e21"
ref: "1f0bec3283626dcbd8ee2f54e238d096d8dea50e"
resolved-ref: "1f0bec3283626dcbd8ee2f54e238d096d8dea50e"
url: "https://github.com/KRTirtho/flutter_desktop_tools.git"
source: git
version: "0.0.1"
Expand Down Expand Up @@ -1001,6 +993,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
local_notifier:
dependency: transitive
description:
name: local_notifier
sha256: cc855aa6362c8840e3d3b35b1c3b058a3a8becdb2b03d5a9aa3f3a1e861f0a03
url: "https://pub.dev"
source: hosted
version: "0.1.5"
logger:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1073,14 +1073,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.1"
native_context_menu:
dependency: transitive
description:
name: native_context_menu
sha256: "566f13d1f55e57bc8aca3b71b157b1ff03c2cc3821f6e9d980f76233ed30c9b7"
url: "https://pub.dev"
source: hosted
version: "0.2.2+5"
oauth2:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dependencies:
flutter_desktop_tools:
git:
url: https://github.com/KRTirtho/flutter_desktop_tools.git
ref: 3c07755ad33fb28a042da0ed26e31086ca318e21
ref: 1f0bec3283626dcbd8ee2f54e238d096d8dea50e
smtc_windows:
git:
url: https://github.com/KRTirtho/smtc_windows.git
Expand Down
9 changes: 3 additions & 6 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

#include <audioplayers_windows/audioplayers_windows_plugin.h>
#include <catcher/catcher_plugin.h>
#include <desktop_multi_window/desktop_multi_window_plugin.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <native_context_menu/native_context_menu_plugin.h>
#include <local_notifier/local_notifier_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <system_theme/system_theme_plugin.h>
Expand All @@ -24,12 +23,10 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
CatcherPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("CatcherPlugin"));
DesktopMultiWindowPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DesktopMultiWindowPlugin"));
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
NativeContextMenuPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("NativeContextMenuPlugin"));
LocalNotifierPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("LocalNotifierPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
Expand Down
3 changes: 1 addition & 2 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_windows
catcher
desktop_multi_window
flutter_secure_storage_windows
native_context_menu
local_notifier
permission_handler_windows
screen_retriever
system_theme
Expand Down

0 comments on commit 296f96c

Please sign in to comment.