antler119 / system_tray

A Flutter package that makes it easy to customize and work with your Flutter desktop app's system tray.
MIT License
214 stars 51 forks source link

Pack icon path splicing function, improve the doc #14

Closed ggdream closed 2 years ago

ggdream commented 2 years ago

Hello, the main tasks are as follows:

  1. 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'
      ]);
    }
  2. 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,
    })
  3. 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);
    }