Fix windows tray issues
Fix urltest issues Add auto changelog
This commit is contained in:
@@ -9,8 +9,10 @@ import 'package:fl_clash/common/archive.dart';
|
||||
import 'package:fl_clash/enum/enum.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tray_manager/tray_manager.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'clash/core.dart';
|
||||
@@ -605,6 +607,117 @@ class AppController {
|
||||
});
|
||||
}
|
||||
|
||||
Future _updateSystemTray({
|
||||
required bool isStart,
|
||||
required Brightness? brightness,
|
||||
}) async {
|
||||
await trayManager.destroy();
|
||||
await trayManager.setIcon(
|
||||
other.getTrayIconPath(
|
||||
isStart: isStart,
|
||||
brightness: brightness ??
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness,
|
||||
),
|
||||
);
|
||||
if (!Platform.isLinux) {
|
||||
await trayManager.setToolTip(
|
||||
appName,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
updateTray() async {
|
||||
if (!Platform.isLinux) {
|
||||
await _updateSystemTray(
|
||||
isStart: appFlowingState.isStart,
|
||||
brightness: appState.brightness,
|
||||
);
|
||||
}
|
||||
List<MenuItem> menuItems = [];
|
||||
final showMenuItem = MenuItem(
|
||||
label: appLocalizations.show,
|
||||
onClick: (_) {
|
||||
window?.show();
|
||||
},
|
||||
);
|
||||
menuItems.add(showMenuItem);
|
||||
final startMenuItem = MenuItem.checkbox(
|
||||
label:
|
||||
appFlowingState.isStart ? appLocalizations.stop : appLocalizations.start,
|
||||
onClick: (_) async {
|
||||
globalState.appController.updateStart();
|
||||
},
|
||||
checked: false,
|
||||
);
|
||||
menuItems.add(startMenuItem);
|
||||
menuItems.add(MenuItem.separator());
|
||||
for (final mode in Mode.values) {
|
||||
menuItems.add(
|
||||
MenuItem.checkbox(
|
||||
label: Intl.message(mode.name),
|
||||
onClick: (_) {
|
||||
globalState.appController.clashConfig.mode = mode;
|
||||
},
|
||||
checked: mode == clashConfig.mode,
|
||||
),
|
||||
);
|
||||
}
|
||||
menuItems.add(MenuItem.separator());
|
||||
if (appFlowingState.isStart) {
|
||||
menuItems.add(
|
||||
MenuItem.checkbox(
|
||||
label: appLocalizations.tun,
|
||||
onClick: (_) {
|
||||
globalState.appController.updateTun();
|
||||
},
|
||||
checked: clashConfig.tun.enable,
|
||||
),
|
||||
);
|
||||
menuItems.add(
|
||||
MenuItem.checkbox(
|
||||
label: appLocalizations.systemProxy,
|
||||
onClick: (_) {
|
||||
globalState.appController.updateSystemProxy();
|
||||
},
|
||||
checked: config.desktopProps.systemProxy,
|
||||
),
|
||||
);
|
||||
menuItems.add(MenuItem.separator());
|
||||
}
|
||||
final autoStartMenuItem = MenuItem.checkbox(
|
||||
label: appLocalizations.autoLaunch,
|
||||
onClick: (_) async {
|
||||
globalState.appController.updateAutoLaunch();
|
||||
},
|
||||
checked: config.appSetting.autoLaunch,
|
||||
);
|
||||
final adminAutoStartMenuItem = MenuItem.checkbox(
|
||||
label: appLocalizations.adminAutoLaunch,
|
||||
onClick: (_) async {
|
||||
globalState.appController.updateAdminAutoLaunch();
|
||||
},
|
||||
checked: config.appSetting.adminAutoLaunch,
|
||||
);
|
||||
menuItems.add(autoStartMenuItem);
|
||||
menuItems.add(adminAutoStartMenuItem);
|
||||
menuItems.add(MenuItem.separator());
|
||||
final exitMenuItem = MenuItem(
|
||||
label: appLocalizations.exit,
|
||||
onClick: (_) async {
|
||||
await globalState.appController.handleExit();
|
||||
},
|
||||
);
|
||||
menuItems.add(exitMenuItem);
|
||||
final menu = Menu(items: menuItems);
|
||||
await trayManager.setContextMenu(menu);
|
||||
if (Platform.isLinux) {
|
||||
await _updateSystemTray(
|
||||
isStart: appFlowingState.isStart,
|
||||
brightness: appState.brightness,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
recoveryData(
|
||||
List<int> data,
|
||||
RecoveryOption recoveryOption,
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tray_manager/tray_manager.dart';
|
||||
import 'package:window_ext/window_ext.dart';
|
||||
|
||||
class TrayManager extends StatefulWidget {
|
||||
final Widget child;
|
||||
@@ -21,129 +22,14 @@ class TrayManager extends StatefulWidget {
|
||||
State<TrayManager> createState() => _TrayContainerState();
|
||||
}
|
||||
|
||||
class _TrayContainerState extends State<TrayManager> with TrayListener {
|
||||
class _TrayContainerState extends State<TrayManager>
|
||||
with TrayListener {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
trayManager.addListener(this);
|
||||
}
|
||||
|
||||
_updateSystemTray({
|
||||
required bool isStart,
|
||||
required Brightness? brightness,
|
||||
}) async {
|
||||
if (Platform.isLinux) {
|
||||
await trayManager.destroy();
|
||||
}
|
||||
await trayManager.setIcon(
|
||||
other.getTrayIconPath(
|
||||
isStart: isStart,
|
||||
brightness: brightness ??
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness,
|
||||
),
|
||||
);
|
||||
if (!Platform.isLinux) {
|
||||
await trayManager.setToolTip(
|
||||
appName,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_updateTray(TrayState trayState) async {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!Platform.isLinux) {
|
||||
_updateSystemTray(
|
||||
isStart: trayState.isStart,
|
||||
brightness: trayState.brightness,
|
||||
);
|
||||
}
|
||||
List<MenuItem> menuItems = [];
|
||||
final showMenuItem = MenuItem(
|
||||
label: appLocalizations.show,
|
||||
onClick: (_) {
|
||||
window?.show();
|
||||
},
|
||||
);
|
||||
menuItems.add(showMenuItem);
|
||||
final startMenuItem = MenuItem.checkbox(
|
||||
label:
|
||||
trayState.isStart ? appLocalizations.stop : appLocalizations.start,
|
||||
onClick: (_) async {
|
||||
globalState.appController.updateStart();
|
||||
},
|
||||
checked: false,
|
||||
);
|
||||
menuItems.add(startMenuItem);
|
||||
menuItems.add(MenuItem.separator());
|
||||
for (final mode in Mode.values) {
|
||||
menuItems.add(
|
||||
MenuItem.checkbox(
|
||||
label: Intl.message(mode.name),
|
||||
onClick: (_) {
|
||||
globalState.appController.clashConfig.mode = mode;
|
||||
},
|
||||
checked: mode == trayState.mode,
|
||||
),
|
||||
);
|
||||
}
|
||||
menuItems.add(MenuItem.separator());
|
||||
if (trayState.isStart) {
|
||||
menuItems.add(
|
||||
MenuItem.checkbox(
|
||||
label: appLocalizations.tun,
|
||||
onClick: (_) {
|
||||
globalState.appController.updateTun();
|
||||
},
|
||||
checked: trayState.tunEnable,
|
||||
),
|
||||
);
|
||||
menuItems.add(
|
||||
MenuItem.checkbox(
|
||||
label: appLocalizations.systemProxy,
|
||||
onClick: (_) {
|
||||
globalState.appController.updateSystemProxy();
|
||||
},
|
||||
checked: trayState.systemProxy,
|
||||
),
|
||||
);
|
||||
menuItems.add(MenuItem.separator());
|
||||
}
|
||||
final autoStartMenuItem = MenuItem.checkbox(
|
||||
label: appLocalizations.autoLaunch,
|
||||
onClick: (_) async {
|
||||
globalState.appController.updateAutoLaunch();
|
||||
},
|
||||
checked: trayState.autoLaunch,
|
||||
);
|
||||
final adminAutoStartMenuItem = MenuItem.checkbox(
|
||||
label: appLocalizations.adminAutoLaunch,
|
||||
onClick: (_) async {
|
||||
globalState.appController.updateAdminAutoLaunch();
|
||||
},
|
||||
checked: trayState.adminAutoLaunch,
|
||||
);
|
||||
menuItems.add(autoStartMenuItem);
|
||||
menuItems.add(adminAutoStartMenuItem);
|
||||
menuItems.add(MenuItem.separator());
|
||||
final exitMenuItem = MenuItem(
|
||||
label: appLocalizations.exit,
|
||||
onClick: (_) async {
|
||||
await globalState.appController.handleExit();
|
||||
},
|
||||
);
|
||||
menuItems.add(exitMenuItem);
|
||||
final menu = Menu();
|
||||
menu.items = menuItems;
|
||||
trayManager.setContextMenu(menu);
|
||||
if (Platform.isLinux) {
|
||||
_updateSystemTray(
|
||||
isStart: trayState.isStart,
|
||||
brightness: trayState.brightness,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Selector4<AppState, AppFlowingState, Config, ClashConfig, TrayState>(
|
||||
@@ -162,7 +48,7 @@ class _TrayContainerState extends State<TrayManager> with TrayListener {
|
||||
return prev != next;
|
||||
},
|
||||
builder: (_, state, child) {
|
||||
_updateTray(state);
|
||||
globalState.appController.updateTray();
|
||||
return child!;
|
||||
},
|
||||
child: widget.child,
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:fl_clash/models/models.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:window_ext/window_ext.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
class WindowManager extends StatefulWidget {
|
||||
@@ -19,7 +20,7 @@ class WindowManager extends StatefulWidget {
|
||||
State<WindowManager> createState() => _WindowContainerState();
|
||||
}
|
||||
|
||||
class _WindowContainerState extends State<WindowManager> with WindowListener {
|
||||
class _WindowContainerState extends State<WindowManager> with WindowListener, WindowExtListener {
|
||||
Function? updateLaunchDebounce;
|
||||
|
||||
_autoLaunchContainer(Widget child) {
|
||||
@@ -47,6 +48,7 @@ class _WindowContainerState extends State<WindowManager> with WindowListener {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
windowExtManager.addListener(this);
|
||||
windowManager.addListener(this);
|
||||
}
|
||||
|
||||
@@ -84,9 +86,16 @@ class _WindowContainerState extends State<WindowManager> with WindowListener {
|
||||
super.onWindowMinimize();
|
||||
}
|
||||
|
||||
@override
|
||||
void onTaskbarCreated() {
|
||||
globalState.appController.updateTray();
|
||||
super.onTaskbarCreated();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
windowManager.removeListener(this);
|
||||
windowExtManager.removeListener(this);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user