Add sqlite store
Optimize android quick action Optimize backup and restore Optimize more details
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fl_clash/common/iterable.dart';
|
||||
import 'package:fl_clash/controller.dart';
|
||||
import 'package:fl_clash/enum/enum.dart';
|
||||
import 'package:fl_clash/models/models.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:tray_manager/tray_manager.dart';
|
||||
@@ -14,10 +13,23 @@ import 'system.dart';
|
||||
import 'window.dart';
|
||||
|
||||
class Tray {
|
||||
static Tray? _instance;
|
||||
|
||||
Tray._internal();
|
||||
|
||||
factory Tray() {
|
||||
_instance ??= Tray._internal();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
String get trayIconSuffix {
|
||||
return system.isWindows ? 'ico' : 'png';
|
||||
}
|
||||
|
||||
Future<void> destroy() async {
|
||||
await trayManager.destroy();
|
||||
}
|
||||
|
||||
String getTryIcon({required bool isStart, required bool tunEnable}) {
|
||||
if (system.isMacOS || !isStart) {
|
||||
return 'assets/images/icon/status_1.$trayIconSuffix';
|
||||
@@ -29,11 +41,10 @@ class Tray {
|
||||
}
|
||||
|
||||
Future _updateSystemTray({
|
||||
bool force = false,
|
||||
required bool isStart,
|
||||
required bool tunEnable,
|
||||
}) async {
|
||||
if (Platform.isLinux || force) {
|
||||
if (Platform.isLinux) {
|
||||
await trayManager.destroy();
|
||||
}
|
||||
await trayManager.setIcon(
|
||||
@@ -47,7 +58,7 @@ class Tray {
|
||||
|
||||
Future<void> update({
|
||||
required TrayState trayState,
|
||||
bool focus = false,
|
||||
required Traffic traffic,
|
||||
}) async {
|
||||
if (system.isAndroid) {
|
||||
return;
|
||||
@@ -56,7 +67,6 @@ class Tray {
|
||||
await _updateSystemTray(
|
||||
isStart: trayState.isStart,
|
||||
tunEnable: trayState.tunEnable,
|
||||
force: focus,
|
||||
);
|
||||
}
|
||||
List<MenuItem> menuItems = [];
|
||||
@@ -70,7 +80,7 @@ class Tray {
|
||||
final startMenuItem = MenuItem.checkbox(
|
||||
label: trayState.isStart ? appLocalizations.stop : appLocalizations.start,
|
||||
onClick: (_) async {
|
||||
globalState.appController.updateStart();
|
||||
appController.updateStart();
|
||||
},
|
||||
checked: false,
|
||||
);
|
||||
@@ -79,7 +89,7 @@ class Tray {
|
||||
final speedStatistics = MenuItem.checkbox(
|
||||
label: appLocalizations.speedStatistics,
|
||||
onClick: (_) async {
|
||||
globalState.appController.updateSpeedStatistics();
|
||||
appController.updateSpeedStatistics();
|
||||
},
|
||||
checked: trayState.showTrayTitle,
|
||||
);
|
||||
@@ -91,7 +101,7 @@ class Tray {
|
||||
MenuItem.checkbox(
|
||||
label: Intl.message(mode.name),
|
||||
onClick: (_) {
|
||||
globalState.appController.changeMode(mode);
|
||||
appController.changeMode(mode);
|
||||
},
|
||||
checked: mode == trayState.mode,
|
||||
),
|
||||
@@ -106,9 +116,8 @@ class Tray {
|
||||
MenuItem.checkbox(
|
||||
label: proxy.name,
|
||||
checked:
|
||||
globalState.getSelectedProxyName(group.name) == proxy.name,
|
||||
appController.getSelectedProxyName(group.name) == proxy.name,
|
||||
onClick: (_) {
|
||||
final appController = globalState.appController;
|
||||
appController.updateCurrentSelectedMap(group.name, proxy.name);
|
||||
appController.changeProxy(
|
||||
groupName: group.name,
|
||||
@@ -134,7 +143,7 @@ class Tray {
|
||||
MenuItem.checkbox(
|
||||
label: appLocalizations.tun,
|
||||
onClick: (_) {
|
||||
globalState.appController.updateTun();
|
||||
appController.updateTun();
|
||||
},
|
||||
checked: trayState.tunEnable,
|
||||
),
|
||||
@@ -143,7 +152,7 @@ class Tray {
|
||||
MenuItem.checkbox(
|
||||
label: appLocalizations.systemProxy,
|
||||
onClick: (_) {
|
||||
globalState.appController.updateSystemProxy();
|
||||
appController.updateSystemProxy();
|
||||
},
|
||||
checked: trayState.systemProxy,
|
||||
),
|
||||
@@ -153,7 +162,7 @@ class Tray {
|
||||
final autoStartMenuItem = MenuItem.checkbox(
|
||||
label: appLocalizations.autoLaunch,
|
||||
onClick: (_) async {
|
||||
globalState.appController.updateAutoLaunch();
|
||||
appController.updateAutoLaunch();
|
||||
},
|
||||
checked: trayState.autoLaunch,
|
||||
);
|
||||
@@ -169,7 +178,7 @@ class Tray {
|
||||
final exitMenuItem = MenuItem(
|
||||
label: appLocalizations.exit,
|
||||
onClick: (_) async {
|
||||
await globalState.appController.handleExit();
|
||||
await appController.handleExit();
|
||||
},
|
||||
);
|
||||
menuItems.add(exitMenuItem);
|
||||
@@ -179,13 +188,9 @@ class Tray {
|
||||
await _updateSystemTray(
|
||||
isStart: trayState.isStart,
|
||||
tunEnable: trayState.tunEnable,
|
||||
force: focus,
|
||||
);
|
||||
}
|
||||
updateTrayTitle(
|
||||
showTrayTitle: trayState.showTrayTitle,
|
||||
traffic: globalState.appState.traffics.list.safeLast(Traffic()),
|
||||
);
|
||||
updateTrayTitle(showTrayTitle: trayState.showTrayTitle, traffic: traffic);
|
||||
}
|
||||
|
||||
Future<void> updateTrayTitle({
|
||||
|
||||
Reference in New Issue
Block a user