Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make system_tray actually use installed icons on Linux Flatpak #236

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ void main(List<String> arguments) async {
);

if (isDesktop) {
final icon = TrayManager.getTrayIcon();
await systemTray.initSystemTray(
title: Platform.isMacOS ? null : 'Rune',
iconPath: TrayManager.getTrayIconPath(),
iconPath: icon.path,
isTemplate: true,
isInstalled: icon.isInstalled,
);

final Menu menu = Menu();
Expand Down
23 changes: 15 additions & 8 deletions lib/utils/tray_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ import 'l10n.dart';

final SystemTray systemTray = SystemTray();

class TrayIcon {
final String path;
final bool isInstalled;

TrayIcon(this.path, this.isInstalled);
}

class TrayManager {
static String getTrayIconPath() {
static TrayIcon getTrayIcon() {
if (Platform.isMacOS) {
return 'assets/mac-tray.svg';
return TrayIcon('assets/mac-tray.svg', false);
}

final brightness =
Expand All @@ -31,14 +38,14 @@ class TrayManager {
: Brightness.light.name;

if (Platform.isWindows) {
return 'assets/tray_icon_$brightness.ico';
return TrayIcon('assets/tray_icon_$brightness.ico', false);
}

if (Platform.isLinux && bool.hasEnvironment('FLATPAK_ID')) {
return 'ci.not.Rune-tray-$brightness';
if (Platform.isLinux && Platform.environment.containsKey('FLATPAK_ID')) {
return TrayIcon('ci.not.Rune-tray-$brightness', true);
}

return 'assets/linux-tray-$brightness.svg';
return TrayIcon('assets/linux-tray-$brightness.svg', false);
}

bool? _cachedPlaying;
Expand Down Expand Up @@ -106,8 +113,8 @@ class TrayManager {
}

Future<void> updateTrayIcon() async {
final iconPath = getTrayIconPath();
await systemTray.setImage(iconPath, isTemplate: true);
final icon = getTrayIcon();
await systemTray.setImage(icon.path, isTemplate: true, isInstalled: icon.isInstalled);
}

static void registerEventHandlers() {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: e0fd539785d2f656a8efd76376c6f2225848b9be
resolved-ref: e0fd539785d2f656a8efd76376c6f2225848b9be
ref: ddbf360835b1db404fbd52b07b250e0e2c950266
resolved-ref: ddbf360835b1db404fbd52b07b250e0e2c950266
url: "https://github.com/Losses/system_tray.git"
source: git
version: "2.0.3"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dependencies:
system_tray:
git:
url: https://github.com/Losses/system_tray.git
ref: e0fd539785d2f656a8efd76376c6f2225848b9be
ref: ddbf360835b1db404fbd52b07b250e0e2c950266
scrollable_positioned_list:
git:
url: https://github.com/Losses/scrollable_positioned_list.git
Expand Down
Loading