A Flutter package that makes it easy to customize and work with your Flutter desktop app's system tray.

Overview

system_tray

A Flutter package that that enables support for system tray menu for desktop flutter apps. on Windows, macOS and Linux.

Features:

- Modify system tray title/icon/tooltip
- Handle system tray event leftMouseUp/rightMouseUp (only for macos、windows)

Getting Started

Install the package using pubspec.yaml

For Windows

For macOS

For Linux

API

Below we show how to use system_tray

Future<void> initSystemTray() async {
    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'
      ]);
    }

    // We first init the systray menu and then add the menu entries
    await _systemTray.initSystemTray("system tray",
        iconPath: path, toolTip: "How to use system tray with Flutter");

    await _systemTray.setContextMenu(
      [
        MenuItem(
          label: 'Show',
          onClicked: () {
            appWindow.show();
          },
        ),
        MenuSeparator(),
        SubMenu(
          label: "SubMenu",
          children: [
            MenuItem(
              label: 'SubItem1',
              enabled: false,
              onClicked: () {
                print("click SubItem1");
              },
            ),
            MenuItem(label: 'SubItem2'),
            MenuItem(label: 'SubItem3'),
          ],
        ),
        MenuSeparator(),
        MenuItem(
          label: 'Exit',
          onClicked: () {
            appWindow.close();
          },
        ),
      ],
    );

    // flash tray icon
    _timer = Timer.periodic(
      const Duration(milliseconds: 500),
      (timer) {
        _toogleTrayIcon = !_toogleTrayIcon;
        _systemTray.setSystemTrayInfo(
          iconPath: _toogleTrayIcon ? "" : path,
        );
      },
    );

    // handle system tray event
    _systemTray.registerSystemTrayEventHandler((eventName) {
      print("eventName: $eventName");
    });
  }
