Skip to content

Commit

Permalink
Additional clean-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism committed May 23, 2024
1 parent f747e34 commit 8b47d3a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 54 deletions.
50 changes: 0 additions & 50 deletions lib/common/common_desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,3 @@ export 'package:lantern/common/tray_handler.dart';
export 'package:lantern/common/ui/websocket.dart';
export 'package:web_socket_channel/io.dart';
export 'package:web_socket_channel/web_socket_channel.dart';

// Include resources here just for desktop compatibility or use

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';
}

// void setSelectedTab(BuildContext context, String name) {
// final tab = name.toNativeUtf8();
// final currentTab = ffiSelectedTab().toDartString();
// setSelectTab(tab);
// // when the user clicks on the active tab again, do nothing
// if (currentTab == name) return;
// // context.pushRoute(Home());
// }

Future<void> setupMenu(bool isConnected) async {
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);
await trayManager.setIcon(systemTrayIcon(isConnected));
}
7 changes: 3 additions & 4 deletions lib/vpn/vpn_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class VPNSwitch extends StatefulWidget {

class _VPNSwitchState extends State<VPNSwitch> with TrayListener, WindowListener {


TrayHandler trayHandler = TrayHandler();

@override
Expand All @@ -28,7 +27,7 @@ class _VPNSwitchState extends State<VPNSwitch> with TrayListener, WindowListener
@override
void dispose() {
if (isDesktop()) {
trayManager.removeListener(this);
trayManager.removeListener(trayHandler);
}
}

Expand All @@ -42,10 +41,10 @@ class _VPNSwitchState extends State<VPNSwitch> with TrayListener, WindowListener
bool isConnected = vpnStatus == 'connected';
if (isConnected) {
sysProxyOff();
await setupMenu(false);
await trayHandler.setupTray(false);
} else {
sysProxyOn();
await setupMenu(true);
await trayHandler.setupTray(true);
}
}

Expand Down

0 comments on commit 8b47d3a

Please sign in to comment.