Skip to content

Commit

Permalink
fix: invalid event handlers for tray (#29)
Browse files Browse the repository at this point in the history
* fix: invalid event handlers for tray

* chore: v1.20.1
  • Loading branch information
igoogolx authored Aug 28, 2024
1 parent ec6a2ec commit 8540604
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
7 changes: 4 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ void main(args) async {
final port = await findAvailablePort(8000, 9000);
final Directory appDocumentsDir = await getApplicationSupportDirectory();
final Version currentVersion = Version.parse(packageInfo.version);
homeDir =
path.join(appDocumentsDir.path, '${currentVersion.major}.0');
homeDir = path.join(appDocumentsDir.path, '${currentVersion.major}.0');
var corePath = path.join(Paths.assetsBin.path, LuxCoreName.name);
if (Platform.isMacOS) {
var owner = await getFileOwner(corePath);
Expand Down Expand Up @@ -84,7 +83,9 @@ void main(args) async {
}
});

initSystemTray(openDashboard, exitApp, isWebviewSupported);
initSystemTray(openDashboard, exitApp, () {
windowManager.focus();
}, isWebviewSupported);

if (!isWebviewSupported) {
openDashboard();
Expand Down
24 changes: 20 additions & 4 deletions lib/tray.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:system_tray/system_tray.dart';

Future<void> initSystemTray(
void Function() openDashboard, exitApp, bool isWebviewSupported) async {
Future<void> initSystemTray(void Function() openDashboard, exitApp, focusWindow,
bool isWebviewSupported) async {
String path = Platform.isWindows ? 'assets/app_icon.ico' : 'assets/tray.icns';

final SystemTray systemTray = SystemTray();
Expand Down Expand Up @@ -35,9 +35,25 @@ Future<void> initSystemTray(
systemTray.registerSystemTrayEventHandler((eventName) {
debugPrint("eventName: $eventName");
if (eventName == kSystemTrayEventClick) {
Platform.isWindows ? openDashboard() : systemTray.popUpContextMenu();
if (Platform.isWindows) {
if (isWebviewSupported) {
focusWindow();
} else {
openDashboard();
}
} else {
systemTray.popUpContextMenu();
}
} else if (eventName == kSystemTrayEventRightClick) {
Platform.isWindows ? systemTray.popUpContextMenu() : openDashboard();
if (!Platform.isWindows) {
if (isWebviewSupported) {
focusWindow();
} else {
openDashboard();
}
} else {
systemTray.popUpContextMenu();
}
}
});
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.20.0-beat.2
version: 1.20.1

environment:
sdk: '>=3.0.6 <4.0.0'
Expand Down

0 comments on commit 8540604

Please sign in to comment.