Issues
  • example won't build for linux

    example won't build for linux

    CMake Error at /snap/flutter/91/usr/share/cmake-3.10/Modules/FindPkgConfig.cmake:415 (message): A required package was not found Call Stack (most recent call first): /snap/flutter/91/usr/share/cmake-3.10/Modules/FindPkgConfig.cmake:593 (_pkg_check_modules_internal) flutter/ephemeral/.plugin_symlinks/system_tray/linux/CMakeLists.txt:10 (pkg_check_modules)

    opened by sgehrman 8
  • keep app open in tray when window closed

    keep app open in tray when window closed

    Hey! Super useful plugin!

    One value in having the tray icon is that if someone closes the window of the application (with the close button or command + q) the app will still appear in the tray and can be opened by clicking the tray icon. Is there a way to do this using the plugin?

    Thanks!

    opened by Nealsoni00 5
  • Show window on tray click (no menu)

    Show window on tray click (no menu)

    Hey! Very useful plugin! -- I just wanted to see if there is a way to show the app directly when they press the tray icon? I ideally would want to show the menu options when they right-click the tray icon.

    opened by Nealsoni00 5
  • build error on flutter 2.13.0-0.3.pre

    build error on flutter 2.13.0-0.3.pre

    system_tray-0.1.0/lib/src/tray.dart:9:1: Error: 'MenuItem' is imported from both 'package:flutter/src/widgets/platform_menu_bar.dart' and 'package:system_tray/src/menu_item.dart'.

    opened by qcdong2016 3
  • The example app does not show system tray menu on macOS.

    The example app does not show system tray menu on macOS.

    Clicking a tray menu icon triggers the event handler with eventName = "leftMouseUp", but does not show system tray menu. (I might misunderstanding something.)

    It occurs on:

    • MacBook Pro Intel Core i7
    • macOS 11.0.1
    • Flutter 2.5.1
    opened by tomoyuki28jp 3
  • Running Flutter app in release / compiled mode doesn't always show the icon in the system tray

    Running Flutter app in release / compiled mode doesn't always show the icon in the system tray

    I have downloaded the repository and have run the example app. In debug, the system tray icon seems to always appear, but when I run in release mode, or do a "flutter build windows" and run the resulting executable, sometimes the icon shows, other times not - even though I do see the .exe process running in the task manager. Is there any way to troubleshoot/debug what's happening in the instances where the icon doesn't show?

    I'm running version ^0.1.1 on Windows 10, Flutter 3.0.1

    opened by Kevin-McKee 1
  • Remove swift print log code

    Remove swift print log code

    When I update my system tray menu on macOS every 5 seconds to show elapsed time, my debug console is flooed with following messages:

    method: SetContextMenu
    method: SetSystemTrayInfo
    method: SetContextMenu
    method: SetSystemTrayInfo
    method: SetContextMenu
    method: SetSystemTrayInfo
    method: SetContextMenu
    method: SetSystemTrayInfo
    method: SetContextMenu
    method: SetSystemTrayInfo
    method: SetContextMenu
    method: SetSystemTrayInfo
    method: SetContextMenu
    method: SetSystemTrayInfo
    method: SetContextMenu
    method: SetSystemTrayInfo
    method: SetContextMenu
    

    Maybe we don't need the debug print code any more? if you want to keep printing them, I think it’s better to surround the print with If DEBUG clause so that the log message won’t be shown in production apps.

    #if DEBUG
      print("method: \(call.method)")
    #endif
    
    opened by tomoyuki28jp 1
  • System tray don't show

    System tray don't show

    I ran the sample code successfully, but did not see the system tray, please help.

    image

    flutter doctor
    Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, 2.10.0, on Microsoft Windows [Version 10.0.22000.434], locale zh-CN)
    [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    [✗] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
        ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.5)
    [✓] Android Studio (version 2020.3)
    [✓] IntelliJ IDEA Ultimate Edition (version 2021.3)
    [✓] Connected device (3 available)
    
    opened by monkeyWie 1
  • There is no tooltip

    There is no tooltip

    Everything works fine except when i call _systemTray.setSystemTrayInfo(title: "Test info 1"); there is no tooltip at all. Maybe that is related to my OS, I am using Win 11.

    Not sure if that can help but in other package it is woriking.

    opened by infodusha 1
  • api of version 0.0.7 is not the same as the source code from github

    api of version 0.0.7 is not the same as the source code from github

    Hello, I found your plugin in pub so I want to have a try. But I can not run my code with issue #3 . To find what is going wrong, I cloned source code from github and run example, it works. So I compared code from pub with the one from github, I found there is some difference between them. For example, class AppWindows is not exposed in pub but exposed in github. The first parameter "title" of member function "initSystemTray" is normal in pub but named in github.

    I think issue #3 might be solved but you have not updated the code, would you please have a look?

    opened by jkouubb 1
  • Linux does not support HideAppWindow and ShowAppWindow

    Linux does not support HideAppWindow and ShowAppWindow

    • Linux support HideAppWindow and ShowAppWindow
    [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method HideAppWindow on channel flutter/system_tray/app_window)
    #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
    <asynchronous suspension>
    #1      AppWindow.hide (package:system_tray/src/app_window.dart:25:5)
    <asynchronous suspension>
    
    tray_callback id:1
    [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method ShowAppWindow on channel flutter/system_tray/app_window)
    #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
    <asynchronous suspension>
    #1      AppWindow.show (package:system_tray/src/app_window.dart:21:5)
    <asynchronous suspension>
    
    tray_callback id:8
    [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method CloseAppWindow on channel flutter/system_tray/app_window)
    #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
    <asynchronous suspension>
    #1      AppWindow.close (package:system_tray/src/app_window.dart:29:5)
    <asynchronous suspension>
    
    opened by dickens7 1
  • Lost connection to device when MenuItem is clicked

    Lost connection to device when MenuItem is clicked

    I am facing some issues that flutter always terminate app running with Lost connection to device. when I tap any MenuItem.

    Since I do not want to show any window, I do not use win.show() in my doWhenWindowReady initialization function. Here is the snippet of my code.

    import 'package:bitsdojo_window/bitsdojo_window.dart';
    import 'package:flutter/material.dart' hide MenuItem;
    import 'package:system_tray/system_tray.dart';
    
    import 'package:url_launcher/url_launcher.dart';
    
    void main() {
      WidgetsFlutterBinding.ensureInitialized();
      runApp(const MenuBar());
    }
    
    class MenuBar extends StatefulWidget {
      const MenuBar({Key? key}) : super(key: key);
    
      @override
      State<MenuBar> createState() => _MenuBarState();
    }
    
    class _MenuBarState extends State<MenuBar> {
      final SystemTray _tray = SystemTray();
      final AppWindow _appWindow = AppWindow();
      final Uri _url = Uri.parse('https://google.com/');
    
      @override
      void initState() {
        super.initState();
        doWhenWindowReady(() {
          initSystemTray();
          // final win = appWindow;
          // const initialSize = Size(600, 450);
          // win.minSize = initialSize;
          // win.size = initialSize;
          // win.alignment = Alignment.center;
          // win.title = "How to use system tray with Flutter";
          // win.show();
        });
      }
    
      @override
      void dispose() {
        super.dispose();
      }
    
      Future<void> initSystemTray() async {
        final menu = [
          MenuItem(
              label: 'Login',
              onClicked: () async {
                print('clicked');
                _launchUrl();
              }),
          MenuSeparator(),
          MenuItem(label: 'About', onClicked: _appWindow.hide),
          MenuSeparator(),
          MenuItem(label: 'Quit', onClicked: _appWindow.close),
        ];
    
        await _tray.initSystemTray(title: '', iconPath: 'assets/Logo.png');
    
        // assign tray menus
        await _tray.setContextMenu(menu);
    
        _tray.registerSystemTrayEventHandler((eventName) {
          debugPrint("eventName: $eventName");
          if (eventName == "lefMouseDown") {
          } else if (eventName == "leftMouseUp") {
            _tray.popUpContextMenu();
          }
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return Container();
      }
    
      void _launchUrl() async {
        if (!await launchUrl(_url)) throw 'Could not launch $_url';
      }
    }
    

    When I initialize win.show(); in my first init function, flutter doesn't terminate my app running and works as desired. However, since I do not need any window UI and just want to use the system tray. Any way to achieve this or a solution?

    opened by huskyjp 0
  • please support taskbar and mac dockbar flash !

    please support taskbar and mac dockbar flash !

    Thank's for you job

    I need to flash the taskbar on windows to notice the user, when the app is in background and has new event happend.

    like this image

    I don't have c++ develop skill, please support this new feature.

    opened by imjakey 0
  • Dispose tray icon

    Dispose tray icon

    When the application closes, the icon remains in the tray until you hover over it. I would like to be able to delete it as needed, or at least when the application closes

    opened by AppetiteTeam 1
  • Hot reloading an app using AppWindow  raises a warning.

    Hot reloading an app using AppWindow raises a warning.

    Hot reloading an app using AppWindow on macOS raises a following warning:

    Error: Message responses can be sent only once. Ignoring duplicate response on channel 'flutter[/system_tray/app_window]()'.
    

    This occurs in the example app too.

    opened by tomoyuki28jp 0
Releases(v0.1.0)
  • v0.1.0(Feb 18, 2022)

  • v0.0.9(Jan 28, 2022)

  • v0.0.8(Jan 27, 2022)

    • [Feature] tray icon support high DPI on windows
    • [Feature] support simple class appwindow for control window on all platforms
    • [Fixed] fixed crash when minimize window, then click on menubar on macOS
    Source code(tar.gz)
    Source code(zip)
Owner
AnTler
AnTler
This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut).

hotkey_manager This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut). hotkey_manager Platform Support Quick Star

