-
Notifications
You must be signed in to change notification settings - Fork 52
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 (#824)
* feat(app): add system tray functionality - Update pubspec.yaml with tray_manager dependency. - Initialize system tray in app.dart and handle menu item clicks. * feat: tray menu for linux * fix: key names --------- Co-authored-by: Feichtmeier <[email protected]>
- Loading branch information
1 parent
3bda489
commit 857bdef
Showing
25 changed files
with
525 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,65 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:tray_manager/tray_manager.dart'; | ||
import 'package:window_manager/window_manager.dart'; | ||
|
||
import '../../l10n/l10n.dart'; | ||
|
||
const _exitAppMenuKey = 'exit_app'; | ||
const _showHideWindowMenuKey = 'show_hide_window'; | ||
|
||
Future<void> initTray() async { | ||
await trayManager.setIcon( | ||
(Platform.isWindows) | ||
? 'assets/images/tray_icon.ico' | ||
: 'assets/images/tray_icon.png', | ||
); | ||
Menu menu = Menu( | ||
items: [ | ||
MenuItem( | ||
key: _showHideWindowMenuKey, | ||
label: 'Show Window', | ||
), | ||
MenuItem.separator(), | ||
MenuItem( | ||
key: _exitAppMenuKey, | ||
label: 'Exit App', | ||
), | ||
], | ||
); | ||
await trayManager.setContextMenu(menu); | ||
} | ||
|
||
Future<void> updateTrayItems(BuildContext context) async { | ||
bool isVisible = await windowManager.isVisible(); | ||
if (!context.mounted) return; | ||
final trayMenuItems = [ | ||
MenuItem( | ||
key: _showHideWindowMenuKey, | ||
label: isVisible ? context.l10n.hideToTray : context.l10n.closeApp, | ||
), | ||
MenuItem.separator(), | ||
MenuItem( | ||
key: _exitAppMenuKey, | ||
label: context.l10n.closeApp, | ||
), | ||
]; | ||
|
||
await trayManager.setContextMenu(Menu(items: trayMenuItems)); | ||
} | ||
|
||
void reactToTray(MenuItem menuItem) { | ||
switch (menuItem.key) { | ||
case _showHideWindowMenuKey: | ||
windowManager.isVisible().then((value) { | ||
if (value) { | ||
windowManager.hide(); | ||
} else { | ||
windowManager.show(); | ||
} | ||
}); | ||
case _exitAppMenuKey: | ||
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.