-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): add system tray functionality
- Update pubspec.yaml with tray_manager dependency. - Initialize system tray in app.dart and handle menu item clicks.
- Loading branch information
1 parent
3a4730c
commit 1c84971
Showing
24 changed files
with
503 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:tray_manager/tray_manager.dart'; | ||
import 'package:window_manager/window_manager.dart'; | ||
|
||
String trayIcon() { | ||
if (Platform.isWindows) { | ||
return 'assets/images/tray_icon.ico'; | ||
} else { | ||
return 'assets/images/tray_icon.png'; | ||
} | ||
} | ||
|
||
class SystemTray with TrayListener { | ||
late List<MenuItem> trayMenuItems; | ||
|
||
Future<void> init() async { | ||
trayManager.addListener(this); | ||
await trayManager.setIcon(trayIcon()); | ||
} | ||
|
||
Future<void> dispose() async { | ||
trayManager.removeListener(this); | ||
} | ||
|
||
Future<void> updateTrayMenuItems( | ||
BuildContext context, | ||
) async { | ||
bool isVisible = await windowManager.isVisible(); | ||
|
||
trayMenuItems = [ | ||
MenuItem( | ||
key: 'show_hide_window', | ||
label: isVisible ? 'Hide Window' : 'Show Window', | ||
), | ||
MenuItem.separator(), | ||
MenuItem( | ||
key: 'close_application', | ||
label: 'Close Application', | ||
), | ||
]; | ||
|
||
await trayManager.setContextMenu(Menu(items: trayMenuItems)); | ||
} | ||
|
||
@override | ||
void onTrayMenuItemClick(MenuItem menuItem) { | ||
switch (menuItem.key) { | ||
case 'show_hide_window': | ||
windowManager.isVisible().then((value) { | ||
if (value) { | ||
windowManager.hide(); | ||
} else { | ||
windowManager.show(); | ||
} | ||
}); | ||
case 'close_application': | ||
windowManager.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import '../../l10n/l10n.dart'; | ||
|
||
enum CloseBtnAction { | ||
alwaysAsk, | ||
hideToTray, | ||
close; | ||
|
||
@override | ||
String toString() => name; | ||
|
||
String localize(AppLocalizations l10n) => switch (this) { | ||
alwaysAsk => l10n.alwaysAsk, | ||
hideToTray => l10n.hideToTray, | ||
close => l10n.closeApp, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.