Skip to content

An open-source cross-platform alternative to AirDrop

fix(linux): resolve the tray icon to an absolute path on Snap (#3354)

Victor Carreras2e7ef1972b0b
diff --git a/app/assets/CHANGELOG.md b/app/assets/CHANGELOG.md
index 11298713..82b51b32 100644
--- a/app/assets/CHANGELOG.md
+++ b/app/assets/CHANGELOG.md
@@ -1,5 +1,6 @@
## Unreleased
+- fix(linux): tray icon fails to load in Snap installations (@vicajilau)
- fix: avoid adding a trailing dot when renaming files without an extension (@ShlomoCode)
- fix(macos): prevent intermittent MissingPluginException during startup (@ShlomoCode)
- fix(macos): file sharing via Share Extension doesn't work in DMG builds (@ShlomoCode, @vdmkotai)
diff --git a/app/lib/util/native/tray_helper.dart b/app/lib/util/native/tray_helper.dart
index 0424907c..0da3c8c6 100644
--- a/app/lib/util/native/tray_helper.dart
+++ b/app/lib/util/native/tray_helper.dart
@@ -6,6 +6,7 @@ import 'package:localsend_app/gen/strings.g.dart';
import 'package:localsend_app/provider/animation_provider.dart';
import 'package:localsend_app/util/native/platform_check.dart';
import 'package:logging/logging.dart';
+import 'package:path/path.dart' as p;
import 'package:refena_flutter/refena_flutter.dart';
import 'package:tray_manager/tray_manager.dart' as tm;
import 'package:window_manager/window_manager.dart';
@@ -32,6 +33,11 @@ Future<void> initTray() async {
if (await File('/.flatpak-info').exists()) {
// Icon for Flatpak, which must exist in /app/share/icons/hicolor/*x*/apps.
icon = 'org.localsend.localsend_app-tray';
+ } else if (Platform.environment.containsKey('SNAP')) {
+ // tray_manager only resolves the asset path against the executable directory when it does not detect a sandbox,
+ // and it treats $SNAP as one. The relative path would then reach libayatana-appindicator, which interprets
+ // anything that is not absolute as an icon theme name. A snap sees the same paths as the host, so resolve it here.
+ icon = p.join(p.dirname(Platform.resolvedExecutable), 'data', 'flutter_assets', Assets.img.logo32White.path);
} else {
icon = Assets.img.logo32White.path;
}