-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into atavism/ios
- Loading branch information
Showing
5 changed files
with
106 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:lantern/common/common.dart'; | ||
import 'package:lantern/common/common_desktop.dart'; | ||
import 'package:tray_manager/tray_manager.dart'; | ||
import 'package:window_manager/window_manager.dart'; | ||
|
||
String systemTrayIcon(bool connected) { | ||
if (connected) { | ||
return Platform.isWindows | ||
? 'assets/images/lantern_connected_32.ico' | ||
: 'assets/images/lantern_connected_32.png'; | ||
} | ||
return Platform.isWindows | ||
? 'assets/images/lantern_disconnected_32.ico' | ||
: 'assets/images/lantern_disconnected_32.png'; | ||
} | ||
|
||
|
||
class TrayHandler with TrayListener { | ||
factory TrayHandler() => _getInstance(); | ||
|
||
static TrayHandler get instance => _getInstance(); | ||
static TrayHandler? _instance; | ||
|
||
static TrayHandler _getInstance() { | ||
_instance ??= TrayHandler._internal(); | ||
return _instance!; | ||
} | ||
|
||
TrayHandler._internal() { | ||
if (isDesktop()) { | ||
setupTray(false); | ||
} | ||
} | ||
|
||
Future<void> setupTray(bool isConnected) async { | ||
await trayManager.setIcon(systemTrayIcon(isConnected)); | ||
Menu menu = Menu( | ||
items: [ | ||
MenuItem( | ||
key: 'status', | ||
disabled: true, | ||
label: isConnected ? 'status_on'.i18n : 'status_off'.i18n, | ||
), | ||
MenuItem( | ||
key: 'status', | ||
label: isConnected ? 'disconnect'.i18n : 'connect'.i18n, | ||
), | ||
MenuItem.separator(), | ||
MenuItem( | ||
key: 'show_window', | ||
label: 'show'.i18n, | ||
), | ||
MenuItem.separator(), | ||
MenuItem( | ||
key: 'exit', | ||
label: 'exit'.i18n, | ||
), | ||
], | ||
); | ||
await trayManager.setContextMenu(menu); | ||
} | ||
|
||
@override | ||
void onTrayMenuItemClick(MenuItem menuItem) { | ||
switch (menuItem.key) { | ||
case 'show': | ||
windowManager.focus(); | ||
windowManager.setSkipTaskbar(false); | ||
case 'exit': | ||
windowManager.destroy(); | ||
ffiExit(); | ||
case 'status': | ||
final status = ffiVpnStatus().toDartString(); | ||
bool isConnected = status == "connected"; | ||
if (isConnected) { | ||
sysProxyOff(); | ||
setupTray(false); | ||
} else { | ||
sysProxyOn(); | ||
setupTray(true); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
Future<void> onTrayIconMouseDown() async { | ||
windowManager.show(); | ||
trayManager.popUpContextMenu(); | ||
} | ||
|
||
@override | ||
void onTrayIconRightMouseDown() { | ||
trayManager.popUpContextMenu(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters