├── .github
├── FUNDING.yml
└── workflows
│ ├── test.yml
│ ├── lint.yml
│ └── build.yml
├── packages
└── tray_manager
│ ├── README.md
│ ├── README-ZH.md
│ ├── example
│ ├── linux
│ │ ├── .gitignore
│ │ ├── main.cc
│ │ ├── flutter
│ │ │ ├── generated_plugin_registrant.h
│ │ │ ├── generated_plugin_registrant.cc
│ │ │ ├── generated_plugins.cmake
│ │ │ └── CMakeLists.txt
│ │ ├── my_application.h
│ │ ├── my_application.cc
│ │ └── CMakeLists.txt
│ ├── analysis_options.yaml
│ ├── macos
│ │ ├── .gitignore
│ │ ├── Runner
│ │ │ ├── Configs
│ │ │ │ ├── Debug.xcconfig
│ │ │ │ ├── Release.xcconfig
│ │ │ │ ├── Warnings.xcconfig
│ │ │ │ └── AppInfo.xcconfig
│ │ │ ├── Assets.xcassets
│ │ │ │ └── AppIcon.appiconset
│ │ │ │ │ ├── app_icon_128.png
│ │ │ │ │ ├── app_icon_16.png
│ │ │ │ │ ├── app_icon_256.png
│ │ │ │ │ ├── app_icon_32.png
│ │ │ │ │ ├── app_icon_512.png
│ │ │ │ │ ├── app_icon_64.png
│ │ │ │ │ ├── app_icon_1024.png
│ │ │ │ │ └── Contents.json
│ │ │ ├── Release.entitlements
│ │ │ ├── AppDelegate.swift
│ │ │ ├── DebugProfile.entitlements
│ │ │ ├── MainFlutterWindow.swift
│ │ │ ├── Info.plist
│ │ │ └── Base.lproj
│ │ │ │ └── MainMenu.xib
│ │ ├── Flutter
│ │ │ ├── Flutter-Debug.xcconfig
│ │ │ ├── Flutter-Release.xcconfig
│ │ │ └── GeneratedPluginRegistrant.swift
│ │ ├── Runner.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ ├── Runner.xcodeproj
│ │ │ ├── project.xcworkspace
│ │ │ │ └── xcshareddata
│ │ │ │ │ └── IDEWorkspaceChecks.plist
│ │ │ └── xcshareddata
│ │ │ │ └── xcschemes
│ │ │ │ └── Runner.xcscheme
│ │ ├── Podfile.lock
│ │ └── Podfile
│ ├── web
│ │ ├── favicon.png
│ │ ├── icons
│ │ │ ├── Icon-192.png
│ │ │ ├── Icon-512.png
│ │ │ ├── Icon-maskable-192.png
│ │ │ └── Icon-maskable-512.png
│ │ ├── manifest.json
│ │ └── index.html
│ ├── images
│ │ ├── tray_icon.ico
│ │ ├── tray_icon.png
│ │ ├── tray_icon_original.ico
│ │ └── tray_icon_original.png
│ ├── windows
│ │ ├── runner
│ │ │ ├── resources
│ │ │ │ └── app_icon.ico
│ │ │ ├── resource.h
│ │ │ ├── CMakeLists.txt
│ │ │ ├── utils.h
│ │ │ ├── runner.exe.manifest
│ │ │ ├── run_loop.h
│ │ │ ├── flutter_window.h
│ │ │ ├── main.cpp
│ │ │ ├── utils.cpp
│ │ │ ├── flutter_window.cpp
│ │ │ ├── run_loop.cpp
│ │ │ ├── Runner.rc
│ │ │ ├── win32_window.h
│ │ │ └── win32_window.cpp
│ │ ├── .gitignore
│ │ ├── flutter
│ │ │ ├── generated_plugin_registrant.h
│ │ │ ├── generated_plugin_registrant.cc
│ │ │ ├── generated_plugins.cmake
│ │ │ └── CMakeLists.txt
│ │ └── CMakeLists.txt
│ ├── pubspec.yaml
│ ├── README.md
│ ├── lib
│ │ ├── main.dart
│ │ └── pages
│ │ │ └── home.dart
│ ├── .gitignore
│ └── .metadata
│ ├── analysis_options.yaml
│ ├── lib
│ ├── tray_manager.dart
│ └── src
│ │ ├── helpers
│ │ └── sandbox.dart
│ │ ├── tray_listener.dart
│ │ └── tray_manager.dart
│ ├── .metadata
│ ├── windows
│ ├── .gitignore
│ ├── include
│ │ └── tray_manager
│ │ │ └── tray_manager_plugin.h
│ ├── CMakeLists.txt
│ └── tray_manager_plugin.cpp
│ ├── .gitignore
│ ├── linux
│ ├── include
│ │ └── tray_manager
│ │ │ └── tray_manager_plugin.h
│ ├── CMakeLists.txt
│ └── tray_manager_plugin.cc
│ ├── pubspec.yaml
│ ├── macos
│ ├── tray_manager.podspec
│ └── Classes
│ │ ├── TrayIcon.swift
│ │ ├── TrayMenu.swift
│ │ └── TrayManagerPlugin.swift
│ ├── LICENSE
│ └── CHANGELOG.md
├── .gitignore
├── screenshots
├── linux.png
├── macos.png
└── windows.png
├── pubspec.yaml
├── .clang-format
├── melos.yaml
├── LICENSE
├── README-ZH.md
└── README.md
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | liberapay: lijy91
2 |
--------------------------------------------------------------------------------
/packages/tray_manager/README.md:
--------------------------------------------------------------------------------
1 | ../../README.md
--------------------------------------------------------------------------------
/packages/tray_manager/README-ZH.md:
--------------------------------------------------------------------------------
1 | ../../README-ZH.md
--------------------------------------------------------------------------------
/packages/tray_manager/example/linux/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .dart_tool/
2 | .idea/
3 |
4 | *.iml
5 | pubspec_overrides.yaml
6 | pubspec.lock
7 |
--------------------------------------------------------------------------------
/screenshots/linux.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/screenshots/linux.png
--------------------------------------------------------------------------------
/screenshots/macos.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/screenshots/macos.png
--------------------------------------------------------------------------------
/screenshots/windows.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/screenshots/windows.png
--------------------------------------------------------------------------------
/packages/tray_manager/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:mostly_reasonable_lints/analysis_options.yaml
2 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:mostly_reasonable_lints/analysis_options.yaml
2 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/.gitignore:
--------------------------------------------------------------------------------
1 | # Flutter-related
2 | **/Flutter/ephemeral/
3 | **/Pods/
4 |
5 | # Xcode-related
6 | **/xcuserdata/
7 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Configs/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Debug.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/web/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/web/favicon.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Configs/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Release.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/images/tray_icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/images/tray_icon.ico
--------------------------------------------------------------------------------
/packages/tray_manager/example/images/tray_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/images/tray_icon.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/web/icons/Icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/web/icons/Icon-192.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/web/icons/Icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/web/icons/Icon-512.png
--------------------------------------------------------------------------------
/packages/tray_manager/lib/tray_manager.dart:
--------------------------------------------------------------------------------
1 | export 'package:menu_base/menu_base.dart';
2 |
3 | export 'src/tray_listener.dart';
4 | export 'src/tray_manager.dart';
5 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/images/tray_icon_original.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/images/tray_icon_original.ico
--------------------------------------------------------------------------------
/packages/tray_manager/example/images/tray_icon_original.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/images/tray_icon_original.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/web/icons/Icon-maskable-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/web/icons/Icon-maskable-192.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/web/icons/Icon-maskable-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/web/icons/Icon-maskable-512.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/resources/app_icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/windows/runner/resources/app_icon.ico
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Flutter/Flutter-Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2 | #include "ephemeral/Flutter-Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Flutter/Flutter-Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
2 | #include "ephemeral/Flutter-Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: tray_manager_workspace
2 | homepage: https://github.com/leanflutter/tray_manager
3 | publish_to: none
4 |
5 | environment:
6 | sdk: ">=3.0.0 <4.0.0"
7 |
8 | dev_dependencies:
9 | melos: ^3.1.0
10 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/linux/main.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | int main(int argc, char** argv) {
4 | g_autoptr(MyApplication) app = my_application_new();
5 | return g_application_run(G_APPLICATION(app), argc, argv);
6 | }
7 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanflutter/tray_manager/HEAD/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Release.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/packages/tray_manager/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: f4abaa0735eba4dfd8f33f73363911d63931fe03
8 | channel: stable
9 |
10 | project_type: plugin
11 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Flutter/GeneratedPluginRegistrant.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | import FlutterMacOS
6 | import Foundation
7 |
8 | import tray_manager
9 |
10 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
11 | TrayManagerPlugin.register(with: registry.registrar(forPlugin: "TrayManagerPlugin"))
12 | }
13 |
--------------------------------------------------------------------------------
/packages/tray_manager/windows/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/
2 |
3 | # Visual Studio user-specific files.
4 | *.suo
5 | *.user
6 | *.userosscache
7 | *.sln.docstates
8 |
9 | # Visual Studio build-related files.
10 | x64/
11 | x86/
12 |
13 | # Visual Studio cache files
14 | # files ending in .cache can be ignored
15 | *.[Cc]ache
16 | # but keep track of directories ending in .cache
17 | !*.[Cc]ache/
18 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral/
2 |
3 | # Visual Studio user-specific files.
4 | *.suo
5 | *.user
6 | *.userosscache
7 | *.sln.docstates
8 |
9 | # Visual Studio build-related files.
10 | x64/
11 | x86/
12 |
13 | # Visual Studio cache files
14 | # files ending in .cache can be ignored
15 | *.[Cc]ache
16 | # but keep track of directories ending in .cache
17 | !*.[Cc]ache/
18 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | @main
5 | class AppDelegate: FlutterAppDelegate {
6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
7 | return true
8 | }
9 |
10 | override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
11 | return true
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/linux/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void fl_register_plugins(FlPluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void RegisterPlugins(flutter::PluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/packages/tray_manager/lib/src/helpers/sandbox.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | /// Returns `true` if the app is running in a sandbox, eg. Flatpak, Snap, Docker, Podman.
4 | bool runningInSandbox() {
5 | return Platform.environment.containsKey('FLATPAK_ID') ||
6 | Platform.environment.containsKey('SNAP') ||
7 | (Platform.environment['container']?.isNotEmpty == true) ||
8 | FileSystemEntity.isFileSync('/.dockerenv');
9 | }
10 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 | #include
10 |
11 | void RegisterPlugins(flutter::PluginRegistry* registry) {
12 | TrayManagerPluginRegisterWithRegistrar(
13 | registry->GetRegistrarForPlugin("TrayManagerPlugin"));
14 | }
15 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/DebugProfile.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.cs.allow-jit
8 |
9 | com.apple.security.network.server
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/packages/tray_manager/lib/src/tray_listener.dart:
--------------------------------------------------------------------------------
1 | import 'package:menu_base/menu_base.dart';
2 |
3 | abstract mixin class TrayListener {
4 | /// Emitted when the mouse clicks the tray icon.
5 | void onTrayIconMouseDown() {}
6 |
7 | /// Emitted when the mouse is released from clicking the tray icon.
8 | void onTrayIconMouseUp() {}
9 |
10 | void onTrayIconRightMouseDown() {}
11 |
12 | void onTrayIconRightMouseUp() {}
13 |
14 | void onTrayMenuItemClick(MenuItem menuItem) {}
15 | }
16 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: test
2 |
3 | on:
4 | push:
5 | branches: [main, dev]
6 | pull_request:
7 | branches: [main]
8 |
9 | jobs:
10 | test:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v3
14 | - uses: subosito/flutter-action@v2
15 | with:
16 | flutter-version: "3.24.5"
17 | channel: "stable"
18 | cache: true
19 | - uses: bluefireteam/melos-action@v3
20 | - run: melos run test --no-select
21 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/linux/my_application.h:
--------------------------------------------------------------------------------
1 | #ifndef FLUTTER_MY_APPLICATION_H_
2 | #define FLUTTER_MY_APPLICATION_H_
3 |
4 | #include
5 |
6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
7 | GtkApplication)
8 |
9 | /**
10 | * my_application_new:
11 | *
12 | * Creates a new Flutter-based application.
13 | *
14 | * Returns: a new #MyApplication.
15 | */
16 | MyApplication* my_application_new();
17 |
18 | #endif // FLUTTER_MY_APPLICATION_H_
19 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/MainFlutterWindow.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | class MainFlutterWindow: NSWindow {
5 | override func awakeFromNib() {
6 | let flutterViewController = FlutterViewController.init()
7 | let windowFrame = self.frame
8 | self.contentViewController = flutterViewController
9 | self.setFrame(windowFrame, display: true)
10 |
11 | RegisterGeneratedPlugins(registry: flutterViewController)
12 |
13 | super.awakeFromNib()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: tray_manager_example
2 | description: Demonstrates how to use the tray_manager plugin.
3 | publish_to: "none"
4 |
5 | environment:
6 | sdk: ">=3.0.0 <4.0.0"
7 |
8 | dependencies:
9 | bot_toast: ^4.0.1
10 | flutter:
11 | sdk: flutter
12 | tray_manager:
13 | path: ../
14 |
15 | dev_dependencies:
16 | flutter_test:
17 | sdk: flutter
18 | mostly_reasonable_lints: ^0.1.2
19 |
20 | flutter:
21 | uses-material-design: true
22 | assets:
23 | - images/
24 |
--------------------------------------------------------------------------------
/.clang-format:
--------------------------------------------------------------------------------
1 | # Defines the Chromium style for automatic reformatting.
2 | # http://clang.llvm.org/docs/ClangFormatStyleOptions.html
3 | BasedOnStyle: Chromium
4 | # This defaults to 'Auto'. Explicitly set it for a while, so that
5 | # 'vector >' in existing files gets formatted to
6 | # 'vector>'. ('Auto' means that clang-format will only use
7 | # 'int>>' if the file already contains at least one such instance.)
8 | Standard: Cpp11
9 | SortIncludes: true
10 | ---
11 | Language: ObjC
12 | ColumnLimit: 100
13 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/linux/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 | #include
10 |
11 | void fl_register_plugins(FlPluginRegistry* registry) {
12 | g_autoptr(FlPluginRegistrar) tray_manager_registrar =
13 | fl_plugin_registry_get_registrar_for_plugin(registry, "TrayManagerPlugin");
14 | tray_manager_plugin_register_with_registrar(tray_manager_registrar);
15 | }
16 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by Runner.rc
4 | //
5 | #define IDI_APP_ICON 101
6 |
7 | // Next default values for new objects
8 | //
9 | #ifdef APSTUDIO_INVOKED
10 | #ifndef APSTUDIO_READONLY_SYMBOLS
11 | #define _APS_NEXT_RESOURCE_VALUE 102
12 | #define _APS_NEXT_COMMAND_VALUE 40001
13 | #define _APS_NEXT_CONTROL_VALUE 1001
14 | #define _APS_NEXT_SYMED_VALUE 101
15 | #endif
16 | #endif
17 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/README.md:
--------------------------------------------------------------------------------
1 | # tray_manager_example
2 |
3 | Demonstrates how to use the tray_manager plugin.
4 |
5 | ## Getting Started
6 |
7 | This project is a starting point for a Flutter application.
8 |
9 | A few resources to get you started if this is your first Flutter project:
10 |
11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
13 |
14 | For help getting started with Flutter, view our
15 | [online documentation](https://flutter.dev/docs), which offers tutorials,
16 | samples, guidance on mobile development, and a full API reference.
17 |
--------------------------------------------------------------------------------
/packages/tray_manager/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 | migrate_working_dir/
12 |
13 | # IntelliJ related
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea/
18 |
19 | # The .vscode folder contains launch configuration and tasks you configure in
20 | # VS Code which you may wish to be included in version control, so this line
21 | # is commented out by default.
22 | #.vscode/
23 |
24 | # Flutter/Dart/Pub related
25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26 | /pubspec.lock
27 | **/doc/api/
28 | .dart_tool/
29 | build/
30 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Configs/Warnings.xcconfig:
--------------------------------------------------------------------------------
1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings
2 | GCC_WARN_UNDECLARED_SELECTOR = YES
3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES
4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE
5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
6 | CLANG_WARN_PRAGMA_PACK = YES
7 | CLANG_WARN_STRICT_PROTOTYPES = YES
8 | CLANG_WARN_COMMA = YES
9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES
10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
12 | GCC_WARN_SHADOW = YES
13 | CLANG_WARN_UNREACHABLE_CODE = YES
14 |
--------------------------------------------------------------------------------
/packages/tray_manager/windows/include/tray_manager/tray_manager_plugin.h:
--------------------------------------------------------------------------------
1 | #ifndef FLUTTER_PLUGIN_TRAY_MANAGER_PLUGIN_H_
2 | #define FLUTTER_PLUGIN_TRAY_MANAGER_PLUGIN_H_
3 |
4 | #include
5 |
6 | #ifdef FLUTTER_PLUGIN_IMPL
7 | #define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
8 | #else
9 | #define FLUTTER_PLUGIN_EXPORT __declspec(dllimport)
10 | #endif
11 |
12 | #if defined(__cplusplus)
13 | extern "C" {
14 | #endif
15 |
16 | FLUTTER_PLUGIN_EXPORT void TrayManagerPluginRegisterWithRegistrar(
17 | FlutterDesktopPluginRegistrarRef registrar);
18 |
19 | #if defined(__cplusplus)
20 | } // extern "C"
21 | #endif
22 |
23 | #endif // FLUTTER_PLUGIN_TRAY_MANAGER_PLUGIN_H_
24 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - FlutterMacOS (1.0.0)
3 | - tray_manager (0.0.1):
4 | - FlutterMacOS
5 |
6 | DEPENDENCIES:
7 | - FlutterMacOS (from `Flutter/ephemeral`)
8 | - tray_manager (from `Flutter/ephemeral/.symlinks/plugins/tray_manager/macos`)
9 |
10 | EXTERNAL SOURCES:
11 | FlutterMacOS:
12 | :path: Flutter/ephemeral
13 | tray_manager:
14 | :path: Flutter/ephemeral/.symlinks/plugins/tray_manager/macos
15 |
16 | SPEC CHECKSUMS:
17 | FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
18 | tray_manager: 9064e219c56d75c476e46b9a21182087930baf90
19 |
20 | PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7
21 |
22 | COCOAPODS: 1.14.3
23 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 | project(runner LANGUAGES CXX)
3 |
4 | add_executable(${BINARY_NAME} WIN32
5 | "flutter_window.cpp"
6 | "main.cpp"
7 | "run_loop.cpp"
8 | "utils.cpp"
9 | "win32_window.cpp"
10 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
11 | "Runner.rc"
12 | "runner.exe.manifest"
13 | )
14 | apply_standard_settings(${BINARY_NAME})
15 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
16 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
17 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
18 | add_dependencies(${BINARY_NAME} flutter_assemble)
19 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:bot_toast/bot_toast.dart';
2 | import 'package:flutter/material.dart';
3 | import 'package:tray_manager_example/pages/home.dart';
4 |
5 | void main() {
6 | WidgetsFlutterBinding.ensureInitialized();
7 |
8 | runApp(const MyApp());
9 | }
10 |
11 | class MyApp extends StatefulWidget {
12 | const MyApp({super.key});
13 |
14 | @override
15 | State createState() => _MyAppState();
16 | }
17 |
18 | class _MyAppState extends State {
19 | @override
20 | Widget build(BuildContext context) {
21 | return MaterialApp(
22 | builder: BotToastInit(),
23 | navigatorObservers: [BotToastNavigatorObserver()],
24 | home: const HomePage(),
25 | );
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Configs/AppInfo.xcconfig:
--------------------------------------------------------------------------------
1 | // Application-level settings for the Runner target.
2 | //
3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the
4 | // future. If not, the values below would default to using the project name when this becomes a
5 | // 'flutter create' template.
6 |
7 | // The application's name. By default this is also the title of the Flutter window.
8 | PRODUCT_NAME = tray_manager_example
9 |
10 | // The application's bundle identifier
11 | PRODUCT_BUNDLE_IDENTIFIER = org.leanflutter.plugins.trayManagerExample
12 |
13 | // The copyright displayed in application information
14 | PRODUCT_COPYRIGHT = Copyright © 2021 org.leanflutter.plugins. All rights reserved.
15 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_UTILS_H_
2 | #define RUNNER_UTILS_H_
3 |
4 | #include
5 | #include
6 |
7 | // Creates a console for the process, and redirects stdout and stderr to
8 | // it for both the runner and the Flutter library.
9 | void CreateAndAttachConsole();
10 |
11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
12 | // encoded in UTF-8. Returns an empty std::string on failure.
13 | std::string Utf8FromUtf16(const wchar_t* utf16_string);
14 |
15 | // Gets the command line arguments passed in as a std::vector,
16 | // encoded in UTF-8. Returns an empty std::vector on failure.
17 | std::vector GetCommandLineArguments();
18 |
19 | #endif // RUNNER_UTILS_H_
20 |
--------------------------------------------------------------------------------
/packages/tray_manager/linux/include/tray_manager/tray_manager_plugin.h:
--------------------------------------------------------------------------------
1 | #ifndef FLUTTER_PLUGIN_TRAY_MANAGER_PLUGIN_H_
2 | #define FLUTTER_PLUGIN_TRAY_MANAGER_PLUGIN_H_
3 |
4 | #include
5 |
6 | G_BEGIN_DECLS
7 |
8 | #ifdef FLUTTER_PLUGIN_IMPL
9 | #define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
10 | #else
11 | #define FLUTTER_PLUGIN_EXPORT
12 | #endif
13 |
14 | typedef struct _TrayManagerPlugin TrayManagerPlugin;
15 | typedef struct {
16 | GObjectClass parent_class;
17 | } TrayManagerPluginClass;
18 |
19 | FLUTTER_PLUGIN_EXPORT GType tray_manager_plugin_get_type();
20 |
21 | FLUTTER_PLUGIN_EXPORT void tray_manager_plugin_register_with_registrar(
22 | FlPluginRegistrar* registrar);
23 |
24 | G_END_DECLS
25 |
26 | #endif // FLUTTER_PLUGIN_TRAY_MANAGER_PLUGIN_H_
27 |
--------------------------------------------------------------------------------
/.github/workflows/lint.yml:
--------------------------------------------------------------------------------
1 | name: lint
2 |
3 | on:
4 | push:
5 | branches: [main, dev]
6 | pull_request:
7 | branches: [main]
8 |
9 | jobs:
10 | analyze:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v3
14 | - uses: subosito/flutter-action@v2
15 | with:
16 | flutter-version: "3.24.5"
17 | channel: "stable"
18 | - uses: bluefireteam/melos-action@v3
19 | - run: melos run analyze
20 |
21 | format:
22 | runs-on: ubuntu-latest
23 | steps:
24 | - uses: actions/checkout@v3
25 | - uses: subosito/flutter-action@v2
26 | with:
27 | flutter-version: "3.24.5"
28 | channel: "stable"
29 | cache: true
30 | - uses: bluefireteam/melos-action@v3
31 | - run: melos run format-check
32 |
--------------------------------------------------------------------------------
/packages/tray_manager/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: tray_manager
2 | description: This plugin allows Flutter desktop apps to defines system tray.
3 | version: 0.5.2
4 | homepage: https://github.com/leanflutter/tray_manager
5 |
6 | platforms:
7 | linux:
8 | macos:
9 | windows:
10 |
11 | topics:
12 | - tray
13 | - tray-manager
14 | - system-tray
15 |
16 | environment:
17 | sdk: ">=3.0.0 <4.0.0"
18 | flutter: ">=3.3.0"
19 |
20 | dependencies:
21 | flutter:
22 | sdk: flutter
23 | menu_base: ^0.1.0
24 | path: ^1.8.0
25 | shortid: ^0.1.2
26 |
27 | dev_dependencies:
28 | flutter_test:
29 | sdk: flutter
30 | mostly_reasonable_lints: ^0.1.2
31 |
32 | flutter:
33 | plugin:
34 | platforms:
35 | linux:
36 | pluginClass: TrayManagerPlugin
37 | macos:
38 | pluginClass: TrayManagerPlugin
39 | windows:
40 | pluginClass: TrayManagerPlugin
41 |
--------------------------------------------------------------------------------
/packages/tray_manager/macos/tray_manager.podspec:
--------------------------------------------------------------------------------
1 | #
2 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
3 | # Run `pod lib lint tray_manager.podspec` to validate before publishing.
4 | #
5 | Pod::Spec.new do |s|
6 | s.name = 'tray_manager'
7 | s.version = '0.0.1'
8 | s.summary = 'A new flutter plugin project.'
9 | s.description = <<-DESC
10 | A new flutter plugin project.
11 | DESC
12 | s.homepage = 'http://example.com'
13 | s.license = { :file => '../LICENSE' }
14 | s.author = { 'Your Company' => 'email@example.com' }
15 | s.source = { :path => '.' }
16 | s.source_files = 'Classes/**/*'
17 | s.dependency 'FlutterMacOS'
18 |
19 | s.platform = :osx, '10.11'
20 | s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
21 | s.swift_version = '5.0'
22 | end
23 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/linux/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | tray_manager
7 | )
8 |
9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
10 | )
11 |
12 | set(PLUGIN_BUNDLED_LIBRARIES)
13 |
14 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
19 | endforeach(plugin)
20 |
21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
24 | endforeach(ffi_plugin)
25 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | tray_manager
7 | )
8 |
9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
10 | )
11 |
12 | set(PLUGIN_BUNDLED_LIBRARIES)
13 |
14 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
19 | endforeach(plugin)
20 |
21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
24 | endforeach(ffi_plugin)
25 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 |
12 | # IntelliJ related
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .idea/
17 |
18 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | **/doc/api/
25 | **/ios/Flutter/.last_build_id
26 | .dart_tool/
27 | .flutter-plugins
28 | .flutter-plugins-dependencies
29 | .packages
30 | .pub-cache/
31 | .pub/
32 | /build/
33 |
34 | # Web related
35 |
36 | # Symbolication related
37 | app.*.symbols
38 |
39 | # Obfuscation related
40 | app.*.map.json
41 |
42 | # Android Studio will place build artifacts here
43 | /android/app/debug
44 | /android/app/profile
45 | /android/app/release
46 |
--------------------------------------------------------------------------------
/melos.yaml:
--------------------------------------------------------------------------------
1 | name: tray_manager_workspace
2 | repository: https://github.com/leanflutter/tray_manager
3 |
4 | packages:
5 | - examples/**
6 | - packages/**
7 |
8 | command:
9 | bootstrap:
10 | # Uses the pubspec_overrides.yaml instead of having Melos modifying the lock file.
11 | usePubspecOverrides: true
12 |
13 | scripts:
14 | analyze:
15 | exec: flutter analyze --fatal-infos
16 | description: Run `flutter analyze` for all packages.
17 |
18 | test:
19 | exec: flutter test
20 | description: Run `flutter test` for a specific package.
21 | packageFilters:
22 | dirExists:
23 | - test
24 |
25 | format:
26 | exec: dart format . --fix
27 | description: Run `dart format` for all packages.
28 |
29 | format-check:
30 | exec: dart format . --fix --set-exit-if-changed
31 | description: Run `dart format` checks for all packages.
32 |
33 | fix:
34 | exec: dart fix . --apply
35 | description: Run `dart fix` for all packages.
36 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/runner.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PerMonitorV2
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/packages/tray_manager/windows/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 | set(PROJECT_NAME "tray_manager")
3 | project(${PROJECT_NAME} LANGUAGES CXX)
4 |
5 | # This value is used when generating builds using this plugin, so it must
6 | # not be changed
7 | set(PLUGIN_NAME "tray_manager_plugin")
8 |
9 | add_library(${PLUGIN_NAME} SHARED
10 | "tray_manager_plugin.cpp"
11 | )
12 | apply_standard_settings(${PLUGIN_NAME})
13 | set_target_properties(${PLUGIN_NAME} PROPERTIES
14 | CXX_VISIBILITY_PRESET hidden)
15 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
16 | target_compile_definitions(${PLUGIN_NAME} PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
17 | target_include_directories(${PLUGIN_NAME} INTERFACE
18 | "${CMAKE_CURRENT_SOURCE_DIR}/include")
19 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
20 |
21 | # List of absolute paths to libraries that should be bundled with the plugin
22 | set(tray_manager_bundled_libraries
23 | ""
24 | PARENT_SCOPE
25 | )
26 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/web/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "short_name": "example",
4 | "start_url": ".",
5 | "display": "standalone",
6 | "background_color": "#0175C2",
7 | "theme_color": "#0175C2",
8 | "description": "A new Flutter project.",
9 | "orientation": "portrait-primary",
10 | "prefer_related_applications": false,
11 | "icons": [
12 | {
13 | "src": "icons/Icon-192.png",
14 | "sizes": "192x192",
15 | "type": "image/png"
16 | },
17 | {
18 | "src": "icons/Icon-512.png",
19 | "sizes": "512x512",
20 | "type": "image/png"
21 | },
22 | {
23 | "src": "icons/Icon-maskable-192.png",
24 | "sizes": "192x192",
25 | "type": "image/png",
26 | "purpose": "maskable"
27 | },
28 | {
29 | "src": "icons/Icon-maskable-512.png",
30 | "sizes": "512x512",
31 | "type": "image/png",
32 | "purpose": "maskable"
33 | }
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: "dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668"
8 | channel: "stable"
9 |
10 | project_type: app
11 |
12 | # Tracks metadata for the flutter migrate command
13 | migration:
14 | platforms:
15 | - platform: root
16 | create_revision: dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668
17 | base_revision: dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668
18 | - platform: web
19 | create_revision: dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668
20 | base_revision: dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668
21 |
22 | # User provided section
23 |
24 | # List of Local paths (relative to this file) that should be
25 | # ignored by the migrate tool.
26 | #
27 | # Files that are not part of the templates will be ignored by default.
28 | unmanaged_files:
29 | - 'lib/main.dart'
30 | - 'ios/Runner.xcodeproj/project.pbxproj'
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022-2024 LiJianying
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/packages/tray_manager/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022-present LiJianying
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/run_loop.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_RUN_LOOP_H_
2 | #define RUNNER_RUN_LOOP_H_
3 |
4 | #include
5 |
6 | #include
7 | #include
8 |
9 | // A runloop that will service events for Flutter instances as well
10 | // as native messages.
11 | class RunLoop {
12 | public:
13 | RunLoop();
14 | ~RunLoop();
15 |
16 | // Prevent copying
17 | RunLoop(RunLoop const&) = delete;
18 | RunLoop& operator=(RunLoop const&) = delete;
19 |
20 | // Runs the run loop until the application quits.
21 | void Run();
22 |
23 | // Registers the given Flutter instance for event servicing.
24 | void RegisterFlutterInstance(
25 | flutter::FlutterEngine* flutter_instance);
26 |
27 | // Unregisters the given Flutter instance from event servicing.
28 | void UnregisterFlutterInstance(
29 | flutter::FlutterEngine* flutter_instance);
30 |
31 | private:
32 | using TimePoint = std::chrono::steady_clock::time_point;
33 |
34 | // Processes all currently pending messages for registered Flutter instances.
35 | TimePoint ProcessFlutterMessages();
36 |
37 | std::set flutter_instances_;
38 | };
39 |
40 | #endif // RUNNER_RUN_LOOP_H_
41 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(FLUTTER_BUILD_NAME)
21 | CFBundleVersion
22 | $(FLUTTER_BUILD_NUMBER)
23 | LSMinimumSystemVersion
24 | $(MACOSX_DEPLOYMENT_TARGET)
25 | NSHumanReadableCopyright
26 | $(PRODUCT_COPYRIGHT)
27 | NSMainNibFile
28 | MainMenu
29 | NSPrincipalClass
30 | NSApplication
31 |
32 |
33 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/flutter_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_FLUTTER_WINDOW_H_
2 | #define RUNNER_FLUTTER_WINDOW_H_
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include "run_loop.h"
10 | #include "win32_window.h"
11 |
12 | // A window that does nothing but host a Flutter view.
13 | class FlutterWindow : public Win32Window {
14 | public:
15 | // Creates a new FlutterWindow driven by the |run_loop|, hosting a
16 | // Flutter view running |project|.
17 | explicit FlutterWindow(RunLoop* run_loop,
18 | const flutter::DartProject& project);
19 | virtual ~FlutterWindow();
20 |
21 | protected:
22 | // Win32Window:
23 | bool OnCreate() override;
24 | void OnDestroy() override;
25 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
26 | LPARAM const lparam) noexcept override;
27 |
28 | private:
29 | // The run loop driving events for this window.
30 | RunLoop* run_loop_;
31 |
32 | // The project to run.
33 | flutter::DartProject project_;
34 |
35 | // The Flutter instance hosted by this window.
36 | std::unique_ptr flutter_controller_;
37 | };
38 |
39 | #endif // RUNNER_FLUTTER_WINDOW_H_
40 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | example
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "flutter_window.h"
6 | #include "run_loop.h"
7 | #include "utils.h"
8 |
9 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
10 | _In_ wchar_t *command_line, _In_ int show_command) {
11 | // Attach to console when present (e.g., 'flutter run') or create a
12 | // new console when running with a debugger.
13 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
14 | CreateAndAttachConsole();
15 | }
16 |
17 | // Initialize COM, so that it is available for use in the library and/or
18 | // plugins.
19 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
20 |
21 | RunLoop run_loop;
22 |
23 | flutter::DartProject project(L"data");
24 |
25 | std::vector command_line_arguments =
26 | GetCommandLineArguments();
27 |
28 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
29 |
30 | FlutterWindow window(&run_loop, project);
31 | Win32Window::Point origin(10, 10);
32 | Win32Window::Size size(1280, 720);
33 | if (!window.CreateAndShow(L"tray_manager_example", origin, size)) {
34 | return EXIT_FAILURE;
35 | }
36 | window.SetQuitOnClose(true);
37 |
38 | run_loop.Run();
39 |
40 | ::CoUninitialize();
41 | return EXIT_SUCCESS;
42 | }
43 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Podfile:
--------------------------------------------------------------------------------
1 | platform :osx, '10.14'
2 |
3 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
4 | ENV['COCOAPODS_DISABLE_STATS'] = 'true'
5 |
6 | project 'Runner', {
7 | 'Debug' => :debug,
8 | 'Profile' => :release,
9 | 'Release' => :release,
10 | }
11 |
12 | def flutter_root
13 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
14 | unless File.exist?(generated_xcode_build_settings_path)
15 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
16 | end
17 |
18 | File.foreach(generated_xcode_build_settings_path) do |line|
19 | matches = line.match(/FLUTTER_ROOT\=(.*)/)
20 | return matches[1].strip if matches
21 | end
22 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
23 | end
24 |
25 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
26 |
27 | flutter_macos_podfile_setup
28 |
29 | target 'Runner' do
30 | use_frameworks!
31 | use_modular_headers!
32 |
33 | flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
34 | end
35 |
36 | post_install do |installer|
37 | installer.pods_project.targets.each do |target|
38 | flutter_additional_macos_build_settings(target)
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/packages/tray_manager/linux/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.10)
2 | set(PROJECT_NAME "tray_manager")
3 | project(${PROJECT_NAME} LANGUAGES CXX)
4 |
5 | # This value is used when generating builds using this plugin, so it must
6 | # not be changed
7 | set(PLUGIN_NAME "tray_manager_plugin")
8 |
9 | find_package(PkgConfig REQUIRED)
10 |
11 | add_library(${PLUGIN_NAME} SHARED
12 | "tray_manager_plugin.cc"
13 | )
14 | apply_standard_settings(${PLUGIN_NAME})
15 | set_target_properties(${PLUGIN_NAME} PROPERTIES
16 | CXX_VISIBILITY_PRESET hidden)
17 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
18 | target_include_directories(${PLUGIN_NAME} INTERFACE
19 | "${CMAKE_CURRENT_SOURCE_DIR}/include")
20 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
21 | target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)
22 |
23 | pkg_check_modules(APPINDICATOR IMPORTED_TARGET ayatana-appindicator3-0.1)
24 | if(APPINDICATOR_FOUND)
25 | target_compile_definitions(${PLUGIN_NAME} PRIVATE HAVE_AYATANA)
26 | else()
27 | pkg_check_modules(APPINDICATOR IMPORTED_TARGET appindicator3-0.1)
28 | endif()
29 | if(APPINDICATOR_FOUND)
30 | target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::APPINDICATOR)
31 | else()
32 | message(
33 | FATAL_ERROR
34 | "\n"
35 | "The `tray_manager` package requires ayatana-appindicator3-0.1 or appindicator3-0.1. See https://github.com/leanflutter/tray_manager#linux-requirements"
36 | )
37 | endif()
38 |
39 | # List of absolute paths to libraries that should be bundled with the plugin
40 | set(tray_manager_bundled_libraries
41 | ""
42 | PARENT_SCOPE
43 | )
44 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "16x16",
5 | "idiom" : "mac",
6 | "filename" : "app_icon_16.png",
7 | "scale" : "1x"
8 | },
9 | {
10 | "size" : "16x16",
11 | "idiom" : "mac",
12 | "filename" : "app_icon_32.png",
13 | "scale" : "2x"
14 | },
15 | {
16 | "size" : "32x32",
17 | "idiom" : "mac",
18 | "filename" : "app_icon_32.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "32x32",
23 | "idiom" : "mac",
24 | "filename" : "app_icon_64.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "128x128",
29 | "idiom" : "mac",
30 | "filename" : "app_icon_128.png",
31 | "scale" : "1x"
32 | },
33 | {
34 | "size" : "128x128",
35 | "idiom" : "mac",
36 | "filename" : "app_icon_256.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "256x256",
41 | "idiom" : "mac",
42 | "filename" : "app_icon_256.png",
43 | "scale" : "1x"
44 | },
45 | {
46 | "size" : "256x256",
47 | "idiom" : "mac",
48 | "filename" : "app_icon_512.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "512x512",
53 | "idiom" : "mac",
54 | "filename" : "app_icon_512.png",
55 | "scale" : "1x"
56 | },
57 | {
58 | "size" : "512x512",
59 | "idiom" : "mac",
60 | "filename" : "app_icon_1024.png",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include
9 |
10 | void CreateAndAttachConsole() {
11 | if (::AllocConsole()) {
12 | FILE *unused;
13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
14 | _dup2(_fileno(stdout), 1);
15 | }
16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
17 | _dup2(_fileno(stdout), 2);
18 | }
19 | std::ios::sync_with_stdio();
20 | FlutterDesktopResyncOutputStreams();
21 | }
22 | }
23 |
24 | std::vector GetCommandLineArguments() {
25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
26 | int argc;
27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
28 | if (argv == nullptr) {
29 | return std::vector();
30 | }
31 |
32 | std::vector command_line_arguments;
33 |
34 | // Skip the first argument as it's the binary name.
35 | for (int i = 1; i < argc; i++) {
36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
37 | }
38 |
39 | ::LocalFree(argv);
40 |
41 | return command_line_arguments;
42 | }
43 |
44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) {
45 | if (utf16_string == nullptr) {
46 | return std::string();
47 | }
48 | int target_length = ::WideCharToMultiByte(
49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
50 | -1, nullptr, 0, nullptr, nullptr);
51 | if (target_length == 0) {
52 | return std::string();
53 | }
54 | std::string utf8_string;
55 | utf8_string.resize(target_length);
56 | int converted_length = ::WideCharToMultiByte(
57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
58 | -1, utf8_string.data(),
59 | target_length, nullptr, nullptr);
60 | if (converted_length == 0) {
61 | return std::string();
62 | }
63 | return utf8_string;
64 | }
65 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on:
4 | push:
5 | branches: [main, dev]
6 | pull_request:
7 | branches: [main]
8 |
9 | jobs:
10 | build-linux:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v3
14 | - uses: subosito/flutter-action@v2
15 | with:
16 | flutter-version: "3.24.5"
17 | channel: "stable"
18 | - run: |
19 | sudo apt-get update
20 | sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev
21 | sudo apt-get install -y keybinder-3.0 libayatana-appindicator3-dev
22 | - uses: bluefireteam/melos-action@v3
23 | - working-directory: ./packages/tray_manager/example
24 | run: |
25 | flutter build linux --release
26 |
27 | build-macos:
28 | runs-on: macos-latest
29 | steps:
30 | - uses: actions/checkout@v3
31 | - uses: subosito/flutter-action@v2
32 | with:
33 | flutter-version: "3.24.5"
34 | channel: "stable"
35 | - uses: bluefireteam/melos-action@v3
36 | - working-directory: ./packages/tray_manager/example
37 | run: |
38 | flutter build macos --release
39 |
40 | build-web:
41 | runs-on: macos-latest
42 | steps:
43 | - uses: actions/checkout@v3
44 | - uses: subosito/flutter-action@v2
45 | with:
46 | flutter-version: "3.24.5"
47 | channel: "stable"
48 | - uses: bluefireteam/melos-action@v3
49 | - working-directory: ./packages/tray_manager/example
50 | run: |
51 | flutter build web --release
52 |
53 | build-windows:
54 | runs-on: windows-latest
55 | steps:
56 | - uses: actions/checkout@v3
57 | - uses: subosito/flutter-action@v2
58 | with:
59 | flutter-version: "3.24.5"
60 | channel: "stable"
61 | - uses: bluefireteam/melos-action@v3
62 | - working-directory: ./packages/tray_manager/example
63 | run: |
64 | flutter build windows --release
65 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/flutter_window.cpp:
--------------------------------------------------------------------------------
1 | #include "flutter_window.h"
2 |
3 | #include
4 |
5 | #include "flutter/generated_plugin_registrant.h"
6 |
7 | FlutterWindow::FlutterWindow(RunLoop* run_loop,
8 | const flutter::DartProject& project)
9 | : run_loop_(run_loop), project_(project) {}
10 |
11 | FlutterWindow::~FlutterWindow() {}
12 |
13 | bool FlutterWindow::OnCreate() {
14 | if (!Win32Window::OnCreate()) {
15 | return false;
16 | }
17 |
18 | RECT frame = GetClientArea();
19 |
20 | // The size here must match the window dimensions to avoid unnecessary surface
21 | // creation / destruction in the startup path.
22 | flutter_controller_ = std::make_unique(
23 | frame.right - frame.left, frame.bottom - frame.top, project_);
24 | // Ensure that basic setup of the controller was successful.
25 | if (!flutter_controller_->engine() || !flutter_controller_->view()) {
26 | return false;
27 | }
28 | RegisterPlugins(flutter_controller_->engine());
29 | run_loop_->RegisterFlutterInstance(flutter_controller_->engine());
30 | SetChildContent(flutter_controller_->view()->GetNativeWindow());
31 | return true;
32 | }
33 |
34 | void FlutterWindow::OnDestroy() {
35 | if (flutter_controller_) {
36 | run_loop_->UnregisterFlutterInstance(flutter_controller_->engine());
37 | flutter_controller_ = nullptr;
38 | }
39 |
40 | Win32Window::OnDestroy();
41 | }
42 |
43 | LRESULT
44 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
45 | WPARAM const wparam,
46 | LPARAM const lparam) noexcept {
47 | // Give Flutter, including plugins, an opportunity to handle window messages.
48 | if (flutter_controller_) {
49 | std::optional result =
50 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
51 | lparam);
52 | if (result) {
53 | return *result;
54 | }
55 | }
56 |
57 | switch (message) {
58 | case WM_FONTCHANGE:
59 | flutter_controller_->engine()->ReloadSystemFonts();
60 | break;
61 | }
62 |
63 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
64 | }
65 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/run_loop.cpp:
--------------------------------------------------------------------------------
1 | #include "run_loop.h"
2 |
3 | #include
4 |
5 | #include
6 |
7 | RunLoop::RunLoop() {}
8 |
9 | RunLoop::~RunLoop() {}
10 |
11 | void RunLoop::Run() {
12 | bool keep_running = true;
13 | TimePoint next_flutter_event_time = TimePoint::clock::now();
14 | while (keep_running) {
15 | std::chrono::nanoseconds wait_duration =
16 | std::max(std::chrono::nanoseconds(0),
17 | next_flutter_event_time - TimePoint::clock::now());
18 | ::MsgWaitForMultipleObjects(
19 | 0, nullptr, FALSE, static_cast(wait_duration.count() / 1000),
20 | QS_ALLINPUT);
21 | bool processed_events = false;
22 | MSG message;
23 | // All pending Windows messages must be processed; MsgWaitForMultipleObjects
24 | // won't return again for items left in the queue after PeekMessage.
25 | while (::PeekMessage(&message, nullptr, 0, 0, PM_REMOVE)) {
26 | processed_events = true;
27 | if (message.message == WM_QUIT) {
28 | keep_running = false;
29 | break;
30 | }
31 | ::TranslateMessage(&message);
32 | ::DispatchMessage(&message);
33 | // Allow Flutter to process messages each time a Windows message is
34 | // processed, to prevent starvation.
35 | next_flutter_event_time =
36 | std::min(next_flutter_event_time, ProcessFlutterMessages());
37 | }
38 | // If the PeekMessage loop didn't run, process Flutter messages.
39 | if (!processed_events) {
40 | next_flutter_event_time =
41 | std::min(next_flutter_event_time, ProcessFlutterMessages());
42 | }
43 | }
44 | }
45 |
46 | void RunLoop::RegisterFlutterInstance(
47 | flutter::FlutterEngine* flutter_instance) {
48 | flutter_instances_.insert(flutter_instance);
49 | }
50 |
51 | void RunLoop::UnregisterFlutterInstance(
52 | flutter::FlutterEngine* flutter_instance) {
53 | flutter_instances_.erase(flutter_instance);
54 | }
55 |
56 | RunLoop::TimePoint RunLoop::ProcessFlutterMessages() {
57 | TimePoint next_event_time = TimePoint::max();
58 | for (auto instance : flutter_instances_) {
59 | std::chrono::nanoseconds wait_duration = instance->ProcessMessages();
60 | if (wait_duration != std::chrono::nanoseconds::max()) {
61 | next_event_time =
62 | std::min(next_event_time, TimePoint::clock::now() + wait_duration);
63 | }
64 | }
65 | return next_event_time;
66 | }
67 |
--------------------------------------------------------------------------------
/packages/tray_manager/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 0.5.2
2 |
3 | * fix(windows): tray icon disappears after explorer restart #85
4 |
5 | ## 0.5.1
6 |
7 | * Prevent plugin to be reregistered when spawning subwindow (#80)
8 | * Fix the sandbox check to also work for docker/podman containers (#78)
9 | * Fix: Resolved a memory leak when setting the icon multiple times on windows (#76)
10 |
11 | ## 0.5.0
12 |
13 | * feat(windows): restore icon and context menu when Explorer restarts if necessary #71
14 |
15 | ## 0.4.0
16 |
17 | * fix: resolve memory leak issue when update menu on macOS (#66)
18 |
19 | ## 0.3.1
20 |
21 | * [macos] Support setting the icon size on macOS. (#60)
22 |
23 | ## 0.3.0
24 |
25 | * chore: Add `bringAppToFront` param to `popUpContextMenu` method (#58)
26 |
27 | ## 0.2.4
28 |
29 | * [windows][bug] fix the crash bug on windows targeting c++20 (#47)
30 |
31 | ## 0.2.3
32 |
33 | * fix(macos): Fix app will crash when closing the tray. #44
34 |
35 | ## 0.2.2
36 |
37 | * fix(linux): ensure icon works in sandboxed environments #43
38 | * Updates minimum supported SDK version to Flutter 3.3/Dart 3.0.
39 |
40 | ## 0.2.1
41 |
42 | * chore: Bump flutter to 3.6
43 | * [linux] Fix libayatana set icon deprecation
44 |
45 | ## 0.2.0
46 |
47 | * [macos] Implemented ` setIconPosition` method. (#25)
48 |
49 | ## 0.1.8
50 |
51 | * [windows] getBounds method returns null when not initialized
52 | * [macos] fixed destroy() not properly destroying tray icons #21 #22
53 | * [macos] Fix getBounds crash
54 |
55 | ## 0.1.7
56 |
57 | * [macos] Optimize tray icon click event response
58 |
59 | ## 0.1.6
60 |
61 | * Support Flutter 3.0
62 | * [macos] Implemented `setTitle` method.
63 | * [linux] Implemented `setTitle` method. #15
64 | * [linux] Fix build on Ubuntu 22.04 #16 #17
65 |
66 | ## 0.1.5
67 |
68 | * Support Checkbox MenuItem #3
69 | * [macos] Fixed onTrayIconMouseDown not triggered
70 |
71 | ## 0.1.4
72 |
73 | * [macos] Fix the problem that the tray highlight state is incorrect #4 #10
74 |
75 | ## 0.1.3
76 |
77 | * [windows] Implemented `setToolTip` Method.
78 |
79 | ## 0.1.2
80 |
81 | * [macos] Add `isTemplate` parameter to `setIcon` method
82 |
83 | ## 0.1.1
84 |
85 | * [linux] Remove `` dependency
86 |
87 | ## 0.1.0
88 |
89 | * Support sub menu.
90 |
91 | ## 0.0.2
92 |
93 | * Implemented `destroy` Method.
94 | * Implemented `setIcon` Method.
95 | * Implemented `setContextMenu` Method.
96 | * Implemented `popUpContextMenu` Method.
97 | * Implemented `getBounds` Method.
98 |
99 | ## 0.0.1
100 |
101 | * Initial release.
102 |
--------------------------------------------------------------------------------
/packages/tray_manager/macos/Classes/TrayIcon.swift:
--------------------------------------------------------------------------------
1 | //
2 | // TrayIcon.swift
3 | // tray_manager
4 | //
5 | // Created by Lijy91 on 2022/5/15.
6 | //
7 |
8 | public class TrayIcon: NSView {
9 | public var onTrayIconMouseDown:(() -> Void)?
10 | public var onTrayIconMouseUp:(() -> Void)?
11 | public var onTrayIconRightMouseDown:(() -> Void)?
12 | public var onTrayIconRightMouseUp:(() -> Void)?
13 |
14 | var statusItem: NSStatusItem?
15 |
16 | public init() {
17 | super.init(frame: NSRect.zero)
18 | statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.variableLength)
19 | statusItem?.button?.addSubview(self)
20 | }
21 |
22 | override init(frame frameRect: NSRect) {
23 | super.init(frame:frameRect);
24 | }
25 |
26 | required init?(coder: NSCoder) {
27 | fatalError("init(coder:) has not been implemented")
28 | }
29 |
30 | public func setImage(_ image: NSImage, _ imagePosition: String) {
31 | if let button = statusItem?.button {
32 | button.image = image
33 | setImagePosition(imagePosition)
34 | }
35 |
36 |
37 | self.frame = statusItem!.button!.frame
38 | }
39 |
40 | public func setImagePosition(_ imagePosition: String) {
41 | if let button = statusItem?.button {
42 | button.imagePosition = imagePosition == "right" ? NSControl.ImagePosition.imageRight : NSControl.ImagePosition.imageLeft
43 | }
44 | self.frame = statusItem!.button!.frame
45 | }
46 |
47 | public func removeImage() {
48 | statusItem?.button?.image = nil
49 | self.frame = statusItem!.button!.frame
50 | }
51 |
52 | public func setTitle(_ title: String) {
53 | if let button = statusItem?.button {
54 | button.title = title
55 | }
56 | self.frame = statusItem!.button!.frame
57 | }
58 |
59 | public func setToolTip(_ toolTip: String) {
60 | if let button = statusItem?.button {
61 | button.toolTip = toolTip
62 | }
63 | }
64 |
65 | public override func mouseDown(with event: NSEvent) {
66 | statusItem?.button?.highlight(true)
67 | self.onTrayIconMouseDown!()
68 | }
69 |
70 | public override func mouseUp(with event: NSEvent) {
71 | statusItem?.button?.highlight(false)
72 | self.onTrayIconMouseUp!()
73 | }
74 |
75 | public override func rightMouseDown(with event: NSEvent) {
76 | self.onTrayIconRightMouseDown!()
77 | }
78 |
79 | public override func rightMouseUp(with event: NSEvent) {
80 | self.onTrayIconRightMouseUp!()
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/linux/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.10)
2 |
3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
4 |
5 | # Configuration provided via flutter tool.
6 | include(${EPHEMERAL_DIR}/generated_config.cmake)
7 |
8 | # TODO: Move the rest of this into files in ephemeral. See
9 | # https://github.com/flutter/flutter/issues/57146.
10 |
11 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...),
12 | # which isn't available in 3.10.
13 | function(list_prepend LIST_NAME PREFIX)
14 | set(NEW_LIST "")
15 | foreach(element ${${LIST_NAME}})
16 | list(APPEND NEW_LIST "${PREFIX}${element}")
17 | endforeach(element)
18 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
19 | endfunction()
20 |
21 | # === Flutter Library ===
22 | # System-level dependencies.
23 | find_package(PkgConfig REQUIRED)
24 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
25 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
26 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
27 |
28 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
29 |
30 | # Published to parent scope for install step.
31 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
32 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
33 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
34 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
35 |
36 | list(APPEND FLUTTER_LIBRARY_HEADERS
37 | "fl_basic_message_channel.h"
38 | "fl_binary_codec.h"
39 | "fl_binary_messenger.h"
40 | "fl_dart_project.h"
41 | "fl_engine.h"
42 | "fl_json_message_codec.h"
43 | "fl_json_method_codec.h"
44 | "fl_message_codec.h"
45 | "fl_method_call.h"
46 | "fl_method_channel.h"
47 | "fl_method_codec.h"
48 | "fl_method_response.h"
49 | "fl_plugin_registrar.h"
50 | "fl_plugin_registry.h"
51 | "fl_standard_message_codec.h"
52 | "fl_standard_method_codec.h"
53 | "fl_string_codec.h"
54 | "fl_value.h"
55 | "fl_view.h"
56 | "flutter_linux.h"
57 | )
58 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
59 | add_library(flutter INTERFACE)
60 | target_include_directories(flutter INTERFACE
61 | "${EPHEMERAL_DIR}"
62 | )
63 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
64 | target_link_libraries(flutter INTERFACE
65 | PkgConfig::GTK
66 | PkgConfig::GLIB
67 | PkgConfig::GIO
68 | )
69 | add_dependencies(flutter flutter_assemble)
70 |
71 | # === Flutter tool backend ===
72 | # _phony_ is a non-existent file to force this command to run every time,
73 | # since currently there's no way to get a full input/output list from the
74 | # flutter tool.
75 | add_custom_command(
76 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
77 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_
78 | COMMAND ${CMAKE_COMMAND} -E env
79 | ${FLUTTER_TOOL_ENVIRONMENT}
80 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
81 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
82 | VERBATIM
83 | )
84 | add_custom_target(flutter_assemble DEPENDS
85 | "${FLUTTER_LIBRARY}"
86 | ${FLUTTER_LIBRARY_HEADERS}
87 | )
88 |
--------------------------------------------------------------------------------
/packages/tray_manager/macos/Classes/TrayMenu.swift:
--------------------------------------------------------------------------------
1 | //
2 | // TrayMenu.swift
3 | // tray_manager
4 | //
5 | // Created by Lijy91 on 2022/5/8.
6 | //
7 |
8 | import AppKit
9 |
10 | public class TrayMenu: NSMenu, NSMenuDelegate {
11 | public var onMenuItemClick:((NSMenuItem) -> Void)?
12 |
13 | public override init(title: String) {
14 | super.init(title: title)
15 | }
16 |
17 | required init(coder: NSCoder) {
18 | super.init(coder: coder)
19 | }
20 |
21 | public init(_ args: [String: Any]) {
22 | super.init(title: "")
23 |
24 | let items: [NSDictionary] = args["items"] as! [NSDictionary];
25 | for item in items {
26 | let menuItem: NSMenuItem
27 |
28 | let itemDict = item as! [String: Any]
29 | let id: Int = itemDict["id"] as! Int
30 | let type: String = itemDict["type"] as! String
31 | let label: String = itemDict["label"] as? String ?? ""
32 | let toolTip: String = itemDict["toolTip"] as? String ?? ""
33 | let checked: Bool? = itemDict["checked"] as? Bool
34 | let disabled: Bool = itemDict["disabled"] as? Bool ?? true
35 |
36 | if (type == "separator") {
37 | menuItem = NSMenuItem.separator()
38 | } else {
39 | menuItem = NSMenuItem()
40 | }
41 |
42 | menuItem.tag = id
43 | menuItem.title = label
44 | menuItem.toolTip = toolTip
45 | menuItem.isEnabled = !disabled
46 | menuItem.action = !disabled ? #selector(statusItemMenuButtonClicked) : nil
47 | menuItem.target = self
48 |
49 | switch (type) {
50 | case "separator":
51 | break
52 | case "submenu":
53 | if let submenuDict = itemDict["submenu"] as? NSDictionary {
54 | let submenu = TrayMenu(submenuDict as! [String : Any])
55 | submenu.onMenuItemClick = { [weak self] (menuItem: NSMenuItem) in
56 | guard let strongSelf = self else { return }
57 | strongSelf.statusItemMenuButtonClicked(menuItem)
58 | }
59 | self.setSubmenu(submenu, for: menuItem)
60 | }
61 | break
62 | case "checkbox":
63 | if (checked == nil) {
64 | menuItem.state = .mixed
65 | } else {
66 | menuItem.state = checked! ? .on : .off
67 | }
68 | break
69 | default:
70 | break
71 | }
72 | self.addItem(menuItem)
73 | }
74 | self.delegate = self
75 | }
76 |
77 | @objc func statusItemMenuButtonClicked(_ sender: Any?) {
78 | if (sender is NSMenuItem && onMenuItemClick != nil) {
79 | let menuItem = sender as! NSMenuItem
80 | self.onMenuItemClick!(menuItem)
81 | }
82 | }
83 |
84 | // NSMenuDelegate
85 |
86 | public func menuDidClose(_ menu: NSMenu) {
87 |
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
53 |
55 |
61 |
62 |
63 |
64 |
65 |
66 |
72 |
74 |
80 |
81 |
82 |
83 |
85 |
86 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/Runner.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 | #pragma code_page(65001)
4 | #include "resource.h"
5 |
6 | #define APSTUDIO_READONLY_SYMBOLS
7 | /////////////////////////////////////////////////////////////////////////////
8 | //
9 | // Generated from the TEXTINCLUDE 2 resource.
10 | //
11 | #include "winres.h"
12 |
13 | /////////////////////////////////////////////////////////////////////////////
14 | #undef APSTUDIO_READONLY_SYMBOLS
15 |
16 | /////////////////////////////////////////////////////////////////////////////
17 | // English (United States) resources
18 |
19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21 |
22 | #ifdef APSTUDIO_INVOKED
23 | /////////////////////////////////////////////////////////////////////////////
24 | //
25 | // TEXTINCLUDE
26 | //
27 |
28 | 1 TEXTINCLUDE
29 | BEGIN
30 | "resource.h\0"
31 | END
32 |
33 | 2 TEXTINCLUDE
34 | BEGIN
35 | "#include ""winres.h""\r\n"
36 | "\0"
37 | END
38 |
39 | 3 TEXTINCLUDE
40 | BEGIN
41 | "\r\n"
42 | "\0"
43 | END
44 |
45 | #endif // APSTUDIO_INVOKED
46 |
47 |
48 | /////////////////////////////////////////////////////////////////////////////
49 | //
50 | // Icon
51 | //
52 |
53 | // Icon with lowest ID value placed first to ensure application icon
54 | // remains consistent on all systems.
55 | IDI_APP_ICON ICON "resources\\app_icon.ico"
56 |
57 |
58 | /////////////////////////////////////////////////////////////////////////////
59 | //
60 | // Version
61 | //
62 |
63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
65 | #else
66 | #define VERSION_AS_NUMBER 1,0,0,0
67 | #endif
68 |
69 | #if defined(FLUTTER_VERSION)
70 | #define VERSION_AS_STRING FLUTTER_VERSION
71 | #else
72 | #define VERSION_AS_STRING "1.0.0"
73 | #endif
74 |
75 | VS_VERSION_INFO VERSIONINFO
76 | FILEVERSION VERSION_AS_NUMBER
77 | PRODUCTVERSION VERSION_AS_NUMBER
78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
79 | #ifdef _DEBUG
80 | FILEFLAGS VS_FF_DEBUG
81 | #else
82 | FILEFLAGS 0x0L
83 | #endif
84 | FILEOS VOS__WINDOWS32
85 | FILETYPE VFT_APP
86 | FILESUBTYPE 0x0L
87 | BEGIN
88 | BLOCK "StringFileInfo"
89 | BEGIN
90 | BLOCK "040904e4"
91 | BEGIN
92 | VALUE "CompanyName", "com.example" "\0"
93 | VALUE "FileDescription", "Demonstrates how to use the tray_manager plugin." "\0"
94 | VALUE "FileVersion", VERSION_AS_STRING "\0"
95 | VALUE "InternalName", "tray_manager_example" "\0"
96 | VALUE "LegalCopyright", "Copyright (C) 2021 com.example. All rights reserved." "\0"
97 | VALUE "OriginalFilename", "tray_manager_example.exe" "\0"
98 | VALUE "ProductName", "tray_manager_example" "\0"
99 | VALUE "ProductVersion", VERSION_AS_STRING "\0"
100 | END
101 | END
102 | BLOCK "VarFileInfo"
103 | BEGIN
104 | VALUE "Translation", 0x409, 1252
105 | END
106 | END
107 |
108 | #endif // English (United States) resources
109 | /////////////////////////////////////////////////////////////////////////////
110 |
111 |
112 |
113 | #ifndef APSTUDIO_INVOKED
114 | /////////////////////////////////////////////////////////////////////////////
115 | //
116 | // Generated from the TEXTINCLUDE 3 resource.
117 | //
118 |
119 |
120 | /////////////////////////////////////////////////////////////////////////////
121 | #endif // not APSTUDIO_INVOKED
122 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/runner/win32_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_WIN32_WINDOW_H_
2 | #define RUNNER_WIN32_WINDOW_H_
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be
11 | // inherited from by classes that wish to specialize with custom
12 | // rendering and input handling
13 | class Win32Window {
14 | public:
15 | struct Point {
16 | unsigned int x;
17 | unsigned int y;
18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {}
19 | };
20 |
21 | struct Size {
22 | unsigned int width;
23 | unsigned int height;
24 | Size(unsigned int width, unsigned int height)
25 | : width(width), height(height) {}
26 | };
27 |
28 | Win32Window();
29 | virtual ~Win32Window();
30 |
31 | // Creates and shows a win32 window with |title| and position and size using
32 | // |origin| and |size|. New windows are created on the default monitor. Window
33 | // sizes are specified to the OS in physical pixels, hence to ensure a
34 | // consistent size to will treat the width height passed in to this function
35 | // as logical pixels and scale to appropriate for the default monitor. Returns
36 | // true if the window was created successfully.
37 | bool CreateAndShow(const std::wstring& title,
38 | const Point& origin,
39 | const Size& size);
40 |
41 | // Release OS resources associated with window.
42 | void Destroy();
43 |
44 | // Inserts |content| into the window tree.
45 | void SetChildContent(HWND content);
46 |
47 | // Returns the backing Window handle to enable clients to set icon and other
48 | // window properties. Returns nullptr if the window has been destroyed.
49 | HWND GetHandle();
50 |
51 | // If true, closing this window will quit the application.
52 | void SetQuitOnClose(bool quit_on_close);
53 |
54 | // Return a RECT representing the bounds of the current client area.
55 | RECT GetClientArea();
56 |
57 | protected:
58 | // Processes and route salient window messages for mouse handling,
59 | // size change and DPI. Delegates handling of these to member overloads that
60 | // inheriting classes can handle.
61 | virtual LRESULT MessageHandler(HWND window,
62 | UINT const message,
63 | WPARAM const wparam,
64 | LPARAM const lparam) noexcept;
65 |
66 | // Called when CreateAndShow is called, allowing subclass window-related
67 | // setup. Subclasses should return false if setup fails.
68 | virtual bool OnCreate();
69 |
70 | // Called when Destroy is called.
71 | virtual void OnDestroy();
72 |
73 | private:
74 | friend class WindowClassRegistrar;
75 |
76 | // OS callback called by message pump. Handles the WM_NCCREATE message which
77 | // is passed when the non-client area is being created and enables automatic
78 | // non-client DPI scaling so that the non-client area automatically
79 | // responsponds to changes in DPI. All other messages are handled by
80 | // MessageHandler.
81 | static LRESULT CALLBACK WndProc(HWND const window,
82 | UINT const message,
83 | WPARAM const wparam,
84 | LPARAM const lparam) noexcept;
85 |
86 | // Retrieves a class instance pointer for |window|
87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept;
88 |
89 | bool quit_on_close_ = false;
90 |
91 | // window handle for top level window.
92 | HWND window_handle_ = nullptr;
93 |
94 | // window handle for hosted content.
95 | HWND child_content_ = nullptr;
96 | };
97 |
98 | #endif // RUNNER_WIN32_WINDOW_H_
99 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 | project(tray_manager_example LANGUAGES CXX)
3 |
4 | set(BINARY_NAME "tray_manager_example")
5 |
6 | cmake_policy(SET CMP0063 NEW)
7 |
8 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
9 |
10 | # Configure build options.
11 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
12 | if(IS_MULTICONFIG)
13 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
14 | CACHE STRING "" FORCE)
15 | else()
16 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
17 | set(CMAKE_BUILD_TYPE "Debug" CACHE
18 | STRING "Flutter build mode" FORCE)
19 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
20 | "Debug" "Profile" "Release")
21 | endif()
22 | endif()
23 |
24 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
25 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
26 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
27 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
28 |
29 | # Use Unicode for all projects.
30 | add_definitions(-DUNICODE -D_UNICODE)
31 |
32 | # Compilation settings that should be applied to most targets.
33 | function(APPLY_STANDARD_SETTINGS TARGET)
34 | target_compile_features(${TARGET} PUBLIC cxx_std_17)
35 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
36 | target_compile_options(${TARGET} PRIVATE /EHsc)
37 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
38 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>")
39 | endfunction()
40 |
41 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
42 |
43 | # Flutter library and tool build rules.
44 | add_subdirectory(${FLUTTER_MANAGED_DIR})
45 |
46 | # Application build
47 | add_subdirectory("runner")
48 |
49 | # Generated plugin build rules, which manage building the plugins and adding
50 | # them to the application.
51 | include(flutter/generated_plugins.cmake)
52 |
53 |
54 | # === Installation ===
55 | # Support files are copied into place next to the executable, so that it can
56 | # run in place. This is done instead of making a separate bundle (as on Linux)
57 | # so that building and running from within Visual Studio will work.
58 | set(BUILD_BUNDLE_DIR "$")
59 | # Make the "install" step default, as it's required to run.
60 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
61 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
62 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
63 | endif()
64 |
65 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
66 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
67 |
68 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
69 | COMPONENT Runtime)
70 |
71 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
72 | COMPONENT Runtime)
73 |
74 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
75 | COMPONENT Runtime)
76 |
77 | if(PLUGIN_BUNDLED_LIBRARIES)
78 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
79 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
80 | COMPONENT Runtime)
81 | endif()
82 |
83 | # Fully re-copy the assets directory on each build to avoid having stale files
84 | # from a previous install.
85 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
86 | install(CODE "
87 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
88 | " COMPONENT Runtime)
89 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
90 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
91 |
92 | # Install the AOT library on non-Debug builds only.
93 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
94 | CONFIGURATIONS Profile;Release
95 | COMPONENT Runtime)
96 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/windows/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 |
3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
4 |
5 | # Configuration provided via flutter tool.
6 | include(${EPHEMERAL_DIR}/generated_config.cmake)
7 |
8 | # TODO: Move the rest of this into files in ephemeral. See
9 | # https://github.com/flutter/flutter/issues/57146.
10 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
11 |
12 | # Set fallback configurations for older versions of the flutter tool.
13 | if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
14 | set(FLUTTER_TARGET_PLATFORM "windows-x64")
15 | endif()
16 |
17 | # === Flutter Library ===
18 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
19 |
20 | # Published to parent scope for install step.
21 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
22 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
23 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
24 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
25 |
26 | list(APPEND FLUTTER_LIBRARY_HEADERS
27 | "flutter_export.h"
28 | "flutter_windows.h"
29 | "flutter_messenger.h"
30 | "flutter_plugin_registrar.h"
31 | "flutter_texture_registrar.h"
32 | )
33 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
34 | add_library(flutter INTERFACE)
35 | target_include_directories(flutter INTERFACE
36 | "${EPHEMERAL_DIR}"
37 | )
38 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
39 | add_dependencies(flutter flutter_assemble)
40 |
41 | # === Wrapper ===
42 | list(APPEND CPP_WRAPPER_SOURCES_CORE
43 | "core_implementations.cc"
44 | "standard_codec.cc"
45 | )
46 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
47 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
48 | "plugin_registrar.cc"
49 | )
50 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
51 | list(APPEND CPP_WRAPPER_SOURCES_APP
52 | "flutter_engine.cc"
53 | "flutter_view_controller.cc"
54 | )
55 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
56 |
57 | # Wrapper sources needed for a plugin.
58 | add_library(flutter_wrapper_plugin STATIC
59 | ${CPP_WRAPPER_SOURCES_CORE}
60 | ${CPP_WRAPPER_SOURCES_PLUGIN}
61 | )
62 | apply_standard_settings(flutter_wrapper_plugin)
63 | set_target_properties(flutter_wrapper_plugin PROPERTIES
64 | POSITION_INDEPENDENT_CODE ON)
65 | set_target_properties(flutter_wrapper_plugin PROPERTIES
66 | CXX_VISIBILITY_PRESET hidden)
67 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
68 | target_include_directories(flutter_wrapper_plugin PUBLIC
69 | "${WRAPPER_ROOT}/include"
70 | )
71 | add_dependencies(flutter_wrapper_plugin flutter_assemble)
72 |
73 | # Wrapper sources needed for the runner.
74 | add_library(flutter_wrapper_app STATIC
75 | ${CPP_WRAPPER_SOURCES_CORE}
76 | ${CPP_WRAPPER_SOURCES_APP}
77 | )
78 | apply_standard_settings(flutter_wrapper_app)
79 | target_link_libraries(flutter_wrapper_app PUBLIC flutter)
80 | target_include_directories(flutter_wrapper_app PUBLIC
81 | "${WRAPPER_ROOT}/include"
82 | )
83 | add_dependencies(flutter_wrapper_app flutter_assemble)
84 |
85 | # === Flutter tool backend ===
86 | # _phony_ is a non-existent file to force this command to run every time,
87 | # since currently there's no way to get a full input/output list from the
88 | # flutter tool.
89 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
90 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
91 | add_custom_command(
92 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
93 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
94 | ${CPP_WRAPPER_SOURCES_APP}
95 | ${PHONY_OUTPUT}
96 | COMMAND ${CMAKE_COMMAND} -E env
97 | ${FLUTTER_TOOL_ENVIRONMENT}
98 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
99 | ${FLUTTER_TARGET_PLATFORM} $
100 | VERBATIM
101 | )
102 | add_custom_target(flutter_assemble DEPENDS
103 | "${FLUTTER_LIBRARY}"
104 | ${FLUTTER_LIBRARY_HEADERS}
105 | ${CPP_WRAPPER_SOURCES_CORE}
106 | ${CPP_WRAPPER_SOURCES_PLUGIN}
107 | ${CPP_WRAPPER_SOURCES_APP}
108 | )
109 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/linux/my_application.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | #include
4 | #ifdef GDK_WINDOWING_X11
5 | #include
6 | #endif
7 |
8 | #include "flutter/generated_plugin_registrant.h"
9 |
10 | struct _MyApplication {
11 | GtkApplication parent_instance;
12 | char** dart_entrypoint_arguments;
13 | };
14 |
15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
16 |
17 | // Implements GApplication::activate.
18 | static void my_application_activate(GApplication* application) {
19 | MyApplication* self = MY_APPLICATION(application);
20 | GtkWindow* window =
21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
22 |
23 | // Use a header bar when running in GNOME as this is the common style used
24 | // by applications and is the setup most users will be using (e.g. Ubuntu
25 | // desktop).
26 | // If running on X and not using GNOME then just use a traditional title bar
27 | // in case the window manager does more exotic layout, e.g. tiling.
28 | // If running on Wayland assume the header bar will work (may need changing
29 | // if future cases occur).
30 | gboolean use_header_bar = TRUE;
31 | #ifdef GDK_WINDOWING_X11
32 | GdkScreen *screen = gtk_window_get_screen(window);
33 | if (GDK_IS_X11_SCREEN(screen)) {
34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
36 | use_header_bar = FALSE;
37 | }
38 | }
39 | #endif
40 | if (use_header_bar) {
41 | GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
42 | gtk_widget_show(GTK_WIDGET(header_bar));
43 | gtk_header_bar_set_title(header_bar, "tray_manager_example");
44 | gtk_header_bar_set_show_close_button(header_bar, TRUE);
45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
46 | }
47 | else {
48 | gtk_window_set_title(window, "tray_manager_example");
49 | }
50 |
51 | gtk_window_set_default_size(window, 1280, 720);
52 | gtk_widget_show(GTK_WIDGET(window));
53 |
54 | g_autoptr(FlDartProject) project = fl_dart_project_new();
55 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
56 |
57 | FlView* view = fl_view_new(project);
58 | gtk_widget_show(GTK_WIDGET(view));
59 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
60 |
61 | fl_register_plugins(FL_PLUGIN_REGISTRY(view));
62 |
63 | gtk_widget_grab_focus(GTK_WIDGET(view));
64 | }
65 |
66 | // Implements GApplication::local_command_line.
67 | static gboolean my_application_local_command_line(GApplication* application, gchar ***arguments, int *exit_status) {
68 | MyApplication* self = MY_APPLICATION(application);
69 | // Strip out the first argument as it is the binary name.
70 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
71 |
72 | g_autoptr(GError) error = nullptr;
73 | if (!g_application_register(application, nullptr, &error)) {
74 | g_warning("Failed to register: %s", error->message);
75 | *exit_status = 1;
76 | return TRUE;
77 | }
78 |
79 | g_application_activate(application);
80 | *exit_status = 0;
81 |
82 | return TRUE;
83 | }
84 |
85 | // Implements GObject::dispose.
86 | static void my_application_dispose(GObject *object) {
87 | MyApplication* self = MY_APPLICATION(object);
88 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
89 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
90 | }
91 |
92 | static void my_application_class_init(MyApplicationClass* klass) {
93 | G_APPLICATION_CLASS(klass)->activate = my_application_activate;
94 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
95 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
96 | }
97 |
98 | static void my_application_init(MyApplication* self) {}
99 |
100 | MyApplication* my_application_new() {
101 | return MY_APPLICATION(g_object_new(my_application_get_type(),
102 | "application-id", APPLICATION_ID,
103 | "flags", G_APPLICATION_NON_UNIQUE,
104 | nullptr));
105 | }
106 |
--------------------------------------------------------------------------------
/packages/tray_manager/example/linux/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.10)
2 | project(runner LANGUAGES CXX)
3 |
4 | set(BINARY_NAME "tray_manager_example")
5 | set(APPLICATION_ID "com.example.tray_manager")
6 |
7 | cmake_policy(SET CMP0063 NEW)
8 |
9 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
10 |
11 | # Root filesystem for cross-building.
12 | if(FLUTTER_TARGET_PLATFORM_SYSROOT)
13 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
14 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
16 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
17 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
18 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
19 | endif()
20 |
21 | # Configure build options.
22 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
23 | set(CMAKE_BUILD_TYPE "Debug" CACHE
24 | STRING "Flutter build mode" FORCE)
25 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
26 | "Debug" "Profile" "Release")
27 | endif()
28 |
29 | # Compilation settings that should be applied to most targets.
30 | function(APPLY_STANDARD_SETTINGS TARGET)
31 | target_compile_features(${TARGET} PUBLIC cxx_std_14)
32 | target_compile_options(${TARGET} PRIVATE -Wall -Werror)
33 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>")
34 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>")
35 | endfunction()
36 |
37 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
38 |
39 | # Flutter library and tool build rules.
40 | add_subdirectory(${FLUTTER_MANAGED_DIR})
41 |
42 | # System-level dependencies.
43 | find_package(PkgConfig REQUIRED)
44 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
45 |
46 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
47 |
48 | # Application build
49 | add_executable(${BINARY_NAME}
50 | "main.cc"
51 | "my_application.cc"
52 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
53 | )
54 | apply_standard_settings(${BINARY_NAME})
55 | target_link_libraries(${BINARY_NAME} PRIVATE flutter)
56 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
57 | add_dependencies(${BINARY_NAME} flutter_assemble)
58 | # Only the install-generated bundle's copy of the executable will launch
59 | # correctly, since the resources must in the right relative locations. To avoid
60 | # people trying to run the unbundled copy, put it in a subdirectory instead of
61 | # the default top-level location.
62 | set_target_properties(${BINARY_NAME}
63 | PROPERTIES
64 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
65 | )
66 |
67 | # Generated plugin build rules, which manage building the plugins and adding
68 | # them to the application.
69 | include(flutter/generated_plugins.cmake)
70 |
71 |
72 | # === Installation ===
73 | # By default, "installing" just makes a relocatable bundle in the build
74 | # directory.
75 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
76 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
77 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
78 | endif()
79 |
80 | # Start with a clean build bundle directory every time.
81 | install(CODE "
82 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
83 | " COMPONENT Runtime)
84 |
85 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
86 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
87 |
88 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
89 | COMPONENT Runtime)
90 |
91 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
92 | COMPONENT Runtime)
93 |
94 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
95 | COMPONENT Runtime)
96 |
97 | if(PLUGIN_BUNDLED_LIBRARIES)
98 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
99 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
100 | COMPONENT Runtime)
101 | endif()
102 |
103 | # Fully re-copy the assets directory on each build to avoid having stale files
104 | # from a previous install.
105 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
106 | install(CODE "
107 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
108 | " COMPONENT Runtime)
109 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
110 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
111 |
112 | # Install the AOT library on non-Debug builds only.
113 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
114 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
115 | COMPONENT Runtime)
116 | endif()
117 |
--------------------------------------------------------------------------------
/README-ZH.md:
--------------------------------------------------------------------------------
1 | > **⚠️ 迁移通知**: 本插件正在迁移到 [libnativeapi/nativeapi-flutter](https://github.com/libnativeapi/nativeapi-flutter)
2 | >
3 | > 新版本基于统一的 C++ 核心库([libnativeapi/nativeapi](https://github.com/libnativeapi/nativeapi)),提供更完整、一致的跨平台原生 API 支持。
4 |
5 | # tray_manager
6 |
7 | [![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] ![][visits-count-image]
8 |
9 | [pub-image]: https://img.shields.io/pub/v/tray_manager.svg
10 | [pub-url]: https://pub.dev/packages/tray_manager
11 | [discord-image]: https://img.shields.io/discord/884679008049037342.svg
12 | [discord-url]: https://discord.gg/zPa6EZ2jqb
13 | [visits-count-image]: https://img.shields.io/badge/dynamic/json?label=Visits%20Count&query=value&url=https://api.countapi.xyz/hit/leanflutter.tray_manager/visits
14 |
15 | 这个插件允许 Flutter 桌面应用定义系统托盘。
16 |
17 | [English](./README.md) | 简体中文
18 |
19 | ---
20 |
21 |
22 |
23 |
24 | - [平台支持](#%E5%B9%B3%E5%8F%B0%E6%94%AF%E6%8C%81)
25 | - [截图](#%E6%88%AA%E5%9B%BE)
26 | - [已知问题](#%E5%B7%B2%E7%9F%A5%E9%97%AE%E9%A2%98)
27 | - [与 app_links 不兼容](#%E4%B8%8E-app_links-%E4%B8%8D%E5%85%BC%E5%AE%B9)
28 | - [在 GNOME 中不显示](#%E5%9C%A8-gnome-%E4%B8%AD%E4%B8%8D%E6%98%BE%E7%A4%BA)
29 | - [快速开始](#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B)
30 | - [安装](#%E5%AE%89%E8%A3%85)
31 | - [Linux requirements](#linux-requirements)
32 | - [用法](#%E7%94%A8%E6%B3%95)
33 | - [监听事件](#%E7%9B%91%E5%90%AC%E4%BA%8B%E4%BB%B6)
34 | - [谁在用使用它?](#%E8%B0%81%E5%9C%A8%E7%94%A8%E4%BD%BF%E7%94%A8%E5%AE%83)
35 | - [API](#api)
36 | - [TrayManager](#traymanager)
37 | - [许可证](#%E8%AE%B8%E5%8F%AF%E8%AF%81)
38 |
39 |
40 |
41 | ## 平台支持
42 |
43 | | Linux | macOS | Windows |
44 | | :---: | :---: | :-----: |
45 | | ✔️ | ✔️ | ✔️ |
46 |
47 | ## 截图
48 |
49 | | macOS | Linux | Windows |
50 | | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
51 | |  |  |  |
52 |
53 | ## 已知问题
54 |
55 | ### 与 app_links 不兼容
56 |
57 | 当同时使用 `app_links` 包和 `tray_manager` 时,可能会出现插件无法正常工作。这是因为低版本 `app_links` 在内部阻止了事件传播,导致菜单点击事件无法触发。
58 |
59 | 要解决此问题:
60 |
61 | 1. 确保你的 `app_links` 包版本大于或等于 6.3.3
62 |
63 | ```yaml
64 | dependencies:
65 | app_links: ^6.3.3
66 | ```
67 |
68 | 2. 使用 [protocol_handler](https://github.com/leanflutter/protocol_handler) 包代替 `app_links` 包。
69 |
70 | ### 在 GNOME 中不显示
71 |
72 | 在使用 GNOME 桌面时, 可能需要安装 [AppIndicator](https://github.com/ubuntu/gnome-shell-extension-appindicator) 扩展以显示图标。
73 |
74 | ## 快速开始
75 |
76 | ### 安装
77 |
78 | 将此添加到你的软件包的 pubspec.yaml 文件:
79 |
80 | ```yaml
81 | dependencies:
82 | tray_manager: ^0.5.2
83 | ```
84 |
85 | 或
86 |
87 | ```yaml
88 | dependencies:
89 | tray_manager:
90 | git:
91 | url: https://github.com/leanflutter/tray_manager.git
92 | ref: main
93 | path: packages/tray_manager
94 | ```
95 |
96 | #### Linux requirements
97 |
98 | - `ayatana-appindicator3-0.1` or `appindicator3-0.1`
99 |
100 | 运行以下命令
101 |
102 | ```
103 | sudo apt-get install libayatana-appindicator3-dev
104 | ```
105 |
106 | 或
107 |
108 | ```
109 | sudo apt-get install appindicator3-0.1 libappindicator3-dev
110 | ```
111 |
112 | ### 用法
113 |
114 | ```dart
115 | import 'package:flutter/material.dart' hide MenuItem;
116 | import 'package:tray_manager/tray_manager.dart';
117 |
118 | await trayManager.setIcon(
119 | Platform.isWindows
120 | ? 'images/tray_icon.ico'
121 | : 'images/tray_icon.png',
122 | );
123 | Menu menu = Menu(
124 | items: [
125 | MenuItem(
126 | key: 'show_window',
127 | label: 'Show Window',
128 | ),
129 | MenuItem.separator(),
130 | MenuItem(
131 | key: 'exit_app',
132 | label: 'Exit App',
133 | ),
134 | ],
135 | );
136 | await trayManager.setContextMenu(menu);
137 | ```
138 |
139 | > 请看这个插件的示例应用,以了解完整的例子。
140 |
141 | #### 监听事件
142 |
143 | ```dart
144 | import 'package:flutter/material.dart';
145 | import 'package:tray_manager/tray_manager.dart';
146 |
147 | class HomePage extends StatefulWidget {
148 | @override
149 | _HomePageState createState() => _HomePageState();
150 | }
151 |
152 | class _HomePageState extends State with TrayListener {
153 | @override
154 | void initState() {
155 | trayManager.addListener(this);
156 | super.initState();
157 | _init();
158 | }
159 |
160 | @override
161 | void dispose() {
162 | trayManager.removeListener(this);
163 | super.dispose();
164 | }
165 |
166 | void _init() {
167 | // ...
168 | }
169 |
170 | @override
171 | Widget build(BuildContext context) {
172 | // ...
173 | }
174 |
175 | @override
176 | void onTrayIconMouseDown() {
177 | // do something, for example pop up the menu
178 | trayManager.popUpContextMenu();
179 | }
180 |
181 | @override
182 | void onTrayIconRightMouseDown() {
183 | // do something
184 | }
185 |
186 | @override
187 | void onTrayIconRightMouseUp() {
188 | // do something
189 | }
190 |
191 | @override
192 | void onTrayMenuItemClick(MenuItem menuItem) {
193 | if (menuItem.key == 'show_window') {
194 | // do something
195 | } else if (menuItem.key == 'exit_app') {
196 | // do something
197 | }
198 | }
199 | }
200 | ```
201 |
202 | ## 谁在用使用它?
203 |
204 | - [Airclap](https://airclap.app/) - 任何文件,任意设备,随意发送。简单好用的跨平台高速文件传输 APP。
205 | - [Biyi (比译)](https://biyidev.com/) - 一个便捷的翻译和词典应用程序。
206 |
207 | ## API
208 |
209 | ### TrayManager
210 |
211 | | Method | Description | Linux | macOS | Windows |
212 | | ---------------- | -------------------------------- | ----- | ----- | ------- |
213 | | destroy | 立即销毁托盘图标 | ✔️ | ✔️ | ✔️ |
214 | | setIcon | 设置与此托盘图标相关的图片。 | ✔️ | ✔️ | ✔️ |
215 | | setIconPosition | 设置托盘图标的图标位置。 | ➖ | ✔️ | ➖ |
216 | | setToolTip | 设置此托盘图标的悬停文本。 | ➖ | ✔️ | ✔️ |
217 | | setContextMenu | 设置此图标的上下文菜单。 | ✔️ | ✔️ | ✔️ |
218 | | popUpContextMenu | 弹出托盘图标的上下文菜单。 | ➖ | ✔️ | ✔️ |
219 | | getBounds | 返回 `Rect` 这个托盘图标的边界。 | ➖ | ✔️ | ✔️ |
220 |
221 | ## 许可证
222 |
223 | [MIT](./LICENSE)
224 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | > **⚠️ Migration Notice**: This plugin is being migrated to [libnativeapi/nativeapi-flutter](https://github.com/libnativeapi/nativeapi-flutter)
2 | >
3 | > The new version is based on a unified C++ core library ([libnativeapi/nativeapi](https://github.com/libnativeapi/nativeapi)), providing more complete and consistent cross-platform native API support.
4 | r
5 |
6 | [![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] ![][visits-count-image]
7 |
8 | [pub-image]: https://img.shields.io/pub/v/tray_manager.svg
9 | [pub-url]: https://pub.dev/packages/tray_manager
10 | [discord-image]: https://img.shields.io/discord/884679008049037342.svg
11 | [discord-url]: https://discord.gg/zPa6EZ2jqb
12 | [visits-count-image]: https://img.shields.io/badge/dynamic/json?label=Visits%20Count&query=value&url=https://api.countapi.xyz/hit/leanflutter.tray_manager/visits
13 |
14 | This plugin allows Flutter desktop apps to defines system tray.
15 |
16 | English | [简体中文](./README-ZH.md)
17 |
18 | ---
19 |
20 |
21 |
22 |
23 | - [Platform Support](#platform-support)
24 | - [Screenshots](#screenshots)
25 | - [Known Issues](#known-issues)
26 | - [Not Working with app_links](#not-working-with-app_links)
27 | - [Not Showing in GNOME](#not-showing-in-gnome)
28 | - [Quick Start](#quick-start)
29 | - [Installation](#installation)
30 | - [Linux requirements](#linux-requirements)
31 | - [Usage](#usage)
32 | - [Listening events](#listening-events)
33 | - [Who's using it?](#whos-using-it)
34 | - [API](#api)
35 | - [TrayManager](#traymanager)
36 | - [License](#license)
37 |
38 |
39 |
40 | ## Platform Support
41 |
42 | | Linux | macOS | Windows |
43 | | :---: | :---: | :-----: |
44 | | ✔️ | ✔️ | ✔️ |
45 |
46 | ## Screenshots
47 |
48 | | macOS | Linux | Windows |
49 | | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
50 | |  |  |  |
51 |
52 | ## Known Issues
53 |
54 | ### Not Working with app_links
55 |
56 | When using the `app_links` package together with `tray_manager`, the plugin may not work properly. This is because older versions of `app_links` internally block event propagation, preventing menu click events from being triggered.
57 |
58 | To resolve this issue:
59 |
60 | 1. Make sure your `app_links` package version is greater than or equal to 6.3.3
61 |
62 | ```yaml
63 | dependencies:
64 | app_links: ^6.3.3
65 | ```
66 |
67 | 2. Use [protocol_handler](https://github.com/leanflutter/protocol_handler) package instead of `app_links` package.
68 |
69 | ### Not Showing in GNOME
70 |
71 | In GNOME desktop environment, the [AppIndicator](https://github.com/ubuntu/gnome-shell-extension-appindicator) extension may be required to display the icon.
72 |
73 | ## Quick Start
74 |
75 | ### Installation
76 |
77 | Add this to your package's pubspec.yaml file:
78 |
79 | ```yaml
80 | dependencies:
81 | tray_manager: ^0.5.2
82 | ```
83 |
84 | Or
85 |
86 | ```yaml
87 | dependencies:
88 | tray_manager:
89 | git:
90 | url: https://github.com/leanflutter/tray_manager.git
91 | ref: main
92 | path: packages/tray_manager
93 | ```
94 |
95 | #### Linux requirements
96 |
97 | - `ayatana-appindicator3-0.1` or `appindicator3-0.1`
98 |
99 | Run the following command
100 |
101 | ```
102 | sudo apt-get install libayatana-appindicator3-dev
103 | ```
104 |
105 | Or
106 |
107 | ```
108 | sudo apt-get install appindicator3-0.1 libappindicator3-dev
109 | ```
110 |
111 | ### Usage
112 |
113 | ```dart
114 | import 'package:flutter/material.dart' hide MenuItem;
115 | import 'package:tray_manager/tray_manager.dart';
116 |
117 | await trayManager.setIcon(
118 | Platform.isWindows
119 | ? 'images/tray_icon.ico'
120 | : 'images/tray_icon.png',
121 | );
122 | Menu menu = Menu(
123 | items: [
124 | MenuItem(
125 | key: 'show_window',
126 | label: 'Show Window',
127 | ),
128 | MenuItem.separator(),
129 | MenuItem(
130 | key: 'exit_app',
131 | label: 'Exit App',
132 | ),
133 | ],
134 | );
135 | await trayManager.setContextMenu(menu);
136 | ```
137 |
138 | > Please see the example app of this plugin for a full example.
139 |
140 | #### Listening events
141 |
142 | ```dart
143 | import 'package:flutter/material.dart';
144 | import 'package:tray_manager/tray_manager.dart';
145 |
146 | class HomePage extends StatefulWidget {
147 | @override
148 | _HomePageState createState() => _HomePageState();
149 | }
150 |
151 | class _HomePageState extends State with TrayListener {
152 | @override
153 | void initState() {
154 | trayManager.addListener(this);
155 | super.initState();
156 | _init();
157 | }
158 |
159 | @override
160 | void dispose() {
161 | trayManager.removeListener(this);
162 | super.dispose();
163 | }
164 |
165 | void _init() {
166 | // ...
167 | }
168 |
169 | @override
170 | Widget build(BuildContext context) {
171 | // ...
172 | }
173 |
174 | @override
175 | void onTrayIconMouseDown() {
176 | // do something, for example pop up the menu
177 | trayManager.popUpContextMenu();
178 | }
179 |
180 | @override
181 | void onTrayIconRightMouseDown() {
182 | // do something
183 | }
184 |
185 | @override
186 | void onTrayIconRightMouseUp() {
187 | // do something
188 | }
189 |
190 | @override
191 | void onTrayMenuItemClick(MenuItem menuItem) {
192 | if (menuItem.key == 'show_window') {
193 | // do something
194 | } else if (menuItem.key == 'exit_app') {
195 | // do something
196 | }
197 | }
198 | }
199 | ```
200 |
201 | ## Who's using it?
202 |
203 | - [Airclap](https://airclap.app/) - Send any file to any device. cross platform, ultra fast and easy to use.
204 | - [Biyi (比译)](https://biyidev.com/) - A convenient translation and dictionary app.
205 |
206 | ## API
207 |
208 | ### TrayManager
209 |
210 | | Method | Description | Linux | macOS | Windows |
211 | | ---------------- | ---------------------------------------------- | ----- | ----- | ------- |
212 | | destroy | Destroys the tray icon immediately. | ✔️ | ✔️ | ✔️ |
213 | | setIcon | Sets the image associated with this tray icon. | ✔️ | ✔️ | ✔️ |
214 | | setIconPosition | Sets the icon position of the tray icon. | ➖ | ✔️ | ➖ |
215 | | setToolTip | Sets the hover text for this tray icon. | ➖ | ✔️ | ✔️ |
216 | | setContextMenu | Sets the context menu for this icon. | ✔️ | ✔️ | ✔️ |
217 | | popUpContextMenu | Pops up the context menu of the tray icon. | ➖ | ✔️ | ✔️ |
218 | | getBounds | Returns `Rect` The bounds of this tray icon. | ➖ | ✔️ | ✔️ |
219 |
220 | ## License
221 |
222 | [MIT](./LICENSE)
223 |
--------------------------------------------------------------------------------
/packages/tray_manager/lib/src/tray_manager.dart:
--------------------------------------------------------------------------------
1 | import 'dart:async';
2 | import 'dart:convert';
3 | import 'dart:io';
4 |
5 | import 'package:flutter/foundation.dart';
6 | import 'package:flutter/services.dart';
7 | import 'package:flutter/widgets.dart';
8 | import 'package:menu_base/menu_base.dart';
9 | import 'package:path/path.dart' as path;
10 | import 'package:shortid/shortid.dart';
11 | import 'package:tray_manager/src/helpers/sandbox.dart';
12 | import 'package:tray_manager/src/tray_listener.dart';
13 |
14 | const kEventOnTrayIconMouseDown = 'onTrayIconMouseDown';
15 | const kEventOnTrayIconMouseUp = 'onTrayIconMouseUp';
16 | const kEventOnTrayIconRightMouseDown = 'onTrayIconRightMouseDown';
17 | const kEventOnTrayIconRightMouseUp = 'onTrayIconRightMouseUp';
18 | const kEventOnTrayMenuItemClick = 'onTrayMenuItemClick';
19 |
20 | enum TrayIconPosition { left, right }
21 |
22 | class TrayManager {
23 | TrayManager._() {
24 | _channel.setMethodCallHandler(_methodCallHandler);
25 | }
26 |
27 | /// The shared instance of [TrayManager].
28 | static final TrayManager instance = TrayManager._();
29 |
30 | final MethodChannel _channel = const MethodChannel('tray_manager');
31 |
32 | final ObserverList _listeners = ObserverList();
33 |
34 | double get _devicePixelRatio {
35 | final flutterView = WidgetsBinding.instance.platformDispatcher.views.single;
36 | return MediaQueryData.fromView(flutterView).devicePixelRatio;
37 | }
38 |
39 | Menu? _menu;
40 |
41 | Future _methodCallHandler(MethodCall call) async {
42 | for (final TrayListener listener in _listeners) {
43 | switch (call.method) {
44 | case kEventOnTrayIconMouseDown:
45 | listener.onTrayIconMouseDown();
46 | break;
47 | case kEventOnTrayIconMouseUp:
48 | listener.onTrayIconMouseUp();
49 | break;
50 | case kEventOnTrayIconRightMouseDown:
51 | listener.onTrayIconRightMouseDown();
52 | break;
53 | case kEventOnTrayIconRightMouseUp:
54 | listener.onTrayIconRightMouseUp();
55 | break;
56 | case kEventOnTrayMenuItemClick:
57 | int id = call.arguments['id'];
58 | MenuItem? menuItem = _menu?.getMenuItemById(id);
59 | if (menuItem != null) {
60 | bool? oldChecked = menuItem.checked;
61 | if (menuItem.onClick != null) {
62 | menuItem.onClick?.call(menuItem);
63 | }
64 | listener.onTrayMenuItemClick(menuItem);
65 |
66 | bool? newChecked = menuItem.checked;
67 | if (oldChecked != newChecked) {
68 | await setContextMenu(_menu!);
69 | }
70 | }
71 | break;
72 | }
73 | }
74 | }
75 |
76 | /// Whether any listeners are currently registered.
77 | bool get hasListeners {
78 | return _listeners.isNotEmpty;
79 | }
80 |
81 | /// Register a closure to be called when the tray events.
82 | void addListener(TrayListener listener) {
83 | _listeners.add(listener);
84 | }
85 |
86 | /// Remove a previously registered closure from the list of closures that are
87 | /// notified when the tray events.
88 | void removeListener(TrayListener listener) {
89 | _listeners.remove(listener);
90 | }
91 |
92 | // Destroys the tray icon immediately.
93 | Future destroy() async {
94 | await _channel.invokeMethod('destroy');
95 | }
96 |
97 | /// Sets the image associated with this tray icon.
98 | ///
99 | /// [iconPath] is the path to the image file.
100 | ///
101 | /// However, if the app is running in a sandbox like Flatpak or Snap,
102 | /// [iconPath] should be the name of the icon as specified in the app's
103 | /// manifest file, without the path or file extension. For example, if the
104 | /// icon is specified as `org.example.app` in the Flatpak manifest file, then
105 | /// the icon should be passed as `org.example.app`.
106 | Future setIcon(
107 | String iconPath, {
108 | bool isTemplate = false, // macOS only
109 | TrayIconPosition iconPosition = TrayIconPosition.left, // macOS only
110 | int iconSize = 18, // macOS only
111 | }) async {
112 | final Map arguments = {
113 | 'id': shortid.generate(),
114 | 'iconPath': path.joinAll([
115 | path.dirname(Platform.resolvedExecutable),
116 | 'data/flutter_assets',
117 | iconPath,
118 | ]),
119 | 'isTemplate': isTemplate,
120 | 'iconPosition': iconPosition.name,
121 | 'iconSize': iconSize,
122 | };
123 |
124 | switch (defaultTargetPlatform) {
125 | case TargetPlatform.linux:
126 | if (runningInSandbox()) {
127 | // Pass the icon name as specified if running in a sandbox.
128 | //
129 | // This is required because when running in a sandbox, paths are not
130 | // the same as seen by the app and the host system.
131 | arguments['iconPath'] = iconPath;
132 | }
133 | break;
134 | case TargetPlatform.macOS:
135 | // Add the icon as base64 string
136 | ByteData imageData = await rootBundle.load(iconPath);
137 | String base64Icon = base64Encode(imageData.buffer.asUint8List());
138 | arguments['base64Icon'] = base64Icon;
139 | break;
140 | default:
141 | break;
142 | }
143 |
144 | await _channel.invokeMethod('setIcon', arguments);
145 | }
146 |
147 | /// Sets the icon position of the tray icon.
148 | ///
149 | /// @platforms macos
150 | Future setIconPosition(TrayIconPosition trayIconPosition) async {
151 | final arguments = {
152 | 'iconPosition': trayIconPosition.name,
153 | };
154 | await _channel.invokeMethod('setIconPosition', arguments);
155 | }
156 |
157 | /// Sets the hover text for this tray icon.
158 | ///
159 | /// Must be called after the icon is set.
160 | /// ```dart
161 | /// await trayManager.setIcon(...);
162 | /// await trayManager.setToolTip(...);
163 | /// ```
164 | Future setToolTip(String toolTip) async {
165 | final Map arguments = {
166 | 'toolTip': toolTip,
167 | };
168 | await _channel.invokeMethod('setToolTip', arguments);
169 | }
170 |
171 | /// Sets the title for this tray icon.
172 | Future setTitle(String title) async {
173 | final Map arguments = {
174 | 'title': title,
175 | };
176 | await _channel.invokeMethod('setTitle', arguments);
177 | }
178 |
179 | /// Sets the context menu for this icon.
180 | Future setContextMenu(Menu menu) async {
181 | _menu = menu;
182 | final Map arguments = {
183 | 'menu': menu.toJson(),
184 | };
185 | await _channel.invokeMethod('setContextMenu', arguments);
186 | }
187 |
188 | /// Pops up the context menu of the tray icon.
189 | ///
190 | /// [bringAppToFront] If true, the app will be brought to the front when the
191 | /// context menu is shown. Only works on Windows.
192 | Future popUpContextMenu({
193 | @Deprecated(
194 | 'This parameter is only supported on Windows and will be removed in the future.',
195 | )
196 | bool bringAppToFront = false,
197 | }) async {
198 | final Map arguments = {
199 | 'bringAppToFront': bringAppToFront,
200 | };
201 | await _channel.invokeMethod('popUpContextMenu', arguments);
202 | }
203 |
204 | /// The bounds of this tray icon.
205 | Future getBounds() async {
206 | final Map arguments = {
207 | 'devicePixelRatio': _devicePixelRatio,
208 | };
209 | final Map? resultData = await _channel.invokeMethod(
210 | 'getBounds',
211 | arguments,
212 | );
213 | if (resultData == null) {
214 | return null;
215 | }
216 | return Rect.fromLTWH(
217 | resultData['x'],
218 | resultData['y'],
219 | resultData['width'],
220 | resultData['height'],
221 | );
222 | }
223 | }
224 |
225 | final trayManager = TrayManager.instance;
226 |
--------------------------------------------------------------------------------
/packages/tray_manager/linux/tray_manager_plugin.cc:
--------------------------------------------------------------------------------
1 | #include "include/tray_manager/tray_manager_plugin.h"
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | #ifdef HAVE_AYATANA
8 | #include
9 | #else
10 | #include
11 | #endif
12 | #include
13 | #include
14 | #include