Skip to content

Commit

Permalink
feat: add popUpContextMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
antler119 committed Jan 28, 2022
1 parent 8830518 commit 15c562f
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 246 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
## 0.0.9

* [Feature] add popUpContextMenu
* [Feature] add new system tray event (leftMouseDown / rightMouseDown)

## 0.0.8

* tray icon support high DPI on windows
* Fixed crash when minimize window, then click on menubar on macOS
* support simple appwindow on ubuntu
* [Feature] tray icon support high DPI on windows
* [Feature] support simple class appwindow for control window on all platforms
* [Fixed] fixed crash when minimize window, then click on menubar on macOS

## 0.0.7

Expand Down
169 changes: 137 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@

A [Flutter package](https://github.com/antler119/system_tray.git) that that enables support for system tray menu for desktop flutter apps. **on Windows, macOS and Linux**.

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

## Install
In the pubspec.yaml of your flutter project, add the following dependency:

```yaml
dependencies:
...
system_tray: ^0.0.8
system_tray: ^0.0.9
```
In your library add the following import:
Expand All @@ -32,18 +28,94 @@ sudo apt-get install appindicator3-0.1 libappindicator3-dev
## Example App
### Windows

<img src="https://raw.githubusercontent.com/antler119/system_tray/master/resources/screenshot_windows.jpg">
<img src="https://raw.githubusercontent.com/antler119/system_tray/master/resources/screenshot_windows.png">

### macOS

<img src="https://raw.githubusercontent.com/antler119/system_tray/master/resources/screenshot_macos.jpg">
<img src="https://raw.githubusercontent.com/antler119/system_tray/master/resources/screenshot_macos.png">

### Linux

<img src="https://raw.githubusercontent.com/antler119/system_tray/master/resources/screenshot_ubuntu.jpg">


## Usage:
<img src="https://raw.githubusercontent.com/antler119/system_tray/master/resources/screenshot_ubuntu.png">

## API

<table>
<tr>
<th>Method</th>
<th>Description</th>
<th>Windows</th>
<th>macOS</th>
<th>Linux</th>
</tr>
<tr>
<td>initSystemTray</td>
<td>Initialize system tray</td>
<td>✔️</td>
<td>✔️</td>
<td>✔️</td>
</tr>
<tr>
<td>setSystemTrayInfo</td>
<td>Modify the tray info</td>
<td>
<ul>
<li>icon</li>
<li>toolTip</li>
</ul>
</td>
<td>
<ul>
<li>title</li>
<li>icon</li>
<li>toolTip</li>
</ul>
</td>
<td>
<ul>
<li>icon</li>
</ul>
</td>
</tr>
<tr>
<td>setContextMenu</td>
<td>Set the tray context menu</td>
<td>✔️</td>
<td>✔️</td>
<td>✔️</td>
</tr>
<tr>
<td>popUpContextMenu</td>
<td>Popup the tray context menu</td>
<td>✔️</td>
<td>✔️</td>
<td>➖</td>
</tr>
<tr>
<td>registerSystemTrayEventHandler</td>
<td>Register system tray event</td>
<td>
<ul>
<li>leftMouseUp</li>
<li>leftMouseDown</li>
<li>leftMouseDblClk</li>
<li>rightMouseUp</li>
<li>rightMouseDown</li>
</ul>
</td>
<td>
<ul>
<li>leftMouseUp</li>
<li>leftMouseDown</li>
<li>rightMouseUp</li>
<li>rightMouseDown</li>
</ul>
</td>
<td>➖</td>
</tr>
</table>

## Usage
Smallest example:

```dart
Expand All @@ -60,16 +132,29 @@ Future<void> initSystemTray() async {
MenuItem(label: 'Exit', onClicked: _appWindow.close),
];
// We first init the systray menu and then add the menu entries
await _systemTray.initSystemTray(
title: "system tray",
iconPath: path,
);
await _systemTray.setContextMenu(menu);
// handle system tray event
_systemTray.registerSystemTrayEventHandler((eventName) {
debugPrint("eventName: $eventName");
if (eventName == "leftMouseDown") {
} else if (eventName == "leftMouseUp") {
_systemTray.popUpContextMenu();
} else if (eventName == "rightMouseDown") {
} else if (eventName == "rightMouseUp") {
_appWindow.show();
}
});
}
```

Icon flashing effect example:
Flashing icon example:

```dart
Future<void> initSystemTray() async {
Expand Down Expand Up @@ -113,27 +198,43 @@ Future<void> initSystemTray() async {
),
MenuSeparator(),
SubMenu(
label: "SubMenu",
label: "Test API",
children: [
MenuItem(
label: 'SubItem1',
enabled: false,
onClicked: () {
debugPrint("click SubItem1");
},
),
MenuItem(
label: 'SubItem2',
onClicked: () {
debugPrint("click SubItem2");
},
),
MenuItem(
label: 'SubItem3',
onClicked: () {
debugPrint("click SubItem3");
},
SubMenu(
label: "setSystemTrayInfo",
children: [
MenuItem(
label: 'set title',
onClicked: () {
final String text = WordPair.random().asPascalCase;
debugPrint("click 'set title' : $text");
_systemTray.setSystemTrayInfo(
title: text,
);
},
),
MenuItem(
label: 'set icon path',
onClicked: () {
debugPrint("click 'set icon path' : $path");
_systemTray.setSystemTrayInfo(
iconPath: path,
);
},
),
MenuItem(
label: 'set tooltip',
onClicked: () {
final String text = WordPair.random().asPascalCase;
debugPrint("click 'set tooltip' : $text");
_systemTray.setSystemTrayInfo(
toolTip: text,
);
},
),
],
),
MenuItem(label: 'disabled Item', enabled: false),
],
),
MenuSeparator(),
Expand All @@ -155,7 +256,11 @@ Future<void> initSystemTray() async {
// handle system tray event
_systemTray.registerSystemTrayEventHandler((eventName) {
debugPrint("eventName: $eventName");
if (eventName == "leftMouseUp") {
if (eventName == "leftMouseDown") {
} else if (eventName == "leftMouseUp") {
_systemTray.popUpContextMenu();
} else if (eventName == "rightMouseDown") {
} else if (eventName == "rightMouseUp") {
_appWindow.show();
}
});
Expand Down
62 changes: 41 additions & 21 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dart:async';
import 'package:flutter/material.dart';

import 'package:bitsdojo_window/bitsdojo_window.dart';

import 'package:english_words/english_words.dart';
import 'package:system_tray/system_tray.dart';

void main() async {
Expand Down Expand Up @@ -88,27 +88,43 @@ class _MyAppState extends State<MyApp> {
),
MenuSeparator(),
SubMenu(
label: "SubMenu",
label: "Test API",
children: [
MenuItem(
label: 'SubItem1',
enabled: false,
onClicked: () {
debugPrint("click SubItem1");
},
),
MenuItem(
label: 'SubItem2',
onClicked: () {
debugPrint("click SubItem2");
},
),
MenuItem(
label: 'SubItem3',
onClicked: () {
debugPrint("click SubItem3");
},
SubMenu(
label: "setSystemTrayInfo",
children: [
MenuItem(
label: 'set title',
onClicked: () {
final String text = WordPair.random().asPascalCase;
debugPrint("click 'set title' : $text");
_systemTray.setSystemTrayInfo(
title: text,
);
},
),
MenuItem(
label: 'set icon path',
onClicked: () {
debugPrint("click 'set icon path' : $path");
_systemTray.setSystemTrayInfo(
iconPath: path,
);
},
),
MenuItem(
label: 'set toolTip',
onClicked: () {
final String text = WordPair.random().asPascalCase;
debugPrint("click 'set toolTip' : $text");
_systemTray.setSystemTrayInfo(
toolTip: text,
);
},
),
],
),
MenuItem(label: 'disabled Item', enabled: false),
],
),
MenuSeparator(),
Expand All @@ -130,8 +146,12 @@ class _MyAppState extends State<MyApp> {
// handle system tray event
_systemTray.registerSystemTrayEventHandler((eventName) {
debugPrint("eventName: $eventName");
if (eventName == "leftMouseUp") {
if (eventName == "leftMouseDown") {
} else if (eventName == "leftMouseUp") {
_appWindow.show();
} else if (eventName == "rightMouseDown") {
} else if (eventName == "rightMouseUp") {
_systemTray.popUpContextMenu();
}
});
}
Expand Down
9 changes: 8 additions & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
english_words:
dependency: "direct main"
description:
name: english_words
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.0"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -197,7 +204,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.8"
version: "0.0.9"
term_glyph:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
bitsdojo_window: 0.1.1+1
english_words: ^4.0.0

dev_dependencies:
flutter_test:
Expand Down
Loading

0 comments on commit 15c562f

Please sign in to comment.