Skip to content

An open-source cross-platform alternative to AirDrop

Linux: Use tray_manager instead of system_tray; remove system_tray (#1255)

ix5f45c5c9598f1
diff --git a/app/lib/util/native/tray_helper.dart b/app/lib/util/native/tray_helper.dart
index 52c468dd..269c6d5a 100644
--- a/app/lib/util/native/tray_helper.dart
+++ b/app/lib/util/native/tray_helper.dart
@@ -1,4 +1,3 @@
-import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:localsend_app/gen/assets.gen.dart';
import 'package:localsend_app/gen/strings.g.dart';
@@ -6,7 +5,6 @@ import 'package:localsend_app/provider/animation_provider.dart';
import 'package:localsend_app/util/native/platform_check.dart';
import 'package:logging/logging.dart';
import 'package:refena_flutter/refena_flutter.dart';
-import 'package:system_tray/system_tray.dart';
import 'package:tray_manager/tray_manager.dart' as tm;
import 'package:window_manager/window_manager.dart';
@@ -21,63 +19,35 @@ Future<void> initTray() async {
if (!checkPlatformHasTray()) {
return;
}
- if (!checkPlatform([TargetPlatform.linux])) {
- try {
- if (checkPlatform([TargetPlatform.windows])) {
- await tm.trayManager.setIcon(
- Assets.img.logo,
- );
- } else if (checkPlatform([TargetPlatform.macOS])) {
- await tm.trayManager.setIcon(Assets.img.logo32Black.path, isTemplate: true);
- } else {
- await tm.trayManager.setIcon(Assets.img.logo32.path);
- }
-
- final items = [
- tm.MenuItem(
- key: TrayEntry.open.name,
- label: t.tray.open,
- ),
- tm.MenuItem(
- key: TrayEntry.close.name,
- label: t.tray.close,
- ),
- ];
- await tm.trayManager.setContextMenu(tm.Menu(items: items));
- await tm.trayManager.setToolTip(t.appName);
- } catch (e) {
- _logger.warning('Failed to init tray', e);
+ try {
+ if (checkPlatform([TargetPlatform.windows])) {
+ await tm.trayManager.setIcon(Assets.img.logo);
+ } else if (checkPlatform([TargetPlatform.macOS])) {
+ await tm.trayManager.setIcon(Assets.img.logo32Black.path, isTemplate: true);
+ } else if (checkPlatform([TargetPlatform.linux])) {
+ await tm.trayManager.setIcon(Assets.img.logo32White.path);
+ } else {
+ await tm.trayManager.setIcon(Assets.img.logo32.path);
}
- } else {
- // The Linux tray display is handled by systemTray instead
- final SystemTray systemTray = SystemTray();
- await systemTray.initSystemTray(
- title: t.appName,
- iconPath: Assets.img.logo32White.path,
- );
-
- final Menu menu = Menu();
- await menu.buildFrom([
- MenuItemLabel(
+ final items = [
+ tm.MenuItem(
+ key: TrayEntry.open.name,
label: t.tray.open,
- onClicked: (menuItem) async {
- await windowManager.show();
- await windowManager.focus();
- },
),
- MenuItemLabel(label: t.tray.close, onClicked: (menuItem) => exit(0)),
- ]);
-
- await systemTray.setContextMenu(menu);
-
- systemTray.registerSystemTrayEventHandler((eventName) {
- if (eventName == kSystemTrayEventClick) {
- systemTray.popUpContextMenu();
- } else if (eventName == kSystemTrayEventRightClick) {
- WindowManager.instance.show();
- }
- });
+ tm.MenuItem(
+ key: TrayEntry.close.name,
+ label: t.tray.close,
+ ),
+ ];
+ await tm.trayManager.setContextMenu(tm.Menu(items: items));
+ // No Linux implementation for setToolTip available as of tray_manager 0.2.2
+ // https://pub.dev/packages/tray_manager#api
+ if (!checkPlatform([TargetPlatform.linux])) {
+ await tm.trayManager.setToolTip(t.appName);
+ }
+ } catch (e) {
+ _logger.warning('Failed to init tray', e);
}
}
diff --git a/app/linux/flutter/generated_plugin_registrant.cc b/app/linux/flutter/generated_plugin_registrant.cc
index 999deafd..a3c82ca8 100644
--- a/app/linux/flutter/generated_plugin_registrant.cc
+++ b/app/linux/flutter/generated_plugin_registrant.cc
@@ -12,7 +12,7 @@
#include <gtk/gtk_plugin.h>
#include <pasteboard/pasteboard_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
-#include <system_tray/system_tray_plugin.h>
+#include <tray_manager/tray_manager_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>
@@ -35,9 +35,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
- g_autoptr(FlPluginRegistrar) system_tray_registrar =
- fl_plugin_registry_get_registrar_for_plugin(registry, "SystemTrayPlugin");
- system_tray_plugin_register_with_registrar(system_tray_registrar);
+ g_autoptr(FlPluginRegistrar) tray_manager_registrar =
+ fl_plugin_registry_get_registrar_for_plugin(registry, "TrayManagerPlugin");
+ tray_manager_plugin_register_with_registrar(tray_manager_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
diff --git a/app/linux/flutter/generated_plugins.cmake b/app/linux/flutter/generated_plugins.cmake
index bf78cd7d..40adb2d3 100644
--- a/app/linux/flutter/generated_plugins.cmake
+++ b/app/linux/flutter/generated_plugins.cmake
@@ -9,7 +9,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
gtk
pasteboard
screen_retriever
- system_tray
+ tray_manager
url_launcher_linux
window_manager
)
diff --git a/app/macos/Flutter/GeneratedPluginRegistrant.swift b/app/macos/Flutter/GeneratedPluginRegistrant.swift
index 793aa288..0d3bb344 100644
--- a/app/macos/Flutter/GeneratedPluginRegistrant.swift
+++ b/app/macos/Flutter/GeneratedPluginRegistrant.swift
@@ -12,6 +12,7 @@ import dynamic_color
import file_selector_macos
import gal
import in_app_purchase_storekit
+import macos_dock_progress
import network_info_plus
import package_info_plus
import pasteboard
@@ -19,7 +20,6 @@ import path_provider_foundation
import photo_manager
import screen_retriever
import shared_preferences_foundation
-import system_tray
import tray_manager
import url_launcher_macos
import video_player_avfoundation
@@ -34,6 +34,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
GalPlugin.register(with: registry.registrar(forPlugin: "GalPlugin"))
InAppPurchasePlugin.register(with: registry.registrar(forPlugin: "InAppPurchasePlugin"))
+ MacosDockProgressPlugin.register(with: registry.registrar(forPlugin: "MacosDockProgressPlugin"))
NetworkInfoPlusPlugin.register(with: registry.registrar(forPlugin: "NetworkInfoPlusPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PasteboardPlugin.register(with: registry.registrar(forPlugin: "PasteboardPlugin"))
@@ -41,7 +42,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PhotoManagerPlugin.register(with: registry.registrar(forPlugin: "PhotoManagerPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
- SystemTrayPlugin.register(with: registry.registrar(forPlugin: "SystemTrayPlugin"))
TrayManagerPlugin.register(with: registry.registrar(forPlugin: "TrayManagerPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
diff --git a/app/pubspec.lock b/app/pubspec.lock
index 83f8a733..636ddbe6 100644
--- a/app/pubspec.lock
+++ b/app/pubspec.lock
@@ -812,6 +812,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
+ macos_dock_progress:
+ dependency: "direct main"
+ description:
+ name: macos_dock_progress
+ sha256: "4dfd32c3117903944d9069ec2b22054e5226180cea57ad94b5908436609eb884"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.0.0"
markdown:
dependency: transitive
description:
@@ -1450,14 +1458,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
- system_tray:
- dependency: "direct main"
- description:
- name: system_tray
- sha256: "40444e5de8ed907822a98694fd031b8accc3cb3c0baa547634ce76189cf3d9cf"
- url: "https://pub.dev"
- source: hosted
- version: "2.0.3"
term_glyph:
dependency: transitive
description:
@@ -1509,12 +1509,11 @@ packages:
tray_manager:
dependency: "direct main"
description:
- path: "."
- ref: b37f5e088e0f02c45a684ae41e9d2da2d5c596db
- resolved-ref: b37f5e088e0f02c45a684ae41e9d2da2d5c596db
- url: "https://github.com/Tienisto/tray_manager.git"
- source: git
- version: "0.2.0"
+ name: tray_manager
+ sha256: e0ac9a88b2700f366b8629b97e8663b6ef450a2f169560a685dc167bfe9c9c29
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.2.2"
type_plus:
dependency: transitive
description:
@@ -1739,6 +1738,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.3.8"
+ windows_taskbar:
+ dependency: "direct main"
+ description:
+ name: windows_taskbar
+ sha256: "204edfdb280a7053febdf50fc9b49b3c007255bd8a83c082d10c174ec6548f33"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.1.2"
xdg_directories:
dependency: transitive
description:
diff --git a/app/pubspec.yaml b/app/pubspec.yaml
index 76df2999..10f12430 100644
--- a/app/pubspec.yaml
+++ b/app/pubspec.yaml
@@ -61,13 +61,7 @@ dependencies:
slang: 3.29.0
slang_flutter: 3.29.0
system_settings: 2.1.0
- system_tray: 2.0.3
- tray_manager:
- # https://github.com/leanflutter/tray_manager/issues/30
- # The Linux tray manager is disabled for now
- git:
- url: https://github.com/Tienisto/tray_manager.git
- ref: b37f5e088e0f02c45a684ae41e9d2da2d5c596db
+ tray_manager: 0.2.2
url_launcher: 6.2.4
uuid: 3.0.7
wakelock_plus: 1.1.4
diff --git a/app/windows/flutter/generated_plugin_registrant.cc b/app/windows/flutter/generated_plugin_registrant.cc
index b67ff36e..d9e22e49 100644
--- a/app/windows/flutter/generated_plugin_registrant.cc
+++ b/app/windows/flutter/generated_plugin_registrant.cc
@@ -14,10 +14,10 @@
#include <pasteboard/pasteboard_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
-#include <system_tray/system_tray_plugin.h>
#include <tray_manager/tray_manager_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>
+#include <windows_taskbar/windows_taskbar_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
@@ -36,12 +36,12 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
- SystemTrayPluginRegisterWithRegistrar(
- registry->GetRegistrarForPlugin("SystemTrayPlugin"));
TrayManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("TrayManagerPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
+ WindowsTaskbarPluginRegisterWithRegistrar(
+ registry->GetRegistrarForPlugin("WindowsTaskbarPlugin"));
}
diff --git a/app/windows/flutter/generated_plugins.cmake b/app/windows/flutter/generated_plugins.cmake
index 170f9874..6b46f5ce 100644
--- a/app/windows/flutter/generated_plugins.cmake
+++ b/app/windows/flutter/generated_plugins.cmake
@@ -11,10 +11,10 @@ list(APPEND FLUTTER_PLUGIN_LIST
pasteboard
permission_handler_windows
screen_retriever
- system_tray
tray_manager
url_launcher_windows
window_manager
+ windows_taskbar
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST