Closed ggdream closed 2 years ago
Encapsulate the icon path splicing work into the library
String path; if (Platform.isWindows) { path = p.joinAll([ p.dirname(Platform.resolvedExecutable), 'data/flutter_assets/assets', 'app_icon.ico' ]); } else if (Platform.isMacOS) { path = p.joinAll(['AppIcon']); } else { path = p.joinAll([ p.dirname(Platform.resolvedExecutable), 'data/flutter_assets/assets', 'app_icon.png' ]); }
Standardize the initialization parameter requirements, the title and icon are changed to mandatory parameters
Future<bool> initSystemTray({ required String title, required String iconPath, String? toolTip, })
In order to facilitate learning and use, a minimal example has been added
Future<void> initSystemTray() async { final path = Platform.isWindows ? 'assets/app_icon.ico' : 'assets/app_icon.png'; final menu = [ MenuItem(label: 'Show', onClicked: _appWindow.show), MenuItem(label: 'Hide', onClicked: _appWindow.hide), MenuItem(label: 'Exit', onClicked: _appWindow.close), ]; await _systemTray.initSystemTray( title: "system tray", iconPath: path, ); await _systemTray.setContextMenu(menu); }
Hello, the main tasks are as follows:
Encapsulate the icon path splicing work into the library
Standardize the initialization parameter requirements, the title and icon are changed to mandatory parameters
In order to facilitate learning and use, a minimal example has been added