-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
79 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
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,80 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:lex/global.dart'; | ||
import 'package:tray_manager/tray_manager.dart'; | ||
import 'package:window_manager/window_manager.dart'; | ||
|
||
/// 初始化系统托盘 | ||
Future<void> initTray() async { | ||
Menu menu = Menu( | ||
items: [ | ||
MenuItem( | ||
key: "show_translate", | ||
label: "输入翻译", | ||
), | ||
// MenuItem( | ||
// key: "ocr", | ||
// label: "文字识别", | ||
// ), | ||
MenuItem.separator(), | ||
MenuItem.submenu( | ||
key: "autoCopy", | ||
label: "自动复制", | ||
submenu: Menu( | ||
items: [ | ||
MenuItem( | ||
key: "closeAutoCopy", | ||
label: "关闭", | ||
onClick: (_) async { | ||
await prefs.setString("autoCopy", "close"); | ||
}, | ||
), | ||
MenuItem.separator(), | ||
MenuItem( | ||
key: "autoCopySource", | ||
label: "原文", | ||
onClick: (_) async { | ||
await prefs.setString("autoCopy", "source"); | ||
}, | ||
), | ||
MenuItem( | ||
key: "autoCopyResult", | ||
label: "译文", | ||
onClick: (_) async { | ||
await prefs.setString("autoCopy", "result"); | ||
}, | ||
), | ||
MenuItem( | ||
key: "autoCopyBoth", | ||
label: "原文+译文", | ||
onClick: (_) async { | ||
await prefs.setString("autoCopy", "both"); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
MenuItem( | ||
key: "show_settings", | ||
label: "应用设置", | ||
), | ||
MenuItem.separator(), | ||
MenuItem( | ||
key: "exit_app", | ||
label: "退出应用", | ||
), | ||
], | ||
); | ||
|
||
await trayManager.destroy(); | ||
await trayManager.setIcon( | ||
Platform.isWindows ? "assets/logo.ico" : "assets/logo.png", | ||
); | ||
await trayManager.setContextMenu(menu); | ||
} | ||
|
||
/// 隐藏窗口到系统托盘 | ||
Future<void> hideToTray() async { | ||
await windowManager.hide(); | ||
await windowManager.setSkipTaskbar(true); | ||
} |