LeanFlutter 61 Jun 16, 2022
This plugin allows Flutter desktop apps to Auto launch on startup / login.

This plugin allows Flutter desktop apps to Auto launch on startup / login.

LeanFlutter 28 Jun 18, 2022
that's simple malware open your cd tray infinity written in c++

Tray Malware that's simple malware open your cd tray infinity written in c++ Which OS Work In Tray Malware Linux Setup Tray Malware sudo apt install m

sami 1 Dec 25, 2021
A Lilu plugin that makes System Information recognize your Realtek card reader as a native one

Realtek Card Reader Driver Friend Introduction A Lilu plugin that makes System Information recognize your Realtek card reader as a native one. Support

FireWolf 44 Jun 23, 2022
A npm package that lets you automate your windows desktop.

js-macro A npm package that lets you automate your windows desktop. npm i js-macro Examples Simple cursor usage const { cursor } = require("js-macro"

4 Jan 28, 2022
A npm package that lets you automate your windows desktop.

js-macro A npm package that lets you automate your windows desktop. npm i js-macro Examples Simple cursor usage const { cursor } = require("js-macro"

4 Jan 28, 2022
SDK for building cross-platform desktop apps in ANSI-C

NAppGUI Cross-Platform C SDK. Build portable desktop applications for Windows, macOS and Linux, using just C. Quick start in Windows Prerequisites Vis

Francisco García Collado 194 Jun 23, 2022
A module for Godot 3.x that makes it easy to send crash reports to Backtrace

Godot Backtrace Module This module adds automatic crash generation support to Godot 3.x with the intent of making it possible to send the crash data t

null 12 Apr 3, 2022
A package to use Material side sheet into your Flutter project. Learn more about side sheet at Material.io

Side Sheet A package to use Material side sheet into your Flutter project. Learn more about side sheet at Material.io Platform Support Android iOS Mac

Lalit Jarwal 5 May 2, 2022
The package allows to use H3 library directly in your Flutter application

The package allows to use H3 library directly in your Flutter application

Ilya Beregovskiy 9 Jun 17, 2022
Handcrafted Flutter application well organized and easy to understand and easy to use.

Handcrafted Flutter application well organized and easy to understand and easy to use.

Justin Dah-kenangnon 2 Feb 1, 2022
Native context menu for Flutter apps

native_context_menu Native context menu for flutter apps Installation flutter pub add native_context_menu Usage import 'package:native_context_menu/na

Andrei Lesnitsky 132 Jun 4, 2022
A modern-day Boss Key software tool. Switch instantly from work to play & play to work with Bosky.

Bosky By: Seanpm2001, Bosky-dev Et; Al. Top README.md Read this article in a different language Sorted by: A-Z Sorting options unavailable ( af Afrika

Sean P. Myrick V19.1.7.2 1 Nov 11, 2021
Flutter app where you can find your information about your Favorite Super Cars ⚡❤

Super Cars App (Flutter) ⚡ Now you can freely discover and browse your Favourite Super Cars ❤ . Speed! ?? Getting Started This project is a starting p

Shehroz Ali 4 Apr 13, 2022
Lock you keyboard and clean your screen. A simple, and easy way to clean your computers.

Pristine Cleaner A screen and keyboard cleaning application made to turn screen black, and lock keyboard for easy cleaning. With features such as star

Rhino Inani 2 Jan 16, 2022
Sloth 🦥 is a coverage guided fuzzing framework for fuzzing Android Native libraries that makes use of libFuzzer and QEMU user-mode emulation

Sloth ?? Sloth is a fuzzing setup that makes use of libFuzzer and QEMU’s user-mode emulation (qemu/linux-user) on x86_64/aarch64 host to emulate aarch

Chaithu 71 Jun 25, 2022
Seam is a pin-based node editor for OpenFrameworks that makes prototyping visual systems easier and faster.

seam Seam is a pin-based node editor for openFrameworks built using: openFrameworks Dear ImGui the node editor extension for ImGui It is heavily WIP,

Austin Clifton 2 Jan 2, 2022
Proof of concept userspace filesystem that executes filenames as shell commands and makes the result accessible though reading the file.

ExecFS Proof of concept userspace filesystem that executes filenames as shell commands and makes the result accessible though reading the file. $ ./ex

Camel Coder 9 Apr 14, 2022
Add virtual monitors to your windows 10 device! Works with Oculus software, obs, and any desktop sharing software

License MIT and CC0 or Public Domain, whichever is least restrictive -- Use it AS IS - NO IMPLICIT OR EXPLICIT warranty This may break your computer,

Rashi Abramson 162 Jun 21, 2022