From c72e6c15200b32b88be1c1d65d807d4c0c4dfe23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Sat, 10 Feb 2024 23:01:59 +0800 Subject: [PATCH 01/10] =?UTF-8?q?[*]=E5=85=A8=E9=9D=A2=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6API=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E5=8F=96=20main.dart=20Tray=20&=20Window=20=E7=9B=91=E5=90=AC?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=94=B9=E6=BA=90=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/frpcController.dart | 9 +- ...roller.dart => frpcSettingController.dart} | 30 ++-- lib/controllers/proxiesController.dart | 16 +- lib/io/frpcManagerStorage.dart | 115 --------------- lib/main.dart | 137 +++--------------- lib/main_tray.dart | 61 ++++++++ lib/main_window.dart | 79 ++++++++++ lib/prefs/FrpcSettingPrefs.dart | 6 +- ...figuration.dart => JsonConfiguration.dart} | 9 +- .../FrpcConfigurationStorage.dart | 38 +++++ .../LauncherConfigurationStorage.dart | 8 +- .../ProxiesConfigurationStorage.dart} | 3 +- lib/storages/injector.dart | 11 +- lib/storages/stories/FrpcStoryStorage.dart | 81 +++++++++++ lib/ui/{model => models}/AccountDialog.dart | 0 lib/ui/{model => models}/AppbarActions.dart | 37 +---- lib/ui/{model => models}/Drawer.dart | 0 .../FloatingActionButton.dart | 0 .../FrpcConfigurationEditorDialog.dart | 4 +- .../{model => models}/FrpcDownloadDialog.dart | 11 +- lib/ui/{model => models}/FrpcDownloadTip.dart | 9 +- .../{model => models}/ProcessListDialog.dart | 0 lib/ui/{model => models}/ToolDialog.dart | 0 lib/ui/{ => views}/auth/login.dart | 4 +- lib/ui/{ => views}/auth/register.dart | 4 +- lib/ui/{ => views}/auth/tokenmode.dart | 4 +- lib/ui/{ => views}/home.dart | 5 +- lib/ui/{ => views}/panel/console.dart | 10 +- lib/ui/{ => views}/panel/home.dart | 9 +- lib/ui/{ => views}/panel/proxies.dart | 10 +- lib/ui/{ => views}/setting/frpcSetting.dart | 10 +- lib/ui/{ => views}/setting/injector.dart | 6 +- .../{ => views}/setting/launcherSetting.dart | 0 lib/ui/{ => views}/tokenmode/panel.dart | 13 +- lib/utils/FileConfiguration.dart | 25 ++-- lib/utils/frpc/ProcessManager.dart | 14 +- pubspec.yaml | 2 +- 37 files changed, 398 insertions(+), 382 deletions(-) rename lib/controllers/{FrpcSettingController.dart => frpcSettingController.dart} (87%) delete mode 100644 lib/io/frpcManagerStorage.dart create mode 100644 lib/main_tray.dart create mode 100644 lib/main_window.dart rename lib/storages/{Configuration.dart => JsonConfiguration.dart} (78%) rename lib/{io/frpcConfigurationStorage.dart => storages/configurations/ProxiesConfigurationStorage.dart} (95%) create mode 100644 lib/storages/stories/FrpcStoryStorage.dart rename lib/ui/{model => models}/AccountDialog.dart (100%) rename lib/ui/{model => models}/AppbarActions.dart (63%) rename lib/ui/{model => models}/Drawer.dart (100%) rename lib/ui/{model => models}/FloatingActionButton.dart (100%) rename lib/ui/{model => models}/FrpcConfigurationEditorDialog.dart (93%) rename lib/ui/{model => models}/FrpcDownloadDialog.dart (92%) rename lib/ui/{model => models}/FrpcDownloadTip.dart (92%) rename lib/ui/{model => models}/ProcessListDialog.dart (100%) rename lib/ui/{model => models}/ToolDialog.dart (100%) rename lib/ui/{ => views}/auth/login.dart (97%) rename lib/ui/{ => views}/auth/register.dart (99%) rename lib/ui/{ => views}/auth/tokenmode.dart (96%) rename lib/ui/{ => views}/home.dart (97%) rename lib/ui/{ => views}/panel/console.dart (91%) rename lib/ui/{ => views}/panel/home.dart (97%) rename lib/ui/{ => views}/panel/proxies.dart (89%) rename lib/ui/{ => views}/setting/frpcSetting.dart (86%) rename lib/ui/{ => views}/setting/injector.dart (91%) rename lib/ui/{ => views}/setting/launcherSetting.dart (100%) rename lib/ui/{ => views}/tokenmode/panel.dart (95%) diff --git a/lib/controllers/frpcController.dart b/lib/controllers/frpcController.dart index af4c0bd0..5eb01455 100644 --- a/lib/controllers/frpcController.dart +++ b/lib/controllers/frpcController.dart @@ -2,9 +2,12 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/io/frpcManagerStorage.dart'; +import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; +import 'package:nyalcf/storages/stories/FrpcStoryStorage.dart'; class FrpcController extends GetxController { + final fcs = FrpcConfigurationStorage(); + /// 是否存在的标志 var exist = false.obs; @@ -31,11 +34,11 @@ class FrpcController extends GetxController { } /// 获取Frpc文件对象 - get file => FrpcManagerStorage.getFile(version.value); + get file => FrpcStoryStorage.getFile(); /// 获取版本号 Future getVersion() async { - return await FrpcManagerStorage.usingVersion; + return fcs.getSettingsFrpcVersion(); } /// 追加信息日志 diff --git a/lib/controllers/FrpcSettingController.dart b/lib/controllers/frpcSettingController.dart similarity index 87% rename from lib/controllers/FrpcSettingController.dart rename to lib/controllers/frpcSettingController.dart index 26a319d8..a1165292 100644 --- a/lib/controllers/FrpcSettingController.dart +++ b/lib/controllers/frpcSettingController.dart @@ -3,12 +3,10 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart' hide Response; +import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; import 'package:nyalcf/utils/Logger.dart'; -import 'package:nyalcf/io/frpcManagerStorage.dart'; -import 'package:nyalcf/models/FrpcConfigModel.dart'; -import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; -import 'package:nyalcf/ui/model/FrpcDownloadDialog.dart'; -import 'package:nyalcf/ui/model/FrpcDownloadTip.dart'; +import 'package:nyalcf/ui/models/FrpcDownloadDialog.dart'; +import 'package:nyalcf/ui/models/FrpcDownloadTip.dart'; import 'package:nyalcf/utils/CPUArch.dart'; import 'package:nyalcf/utils/frpc/Archive.dart'; @@ -17,6 +15,7 @@ class FrpcSettingController extends GetxController { BuildContext context; List> arch = >[]; + final fcs = FrpcConfigurationStorage(); var platform = ''; String? get custom_path => Platform.environment['NYA_LCF_FRPC_PATH']; @@ -40,17 +39,17 @@ class FrpcSettingController extends GetxController { load() async { cpu_arch.value = await CPUArch.getCPUArchitecture(); - await FrpcSettingPrefs.refresh(); - final frpcinfo = await FrpcSettingPrefs.getFrpcInfo(); - frpc_download_use_mirror.value = frpcinfo.github_mirror; + // await FrpcSettingPrefs.refresh(); + // final frpcinfo = await FrpcSettingPrefs.getFrpcInfo(); + frpc_download_use_mirror.value = fcs.getSettingsGitHubMirror(); - frpc_version.value = await FrpcManagerStorage.usingVersion; + frpc_version.value = await fcs.getSettingsFrpcVersion(); _load_tip(); _load_frpc_dropdownitem(); } void _load_tip() async { - _frpc_downloaded_versions = await FrpcManagerStorage.downloadedVersions; + _frpc_downloaded_versions = fcs.getInstalledVersions(); if (_frpc_downloaded_versions.isEmpty || (custom_path != null && await File(custom_path!).exists())) { frpc_download_tip.value = FrpcDownloadTip.tip(context: context); @@ -96,15 +95,12 @@ class FrpcSettingController extends GetxController { final unarchive = await FrpcArchive.unarchive( platform: platform, arch: arch[frpc_download_arch.value]['arch'], - version: '0.51.3', + version: fcs.getSettingsFrpcVersion(), ); if (unarchive) { - FrpcSettingPrefs.setFrpcDownloadedVersionsInfo('0.51.3'); - FrpcManagerStorage.save( - FrpcConfigModel( - settings: (await FrpcSettingPrefs.getFrpcInfo()).settings, - lists: (await FrpcSettingPrefs.getFrpcInfo()).lists), - ); + fcs.setSettingsFrpcVersion('0.51.3'); + fcs.addInstalledVersion('0.51.3'); + fcs.save(); /**if (!Platform.isWindows) { print('*nix platform, change file permission'); await FrpcManagerStorage.setRunPermission(); diff --git a/lib/controllers/proxiesController.dart b/lib/controllers/proxiesController.dart index 1ba0f553..b4820f12 100644 --- a/lib/controllers/proxiesController.dart +++ b/lib/controllers/proxiesController.dart @@ -4,12 +4,12 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/userController.dart'; +import 'package:nyalcf/storages/configurations/ProxiesConfigurationStorage.dart'; import 'package:nyalcf/utils/network/dio/proxies/configuration.dart'; import 'package:nyalcf/utils/network/dio/proxies/get.dart'; -import 'package:nyalcf/io/frpcConfigurationStorage.dart'; +import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; import 'package:nyalcf/models/ProxyInfoModel.dart'; -import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; -import 'package:nyalcf/ui/model/FrpcConfigurationEditorDialog.dart'; +import 'package:nyalcf/ui/models/FrpcConfigurationEditorDialog.dart'; import 'package:nyalcf/utils/Logger.dart'; import 'package:nyalcf/utils/frpc/ProcessManager.dart'; @@ -22,6 +22,7 @@ class ProxiesController extends GetxController { ProxiesController({required this.context}); final context; + final fcs = FrpcConfigurationStorage(); final FrpcController f_c = Get.find(); final UserController c = Get.find(); @@ -105,8 +106,7 @@ class ProxiesController extends GetxController { icon: Icon(Icons.play_circle), tooltip: '启动', onPressed: () async { - final frpcinfo = await FrpcSettingPrefs.getFrpcInfo(); - if (frpcinfo.frpc_downloaded_versions.isNotEmpty) { + if (fcs.getInstalledVersions().isNotEmpty) { FrpcProcessManager() .nwprcs(frp_token: c.frp_token.value, proxy_id: element.id); Get.snackbar( @@ -140,7 +140,7 @@ class ProxiesController extends GetxController { ); } - final fp = await FrpcConfigurationStorage.getConfigPath(element.id); + final fp = await ProxiesConfigurationStorage.getConfigPath(element.id); String text = ''; /// 判空 @@ -158,7 +158,7 @@ class ProxiesController extends GetxController { if (res is String) { Logger.info('Successfully get config ini'); text = res; - FrpcConfigurationStorage.setConfig(element.id, res); + ProxiesConfigurationStorage.setConfig(element.id, res); Get.close(0); showDialogX(text); } else if (res == null) { @@ -202,7 +202,7 @@ class ProxiesController extends GetxController { )); } - final fcsp = await FrpcConfigurationStorage.getConfigPath(element.id); + final fcsp = await ProxiesConfigurationStorage.getConfigPath(element.id); if (fcsp != null) list.add( diff --git a/lib/io/frpcManagerStorage.dart b/lib/io/frpcManagerStorage.dart deleted file mode 100644 index 4bbbbe68..00000000 --- a/lib/io/frpcManagerStorage.dart +++ /dev/null @@ -1,115 +0,0 @@ -import 'dart:convert'; -import 'dart:io'; - -import 'package:nyalcf/models/FrpcConfigModel.dart'; -import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; -import 'package:nyalcf/utils/PathProvider.dart'; -import 'package:nyalcf/utils/Logger.dart'; - -@deprecated -class FrpcManagerStorage { - static final _s_path = PathProvider.appSupportPath; - - static Future get _path async { - return '${_s_path}/frpc'; - } - - static Future read() async { - try { - final String result = - await File('${_path}/info.json').readAsString(encoding: utf8); - return FrpcConfigModel.fromJson(jsonDecode(result)); - } catch (e) { - return null; - } - } - - static Future get _info async => - FrpcSettingPrefs.getFrpcInfo(); - - static void init() { - _path.then((path) { - if (!Directory(path).existsSync()) Directory(path).createSync(); - final infoF = File('${path}/info.json'); - if (!infoF.existsSync()) { - Map json = { - 'settings': { - 'frpc_version': '', - 'github_mirror': true, - }, - 'lists': { - 'frpc_downloaded_versions': [], - }, - }; - infoF.writeAsStringSync(jsonEncode(json)); - } - }); - } - - /// 获取Frpc文件 - static Future getFile(String version) async { - return File(await getFilePath(version)); - } - - /// 获取Frpc文件 - static Future getFilePath(String version) async { - final name; - if (Platform.isWindows) - name = 'frpc.exe'; - else - name = 'frpc'; - return await getRunPath(version) + name; - } - - /// 获取Frpc运行路径 - static Future getRunPath(String version) async { - var path = '${await _path}/${version}/'; - if (Platform.isWindows) path = path.replaceAll('/', '\\'); - return path; - } - - /// 获取正在使用的版本 - static Future get usingVersion async { - final version = (await _info).frpc_version; - return version; - } - - /*/// 自定义GitHub代理列表 - static Future> get proxies async { - final url = (await _info).github_proxies; - return url; - }*/ - - /// GitHub代理 - static Future get useGithubMirror async { - final mirror = (await _info).github_mirror; - return mirror; - } - - /// 获取已安装版本列表 - static Future> get downloadedVersions async { - final versions = (await _info).frpc_downloaded_versions; - Logger.debug(versions); - return versions; - } - - /// 存储至磁盘 - static Future save(FrpcConfigModel data) async { - final String write_data = jsonEncode(data); - await File('${await _path}/info.json') - .writeAsString(write_data, encoding: utf8); - } - - static Future setRunPermission() async { - Logger.info('Set run permission: ${await getFilePath('0.51.3')}'); - final process = await Process.run( - 'chmod', - [ - 'u+x', - await getFilePath('0.51.3'), - ], - ); - Logger.debug(process.stdout.toString()); - Logger.debug(process.stderr.toString()); - } -} diff --git a/lib/main.dart b/lib/main.dart index e84e2a6a..fa3559b6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,25 +1,21 @@ -import 'dart:io'; - import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:flutter/material.dart'; import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart'; import 'package:nyalcf/storages/injector.dart'; -import 'package:nyalcf/ui/model/AppbarActions.dart'; import 'package:nyalcf/utils/PathProvider.dart'; -import 'package:nyalcf/utils/frpc/ProcessManager.dart'; +import 'package:nyalcf/main_tray.dart'; +import 'package:nyalcf/main_window.dart'; import 'package:tray_manager/tray_manager.dart'; -import 'package:flutter/services.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/protocol_activation.dart'; -import 'package:nyalcf/ui/auth/login.dart'; -import 'package:nyalcf/ui/auth/register.dart'; -import 'package:nyalcf/ui/auth/tokenmode.dart'; -import 'package:nyalcf/ui/home.dart'; -import 'package:nyalcf/ui/panel/console.dart'; -import 'package:nyalcf/ui/panel/home.dart'; -import 'package:nyalcf/ui/panel/proxies.dart'; -import 'package:nyalcf/ui/setting/injector.dart'; -import 'package:nyalcf/ui/tokenmode/panel.dart'; +import 'package:nyalcf/ui/views/auth/login.dart'; +import 'package:nyalcf/ui/views/auth/register.dart'; +import 'package:nyalcf/ui/views/auth/tokenmode.dart'; +import 'package:nyalcf/ui/views/home.dart'; +import 'package:nyalcf/ui/views/panel/console.dart'; +import 'package:nyalcf/ui/views/panel/home.dart'; +import 'package:nyalcf/ui/views/panel/proxies.dart'; +import 'package:nyalcf/ui/views/setting/injector.dart'; +import 'package:nyalcf/ui/views/tokenmode/panel.dart'; import 'package:nyalcf/utils/Logger.dart'; import 'package:nyalcf/utils/Updater.dart'; import 'package:window_manager/window_manager.dart'; @@ -39,39 +35,7 @@ void main() async { runApp(const App()); - doWhenWindowReady(() async { - SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); - const initialSize = Size(800, 500); - appWindow.minSize = initialSize; - appWindow.size = initialSize; - appWindow.alignment = Alignment.center; - appWindow.title = 'Nya LoCyanFrp! - LCF启动器'; - appWindow.show(); - await trayManager.setToolTip('Nya~'); - await trayManager.setIcon( - Platform.isWindows ? 'asset/icon/icon.ico' : 'asset/icon/icon.png', - ); - Menu menu = Menu( - items: [ - MenuItem( - key: 'show_window', - label: '打开界面', - ), - MenuItem( - key: 'hide_window', - label: '隐藏界面', - ), - MenuItem.separator(), - MenuItem( - key: 'exit_app', - label: '退出', - ), - ], - ); - trayManager.setContextMenu(menu); - - await ProtocolActivation.registerProtocolActivation(callback); - }); + doWhenWindowReady(MainWindow.doWhenWindowReady); } class App extends StatefulWidget { @@ -81,7 +45,7 @@ class App extends StatefulWidget { _AppState createState() => _AppState(); } -class _AppState extends State with TrayListener, WindowListener { +class _AppState extends State with WindowListener, TrayListener { final title = 'Nya LoCyanFrp!'; /// 根组件 @@ -121,42 +85,6 @@ class _AppState extends State with TrayListener, WindowListener { setState(() {}); } - @override - void onWindowClose() async { - bool _isPreventClose = await windowManager.isPreventClose(); - if (_isPreventClose) { - appWindow.restore(); - await Get.dialog(AlertDialog( - title: Text('关闭NyaLCF'), - content: Text('确定要关闭NyaLCF吗,要是Frpc没关掉猫猫会生气把Frpc一脚踹翻的哦!'), - actions: [ - TextButton( - child: Text( - '取消', - ), - onPressed: () async { - Get.close(0); - }), - TextButton( - child: Text( - '确定', - style: TextStyle(color: Colors.red), - ), - onPressed: () { - try { - FrpcProcessManager().killAll(); - } catch (e) { - Logger.error('Failed to close all process: ${e}'); - } - appWindow.close(); - windowManager.destroy(); - }, - ), - ], - )); - } - } - /// 组件销毁时操作 @override void dispose() { @@ -165,40 +93,13 @@ class _AppState extends State with TrayListener, WindowListener { super.dispose(); } - /// 鼠标左件托盘图标 @override - void onTrayIconMouseDown() { - appWindow.restore(); - } - - /// 鼠标右键托盘图标 + onWindowClose() => MainWindow.onWindowClose(); @override - void onTrayIconRightMouseDown() { - trayManager.popUpContextMenu(); - } - - // /// 保留备用 - // @override - // void onTrayIconRightMouseUp() {} - - /// 托盘菜单点击事件 + onTrayIconMouseDown() => MainTray.onTrayIconMouseDown(); @override - void onTrayMenuItemClick(MenuItem menuItem) { - switch (menuItem.key) { - case 'show_window': - appWindow.restore(); - break; - case 'hide_window': - appWindow.hide(); - break; - case 'exit_app': - appWindow.restore(); - AppbarActionsX().closeAlertDialog(); - break; - } - } -} - -void callback(deepLink) { - Logger.debug(deepLink); + onTrayIconRightMouseDown() => MainTray.onTrayIconRightMouseDown(); + @override + onTrayMenuItemClick(MenuItem menuItem) => + MainTray.onTrayMenuItemClick(menuItem); } diff --git a/lib/main_tray.dart b/lib/main_tray.dart new file mode 100644 index 00000000..5caed876 --- /dev/null +++ b/lib/main_tray.dart @@ -0,0 +1,61 @@ +import 'package:bitsdojo_window/bitsdojo_window.dart'; +import 'package:get/get.dart'; +import 'package:nyalcf/main_window.dart'; +import 'package:tray_manager/tray_manager.dart'; + +class MainTray { + static final Menu menu = Menu( + items: [ + MenuItem( + key: 'show_window', + label: '打开界面', + ), + MenuItem( + key: 'hide_window', + label: '隐藏界面', + ), + MenuItem( + key: 'force_app_update', + label: '强制更新App界面', + ), + MenuItem.separator(), + MenuItem( + key: 'exit_app', + label: '退出', + ), + ], + ); + + /// 鼠标左键托盘图标 + static void onTrayIconMouseDown() { + appWindow.restore(); + } + + /// 鼠标右键托盘图标 + static void onTrayIconRightMouseDown() { + trayManager.popUpContextMenu(); + } + + // /// 保留备用 + // @override + // void onTrayIconRightMouseUp() {} + + /// 托盘菜单点击事件 + static void onTrayMenuItemClick(MenuItem menuItem) { + switch (menuItem.key) { + case 'show_window': + appWindow.restore(); + break; + case 'hide_window': + appWindow.hide(); + break; + case 'app_force_update': + Get.forceAppUpdate(); + break; + case 'exit_app': + appWindow.restore(); + MainWindow.onWindowClose(); + break; + } + } +} diff --git a/lib/main_window.dart b/lib/main_window.dart new file mode 100644 index 00000000..f290b5f9 --- /dev/null +++ b/lib/main_window.dart @@ -0,0 +1,79 @@ +import 'dart:io'; + +import 'package:bitsdojo_window/bitsdojo_window.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:get/get.dart'; +import 'package:nyalcf/main_tray.dart'; +import 'package:nyalcf/protocol_activation.dart'; +import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/utils/frpc/ProcessManager.dart'; +import 'package:tray_manager/tray_manager.dart'; +import 'package:window_manager/window_manager.dart'; + +class MainWindow { + /// 启动操作 + static void doWhenWindowReady() async { + // 禁用系统窗口操作(主要适配MacOS) + SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); + + // 设置主窗体参数 + const initialSize = Size(800, 500); + appWindow.minSize = initialSize; + appWindow.size = initialSize; + appWindow.alignment = Alignment.center; + appWindow.title = 'Nya LoCyanFrp! - 乐青映射启动器'; + + // 设置托盘菜单 + await trayManager.setToolTip('Nya~'); + await trayManager.setIcon( + Platform.isWindows ? 'asset/icon/icon.ico' : 'asset/icon/icon.png', + ); + trayManager.setContextMenu(MainTray.menu); + + // Protocol Channel + void callback(deepLink) { + Logger.debug(deepLink); + } + await ProtocolActivation.registerProtocolActivation(callback); + + // 显示主窗体 + appWindow.show(); + } + + /// 关闭拦截 + static void onWindowClose() async { + bool _isPreventClose = await windowManager.isPreventClose(); + if (_isPreventClose) { + appWindow.restore(); + await Get.dialog(AlertDialog( + title: Text('关闭 Nya LoCyanFrp!'), + content: Text('确定要关闭 Nya LoCyanFrp! 吗,要是 Frpc 没关掉猫猫会生气把 Frpc 一脚踹翻的哦!'), + actions: [ + TextButton( + child: Text( + '取消', + ), + onPressed: () async { + Get.close(0); + }), + TextButton( + child: Text( + '确定', + style: TextStyle(color: Colors.red), + ), + onPressed: () { + try { + FrpcProcessManager().killAll(); + } catch (e) { + Logger.error('Failed to close all process: ${e}'); + } + appWindow.close(); + windowManager.destroy(); + }, + ), + ], + )); + } + } +} diff --git a/lib/prefs/FrpcSettingPrefs.dart b/lib/prefs/FrpcSettingPrefs.dart index fa158872..6a5c406d 100644 --- a/lib/prefs/FrpcSettingPrefs.dart +++ b/lib/prefs/FrpcSettingPrefs.dart @@ -1,7 +1,7 @@ -import 'package:nyalcf/io/frpcManagerStorage.dart'; import 'package:nyalcf/models/FrpcConfigModel.dart'; import 'package:shared_preferences/shared_preferences.dart'; +@deprecated class FrpcSettingPrefs { static Future setFrpcInfo(FrpcConfigModel frpcinfo) async { SharedPreferences prefs = await SharedPreferences.getInstance(); @@ -47,7 +47,7 @@ class FrpcSettingPrefs { } static Future refresh() async { - final res = await FrpcManagerStorage.read(); - if (res != null) setFrpcInfo(res); + //final res = await FrpcManagerStorage.read(); + //if (res != null) setFrpcInfo(res); } } diff --git a/lib/storages/Configuration.dart b/lib/storages/JsonConfiguration.dart similarity index 78% rename from lib/storages/Configuration.dart rename to lib/storages/JsonConfiguration.dart index a3799282..fbe3dbfc 100644 --- a/lib/storages/Configuration.dart +++ b/lib/storages/JsonConfiguration.dart @@ -4,24 +4,29 @@ import 'package:nyalcf/utils/FileConfiguration.dart'; import 'package:nyalcf/utils/PathProvider.dart'; import 'package:nyalcf/utils/Logger.dart'; -abstract class Configuration { +abstract class JsonConfiguration { var path = PathProvider.appSupportPath; /// 配置文件和默认ConfigMap File? file; + String get handle; Future> get def_config async => {}; /// 附加Init方法 void init() => {}; Future asyncInit() async => {}; - FileConfiguration get cfg => FileConfiguration(file: this.file); + FileConfiguration get cfg => FileConfiguration( + file: this.file, + handle: handle, + ); /// 保存 void save() => cfg.save(replace: true); /// 默认初始化函数 void initCfg() async { + cfg.initMap(); cfg.fromMap(await def_config); Logger.debug(file); cfg.save(); diff --git a/lib/storages/configurations/FrpcConfigurationStorage.dart b/lib/storages/configurations/FrpcConfigurationStorage.dart index 8b137891..bcaec611 100644 --- a/lib/storages/configurations/FrpcConfigurationStorage.dart +++ b/lib/storages/configurations/FrpcConfigurationStorage.dart @@ -1 +1,39 @@ +import 'dart:convert'; +import 'dart:io'; +import 'package:crypto/crypto.dart'; +import 'package:nyalcf/storages/JsonConfiguration.dart'; + +class FrpcConfigurationStorage extends JsonConfiguration { + @override + File get file => File('$path/frpc.json'); + @override + String get handle => sha1.convert(utf8.encode('FRPCCONF')).toString(); + + @override + Future> get def_config async => { + 'settings': { + 'frpc_version': '', + 'github_mirror': true, + }, + 'lists': { + 'frpc_installed_versions': [], + }, + }; + + /// 使用的 Frpc 版本 + String getSettingsFrpcVersion() => cfg.getString('settings.frpc_version'); + void setSettingsFrpcVersion(String value) => cfg.setString('settings.frpc_version', value); + + /// 使用镜像源 + bool getSettingsGitHubMirror() => cfg.getBool('settings.github_mirror'); + void setSettingsGitHubMirror(bool value) => cfg.setBool('settings.github_mirror', value); + + /// 已安装的 Frpc 版本 + List getInstalledVersions() => cfg.getStringList('lists.frpc_installed_versions'); + void addInstalledVersion(String value) { + final List list = getInstalledVersions(); + list.add(value); + cfg.setStringList('list.frpc_installed_versions', list); + } +} diff --git a/lib/storages/configurations/LauncherConfigurationStorage.dart b/lib/storages/configurations/LauncherConfigurationStorage.dart index 5d530018..c3710a9e 100644 --- a/lib/storages/configurations/LauncherConfigurationStorage.dart +++ b/lib/storages/configurations/LauncherConfigurationStorage.dart @@ -1,13 +1,17 @@ +import 'dart:convert'; import 'dart:io'; +import 'package:crypto/crypto.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -import 'package:nyalcf/storages/Configuration.dart'; +import 'package:nyalcf/storages/JsonConfiguration.dart'; import 'package:nyalcf/utils/ThemeControl.dart'; -class LauncherConfigurationStorage extends Configuration { +class LauncherConfigurationStorage extends JsonConfiguration { @override File get file => File('$path/launcher.json'); + @override + String get handle => sha1.convert(utf8.encode('LAUNCHERCONF')).toString(); @override Future> get def_config async => { diff --git a/lib/io/frpcConfigurationStorage.dart b/lib/storages/configurations/ProxiesConfigurationStorage.dart similarity index 95% rename from lib/io/frpcConfigurationStorage.dart rename to lib/storages/configurations/ProxiesConfigurationStorage.dart index fe305c05..b717e306 100644 --- a/lib/io/frpcConfigurationStorage.dart +++ b/lib/storages/configurations/ProxiesConfigurationStorage.dart @@ -2,8 +2,7 @@ import 'dart:io'; import 'package:nyalcf/utils/PathProvider.dart'; -@deprecated -class FrpcConfigurationStorage { +class ProxiesConfigurationStorage { static var _path = PathProvider.appSupportPath; /// 配置文件目录路径 diff --git a/lib/storages/injector.dart b/lib/storages/injector.dart index 8835bb45..4a691b7c 100644 --- a/lib/storages/injector.dart +++ b/lib/storages/injector.dart @@ -1,18 +1,15 @@ -import 'package:nyalcf/io/frpcManagerStorage.dart'; +import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart'; class StoragesInjector { static init() async { final lcs = await LauncherConfigurationStorage(); + final fcs = await FrpcConfigurationStorage(); lcs.initCfg(); + fcs.initCfg(); /// Deprecated config load will remove in future. - await loadOldCfg(); - } - - @deprecated - static Future loadOldCfg() async { - FrpcManagerStorage.init(); + // await loadOldCfg(); } } diff --git a/lib/storages/stories/FrpcStoryStorage.dart b/lib/storages/stories/FrpcStoryStorage.dart new file mode 100644 index 00000000..d7b9fa6a --- /dev/null +++ b/lib/storages/stories/FrpcStoryStorage.dart @@ -0,0 +1,81 @@ +import 'dart:io'; + +import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; +import 'package:nyalcf/utils/PathProvider.dart'; +import 'package:nyalcf/utils/Logger.dart'; + +class FrpcStoryStorage { + static final _s_path = PathProvider.appSupportPath; + static final fcs = FrpcConfigurationStorage(); + + static Future get _path async { + return '${_s_path}/frpc'; + } + + /// 获取Frpc文件 + static Future getFile() async { + return File(await getFilePath()); + } + + /// 获取Frpc文件 + static Future getFilePath() async { + final name; + if (Platform.isWindows) + name = 'frpc.exe'; + else + name = 'frpc'; + return await getRunPath() + name; + } + + /// 获取Frpc运行路径 + static Future getRunPath() async { + var path = '${await _path}/${fcs.getSettingsFrpcVersion()}/'; + if (Platform.isWindows) path = path.replaceAll('/', '\\'); + return path; + } + + // /// 获取正在使用的版本 + // static Future get usingVersion async { + // final version = (await _info).frpc_version; + // return version; + // } + // + // /*/// 自定义GitHub代理列表 + // static Future> get proxies async { + // final url = (await _info).github_proxies; + // return url; + // }*/ + // + // /// GitHub代理 + // static Future get useGithubMirror async { + // final mirror = (await _info).github_mirror; + // return mirror; + // } + // + // /// 获取已安装版本列表 + // static Future> get downloadedVersions async { + // final versions = (await _info).frpc_downloaded_versions; + // Logger.debug(versions); + // return versions; + // } + // + // /// 存储至磁盘 + // static Future save(FrpcConfigModel data) async { + // final String write_data = jsonEncode(data); + // await File('${await _path}/info.json') + // .writeAsString(write_data, encoding: utf8); + // } + + static Future setRunPermission() async { + Logger.info('Set run permission: ${await getFilePath()}'); + final process = await Process.run( + 'chmod', + [ + 'u+x', + await getFilePath(), + ], + ); + Logger.debug(process.stdout.toString()); + Logger.debug(process.stderr.toString()); + } +} diff --git a/lib/ui/model/AccountDialog.dart b/lib/ui/models/AccountDialog.dart similarity index 100% rename from lib/ui/model/AccountDialog.dart rename to lib/ui/models/AccountDialog.dart diff --git a/lib/ui/model/AppbarActions.dart b/lib/ui/models/AppbarActions.dart similarity index 63% rename from lib/ui/model/AppbarActions.dart rename to lib/ui/models/AppbarActions.dart index cb7812fe..90bc5199 100644 --- a/lib/ui/model/AppbarActions.dart +++ b/lib/ui/models/AppbarActions.dart @@ -2,9 +2,7 @@ import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/utils/Logger.dart'; -import 'package:nyalcf/utils/frpc/ProcessManager.dart'; -import 'package:window_manager/window_manager.dart'; +import 'package:nyalcf/main_window.dart'; class AppbarActionsX { AppbarActionsX( @@ -49,7 +47,7 @@ class AppbarActionsX { /// 关闭 IconButton( - onPressed: () => {closeAlertDialog()}, + onPressed: () => MainWindow.onWindowClose(), icon: Icon(Icons.close), tooltip: '关闭', color: Colors.white, @@ -76,35 +74,4 @@ class AppbarActionsX { l.addAll(_list()); return l; } - - closeAlertDialog() async { - await Get.dialog(AlertDialog( - title: Text('关闭NyaLCF'), - content: Text('确定要关闭NyaLCF吗,要是Frpc没关掉猫猫会生气把Frpc一脚踹翻的哦!'), - actions: [ - TextButton( - child: Text( - '取消', - ), - onPressed: () async { - Get.close(0); - }), - TextButton( - child: Text( - '确定', - style: TextStyle(color: Colors.red), - ), - onPressed: () { - try { - FrpcProcessManager().killAll(); - } catch (e) { - Logger.error('Failed to close all process: ${e}'); - } - appWindow.close(); - windowManager.destroy(); - }, - ), - ], - )); - } } diff --git a/lib/ui/model/Drawer.dart b/lib/ui/models/Drawer.dart similarity index 100% rename from lib/ui/model/Drawer.dart rename to lib/ui/models/Drawer.dart diff --git a/lib/ui/model/FloatingActionButton.dart b/lib/ui/models/FloatingActionButton.dart similarity index 100% rename from lib/ui/model/FloatingActionButton.dart rename to lib/ui/models/FloatingActionButton.dart diff --git a/lib/ui/model/FrpcConfigurationEditorDialog.dart b/lib/ui/models/FrpcConfigurationEditorDialog.dart similarity index 93% rename from lib/ui/model/FrpcConfigurationEditorDialog.dart rename to lib/ui/models/FrpcConfigurationEditorDialog.dart index f024fe42..effc15cb 100644 --- a/lib/ui/model/FrpcConfigurationEditorDialog.dart +++ b/lib/ui/models/FrpcConfigurationEditorDialog.dart @@ -5,7 +5,7 @@ import 'package:highlight/languages/ini.dart'; import 'package:flutter_highlight/themes/monokai-sublime.dart'; import 'package:nyalcf/controllers/proxiesController.dart'; import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/io/frpcConfigurationStorage.dart'; +import 'package:nyalcf/storages/configurations/ProxiesConfigurationStorage.dart'; class FrpcConfigEditorDialogX { FrpcConfigEditorDialogX({ @@ -58,7 +58,7 @@ class FrpcConfigEditorDialogX { child: Text('保存'), onPressed: () async { //关闭 返回true - await FrpcConfigurationStorage.setConfig(proxy_id, c.fullText); + await ProxiesConfigurationStorage.setConfig(proxy_id, c.fullText); p_c.reload(u_c.user, u_c.token); Get.close(0); }, diff --git a/lib/ui/model/FrpcDownloadDialog.dart b/lib/ui/models/FrpcDownloadDialog.dart similarity index 92% rename from lib/ui/model/FrpcDownloadDialog.dart rename to lib/ui/models/FrpcDownloadDialog.dart index 6ed14477..ed007830 100644 --- a/lib/ui/model/FrpcDownloadDialog.dart +++ b/lib/ui/models/FrpcDownloadDialog.dart @@ -1,15 +1,16 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/FrpcSettingController.dart'; +import 'package:nyalcf/controllers/frpcSettingController.dart'; +import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; import 'package:nyalcf/utils/network/dio/frpc/download.dart'; -import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; import 'package:nyalcf/utils/Logger.dart'; class FrpcDownloadDialogX { FrpcDownloadDialogX({required this.context}); - final FrpcSettingController ds_c = Get.find(); final context; + final fcs = FrpcConfigurationStorage(); + final FrpcSettingController ds_c = Get.find(); Widget build() { return SimpleDialog( @@ -42,8 +43,8 @@ class FrpcDownloadDialogX { version: '0.51.3', progressCallback: ds_c.downloadFrpcCallback, cancelToken: ds_c.downloadCancelToken, - useMirror: - (await FrpcSettingPrefs.getFrpcInfo()).github_mirror); + useMirror: fcs.getSettingsGitHubMirror(), + ); ds_c.frpc_download_cancel = res; ds_c.refreshDownloadShow(); }, diff --git a/lib/ui/model/FrpcDownloadTip.dart b/lib/ui/models/FrpcDownloadTip.dart similarity index 92% rename from lib/ui/model/FrpcDownloadTip.dart rename to lib/ui/models/FrpcDownloadTip.dart index 412d88fa..e2abfa16 100644 --- a/lib/ui/model/FrpcDownloadTip.dart +++ b/lib/ui/models/FrpcDownloadTip.dart @@ -1,11 +1,12 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/FrpcSettingController.dart'; -import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; +import 'package:nyalcf/controllers/frpcSettingController.dart'; +import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; import 'FrpcDownloadDialog.dart'; class FrpcDownloadTip { + static final fcs = FrpcConfigurationStorage(); static final FrpcSettingController ds_c = Get.find(); static Container tip({required context}) => Container( @@ -65,9 +66,7 @@ class FrpcDownloadTip { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('已安装版本列表:'), - Text((await FrpcSettingPrefs.getFrpcInfo()) - .lists['frpc_downloaded_versions'] - .toString()), + Text(fcs.getInstalledVersions().toString()), Text('已指定的 Frpc 文件路径:${ds_c.custom_path ?? '无'}'), ], ), diff --git a/lib/ui/model/ProcessListDialog.dart b/lib/ui/models/ProcessListDialog.dart similarity index 100% rename from lib/ui/model/ProcessListDialog.dart rename to lib/ui/models/ProcessListDialog.dart diff --git a/lib/ui/model/ToolDialog.dart b/lib/ui/models/ToolDialog.dart similarity index 100% rename from lib/ui/model/ToolDialog.dart rename to lib/ui/models/ToolDialog.dart diff --git a/lib/ui/auth/login.dart b/lib/ui/views/auth/login.dart similarity index 97% rename from lib/ui/auth/login.dart rename to lib/ui/views/auth/login.dart index d2f21bb7..661ca5e0 100644 --- a/lib/ui/auth/login.dart +++ b/lib/ui/views/auth/login.dart @@ -3,8 +3,8 @@ import 'package:get/get.dart'; import 'package:nyalcf/utils/network/dio/auth/loginAuth.dart'; import 'package:nyalcf/models/UserInfoModel.dart'; import 'package:nyalcf/prefs/UserInfoPrefs.dart'; -import 'package:nyalcf/ui/model/AppbarActions.dart'; -import 'package:nyalcf/ui/model/FloatingActionButton.dart'; +import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/ui/models/FloatingActionButton.dart'; class Login extends StatefulWidget { const Login({super.key, required this.title}); diff --git a/lib/ui/auth/register.dart b/lib/ui/views/auth/register.dart similarity index 99% rename from lib/ui/auth/register.dart rename to lib/ui/views/auth/register.dart index 593150d7..77d8d1fd 100644 --- a/lib/ui/auth/register.dart +++ b/lib/ui/views/auth/register.dart @@ -4,8 +4,8 @@ import 'package:nyalcf/utils/network/dio/auth/loginAuth.dart'; import 'package:nyalcf/utils/network/dio/auth/registerAuth.dart'; import 'package:nyalcf/models/UserInfoModel.dart'; import 'package:nyalcf/prefs/UserInfoPrefs.dart'; -import 'package:nyalcf/ui/model/AppbarActions.dart'; -import 'package:nyalcf/ui/model/FloatingActionButton.dart'; +import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/ui/models/FloatingActionButton.dart'; class Register extends StatefulWidget { const Register({super.key, required this.title}); diff --git a/lib/ui/auth/tokenmode.dart b/lib/ui/views/auth/tokenmode.dart similarity index 96% rename from lib/ui/auth/tokenmode.dart rename to lib/ui/views/auth/tokenmode.dart index 175a42ba..d0229302 100644 --- a/lib/ui/auth/tokenmode.dart +++ b/lib/ui/views/auth/tokenmode.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/prefs/TokenModePrefs.dart'; -import 'package:nyalcf/ui/model/AppbarActions.dart'; -import 'package:nyalcf/ui/model/FloatingActionButton.dart'; +import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/ui/models/FloatingActionButton.dart'; class TokenModeAuth extends StatefulWidget { TokenModeAuth({super.key, required this.title}); diff --git a/lib/ui/home.dart b/lib/ui/views/home.dart similarity index 97% rename from lib/ui/home.dart rename to lib/ui/views/home.dart index b66919f0..b6db7031 100644 --- a/lib/ui/home.dart +++ b/lib/ui/views/home.dart @@ -2,12 +2,11 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/frpcController.dart'; import 'package:nyalcf/controllers/userController.dart'; +import 'package:nyalcf/ui/models/AppbarActions.dart'; import 'package:nyalcf/utils/network/dio/auth/userAuth.dart'; import 'package:nyalcf/io/userInfoStorage.dart'; import 'package:nyalcf/models/UserInfoModel.dart'; -import 'package:nyalcf/ui/model/FloatingActionButton.dart'; - -import 'model/AppbarActions.dart'; +import 'package:nyalcf/ui/models/FloatingActionButton.dart'; class Home extends StatelessWidget { Home({super.key, required this.title}); diff --git a/lib/ui/panel/console.dart b/lib/ui/views/panel/console.dart similarity index 91% rename from lib/ui/panel/console.dart rename to lib/ui/views/panel/console.dart index 36ec37e5..ca882b7f 100644 --- a/lib/ui/panel/console.dart +++ b/lib/ui/views/panel/console.dart @@ -3,11 +3,11 @@ import 'package:get/get.dart'; import 'package:nyalcf/controllers/consoleController.dart'; import 'package:nyalcf/controllers/frpcController.dart'; import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/ui/model/AccountDialog.dart'; -import 'package:nyalcf/ui/model/AppbarActions.dart'; -import 'package:nyalcf/ui/model/Drawer.dart'; -import 'package:nyalcf/ui/model/FloatingActionButton.dart'; -import 'package:nyalcf/ui/model/ProcessListDialog.dart'; +import 'package:nyalcf/ui/models/AccountDialog.dart'; +import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/ui/models/Drawer.dart'; +import 'package:nyalcf/ui/models/FloatingActionButton.dart'; +import 'package:nyalcf/ui/models/ProcessListDialog.dart'; import 'package:nyalcf/utils/frpc/ProcessManager.dart'; class PanelConsole extends StatelessWidget { diff --git a/lib/ui/panel/home.dart b/lib/ui/views/panel/home.dart similarity index 97% rename from lib/ui/panel/home.dart rename to lib/ui/views/panel/home.dart index 99ac0625..67cae175 100644 --- a/lib/ui/panel/home.dart +++ b/lib/ui/views/panel/home.dart @@ -5,14 +5,13 @@ import 'package:get/get.dart'; import 'package:nyalcf/controllers/consoleController.dart'; import 'package:nyalcf/controllers/panelController.dart'; import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/ui/model/AccountDialog.dart'; -import 'package:nyalcf/ui/model/Drawer.dart'; -import 'package:nyalcf/ui/model/FloatingActionButton.dart'; +import 'package:nyalcf/ui/models/AccountDialog.dart'; +import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/ui/models/Drawer.dart'; +import 'package:nyalcf/ui/models/FloatingActionButton.dart'; import 'package:nyalcf/utils/Logger.dart'; import 'package:url_launcher/url_launcher.dart'; -import '../model/AppbarActions.dart'; - class PanelHome extends StatelessWidget { PanelHome({super.key, required this.title}); diff --git a/lib/ui/panel/proxies.dart b/lib/ui/views/panel/proxies.dart similarity index 89% rename from lib/ui/panel/proxies.dart rename to lib/ui/views/panel/proxies.dart index 478549ff..77383ab5 100644 --- a/lib/ui/panel/proxies.dart +++ b/lib/ui/views/panel/proxies.dart @@ -2,11 +2,10 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/proxiesController.dart'; import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; -import 'package:nyalcf/ui/model/AccountDialog.dart'; -import 'package:nyalcf/ui/model/AppbarActions.dart'; -import 'package:nyalcf/ui/model/Drawer.dart'; -import 'package:nyalcf/ui/model/FloatingActionButton.dart'; +import 'package:nyalcf/ui/models/AccountDialog.dart'; +import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/ui/models/Drawer.dart'; +import 'package:nyalcf/ui/models/FloatingActionButton.dart'; class PanelProxies extends StatelessWidget { PanelProxies({required this.title}); @@ -18,7 +17,6 @@ class PanelProxies extends StatelessWidget { Widget build(BuildContext context) { final p_c = Get.put(ProxiesController(context: context)); - FrpcSettingPrefs.refresh(); p_c.load(c.user, c.token); return Scaffold( diff --git a/lib/ui/setting/frpcSetting.dart b/lib/ui/views/setting/frpcSetting.dart similarity index 86% rename from lib/ui/setting/frpcSetting.dart rename to lib/ui/views/setting/frpcSetting.dart index 60282d19..12b5aef8 100644 --- a/lib/ui/setting/frpcSetting.dart +++ b/lib/ui/views/setting/frpcSetting.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/FrpcSettingController.dart'; -import 'package:nyalcf/io/frpcManagerStorage.dart'; -import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; +import 'package:nyalcf/controllers/frpcSettingController.dart'; +import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; class FrpcSetting { FrpcSetting({required this.context}); final context; + final fcs = FrpcConfigurationStorage(); final FrpcSettingController ds_c = Get.find(); Widget widget() { @@ -43,10 +43,8 @@ class FrpcSetting { Switch( value: ds_c.frpc_download_use_mirror.value, onChanged: (value) async { - FrpcSettingPrefs.setDownloadUseMirror(value); + fcs.setSettingsGitHubMirror(value); ds_c.frpc_download_use_mirror.value = value; - FrpcManagerStorage.save( - await FrpcSettingPrefs.getFrpcInfo()); }, ), ], diff --git a/lib/ui/setting/injector.dart b/lib/ui/views/setting/injector.dart similarity index 91% rename from lib/ui/setting/injector.dart rename to lib/ui/views/setting/injector.dart index bacd568f..ae8830be 100644 --- a/lib/ui/setting/injector.dart +++ b/lib/ui/views/setting/injector.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/FrpcSettingController.dart'; +import 'package:nyalcf/controllers/frpcSettingController.dart'; import 'package:nyalcf/controllers/launcherSettingController.dart'; -import 'package:nyalcf/ui/model/AppbarActions.dart'; -import 'package:nyalcf/ui/model/FloatingActionButton.dart'; +import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/ui/models/FloatingActionButton.dart'; import 'frpcSetting.dart'; import 'launcherSetting.dart'; diff --git a/lib/ui/setting/launcherSetting.dart b/lib/ui/views/setting/launcherSetting.dart similarity index 100% rename from lib/ui/setting/launcherSetting.dart rename to lib/ui/views/setting/launcherSetting.dart diff --git a/lib/ui/tokenmode/panel.dart b/lib/ui/views/tokenmode/panel.dart similarity index 95% rename from lib/ui/tokenmode/panel.dart rename to lib/ui/views/tokenmode/panel.dart index 998ea6b7..712df4e3 100644 --- a/lib/ui/tokenmode/panel.dart +++ b/lib/ui/views/tokenmode/panel.dart @@ -4,11 +4,11 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/consoleController.dart'; import 'package:nyalcf/controllers/frpcController.dart'; -import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; import 'package:nyalcf/prefs/TokenModePrefs.dart'; -import 'package:nyalcf/ui/model/AppbarActions.dart'; -import 'package:nyalcf/ui/model/FloatingActionButton.dart'; -import 'package:nyalcf/ui/model/ProcessListDialog.dart'; +import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; +import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/ui/models/FloatingActionButton.dart'; +import 'package:nyalcf/ui/models/ProcessListDialog.dart'; import 'package:nyalcf/utils/frpc/ProcessManager.dart'; class TokenModePanel extends StatefulWidget { @@ -27,6 +27,8 @@ class _TokenModePanelState extends State { final proxyController = TextEditingController(); + final fcs = FrpcConfigurationStorage(); + final FrpcController f_c = Get.find(); final ConsoleController c_c = Get.put(ConsoleController()); @@ -84,11 +86,10 @@ class _TokenModePanelState extends State { final String? frp_token = await TokenModePrefs.getToken(); // 判断frp_token是否为空 if (frp_token != null) if (proxyController.text != '') { - final frpcinfo = await FrpcSettingPrefs.getFrpcInfo(); // 检测是否定义了环境变量 if (f_c.custom_path == null) { // 无环境变量已安装Frpc - if (frpcinfo.frpc_downloaded_versions.isNotEmpty) { + if (fcs.getInstalledVersions().isNotEmpty) { FrpcProcessManager().nwprcs( frp_token: frp_token, proxy_id: int.parse(proxyController.text), diff --git a/lib/utils/FileConfiguration.dart b/lib/utils/FileConfiguration.dart index c1031fdf..2f482993 100644 --- a/lib/utils/FileConfiguration.dart +++ b/lib/utils/FileConfiguration.dart @@ -6,12 +6,17 @@ import 'package:nyalcf/utils/Logger.dart'; class FileConfiguration { FileConfiguration({ this.file = null, + required this.handle, }); File? file; // Dart Dart 草你吗,定义File?传Future不报错 + final String handle; - static Map tmp_data = Map(); + static Map tmp_data = {}; + void initMap() { + tmp_data[handle] = Map(); + } /// 一堆B方法 /// 气死我里 /// String @@ -43,7 +48,7 @@ class FileConfiguration { /// 设置值 void set(String node, dynamic value) { List nl = _parseNode(node); - dynamic last = tmp_data; // 初始化last为tmp_data的引用 + dynamic last = tmp_data[handle]; // 初始化last为tmp_data的引用 String? n; for (int i = 0; i < nl.length; i++) { n = nl[i]; @@ -57,7 +62,7 @@ class FileConfiguration { // 移动到下一个节点 last = last[n]; } - Logger.debug('写入tmp_data状态值: ${tmp_data}'); + Logger.debug('写入tmp_data状态值: ${tmp_data[handle]}'); Logger.debug('写入迭代NODE: $n'); Logger.debug('写入迭代LAST: $last'); } @@ -72,12 +77,12 @@ class FileConfiguration { for (n in nl) { if (last != null) { last = last[n]; - Logger.debug('目标tmp_data状态值: ${tmp_data}'); + Logger.debug('目标tmp_data状态值: ${tmp_data[handle]}'); Logger.debug('读取迭代NODE: $n'); Logger.debug('读取迭代LAST: $last'); } else { - last = tmp_data[n]; - Logger.debug('目标tmp_data状态值: ${tmp_data}'); + last = tmp_data[handle][n]; + Logger.debug('目标tmp_data状态值: ${tmp_data[handle]}'); Logger.debug('读取迭代NODE: $n'); Logger.debug('读取迭代LAST: $last'); } @@ -124,14 +129,14 @@ class FileConfiguration { /// 转为 String @override - String toString() => json.encode(tmp_data); + String toString() => json.encode(tmp_data[handle]); /// 转为 Map String - String toMapString() => tmp_data.toString(); + String toMapString() => tmp_data[handle].toString(); /// 从 String 导入 - fromString(String j) => tmp_data = json.decode(j); + fromString(String j) => tmp_data[handle] = json.decode(j); /// 从 Map 导入 - fromMap(Map map) => tmp_data = map; + fromMap(Map map) => tmp_data[handle] = map; } diff --git a/lib/utils/frpc/ProcessManager.dart b/lib/utils/frpc/ProcessManager.dart index 89fa9c23..4b2b6269 100644 --- a/lib/utils/frpc/ProcessManager.dart +++ b/lib/utils/frpc/ProcessManager.dart @@ -4,15 +4,15 @@ import 'dart:io'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/consoleController.dart'; import 'package:nyalcf/controllers/frpcController.dart'; -import 'package:nyalcf/io/frpcConfigurationStorage.dart'; -import 'package:nyalcf/io/frpcManagerStorage.dart'; +import 'package:nyalcf/storages/configurations/ProxiesConfigurationStorage.dart'; +import 'package:nyalcf/storages/stories/FrpcStoryStorage.dart'; import 'package:nyalcf/utils/Logger.dart'; class FrpcProcessManager { final FrpcController f_c = Get.find(); final ConsoleController c_c = Get.find(); - final frpc_work_path = FrpcManagerStorage.getRunPath('0.51.3'); + final frpc_work_path = FrpcStoryStorage.getRunPath(); void nwprcs({ required String frp_token, @@ -21,12 +21,12 @@ class FrpcProcessManager { }) async { if (!Platform.isWindows) { Logger.info('*nix platform, change file permission'); - await FrpcManagerStorage.setRunPermission(); + await FrpcStoryStorage.setRunPermission(); } final Map p_map = Map(); List arguments = []; - final conf_path = await FrpcConfigurationStorage.getConfigPath(proxy_id); + final conf_path = await ProxiesConfigurationStorage.getConfigPath(proxy_id); if (conf_path != null) { arguments = ['-c', conf_path]; } else { @@ -39,9 +39,9 @@ class FrpcProcessManager { } final process = await Process.start( - frpc_path ?? await FrpcManagerStorage.getFilePath('0.51.3'), + frpc_path ?? await FrpcStoryStorage.getFilePath(), arguments, - workingDirectory: await FrpcManagerStorage.getRunPath('0.51.3'), + workingDirectory: await FrpcStoryStorage.getRunPath(), ); p_map['process'] = process; p_map['proxy_id'] = proxy_id; diff --git a/pubspec.yaml b/pubspec.yaml index 72253429..42214638 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 0.1.7+rc1 +version: 0.1.7+rc2 environment: sdk: '>=3.1.5 <4.0.0' From 5a9b5f033cd084aea424cfb854a43dfac44b2d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Sat, 10 Feb 2024 23:11:39 +0800 Subject: [PATCH 02/10] =?UTF-8?q?[*]=E6=8F=90=E5=8F=96=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/storages/JsonConfiguration.dart | 4 +++- lib/storages/configurations/FrpcConfigurationStorage.dart | 2 +- lib/storages/configurations/LauncherConfigurationStorage.dart | 4 +--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/storages/JsonConfiguration.dart b/lib/storages/JsonConfiguration.dart index fbe3dbfc..126e50f6 100644 --- a/lib/storages/JsonConfiguration.dart +++ b/lib/storages/JsonConfiguration.dart @@ -1,5 +1,7 @@ +import 'dart:convert'; import 'dart:io'; +import 'package:crypto/crypto.dart'; import 'package:nyalcf/utils/FileConfiguration.dart'; import 'package:nyalcf/utils/PathProvider.dart'; import 'package:nyalcf/utils/Logger.dart'; @@ -18,7 +20,7 @@ abstract class JsonConfiguration { FileConfiguration get cfg => FileConfiguration( file: this.file, - handle: handle, + handle: sha1.convert(utf8.encode(handle)).toString(), ); /// 保存 diff --git a/lib/storages/configurations/FrpcConfigurationStorage.dart b/lib/storages/configurations/FrpcConfigurationStorage.dart index bcaec611..e75157d6 100644 --- a/lib/storages/configurations/FrpcConfigurationStorage.dart +++ b/lib/storages/configurations/FrpcConfigurationStorage.dart @@ -8,7 +8,7 @@ class FrpcConfigurationStorage extends JsonConfiguration { @override File get file => File('$path/frpc.json'); @override - String get handle => sha1.convert(utf8.encode('FRPCCONF')).toString(); + String get handle => 'FRPC'; @override Future> get def_config async => { diff --git a/lib/storages/configurations/LauncherConfigurationStorage.dart b/lib/storages/configurations/LauncherConfigurationStorage.dart index c3710a9e..e4ddbd17 100644 --- a/lib/storages/configurations/LauncherConfigurationStorage.dart +++ b/lib/storages/configurations/LauncherConfigurationStorage.dart @@ -1,6 +1,4 @@ -import 'dart:convert'; import 'dart:io'; -import 'package:crypto/crypto.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; @@ -11,7 +9,7 @@ class LauncherConfigurationStorage extends JsonConfiguration { @override File get file => File('$path/launcher.json'); @override - String get handle => sha1.convert(utf8.encode('LAUNCHERCONF')).toString(); + String get handle => 'LAUNCHER'; @override Future> get def_config async => { From c35d89be017d9d06d411ba9191666950e974f125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Mon, 12 Feb 2024 12:56:49 +0800 Subject: [PATCH 03/10] =?UTF-8?q?[*]Broken=20changes:=E5=A4=A7=E9=87=8F?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0const=E6=8F=90=E9=AB=98=E6=80=A7=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E7=A7=BB=E9=99=A4=E4=B8=80=E9=83=A8=E5=88=86=E4=B8=8D?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E7=9A=84await=EF=BC=8C=E9=81=B5=E5=BE=AA?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BF=AE=E6=94=B9=E4=B8=8D=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=EF=BC=8C=E6=B7=BB=E5=8A=A0linter=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analysis_options.yaml | 4 + lib/controllers/consoleController.dart | 36 +-- lib/controllers/frpcController.dart | 42 +-- lib/controllers/frpcSettingController.dart | 118 ++++---- .../launcherSettingController.dart | 51 ++-- lib/controllers/proxiesController.dart | 70 ++--- lib/controllers/userController.dart | 4 +- lib/io/userInfoStorage.dart | 8 +- lib/main.dart | 4 +- lib/main_window.dart | 14 +- lib/models/FrpcConfigModel.dart | 37 --- lib/models/ProxyInfoModel.dart | 28 +- lib/models/UpdateInfoModel.dart | 4 +- lib/models/UserInfoModel.dart | 8 +- lib/prefs/FrpcSettingPrefs.dart | 53 ---- lib/prefs/ProxiesPrefs.dart | 1 - lib/prefs/TokenModePrefs.dart | 4 +- lib/prefs/UserInfoPrefs.dart | 6 +- lib/storages/JsonConfiguration.dart | 9 +- .../FrpcConfigurationStorage.dart | 4 +- .../LauncherConfigurationStorage.dart | 6 +- .../ProxiesConfigurationStorage.dart | 23 +- lib/storages/injector.dart | 4 +- lib/storages/stories/FrpcStoryStorage.dart | 11 +- lib/ui/models/AccountDialog.dart | 16 +- lib/ui/models/AppbarActions.dart | 16 +- lib/ui/models/Drawer.dart | 14 +- lib/ui/models/FloatingActionButton.dart | 3 +- .../models/FrpcConfigurationEditorDialog.dart | 32 +- lib/ui/models/FrpcDownloadDialog.dart | 46 +-- lib/ui/models/FrpcDownloadTip.dart | 125 ++++---- lib/ui/models/ProcessListDialog.dart | 8 +- lib/ui/models/ToolDialog.dart | 10 +- lib/ui/views/auth/login.dart | 23 +- lib/ui/views/auth/register.dart | 48 +-- lib/ui/views/auth/tokenmode.dart | 8 +- lib/ui/views/home.dart | 10 +- lib/ui/views/panel/console.dart | 34 +-- lib/ui/views/panel/home.dart | 278 +++++++++--------- lib/ui/views/panel/proxies.dart | 20 +- lib/ui/views/setting/frpcSetting.dart | 102 ++++--- lib/ui/views/setting/injector.dart | 17 +- lib/ui/views/setting/launcherSetting.dart | 260 ++++++++-------- lib/ui/views/tokenmode/panel.dart | 123 ++++---- lib/utils/CPUArch.dart | 4 +- lib/utils/FileConfiguration.dart | 61 ++-- lib/utils/Logger.dart | 30 +- lib/utils/PathProvider.dart | 28 +- lib/utils/ThemeControl.dart | 40 ++- lib/utils/Updater.dart | 28 +- lib/utils/frpc/Archive.dart | 19 +- lib/utils/frpc/ProcessManager.dart | 98 +++--- lib/utils/network/dio/auth/loginAuth.dart | 6 +- lib/utils/network/dio/auth/registerAuth.dart | 19 +- lib/utils/network/dio/auth/userAuth.dart | 27 +- lib/utils/network/dio/basicConfig.dart | 14 +- lib/utils/network/dio/frpc/download.dart | 28 +- lib/utils/network/dio/launcher/update.dart | 4 +- lib/utils/network/dio/other/announcement.dart | 7 +- .../network/dio/proxies/configuration.dart | 14 +- lib/utils/network/dio/proxies/get.dart | 34 +-- pubspec.lock | 22 +- pubspec.yaml | 4 + 63 files changed, 1080 insertions(+), 1149 deletions(-) delete mode 100644 lib/models/FrpcConfigModel.dart delete mode 100644 lib/prefs/FrpcSettingPrefs.dart delete mode 100644 lib/prefs/ProxiesPrefs.dart diff --git a/analysis_options.yaml b/analysis_options.yaml index a567d160..de8234a4 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -25,6 +25,10 @@ linter: # producing the lint. rules: prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + always_use_package_imports: true + avoid_web_libraries_in_flutter: true + use_build_context_synchronously: false + annotate_overrides: true # avoid_print: false # Uncomment to disable the `avoid_print` rule # Additional information about this file can be found at diff --git a/lib/controllers/consoleController.dart b/lib/controllers/consoleController.dart index 69a3d155..0abb6bcd 100644 --- a/lib/controllers/consoleController.dart +++ b/lib/controllers/consoleController.dart @@ -1,52 +1,54 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/utils/frpc/ProcessManager.dart'; /// 控制台 GetX 状态控制器 class ConsoleController extends GetxController { - var widgets = [].obs; + RxList widgets = [].obs; /// UI组件列表 - var process_list = [].obs; + RxList> processList = >[].obs; /// 进程管理列表 /// 添加进程 - addProcess(p_map) { - process_list.add(p_map); - process_list.refresh(); + addProcess(Map pMap) { + processList.add(pMap); + processList.refresh(); } /// 移除进程 - removeProcess(p_map) { - process_list.remove(p_map); - process_list.refresh(); + removeProcess(Map pMap) { + processList.remove(pMap); + processList.refresh(); } /// 清空进程 clearProcess() { - process_list.clear(); - process_list.refresh(); + processList.clear(); + processList.refresh(); } /// 加载进程管理信息 load() { widgets.value = []; - process_list.forEach((element) { - final process = element['process']; - final proxy_id = element['proxy_id']; + for (Map element in processList) { + final Process process = element['process']; + final int proxyId = element['proxy_id']; /// 添加进程管理信息至UI组件列表 - widgets.add(DataRow(cells: [ + widgets.add(DataRow(cells: [ DataCell(Text(process.pid.toString())), /// 进程ID - DataCell(Text(proxy_id.toString())), + DataCell(Text(proxyId.toString())), /// 代理ID DataCell( IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), onPressed: () { /// 杀死进程 FrpcProcessManager().kill(element); @@ -56,6 +58,6 @@ class ConsoleController extends GetxController { ), ])); widgets.refresh(); - }); + } } } diff --git a/lib/controllers/frpcController.dart b/lib/controllers/frpcController.dart index 5eb01455..b21b4c23 100644 --- a/lib/controllers/frpcController.dart +++ b/lib/controllers/frpcController.dart @@ -6,14 +6,14 @@ import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; import 'package:nyalcf/storages/stories/FrpcStoryStorage.dart'; class FrpcController extends GetxController { - final fcs = FrpcConfigurationStorage(); + final FrpcConfigurationStorage fcs = FrpcConfigurationStorage(); /// 是否存在的标志 - var exist = false.obs; + RxBool exist = false.obs; /// 过滤后的输出文本 - var process_out = [ - SelectableText( + RxList processOut = [ + const SelectableText( '[SYSTEM] Welcome to frpc console.', style: TextStyle( color: Colors.green, @@ -24,9 +24,9 @@ class FrpcController extends GetxController { ].obs; /// 版本号 - var version = ''.obs; + RxString version = ''.obs; - String? get custom_path => Platform.environment['NYA_LCF_FRPC_PATH']; + String? get customPath => Platform.environment['NYA_LCF_FRPC_PATH']; /// 加载方法 load() async { @@ -42,15 +42,15 @@ class FrpcController extends GetxController { } /// 追加信息日志 - void appendInfoLog(element) { + void appendInfoLog(String element) { /// 如果输出文本长度超过500,则移除第一条文本 - if (process_out.length >= 500) process_out.remove(process_out.first); + if (processOut.length >= 500) processOut.remove(processOut.first); /// 添加信息日志文本 - process_out.add( + processOut.add( SelectableText( '[FRPC][INFO] $element', - style: TextStyle( + style: const TextStyle( color: Colors.teal, fontWeight: FontWeight.w200, fontFamily: 'Droid Sans Mono', @@ -59,19 +59,19 @@ class FrpcController extends GetxController { ); /// 刷新输出文本 - process_out.refresh(); + processOut.refresh(); } /// 追加警告日志 - void appendWarnLog(element) { + void appendWarnLog(String element) { /// 如果输出文本长度超过500,则移除第一条文本 - if (process_out.length >= 500) process_out.remove(process_out.first); + if (processOut.length >= 500) processOut.remove(processOut.first); /// 添加警告日志文本 - process_out.add( + processOut.add( SelectableText( '[FRPC][WARN] $element', - style: TextStyle( + style: const TextStyle( color: Colors.orange, fontWeight: FontWeight.w200, fontFamily: 'Droid Sans Mono', @@ -80,19 +80,19 @@ class FrpcController extends GetxController { ); /// 刷新输出文本 - process_out.refresh(); + processOut.refresh(); } /// 追加错误日志 - void appendErrorLog(element) { + void appendErrorLog(String element) { /// 如果输出文本长度超过500,则移除第一条文本 - if (process_out.length >= 500) process_out.remove(process_out.first); + if (processOut.length >= 500) processOut.remove(processOut.first); /// 添加错误日志文本 - process_out.add( + processOut.add( SelectableText( '[FRPC][ERROR] $element', - style: TextStyle( + style: const TextStyle( color: Colors.red, fontWeight: FontWeight.w200, fontFamily: 'Droid Sans Mono', @@ -101,6 +101,6 @@ class FrpcController extends GetxController { ); /// 刷新输出文本 - process_out.refresh(); + processOut.refresh(); } } diff --git a/lib/controllers/frpcSettingController.dart b/lib/controllers/frpcSettingController.dart index a1165292..6e41116d 100644 --- a/lib/controllers/frpcSettingController.dart +++ b/lib/controllers/frpcSettingController.dart @@ -15,73 +15,73 @@ class FrpcSettingController extends GetxController { BuildContext context; List> arch = >[]; - final fcs = FrpcConfigurationStorage(); + final FrpcConfigurationStorage fcs = FrpcConfigurationStorage(); - var platform = ''; - String? get custom_path => Platform.environment['NYA_LCF_FRPC_PATH']; + String platform = ''; + String? get customPath => Platform.environment['NYA_LCF_FRPC_PATH']; - var frpc_download_tip = Container().obs; - var frpc_download_arch_list = [ - DropdownMenuItem(value: 0, child: Text('加载中')), + Rx frpcDownloadTip = const Card().obs; + var frpcDownloadArchList = >[ + const DropdownMenuItem(value: 0, child: Text('加载中')), ].obs; - var frpc_download_arch = 0.obs; - var frpc_download_progress = 0.0.obs; - var frpc_download_show = [].obs; - var _frpc_downloaded_versions = []; - dynamic frpc_download_cancel = false; - var frpc_download_use_mirror = false.obs; + var frpcDownloadArch = 0.obs; + var frpcDownloadProgress = 0.0.obs; + var frpcDownloadShow = [].obs; + List _frpcDownloadedVersions = []; + dynamic frpcDownloadCancel = false; + var frpcDownloadUseMirror = false.obs; - var frpc_version = ''.obs; + var frpcVersion = ''.obs; - var github_proxy = ''.obs; + var githubProxy = ''.obs; - var cpu_arch = ''.obs; + var cpuArch = ''.obs; load() async { - cpu_arch.value = await CPUArch.getCPUArchitecture(); + cpuArch.value = (await CPUArch.getCPUArchitecture())!; // await FrpcSettingPrefs.refresh(); // final frpcinfo = await FrpcSettingPrefs.getFrpcInfo(); - frpc_download_use_mirror.value = fcs.getSettingsGitHubMirror(); + frpcDownloadUseMirror.value = fcs.getSettingsGitHubMirror(); - frpc_version.value = await fcs.getSettingsFrpcVersion(); - _load_tip(); - _load_frpc_dropdownitem(); + frpcVersion.value = fcs.getSettingsFrpcVersion(); + _loadTip(); + _loadFrpcDropdownitem(); } - void _load_tip() async { - _frpc_downloaded_versions = fcs.getInstalledVersions(); - if (_frpc_downloaded_versions.isEmpty || - (custom_path != null && await File(custom_path!).exists())) { - frpc_download_tip.value = FrpcDownloadTip.tip(context: context); + void _loadTip() async { + _frpcDownloadedVersions = fcs.getInstalledVersions(); + if (_frpcDownloadedVersions.isEmpty || + (customPath != null && await File(customPath!).exists())) { + frpcDownloadTip.value = FrpcDownloadTip.tip(context: context); } else { - frpc_download_tip.value = + frpcDownloadTip.value = await FrpcDownloadTip.downloaded(context: context); } } /// 加载Frpc下载列表 - void _load_frpc_dropdownitem() { - frpc_download_arch_list.value = _buildArchDMIWidgetList(); - Logger.debug(frpc_download_arch_list); + void _loadFrpcDropdownitem() { + frpcDownloadArchList.value = _buildArchDMIWidgetList(); + Logger.debug(frpcDownloadArchList); } void refreshDownloadShow() async { - if (frpc_download_cancel is bool) { - if (frpc_download_cancel) { - frpc_download_show.clear(); - frpc_download_show.add(Text( + if (frpcDownloadCancel is bool) { + if (frpcDownloadCancel) { + frpcDownloadShow.clear(); + frpcDownloadShow.add(const Text( '下载取消', style: TextStyle(color: Colors.orange), )); - frpc_download_cancel = false; - downloadCancelToken = new CancelToken(); + frpcDownloadCancel = false; + downloadCancelToken = CancelToken(); } else { - frpc_download_show.clear(); - frpc_download_show.add(LinearProgressIndicator( - value: frpc_download_progress.value, + frpcDownloadShow.clear(); + frpcDownloadShow.add(LinearProgressIndicator( + value: frpcDownloadProgress.value, )); } - } else if (frpc_download_cancel is Response) { + } else if (frpcDownloadCancel is Response) { Get.close(0); /*await showDialog( context: context, @@ -92,9 +92,9 @@ class FrpcSettingController extends GetxController { barrierDismissible: false); Future.delayed(const Duration(seconds: 2), () async { //延时执行 - final unarchive = await FrpcArchive.unarchive( + final bool unarchive = await FrpcArchive.unarchive( platform: platform, - arch: arch[frpc_download_arch.value]['arch'], + arch: arch[frpcDownloadArch.value]['arch'], version: fcs.getSettingsFrpcVersion(), ); if (unarchive) { @@ -105,45 +105,45 @@ class FrpcSettingController extends GetxController { print('*nix platform, change file permission'); await FrpcManagerStorage.setRunPermission(); }*/ - _load_tip(); + _loadTip(); } else { Get.snackbar( '解压 Frpc 时发生错误..呜呜..', '请检查磁盘是否被塞满了..或者是已经安装了!受不了了呜呜呜...', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } /// 关闭对话框 Get.close(0); Get.close(0); - }); + },); } else { - frpc_download_show.clear(); - frpc_download_show.add(Text( + frpcDownloadShow.clear(); + frpcDownloadShow.add(const Text( '发生错误', style: TextStyle(color: Colors.red), )); Get.snackbar( '下载 Frpc 时发生错误..呜呜..', - frpc_download_cancel.toString(), + frpcDownloadCancel.toString(), snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } } /// 构建Arch列表 - List _buildArchDMIWidgetList() { - final Set> _arch = Set(); - final List dmil = []; + List> _buildArchDMIWidgetList() { + dynamic arch = >{}; + final List> dmil = >[]; /// Platform = Windows if (Platform.isWindows) { platform = 'windows'; Logger.info('Build windows platform arch list'); - _arch.addAll([ + arch.addAll([ {'arch': 'amd64', 'name': 'x86_64/amd64'}, {'arch': '386', 'name': 'x86/i386/amd32'}, {'arch': 'arm64', 'name': 'arm64/armv8'}, @@ -154,7 +154,7 @@ class FrpcSettingController extends GetxController { if (Platform.isLinux) { platform = 'linux'; Logger.info('Build linux platform arch list'); - _arch.addAll([ + arch.addAll([ {'arch': 'amd64', 'name': 'x86_64/amd64'}, {'arch': '386', 'name': 'x86/i386/amd32'}, {'arch': 'arm64', 'name': 'arm64/armv8'}, @@ -171,12 +171,12 @@ class FrpcSettingController extends GetxController { if (Platform.isMacOS) { platform = 'darwin'; Logger.info('Build macos platform arch list'); - _arch.addAll([ + arch.addAll([ {'arch': 'amd64', 'name': 'x86_64/amd64'}, {'arch': 'arm64', 'name': 'arm64/armv8'}, ]); } - arch = _arch.toList(); + arch = arch.toList(); /// 遍历构建 for (var i = 0; i <= arch.length - 1; i++) { @@ -202,20 +202,20 @@ class FrpcSettingController extends GetxController { required int value, }) { return DropdownMenuItem( - child: Text(version), value: value, + child: Text(version), ); } CancelToken downloadCancelToken = CancelToken(); void downloadFrpcCallback(received, total) { - Logger.debug('Download callback: ${received}'); + Logger.debug('Download callback: $received'); if (total != -1) { if (!downloadCancelToken.isCancelled) { - frpc_download_progress.value = received / total; + frpcDownloadProgress.value = received / total; } else { - frpc_download_progress.value = -1; + frpcDownloadProgress.value = -1; } } else { Logger.info('Download failed: file total is -1'); diff --git a/lib/controllers/launcherSettingController.dart b/lib/controllers/launcherSettingController.dart index a77cc8f2..f228ac15 100644 --- a/lib/controllers/launcherSettingController.dart +++ b/lib/controllers/launcherSettingController.dart @@ -7,64 +7,65 @@ import 'package:nyalcf/utils/Logger.dart'; class DSettingLauncherController extends GetxController { final lcs = LauncherConfigurationStorage(); - var app_name = ''.obs; - var app_version = ''.obs; - var app_package_name = ''.obs; + var appName = ''.obs; + var appVersion = ''.obs; + var appPackageName = ''.obs; - var theme_auto = false.obs; - var theme_dark = false.obs; - var theme_light_seed = ''.obs; - var theme_light_seed_enable = false.obs; + var themeAuto = false.obs; + var themeDark = false.obs; + var themeLightSeed = ''.obs; + var themeLightSeedEnable = false.obs; - var switch_theme_dark = Row().obs; + var switchThemeDark = const Row().obs; - var debug_mode = false.obs; + var debugMode = false.obs; load() async { final packageInfo = await PackageInfo.fromPlatform(); - app_name.value = packageInfo.appName; - app_version.value = packageInfo.version; - app_package_name.value = packageInfo.packageName; + appName.value = packageInfo.appName; + appVersion.value = packageInfo.version; + appPackageName.value = packageInfo.packageName; - theme_light_seed.value = lcs.getThemeLightSeedValue(); - theme_light_seed_enable.value = lcs.getThemeLightSeedEnable(); + themeLightSeed.value = lcs.getThemeLightSeedValue(); + themeLightSeedEnable.value = lcs.getThemeLightSeedEnable(); // 新配置 - theme_auto.value = lcs.getThemeAuto(); - theme_dark.value = lcs.getThemeDarkEnable(); - debug_mode.value = lcs.getDebug(); + themeAuto.value = lcs.getThemeAuto(); + themeDark.value = lcs.getThemeDarkEnable(); + debugMode.value = lcs.getDebug(); loadx(); } void loadx() { - if (!(theme_auto.value)) { + if (!(themeAuto.value)) { Logger.debug('Auto theme is disabled, add button to switch theme'); - switch_theme_dark.value = Row( + switchThemeDark.value = Row( children: [ - Expanded( + const Expanded( child: ListTile( leading: Icon(Icons.dark_mode), title: Text('深色主题'), ), ), Switch( - value: theme_dark.value, + value: themeDark.value, onChanged: switchDarkTheme, ), ], ); } else { - switch_theme_dark.value = Row(); + switchThemeDark.value = const Row(); } } void switchDarkTheme(value) async { lcs.setThemeDarkEnable(value); lcs.save(); - theme_dark.value = value; - if (value) + themeDark.value = value; + if (value) { Get.changeThemeMode(ThemeMode.dark); - else + } else { Get.changeThemeMode(ThemeMode.light); + } Get.forceAppUpdate(); loadx(); // ThemeControl.switchDarkTheme(value); diff --git a/lib/controllers/proxiesController.dart b/lib/controllers/proxiesController.dart index b4820f12..b1fd1fbb 100644 --- a/lib/controllers/proxiesController.dart +++ b/lib/controllers/proxiesController.dart @@ -12,23 +12,20 @@ import 'package:nyalcf/models/ProxyInfoModel.dart'; import 'package:nyalcf/ui/models/FrpcConfigurationEditorDialog.dart'; import 'package:nyalcf/utils/Logger.dart'; import 'package:nyalcf/utils/frpc/ProcessManager.dart'; +import 'package:nyalcf/controllers/frpcController.dart'; -import 'frpcController.dart'; - -/** - * 代理 GetX 状态控制器 - */ +/// 代理 GetX 状态控制器 class ProxiesController extends GetxController { ProxiesController({required this.context}); - final context; + final BuildContext context; final fcs = FrpcConfigurationStorage(); - final FrpcController f_c = Get.find(); - final UserController c = Get.find(); + final FrpcController fctr = Get.find(); + final UserController uctr = Get.find(); var proxiesListWidgets = [ - DataRow(cells: [ + const DataRow(cells: [ DataCell(SizedBox( height: 22.0, width: 22.0, @@ -45,9 +42,7 @@ class ProxiesController extends GetxController { ]) ].obs; - /** - * 加载代理列表 - */ + /// 加载代理列表 load(username, token) async { var proxies = await ProxiesGetDio().get(username, token); if (proxies is List) { @@ -57,19 +52,19 @@ class ProxiesController extends GetxController { DataRow( cells: [ DataCell( - Container( + SizedBox( width: 150.0, height: 30.0, - child: SelectableText(element.proxy_name), + child: SelectableText(element.proxyName), ), ), DataCell(SelectableText(element.id.toString())), DataCell(SelectableText(element.node.toString())), - DataCell(SelectableText(element.proxy_type)), - DataCell(SelectableText(element.local_ip)), + DataCell(SelectableText(element.proxyType)), + DataCell(SelectableText(element.localIP)), DataCell( SelectableText( - '${element.local_port} -> ${element.remote_port}'), + '${element.localPort} -> ${element.remotePort}'), ), DataCell( Row(children: await _buildActions(element)), @@ -81,7 +76,7 @@ class ProxiesController extends GetxController { proxiesListWidgets.refresh(); } else { proxiesListWidgets.value = [ - DataRow(cells: [ + const DataRow(cells: [ DataCell(Text('获取失败,请尝试刷新一下~')), DataCell(Text('-')), DataCell(Text('-')), @@ -93,9 +88,9 @@ class ProxiesController extends GetxController { ]; Get.snackbar( '发生错误', - '无法获取隧道列表信息: ${proxies}', + '无法获取隧道列表信息: $proxies', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } } @@ -103,30 +98,30 @@ class ProxiesController extends GetxController { _buildActions(element) async { final List list = [ IconButton( - icon: Icon(Icons.play_circle), + icon: const Icon(Icons.play_circle), tooltip: '启动', onPressed: () async { if (fcs.getInstalledVersions().isNotEmpty) { FrpcProcessManager() - .nwprcs(frp_token: c.frp_token.value, proxy_id: element.id); + .nwprcs(frpToken: uctr.frpToken.value, proxyId: element.id); Get.snackbar( '启动命令已发出', '请查看控制台确认是否启动成功', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } else { Get.snackbar( '笨..笨蛋!', '你还没有安装Frpc!请先到 设置->FRPC 安装Frpc才能启动喵!', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } }, ), IconButton( - icon: Icon(Icons.edit), + icon: const Icon(Icons.edit), tooltip: '编辑配置文件', onPressed: () async { /// 展示编辑框 @@ -134,7 +129,7 @@ class ProxiesController extends GetxController { Get.dialog( FrpcConfigEditorDialogX(context: context).dialog( text, - proxy_id: element.id, + proxyId: element.id, ), barrierDismissible: false, ); @@ -154,7 +149,7 @@ class ProxiesController extends GetxController { Get.dialog(FrpcConfigEditorDialogX(context: context).loading(), barrierDismissible: false); final res = await ProxiesConfigurationDio() - .get(c.frp_token.value, element.id); + .get(uctr.frpToken.value, element.id); if (res is String) { Logger.info('Successfully get config ini'); text = res; @@ -166,7 +161,7 @@ class ProxiesController extends GetxController { '获取配置文件失败', '返回值无效', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); Get.close(0); } else { @@ -175,7 +170,7 @@ class ProxiesController extends GetxController { '获取配置文件失败', res.toString(), snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); Get.close(0); } @@ -187,7 +182,7 @@ class ProxiesController extends GetxController { if (element.domain != null) { list.add(IconButton( - icon: Icon(Icons.copy), + icon: const Icon(Icons.copy), tooltip: '复制绑定域名:${element.domain}', onPressed: () { Clipboard.setData( @@ -195,7 +190,7 @@ class ProxiesController extends GetxController { text: element.domain, ), ); - ScaffoldMessenger.of(context).showSnackBar(SnackBar( + ScaffoldMessenger.of(context).showSnackBar(const SnackBar( content: Text('已复制'), )); }, @@ -204,27 +199,26 @@ class ProxiesController extends GetxController { final fcsp = await ProxiesConfigurationStorage.getConfigPath(element.id); - if (fcsp != null) + if (fcsp != null) { list.add( IconButton( - icon: Icon(Icons.remove), + icon: const Icon(Icons.remove), tooltip: '移除自定义配置文件', onPressed: () async { File(fcsp).delete(); - reload(c.user, c.token); + reload(uctr.user, uctr.token); }, ), ); + } return list; } - /** - * 重新加载代理列表 - */ + /// 重新加载代理列表 reload(username, token) { proxiesListWidgets.value = [ - DataRow(cells: [ + const DataRow(cells: [ DataCell(SizedBox( height: 22.0, width: 22.0, diff --git a/lib/controllers/userController.dart b/lib/controllers/userController.dart index 801f62e5..c2ced0f2 100644 --- a/lib/controllers/userController.dart +++ b/lib/controllers/userController.dart @@ -23,7 +23,7 @@ class UserController extends GetxController { var outbound = 0.obs; /// FRP令牌 - var frp_token = ''.obs; + var frpToken = ''.obs; /// 总流量 var traffic = 0.obs; @@ -41,7 +41,7 @@ class UserController extends GetxController { avatar.value = userinfo.avatar; inbound.value = userinfo.inbound; outbound.value = userinfo.outbound; - frp_token.value = userinfo.frp_token; + frpToken.value = userinfo.frpToken; traffic.value = userinfo.traffic; int hour = DateTime.now().hour; diff --git a/lib/io/userInfoStorage.dart b/lib/io/userInfoStorage.dart index dc245930..f0ff47d9 100644 --- a/lib/io/userInfoStorage.dart +++ b/lib/io/userInfoStorage.dart @@ -10,9 +10,9 @@ class UserInfoStorage { /// 保存数据 static Future save(UserInfoModel data) async { - final String write_data = jsonEncode(data); - await File('${_path}/session.json') - .writeAsString(write_data, encoding: utf8); + final String writeData = jsonEncode(data); + await File('$_path/session.json') + .writeAsString(writeData, encoding: utf8); } /// 读取数据 @@ -29,6 +29,6 @@ class UserInfoStorage { /// 退出登录 /// 只是删除session.json static sigo() async { - await File('${_path}/session.json').delete(); + await File('$_path/session.json').delete(); } } diff --git a/lib/main.dart b/lib/main.dart index fa3559b6..fad38898 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -51,7 +51,7 @@ class _AppState extends State with WindowListener, TrayListener { /// 根组件 @override Widget build(BuildContext context) { - ThemeData _theme_data = LauncherConfigurationStorage().getTheme(); + ThemeData themeData = LauncherConfigurationStorage().getTheme(); return GetMaterialApp( logWriterCallback: Logger.getxLogWriter, @@ -67,7 +67,7 @@ class _AppState extends State with WindowListener, TrayListener { '/panel/console': (context) => PanelConsole(title: title), '/setting': (context) => SettingInjector(title: title), }, - theme: _theme_data, + theme: themeData, ); } diff --git a/lib/main_window.dart b/lib/main_window.dart index f290b5f9..e68746cb 100644 --- a/lib/main_window.dart +++ b/lib/main_window.dart @@ -43,22 +43,22 @@ class MainWindow { /// 关闭拦截 static void onWindowClose() async { - bool _isPreventClose = await windowManager.isPreventClose(); - if (_isPreventClose) { + bool isPreventClose = await windowManager.isPreventClose(); + if (isPreventClose) { appWindow.restore(); await Get.dialog(AlertDialog( - title: Text('关闭 Nya LoCyanFrp!'), - content: Text('确定要关闭 Nya LoCyanFrp! 吗,要是 Frpc 没关掉猫猫会生气把 Frpc 一脚踹翻的哦!'), + title: const Text('关闭 Nya LoCyanFrp!'), + content: const Text('确定要关闭 Nya LoCyanFrp! 吗,要是 Frpc 没关掉猫猫会生气把 Frpc 一脚踹翻的哦!'), actions: [ TextButton( - child: Text( + child: const Text( '取消', ), onPressed: () async { Get.close(0); }), TextButton( - child: Text( + child: const Text( '确定', style: TextStyle(color: Colors.red), ), @@ -66,7 +66,7 @@ class MainWindow { try { FrpcProcessManager().killAll(); } catch (e) { - Logger.error('Failed to close all process: ${e}'); + Logger.error('Failed to close all process: $e'); } appWindow.close(); windowManager.destroy(); diff --git a/lib/models/FrpcConfigModel.dart b/lib/models/FrpcConfigModel.dart deleted file mode 100644 index dd910455..00000000 --- a/lib/models/FrpcConfigModel.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:nyalcf/utils/Logger.dart'; - -class FrpcConfigModel { - FrpcConfigModel({ - required this.settings, - required this.lists, - }); - - Map settings = Map(); - Map> lists = Map(); - - String get frpc_version { - return settings['frpc_version']; - } - - bool get github_mirror { - Logger.debug('Mir: ${settings['github_mirror']}'); - return settings['github_mirror']; - } - - List get frpc_downloaded_versions { - return lists['frpc_downloaded_versions'] ?? []; - } - - List get github_proxies { - return lists['github_proxies'] ?? []; - } - - FrpcConfigModel.fromJson(Map json) - : settings = json['settings'], - lists = json['lists']; - - Map toJson() => { - 'settings': settings, - 'lists': lists, - }; -} diff --git a/lib/models/ProxyInfoModel.dart b/lib/models/ProxyInfoModel.dart index 517d3e1d..c323923e 100644 --- a/lib/models/ProxyInfoModel.dart +++ b/lib/models/ProxyInfoModel.dart @@ -1,31 +1,31 @@ class ProxyInfoModel { ProxyInfoModel({ - required this.proxy_name, - required this.use_compression, - required this.local_ip, + required this.proxyName, + required this.useCompression, + required this.localIP, required this.node, - required this.local_port, - required this.remote_port, + required this.localPort, + required this.remotePort, required this.domain, required this.icp, required this.sk, required this.id, - required this.proxy_type, - required this.use_encryption, + required this.proxyType, + required this.useEncryption, required this.status, }); - final String proxy_name; - final bool use_compression; - final String local_ip; + final String proxyName; + final bool useCompression; + final String localIP; final int node; - final int local_port; - final int remote_port; + final int localPort; + final int remotePort; final String? domain; final String? icp; final String sk; final int id; - final String proxy_type; - final bool use_encryption; + final String proxyType; + final bool useEncryption; final status; } diff --git a/lib/models/UpdateInfoModel.dart b/lib/models/UpdateInfoModel.dart index cbf95b46..5e9f778b 100644 --- a/lib/models/UpdateInfoModel.dart +++ b/lib/models/UpdateInfoModel.dart @@ -2,10 +2,10 @@ class UpdateInfoModel { UpdateInfoModel({ required this.version, required this.tag, - required this.download_url, + required this.downloadUrl, }); final String version; final String tag; - final List download_url; + final List downloadUrl; } diff --git a/lib/models/UserInfoModel.dart b/lib/models/UserInfoModel.dart index c81a0762..acaaf35b 100644 --- a/lib/models/UserInfoModel.dart +++ b/lib/models/UserInfoModel.dart @@ -6,7 +6,7 @@ class UserInfoModel { required this.avatar, required this.inbound, required this.outbound, - required this.frp_token, + required this.frpToken, required this.traffic, }); @@ -16,7 +16,7 @@ class UserInfoModel { final String avatar; final int inbound; final int outbound; - final String frp_token; + final String frpToken; final int traffic; UserInfoModel.fromJson(Map json) @@ -26,7 +26,7 @@ class UserInfoModel { avatar = json['avatar'], inbound = json['inbound'], outbound = json['outbound'], - frp_token = json['frp_token'], + frpToken = json['frp_token'], traffic = json['traffic']; Map toJson() => { @@ -36,7 +36,7 @@ class UserInfoModel { 'avatar': avatar, 'inbound': inbound, 'outbound': outbound, - 'frp_token': frp_token, + 'frp_token': frpToken, 'traffic': traffic }; } diff --git a/lib/prefs/FrpcSettingPrefs.dart b/lib/prefs/FrpcSettingPrefs.dart deleted file mode 100644 index 6a5c406d..00000000 --- a/lib/prefs/FrpcSettingPrefs.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'package:nyalcf/models/FrpcConfigModel.dart'; -import 'package:shared_preferences/shared_preferences.dart'; - -@deprecated -class FrpcSettingPrefs { - static Future setFrpcInfo(FrpcConfigModel frpcinfo) async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setString('frpc@setting@frpc_version', frpcinfo.frpc_version); - prefs.setStringList('frpc@list@frpc_downloaded_versions', - frpcinfo.frpc_downloaded_versions); - prefs.setBool('frpc@setting@github_mirror', frpcinfo.github_mirror); - prefs.setStringList('frpc@list@github_proxies', frpcinfo.github_proxies); - } - - static Future setFrpcDownloadedVersionsInfo(String version) async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - final newlist = - (await getFrpcInfo()).lists['frpc_downloaded_versions'] ?? []; - newlist.add(version); - prefs.setStringList( - 'frpc@list@frpc_downloaded_versions', newlist.toSet().toList()); - } - - static Future setDownloadUseMirror(bool value) async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setBool('frpc@setting@github_mirror', value); - } - - static Future getFrpcInfo() async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - final s_frpc_version = prefs.getString('frpc@setting@frpc_version') ?? ''; - final l_frpc_downloaded_versions = - prefs.getStringList('frpc@list@frpc_downloaded_versions') ?? []; - final s_github_mirror = prefs.getBool('frpc@setting@github_mirror') ?? true; - final l_github_proxies = - prefs.getStringList('frpc@list@github_proxies') ?? []; - - final Map settings = Map(); - settings['frpc_version'] = s_frpc_version; - settings['github_mirror'] = s_github_mirror; - - final Map> lists = Map(); - lists['frpc_downloaded_versions'] = l_frpc_downloaded_versions; - lists['github_proxies'] = l_github_proxies; - - return FrpcConfigModel(settings: settings, lists: lists); - } - - static Future refresh() async { - //final res = await FrpcManagerStorage.read(); - //if (res != null) setFrpcInfo(res); - } -} diff --git a/lib/prefs/ProxiesPrefs.dart b/lib/prefs/ProxiesPrefs.dart deleted file mode 100644 index bf14eec3..00000000 --- a/lib/prefs/ProxiesPrefs.dart +++ /dev/null @@ -1 +0,0 @@ -class ProxiesPrefs {} diff --git a/lib/prefs/TokenModePrefs.dart b/lib/prefs/TokenModePrefs.dart index 507d7b24..d4763d2a 100644 --- a/lib/prefs/TokenModePrefs.dart +++ b/lib/prefs/TokenModePrefs.dart @@ -8,7 +8,7 @@ class TokenModePrefs { static Future getToken() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - final frp_token = prefs.getString('token_mode@frp_token'); - return frp_token; + final frpToken = prefs.getString('token_mode@frp_token'); + return frpToken; } } diff --git a/lib/prefs/UserInfoPrefs.dart b/lib/prefs/UserInfoPrefs.dart index e7c8b3a4..c6b08bdb 100644 --- a/lib/prefs/UserInfoPrefs.dart +++ b/lib/prefs/UserInfoPrefs.dart @@ -12,7 +12,7 @@ class UserInfoPrefs { prefs.setString('user_avatar', userinfo.avatar); prefs.setInt('user_inbound', userinfo.inbound); prefs.setInt('user_outbound', userinfo.outbound); - prefs.setString('user_frp_token', userinfo.frp_token); + prefs.setString('user_frp_token', userinfo.frpToken); prefs.setInt('user_traffic', userinfo.traffic); } @@ -44,7 +44,7 @@ class UserInfoPrefs { prefs.getString('user_avatar') ?? 'https://cravatar.cn/avatar/'; int inbound = prefs.getInt('user_inbound') ?? 0; int outbound = prefs.getInt('user_outbound') ?? 0; - String frp_token = prefs.getString('user_frp_token') ?? ''; + String frpToken = prefs.getString('user_frp_token') ?? ''; int traffic = prefs.getInt('user_traffic') ?? 0; return UserInfoModel( user: user, @@ -53,7 +53,7 @@ class UserInfoPrefs { avatar: avatar, inbound: inbound, outbound: outbound, - frp_token: frp_token, + frpToken: frpToken, traffic: traffic, ); } diff --git a/lib/storages/JsonConfiguration.dart b/lib/storages/JsonConfiguration.dart index 126e50f6..97ed8e21 100644 --- a/lib/storages/JsonConfiguration.dart +++ b/lib/storages/JsonConfiguration.dart @@ -4,7 +4,6 @@ import 'dart:io'; import 'package:crypto/crypto.dart'; import 'package:nyalcf/utils/FileConfiguration.dart'; import 'package:nyalcf/utils/PathProvider.dart'; -import 'package:nyalcf/utils/Logger.dart'; abstract class JsonConfiguration { var path = PathProvider.appSupportPath; @@ -12,14 +11,14 @@ abstract class JsonConfiguration { /// 配置文件和默认ConfigMap File? file; String get handle; - Future> get def_config async => {}; + Future> get defConfig async => {}; /// 附加Init方法 void init() => {}; Future asyncInit() async => {}; FileConfiguration get cfg => FileConfiguration( - file: this.file, + file: file, handle: sha1.convert(utf8.encode(handle)).toString(), ); @@ -29,8 +28,8 @@ abstract class JsonConfiguration { /// 默认初始化函数 void initCfg() async { cfg.initMap(); - cfg.fromMap(await def_config); - Logger.debug(file); + cfg.fromMap(await defConfig); + //Logger.debug(file); cfg.save(); init(); asyncInit(); diff --git a/lib/storages/configurations/FrpcConfigurationStorage.dart b/lib/storages/configurations/FrpcConfigurationStorage.dart index e75157d6..bb7f10a2 100644 --- a/lib/storages/configurations/FrpcConfigurationStorage.dart +++ b/lib/storages/configurations/FrpcConfigurationStorage.dart @@ -1,6 +1,4 @@ -import 'dart:convert'; import 'dart:io'; -import 'package:crypto/crypto.dart'; import 'package:nyalcf/storages/JsonConfiguration.dart'; @@ -11,7 +9,7 @@ class FrpcConfigurationStorage extends JsonConfiguration { String get handle => 'FRPC'; @override - Future> get def_config async => { + Future> get defConfig async => { 'settings': { 'frpc_version': '', 'github_mirror': true, diff --git a/lib/storages/configurations/LauncherConfigurationStorage.dart b/lib/storages/configurations/LauncherConfigurationStorage.dart index e4ddbd17..85ae26ac 100644 --- a/lib/storages/configurations/LauncherConfigurationStorage.dart +++ b/lib/storages/configurations/LauncherConfigurationStorage.dart @@ -12,7 +12,7 @@ class LauncherConfigurationStorage extends JsonConfiguration { String get handle => 'LAUNCHER'; @override - Future> get def_config async => { + Future> get defConfig async => { 'debug': true, 'theme': { 'auto': true, @@ -49,7 +49,7 @@ class LauncherConfigurationStorage extends JsonConfiguration { SchedulerBinding.instance.platformDispatcher.platformBrightness == Brightness.dark; final auto = cfg.getBool('theme.auto'); - final dark_enable = cfg.getBool('theme.dark.enable'); + final darkEnable = cfg.getBool('theme.dark.enable'); if (auto) { switch (systemThemeMode) { case true: @@ -57,7 +57,7 @@ class LauncherConfigurationStorage extends JsonConfiguration { case false: return ThemeControl.light; } - } else if (dark_enable) return ThemeControl.dark; + } else if (darkEnable) {return ThemeControl.dark;} return ThemeControl.light; } } diff --git a/lib/storages/configurations/ProxiesConfigurationStorage.dart b/lib/storages/configurations/ProxiesConfigurationStorage.dart index b717e306..13472fdc 100644 --- a/lib/storages/configurations/ProxiesConfigurationStorage.dart +++ b/lib/storages/configurations/ProxiesConfigurationStorage.dart @@ -3,33 +3,34 @@ import 'dart:io'; import 'package:nyalcf/utils/PathProvider.dart'; class ProxiesConfigurationStorage { - static var _path = PathProvider.appSupportPath; + static final _path = PathProvider.appSupportPath; /// 配置文件目录路径 static get _configDir async { - final dir = Directory('${_path}/frpc/proxies'); + final dir = Directory('$_path/frpc/proxies'); if (!await dir.exists()) await dir.create(); - return '${_path}/frpc/proxies'; + return '$_path/frpc/proxies'; } /// 配置文件路径 - static _startConfigPath(int proxy_id) async => - '${await _configDir}/${proxy_id}.nya'; + static _startConfigPath(int proxyId) async => + '${await _configDir}/$proxyId.nya'; /// 设置配置文件 - static setConfig(int proxy_id, String ini) async { - final String cp = await _startConfigPath(proxy_id); + static setConfig(int proxyId, String ini) async { + final String cp = await _startConfigPath(proxyId); final f = File(cp); if (!(await f.exists())) f.create(); f.writeAsString(ini); } /// 获取配置文件路径 - static Future getConfigPath(int proxy_id) async { - final String cp = await _startConfigPath(proxy_id); - if (await File(cp).exists()) + static Future getConfigPath(int proxyId) async { + final String cp = await _startConfigPath(proxyId); + if (await File(cp).exists()) { return cp; - else + } else { return null; + } } } diff --git a/lib/storages/injector.dart b/lib/storages/injector.dart index 4a691b7c..71f3f218 100644 --- a/lib/storages/injector.dart +++ b/lib/storages/injector.dart @@ -3,8 +3,8 @@ import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart class StoragesInjector { static init() async { - final lcs = await LauncherConfigurationStorage(); - final fcs = await FrpcConfigurationStorage(); + final lcs = LauncherConfigurationStorage(); + final fcs = FrpcConfigurationStorage(); lcs.initCfg(); fcs.initCfg(); diff --git a/lib/storages/stories/FrpcStoryStorage.dart b/lib/storages/stories/FrpcStoryStorage.dart index d7b9fa6a..b6f0fdbb 100644 --- a/lib/storages/stories/FrpcStoryStorage.dart +++ b/lib/storages/stories/FrpcStoryStorage.dart @@ -5,11 +5,11 @@ import 'package:nyalcf/utils/PathProvider.dart'; import 'package:nyalcf/utils/Logger.dart'; class FrpcStoryStorage { - static final _s_path = PathProvider.appSupportPath; + static final _supportPath = PathProvider.appSupportPath; static final fcs = FrpcConfigurationStorage(); static Future get _path async { - return '${_s_path}/frpc'; + return '$_supportPath/frpc'; } /// 获取Frpc文件 @@ -19,11 +19,12 @@ class FrpcStoryStorage { /// 获取Frpc文件 static Future getFilePath() async { - final name; - if (Platform.isWindows) + final String name; + if (Platform.isWindows) { name = 'frpc.exe'; - else + } else { name = 'frpc'; + } return await getRunPath() + name; } diff --git a/lib/ui/models/AccountDialog.dart b/lib/ui/models/AccountDialog.dart index 4c0a5964..75c64ec3 100644 --- a/lib/ui/models/AccountDialog.dart +++ b/lib/ui/models/AccountDialog.dart @@ -10,7 +10,7 @@ import 'package:url_launcher/url_launcher.dart'; class AccountDialogX { const AccountDialogX({required this.context}); - final context; + final BuildContext context; Widget build() { return SimpleDialog( @@ -29,21 +29,21 @@ class AccountDialogX { '发生错误', e.toString(), snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } Logger.info('Dispose controllers'); try { - final DPanelController dp_c = Get.find(); - dp_c.dispose(); + final DPanelController dpctr = Get.find(); + dpctr.dispose(); } catch (ignore) {} try { - final ProxiesController p_c = Get.find(); - p_c.dispose(); + final ProxiesController pctr = Get.find(); + pctr.dispose(); } catch (ignore) {} try { - final ConsoleController c_c = Get.find(); - c_c.dispose(); + final ConsoleController cctr = Get.find(); + cctr.dispose(); } catch (ignore) {} Get.toNamed('/'); }), diff --git a/lib/ui/models/AppbarActions.dart b/lib/ui/models/AppbarActions.dart index 90bc5199..1a7d7158 100644 --- a/lib/ui/models/AppbarActions.dart +++ b/lib/ui/models/AppbarActions.dart @@ -6,11 +6,11 @@ import 'package:nyalcf/main_window.dart'; class AppbarActionsX { AppbarActionsX( - {this.context = null, - List this.append = const [], + {this.context, + this.append = const [], this.setting = true}); - final UserController c = Get.find(); + final UserController uctr = Get.find(); final BuildContext? context; bool setting; @@ -22,10 +22,10 @@ class AppbarActionsX { WindowTitleBarBox( child: MoveWindow( child: Transform.translate( - offset: Offset(0, -5.0), + offset: const Offset(0, -5.0), child: IconButton( onPressed: () => {}, - icon: Icon(Icons.select_all), + icon: const Icon(Icons.select_all), tooltip: '按住移动', splashColor: Colors.transparent, highlightColor: Colors.transparent, @@ -40,7 +40,7 @@ class AppbarActionsX { /// 最小化 IconButton( onPressed: () => {appWindow.minimize()}, - icon: Icon(Icons.horizontal_rule), + icon: const Icon(Icons.horizontal_rule), tooltip: '最小化', color: Colors.white, ), @@ -48,7 +48,7 @@ class AppbarActionsX { /// 关闭 IconButton( onPressed: () => MainWindow.onWindowClose(), - icon: Icon(Icons.close), + icon: const Icon(Icons.close), tooltip: '关闭', color: Colors.white, ), @@ -62,7 +62,7 @@ class AppbarActionsX { l.add( IconButton( onPressed: () => {Get.toNamed('/setting')}, - icon: Icon( + icon: const Icon( Icons.settings, color: Colors.white, ), diff --git a/lib/ui/models/Drawer.dart b/lib/ui/models/Drawer.dart index 4f83d747..279fc8c0 100644 --- a/lib/ui/models/Drawer.dart +++ b/lib/ui/models/Drawer.dart @@ -12,7 +12,7 @@ class DrawerX { padding: EdgeInsets.zero, children: [ DrawerHeader( - decoration: BoxDecoration( + decoration: const BoxDecoration( image: DecorationImage( image: NetworkImage('https://api.imlazy.ink/img'), fit: BoxFit.cover), @@ -22,18 +22,18 @@ class DrawerX { DecoratedBox( decoration: BoxDecoration( color: - Color.fromRGBO(255, 101, 160, 0.4196078431372549), + const Color.fromRGBO(255, 101, 160, 0.4196078431372549), borderRadius: BorderRadius.circular(50.0)), child: Center( child: Container( - padding: EdgeInsets.all(5.0), - child: Text( + padding: const EdgeInsets.all(5.0), + child: const Text( '菜单', style: TextStyle(color: Colors.white), )))) ])), ListTile( - leading: Icon(Icons.dashboard), + leading: const Icon(Icons.dashboard), title: const Text('仪表板'), onTap: () { Get.close(0); @@ -41,7 +41,7 @@ class DrawerX { }, ), ListTile( - leading: Icon(Icons.list), + leading: const Icon(Icons.list), title: const Text('隧道列表'), onTap: () { Get.close(0); @@ -49,7 +49,7 @@ class DrawerX { }, ), ListTile( - leading: Icon(Icons.last_page), + leading: const Icon(Icons.last_page), title: const Text('控制台'), onTap: () { Get.close(0); diff --git a/lib/ui/models/FloatingActionButton.dart b/lib/ui/models/FloatingActionButton.dart index e1f5146b..c21a7c94 100644 --- a/lib/ui/models/FloatingActionButton.dart +++ b/lib/ui/models/FloatingActionButton.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; - -import 'ToolDialog.dart'; +import 'package:nyalcf/ui/models/ToolDialog.dart'; class FloatingActionButtonX { Builder button() { diff --git a/lib/ui/models/FrpcConfigurationEditorDialog.dart b/lib/ui/models/FrpcConfigurationEditorDialog.dart index effc15cb..8863c8af 100644 --- a/lib/ui/models/FrpcConfigurationEditorDialog.dart +++ b/lib/ui/models/FrpcConfigurationEditorDialog.dart @@ -12,21 +12,21 @@ class FrpcConfigEditorDialogX { required this.context, }); - final context; + final BuildContext context; - final UserController u_c = Get.find(); - final ProxiesController p_c = Get.find(); + final UserController uctr = Get.find(); + final ProxiesController pctr = Get.find(); - CodeController _controller(def_text) => CodeController( - text: def_text, + CodeController _controller(defText) => CodeController( + text: defText, language: ini, - analyzer: DefaultLocalAnalyzer(), + analyzer: const DefaultLocalAnalyzer(), ); - Widget dialog(text, {required proxy_id}) { + Widget dialog(text, {required proxyId}) { final c = _controller(text); return AlertDialog( - title: Text('编辑配置文件'), + title: const Text('编辑配置文件'), content: SizedBox( width: 600.0, child: CodeTheme( @@ -36,11 +36,11 @@ class FrpcConfigEditorDialogX { child: SingleChildScrollView( child: CodeField( controller: c, - gutterStyle: GutterStyle( + gutterStyle: const GutterStyle( showErrors: false, showLineNumbers: false, ), - textStyle: TextStyle( + textStyle: const TextStyle( fontFamily: 'Droid Sans Mono', fontSize: 12, ), @@ -49,17 +49,17 @@ class FrpcConfigEditorDialogX { ), actions: [ ElevatedButton( - child: Text('放弃'), + child: const Text('放弃'), onPressed: () { Get.close(0); }, ), ElevatedButton( - child: Text('保存'), + child: const Text('保存'), onPressed: () async { //关闭 返回true - await ProxiesConfigurationStorage.setConfig(proxy_id, c.fullText); - p_c.reload(u_c.user, u_c.token); + await ProxiesConfigurationStorage.setConfig(proxyId, c.fullText); + pctr.reload(uctr.user, uctr.token); Get.close(0); }, ), @@ -73,8 +73,8 @@ class FrpcConfigEditorDialogX { children: [ Container( margin: - EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), - child: Column( + const EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), + child: const Column( children: [ SizedBox( height: 22.0, diff --git a/lib/ui/models/FrpcDownloadDialog.dart b/lib/ui/models/FrpcDownloadDialog.dart index ed007830..61f541ae 100644 --- a/lib/ui/models/FrpcDownloadDialog.dart +++ b/lib/ui/models/FrpcDownloadDialog.dart @@ -8,9 +8,9 @@ import 'package:nyalcf/utils/Logger.dart'; class FrpcDownloadDialogX { FrpcDownloadDialogX({required this.context}); - final context; + final BuildContext context; final fcs = FrpcConfigurationStorage(); - final FrpcSettingController ds_c = Get.find(); + final FrpcSettingController dsctr = Get.find(); Widget build() { return SimpleDialog( @@ -18,37 +18,37 @@ class FrpcDownloadDialogX { children: [ Container( margin: - EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), + const EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), child: Column( children: [ - Text('猫猫翻遍了系统变量,识别到 CPU 架构为:${ds_c.cpu_arch}'), + Text('猫猫翻遍了系统变量,识别到 CPU 架构为:${dsctr.cpuArch}'), Obx(() => DropdownButton( - value: ds_c.frpc_download_arch.value, - items: ds_c.frpc_download_arch_list, + value: dsctr.frpcDownloadArch.value, + items: dsctr.frpcDownloadArchList, onChanged: (value) { - Logger.info('Selected arch: ${ds_c.arch[value]['arch']}'); - ds_c.frpc_download_arch.value = value; + Logger.info('Selected arch: ${dsctr.arch[value]['arch']}'); + dsctr.frpcDownloadArch.value = value; }, )), ElevatedButton( onPressed: () async { /// 刷新UI,下载frpc - ds_c.refreshDownloadShow(); + dsctr.refreshDownloadShow(); /// 开始下载 Get.dialog(_downloading(), barrierDismissible: false); final res = await FrpcDownloadDio().download( - arch: ds_c.arch[ds_c.frpc_download_arch.value]['arch'], - platform: ds_c.platform, + arch: dsctr.arch[dsctr.frpcDownloadArch.value]['arch'], + platform: dsctr.platform, version: '0.51.3', - progressCallback: ds_c.downloadFrpcCallback, - cancelToken: ds_c.downloadCancelToken, + progressCallback: dsctr.downloadFrpcCallback, + cancelToken: dsctr.downloadCancelToken, useMirror: fcs.getSettingsGitHubMirror(), ); - ds_c.frpc_download_cancel = res; - ds_c.refreshDownloadShow(); + dsctr.frpcDownloadCancel = res; + dsctr.refreshDownloadShow(); }, - child: Text('开始下载'), + child: const Text('开始下载'), ), ], ), @@ -63,18 +63,18 @@ class FrpcDownloadDialogX { children: [ Container( margin: - EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), + const EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), child: Column( children: [ - Obx(() => Column(children: ds_c.frpc_download_show.value)), + Obx(() => Column(children: dsctr.frpcDownloadShow.value)), Obx(() => Text( - '进度:${(ds_c.frpc_download_progress.value * 100).toStringAsFixed(2)}%')), + '进度:${(dsctr.frpcDownloadProgress.value * 100).toStringAsFixed(2)}%')), ElevatedButton( onPressed: () async { - ds_c.downloadCancelToken.cancel(); + dsctr.downloadCancelToken.cancel(); Get.close(0); }, - child: Text('取消'), + child: const Text('取消'), ), ], ), @@ -97,8 +97,8 @@ class FrpcDownloadDialogX { children: [ Container( margin: - EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), - child: Column( + const EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), + child: const Column( children: [ SizedBox( height: 22.0, diff --git a/lib/ui/models/FrpcDownloadTip.dart b/lib/ui/models/FrpcDownloadTip.dart index e2abfa16..73f47f0c 100644 --- a/lib/ui/models/FrpcDownloadTip.dart +++ b/lib/ui/models/FrpcDownloadTip.dart @@ -2,77 +2,28 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/frpcSettingController.dart'; import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; - -import 'FrpcDownloadDialog.dart'; +import 'package:nyalcf/ui/models/FrpcDownloadDialog.dart'; class FrpcDownloadTip { static final fcs = FrpcConfigurationStorage(); - static final FrpcSettingController ds_c = Get.find(); + static final FrpcSettingController fsctr = Get.find(); - static Container tip({required context}) => Container( - child: Card( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ListTile( - leading: Icon(Icons.warning), - title: Text('尚未安装任何版本的 Frpc'), - ), - Container( - margin: EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text('无法启动隧道了...呜呜...'), - Container( - margin: EdgeInsets.only(top: 10.0), - child: Row( - children: [ - ElevatedButton( - onPressed: () async { - showDialog( - context: context, - builder: (context) { - return new FrpcDownloadDialogX( - context: context) - .build(); - }); - }, - child: Text('下载'), - ), - ], - ), - ), - ], - ), - ) - ], - ), + static Card tip({required context}) => Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const ListTile( + leading: Icon(Icons.warning), + title: Text('尚未安装任何版本的 Frpc'), ), - ); - - static Future downloaded({required context}) async => Container( - child: Card( + Container( + margin: const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - ListTile( - leading: Icon(Icons.check_circle), - title: Text('可用的 Frpc 版本已安装!素晴らしい!'), - ), + const Text('无法启动隧道了...呜呜...'), Container( - margin: EdgeInsets.only(left: 20.0, right: 20.0, bottom: 10.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text('已安装版本列表:'), - Text(fcs.getInstalledVersions().toString()), - Text('已指定的 Frpc 文件路径:${ds_c.custom_path ?? '无'}'), - ], - ), - ), - Container( - margin: EdgeInsets.only(left: 20.0, bottom: 20.0), + margin: const EdgeInsets.only(top: 10.0), child: Row( children: [ ElevatedButton( @@ -80,17 +31,61 @@ class FrpcDownloadTip { showDialog( context: context, builder: (context) { - return new FrpcDownloadDialogX(context: context) + return FrpcDownloadDialogX( + context: context) .build(); }); }, - child: Text('重新下载'), + child: const Text('下载'), ), ], ), ), ], ), + ) + ], + ), + ); + + static Future downloaded({required context}) async => Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const ListTile( + leading: Icon(Icons.check_circle), + title: Text('可用的 Frpc 版本已安装!素晴らしい!'), + ), + Container( + margin: const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 10.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text('已安装版本列表:'), + Text(fcs.getInstalledVersions().toString()), + Text('已指定的 Frpc 文件路径:${fsctr.customPath ?? '无'}'), + ], + ), + ), + Container( + margin: const EdgeInsets.only(left: 20.0, bottom: 20.0), + child: Row( + children: [ + ElevatedButton( + onPressed: () async { + showDialog( + context: context, + builder: (context) { + return FrpcDownloadDialogX(context: context) + .build(); + }); + }, + child: const Text('重新下载'), + ), + ], + ), ), - ); + ], + ), + ); } diff --git a/lib/ui/models/ProcessListDialog.dart b/lib/ui/models/ProcessListDialog.dart index f04ed5a5..f3bcf7e9 100644 --- a/lib/ui/models/ProcessListDialog.dart +++ b/lib/ui/models/ProcessListDialog.dart @@ -5,8 +5,8 @@ import 'package:nyalcf/controllers/consoleController.dart'; class ProcessListDialogX { ProcessListDialogX({required this.context}); - final context; - final ConsoleController c_c = Get.find(); + final BuildContext context; + final ConsoleController cctr = Get.find(); Widget build() { return SimpleDialog( @@ -14,12 +14,12 @@ class ProcessListDialogX { children: [ Obx( () => DataTable( - columns: [ + columns: const [ DataColumn(label: Text('进程PID')), DataColumn(label: Text('隧道ID')), DataColumn(label: Text('操作')), ], - rows: c_c.widgets.value, + rows: cctr.widgets.value, ), ), ], diff --git a/lib/ui/models/ToolDialog.dart b/lib/ui/models/ToolDialog.dart index 70c7c7ac..eacd9483 100644 --- a/lib/ui/models/ToolDialog.dart +++ b/lib/ui/models/ToolDialog.dart @@ -5,7 +5,7 @@ import 'package:url_launcher/url_launcher.dart'; class ToolDialogX { const ToolDialogX({required this.context}); - final context; + final BuildContext context; Widget build() { return SimpleDialog( @@ -20,7 +20,7 @@ class ToolDialogX { '发生错误', '无法打开网页,请检查设备是否存在WebView', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } }), @@ -33,7 +33,7 @@ class ToolDialogX { '发生错误', '无法打开网页,请检查设备是否存在WebView', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } }), @@ -46,7 +46,7 @@ class ToolDialogX { '发生错误', '无法打开网页,请检查设备是否存在WebView', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } }), @@ -59,7 +59,7 @@ class ToolDialogX { '发生错误', '无法打开网页,请检查设备是否存在WebView', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } }), diff --git a/lib/ui/views/auth/login.dart b/lib/ui/views/auth/login.dart index 661ca5e0..24ca47e3 100644 --- a/lib/ui/views/auth/login.dart +++ b/lib/ui/views/auth/login.dart @@ -51,7 +51,7 @@ class _LoginState extends State { child: Column( children: [ Container( - margin: EdgeInsets.all(6.0), + margin: const EdgeInsets.all(6.0), child: TextFormField( decoration: const InputDecoration( labelText: '用户名', @@ -62,7 +62,7 @@ class _LoginState extends State { ), ), Container( - margin: EdgeInsets.all(6.0), + margin: const EdgeInsets.all(6.0), child: TextFormField( obscureText: true, decoration: const InputDecoration( @@ -74,9 +74,12 @@ class _LoginState extends State { ), ), Container( - margin: const EdgeInsets.all(8.0), - child: ElevatedButton( - onPressed: () => {_login()}, child: Text('登录'))), + margin: const EdgeInsets.all(8.0), + child: ElevatedButton( + onPressed: () => {_login()}, + child: const Text('登录'), + ), + ), ], ), ), @@ -93,21 +96,21 @@ class _LoginState extends State { '无效数据', '请输入用户名', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } else if (passwordController.text == '') { Get.snackbar( '无效数据', '请输入密码', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } else { Get.snackbar( '登录中', '正在请求...', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); final res = await LoginAuth() .requestLogin(userController.text, passwordController.text); @@ -120,7 +123,7 @@ class _LoginState extends State { '登录成功', '欢迎您,指挥官 ${res.user}', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); Get.toNamed('/panel/home'); } else { @@ -128,7 +131,7 @@ class _LoginState extends State { '登录失败', res.toString(), snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } } diff --git a/lib/ui/views/auth/register.dart b/lib/ui/views/auth/register.dart index 77d8d1fd..e09f49d1 100644 --- a/lib/ui/views/auth/register.dart +++ b/lib/ui/views/auth/register.dart @@ -63,7 +63,7 @@ class _RegisterState extends State { child: Column( children: [ Container( - margin: EdgeInsets.all(6.0), + margin: const EdgeInsets.all(6.0), child: TextFormField( controller: userController, decoration: const InputDecoration( @@ -74,7 +74,7 @@ class _RegisterState extends State { ), ), Container( - margin: EdgeInsets.all(6.0), + margin: const EdgeInsets.all(6.0), child: TextFormField( obscureText: true, controller: passwordController, @@ -86,7 +86,7 @@ class _RegisterState extends State { ), ), Container( - margin: EdgeInsets.all(6.0), + margin: const EdgeInsets.all(6.0), child: TextFormField( obscureText: true, controller: confirmPasswordController, @@ -98,7 +98,7 @@ class _RegisterState extends State { ), ), Container( - margin: EdgeInsets.all(6.0), + margin: const EdgeInsets.all(6.0), child: TextFormField( controller: emailController, decoration: const InputDecoration( @@ -109,7 +109,7 @@ class _RegisterState extends State { ), ), Container( - margin: EdgeInsets.all(6.0), + margin: const EdgeInsets.all(6.0), child: Row( children: [ SizedBox( @@ -126,7 +126,7 @@ class _RegisterState extends State { SizedBox( width: 100.0, child: Transform.translate( - offset: Offset(10.0, 0.0), + offset: const Offset(10.0, 0.0), child: Container( margin: const EdgeInsets.all(8.0), child: ElevatedButton( @@ -137,7 +137,7 @@ class _RegisterState extends State { '正在请求发送验证码', snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); final res = await RegisterAuth() .requestCode( @@ -150,7 +150,7 @@ class _RegisterState extends State { snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); } else { Get.snackbar( @@ -159,7 +159,7 @@ class _RegisterState extends State { snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); } } else { @@ -169,7 +169,7 @@ class _RegisterState extends State { snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); } } else { @@ -178,11 +178,11 @@ class _RegisterState extends State { '请输入邮箱', snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); } }, - child: Text('获取'), + child: const Text('获取'), ), ), ), @@ -191,7 +191,7 @@ class _RegisterState extends State { ), ), Container( - margin: EdgeInsets.all(6.0), + margin: const EdgeInsets.all(6.0), child: TextFormField( controller: qqController, decoration: const InputDecoration( @@ -220,35 +220,35 @@ class _RegisterState extends State { '正在自动登录', snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); - final res_login = + final resLogin = await LoginAuth().requestLogin( userController.text, passwordController.text, ); /// 从登录页面抄过来的 - if (res_login is UserInfoModel) { + if (resLogin is UserInfoModel) { //UserInfoCache.info = res; //print(UserInfoCache.info); - await UserInfoPrefs.setInfo(res_login); + await UserInfoPrefs.setInfo(resLogin); UserInfoPrefs.saveToFile(); Get.snackbar( '登录成功', - '欢迎您,指挥官 ${res_login.user}', + '欢迎您,指挥官 ${resLogin.user}', snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); Get.toNamed('/panel/home'); } else { Get.snackbar( '登录失败', - '无法自动完成登录,请尝试手动登录,原因: ${res_login.toString()}', + '无法自动完成登录,请尝试手动登录,原因: ${resLogin.toString()}', snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); Get.toNamed('/login'); } @@ -258,7 +258,7 @@ class _RegisterState extends State { '注册失败,内部错误', snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); } } else { @@ -267,11 +267,11 @@ class _RegisterState extends State { '注册失败,原因:${res.toString()}', snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); } }, - child: Text('注册'), + child: const Text('注册'), ), ), ], diff --git a/lib/ui/views/auth/tokenmode.dart b/lib/ui/views/auth/tokenmode.dart index d0229302..18cc0f3b 100644 --- a/lib/ui/views/auth/tokenmode.dart +++ b/lib/ui/views/auth/tokenmode.dart @@ -5,7 +5,7 @@ import 'package:nyalcf/ui/models/AppbarActions.dart'; import 'package:nyalcf/ui/models/FloatingActionButton.dart'; class TokenModeAuth extends StatefulWidget { - TokenModeAuth({super.key, required this.title}); + const TokenModeAuth({super.key, required this.title}); final String title; @@ -51,7 +51,7 @@ class _TokenModeAuthState extends State { child: Column( children: [ Container( - margin: EdgeInsets.all(6.0), + margin: const EdgeInsets.all(6.0), child: TextFormField( obscureText: true, decoration: const InputDecoration( @@ -75,11 +75,11 @@ class _TokenModeAuthState extends State { '请输入Frp Token', snackPosition: SnackPosition.BOTTOM, animationDuration: - Duration(milliseconds: 300), + const Duration(milliseconds: 300), ); } }, - child: Text('下一步'), + child: const Text('下一步'), ), ), const Text( diff --git a/lib/ui/views/home.dart b/lib/ui/views/home.dart index b6db7031..6d37e270 100644 --- a/lib/ui/views/home.dart +++ b/lib/ui/views/home.dart @@ -15,7 +15,7 @@ class Home extends StatelessWidget { final String title; // FrpcController实例 - final FrpcController f_c = Get.put(FrpcController()); + final FrpcController fctr = Get.put(FrpcController()); // _HC控制器实例 final hc = Get.put(_HC()); @@ -68,7 +68,7 @@ class _HC extends GetxController { style: TextStyle(fontSize: 30), ), const Text('にゃ~にゃ~,检测到保存数据,正在校验以自动登录'), - Row( + const Row( mainAxisSize: MainAxisSize.min, children: [ SizedBox( @@ -98,7 +98,7 @@ class _HC extends GetxController { '欢迎回来', '已经自动登录啦~', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); // 跳转到面板首页 Get.toNamed('/panel/home'); @@ -108,7 +108,7 @@ class _HC extends GetxController { '令牌校验失败', '可能登录已过期或网络不畅,请重新登录喵呜...', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); // 重新初始化启动内容 _initStartup(); @@ -160,7 +160,7 @@ class _HC extends GetxController { const Icon(Icons.arrow_right), Container( /// 对齐,防止强迫症当场死亡 - margin: EdgeInsets.only(right: 7.0), + margin: const EdgeInsets.only(right: 7.0), child: const Text('仅使用使用Frp Token登录'), ), ], diff --git a/lib/ui/views/panel/console.dart b/lib/ui/views/panel/console.dart index ca882b7f..d2046d8d 100644 --- a/lib/ui/views/panel/console.dart +++ b/lib/ui/views/panel/console.dart @@ -13,14 +13,14 @@ import 'package:nyalcf/utils/frpc/ProcessManager.dart'; class PanelConsole extends StatelessWidget { PanelConsole({super.key, required this.title}); - final UserController c = Get.find(); - final FrpcController f_c = Get.find(); - final ConsoleController c_c = Get.find(); + final UserController uctr = Get.find(); + final FrpcController fctr = Get.find(); + final ConsoleController cctr = Get.find(); final String title; @override Widget build(BuildContext context) { - c_c.load(); + cctr.load(); return Scaffold( appBar: AppBar( title: @@ -35,7 +35,7 @@ class PanelConsole extends StatelessWidget { icon: Obx(() => ClipRRect( borderRadius: BorderRadius.circular(500), child: Image.network( - '${c.avatar}', + '${uctr.avatar}', width: 35, ), )), @@ -49,44 +49,44 @@ class PanelConsole extends StatelessWidget { children: [ Obx( () => Card( - margin: EdgeInsets.all(20.0), + margin: const EdgeInsets.all(20.0), color: Colors.grey.shade900, child: SizedBox( width: Checkbox.width, height: 340.0, child: Container( - margin: EdgeInsets.all(10.0), + margin: const EdgeInsets.all(10.0), child: ListView( - children: f_c.process_out, + children: fctr.processOut, ), ), ), ), ), Container( - margin: EdgeInsets.only(left: 20.0, right: 20.0), + margin: const EdgeInsets.only(left: 20.0, right: 20.0), child: Row( children: [ ElevatedButton( - child: Text('查看进程列表'), + child: const Text('查看进程列表'), onPressed: () { Get.dialog(ProcessListDialogX(context: context).build()); }, ), ElevatedButton( - child: Text( - '关闭所有进程', - style: TextStyle( - color: Colors.white, - ), - ), onPressed: () { FrpcProcessManager().killAll(); - c_c.widgets.refresh(); + cctr.widgets.refresh(); }, style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Colors.red), ), + child: const Text( + '关闭所有进程', + style: TextStyle( + color: Colors.white, + ), + ), ), ], ), diff --git a/lib/ui/views/panel/home.dart b/lib/ui/views/panel/home.dart index 67cae175..339f67af 100644 --- a/lib/ui/views/panel/home.dart +++ b/lib/ui/views/panel/home.dart @@ -15,15 +15,15 @@ import 'package:url_launcher/url_launcher.dart'; class PanelHome extends StatelessWidget { PanelHome({super.key, required this.title}); - final UserController c = Get.find(); - final DPanelController dp_c = Get.put(DPanelController()); - final ConsoleController c_c = Get.put(ConsoleController()); + final UserController uctr = Get.find(); + final DPanelController dpctr = Get.put(DPanelController()); + final ConsoleController cctr = Get.put(ConsoleController()); final String title; @override Widget build(BuildContext context) { - c.load(); - dp_c.load(); + uctr.load(); + dpctr.load(); return Scaffold( appBar: AppBar( @@ -39,7 +39,7 @@ class PanelHome extends StatelessWidget { icon: Obx(() => ClipRRect( borderRadius: BorderRadius.circular(500), child: Image.network( - '${c.avatar}', + '${uctr.avatar}', width: 35, ), )), @@ -51,162 +51,160 @@ class PanelHome extends StatelessWidget { body: ListView( padding: const EdgeInsets.all(20.0), children: [ - Container( - child: Column( - children: [ - Obx(() => Text( - '指挥官 ${c.user},${c.welcomeText}喵!', - style: TextStyle(fontSize: 15), - )), - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column(children: [ - Card( - child: Column( - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ListTile( - leading: Icon(Icons.info), - title: Text('指挥官信息'), + Column( + children: [ + Obx(() => Text( + '指挥官 ${uctr.user},${uctr.welcomeText}喵!', + style: const TextStyle(fontSize: 15), + )), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column(children: [ + Card( + child: Column( + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const ListTile( + leading: Icon(Icons.info), + title: Text('指挥官信息'), + ), + Container( + margin: const EdgeInsets.only( + left: 15.0, right: 15.0, bottom: 15.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Obx(() => Text('用户名:${uctr.user}')), + Obx(() => Text('邮箱:${uctr.email}')), + Obx(() => Text( + '限制速率:${uctr.inbound / 1024 * 8}Mbps/${uctr.outbound / 1024 * 8}Mbps')), + Obx(() => + Text('剩余流量:${uctr.traffic / 1024}GiB')) + ], ), - Container( - margin: EdgeInsets.only( - left: 15.0, right: 15.0, bottom: 15.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Obx(() => Text('用户名:${c.user}')), - Obx(() => Text('邮箱:${c.email}')), - Obx(() => Text( - '限制速率:${c.inbound / 1024 * 8}Mbps/${c.outbound / 1024 * 8}Mbps')), - Obx(() => Text('剩余流量:${c.traffic / 1024}GiB')) - ], - ), - ) - ], - ), + ) + ], ), - Card( - child: Column( - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ListTile( - leading: Icon(Icons.looks), - title: Text('会话详情'), + ), + Card( + child: Column( + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const ListTile( + leading: Icon(Icons.looks), + title: Text('会话详情'), + ), + Container( + margin: const EdgeInsets.only( + left: 15.0, right: 15.0, bottom: 15.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Card( + child: Column(children: [ + const Text('Frp Token'), + ElevatedButton( + onPressed: () async { + Clipboard.setData( + ClipboardData( + text: uctr.frpToken.value, + ), + ); + ScaffoldMessenger.of(context) + .showSnackBar(const SnackBar( + content: Text('已复制'), + )); + }, + child: const Text('点击复制')) + ])), + Card( + child: Column(children: [ + const Text('Token'), + ElevatedButton( + onPressed: () async { + Clipboard.setData( + ClipboardData( + text: uctr.token.value, + ), + ); + ScaffoldMessenger.of(context) + .showSnackBar(const SnackBar( + content: Text('已复制'), + )); + }, + child: const Text('点击复制')) + ])) + ], ), - Container( - margin: EdgeInsets.only( - left: 15.0, right: 15.0, bottom: 15.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Card( - child: Column(children: [ - Text('Frp Token'), - ElevatedButton( - onPressed: () async { - Clipboard.setData( - ClipboardData( - text: c.frp_token.value, - ), - ); - ScaffoldMessenger.of(context) - .showSnackBar(SnackBar( - content: Text('已复制'), - )); - }, - child: Text('点击复制')) - ])), - Card( - child: Column(children: [ - Text('Token'), - ElevatedButton( - onPressed: () async { - Clipboard.setData( - ClipboardData( - text: c.token.value, - ), - ); - ScaffoldMessenger.of(context) - .showSnackBar(SnackBar( - content: Text('已复制'), - )); - }, - child: Text('点击复制')) - ])) - ], - ), - ) - ], - ), + ) + ], ), - Container( - child: Card( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - ListTile( - leading: Icon(Icons.access_time), - title: Text('通知'), - ), - Flexible( - fit: FlexFit.loose, - child: Container( - margin: EdgeInsets.only( - left: 15.0, right: 15.0, bottom: 15.0), - child: Obx(() => MarkdownBody( - selectable: true, - onTapLink: (text, url, title) { - if (url != null) { - Logger.debug( - 'Launch url from Announcement: ${url}'); - launchUrl(Uri.parse(url)); - } - }, - data: '${dp_c.announcement_common}')))) - ], - ), - )), - ])), - Expanded( - child: Card( + ), + Card( child: Column( mainAxisSize: MainAxisSize.min, children: [ - ListTile( - leading: Icon(Icons.announcement), - title: Text('公告'), + const ListTile( + leading: Icon(Icons.access_time), + title: Text('通知'), ), Flexible( fit: FlexFit.loose, child: Container( - margin: EdgeInsets.only( + margin: const EdgeInsets.only( left: 15.0, right: 15.0, bottom: 15.0), child: Obx(() => MarkdownBody( selectable: true, onTapLink: (text, url, title) { if (url != null) { Logger.debug( - 'Launch url from Announcement: ${url}'); + 'Launch url from Announcement: $url'); launchUrl(Uri.parse(url)); } }, - data: '${dp_c.announcement}')))) + data: '${dpctr.announcement_common}')))) ], ), - )), - ], - ), - ], - ), + ), + ])), + Expanded( + child: Card( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const ListTile( + leading: Icon(Icons.announcement), + title: Text('公告'), + ), + Flexible( + fit: FlexFit.loose, + child: Container( + margin: const EdgeInsets.only( + left: 15.0, right: 15.0, bottom: 15.0), + child: Obx(() => MarkdownBody( + selectable: true, + onTapLink: (text, url, title) { + if (url != null) { + Logger.debug( + 'Launch url from Announcement: $url'); + launchUrl(Uri.parse(url)); + } + }, + data: '${dpctr.announcement}')))) + ], + ), + )), + ], + ), + ], ), ], ), diff --git a/lib/ui/views/panel/proxies.dart b/lib/ui/views/panel/proxies.dart index 77383ab5..30085f33 100644 --- a/lib/ui/views/panel/proxies.dart +++ b/lib/ui/views/panel/proxies.dart @@ -8,16 +8,16 @@ import 'package:nyalcf/ui/models/Drawer.dart'; import 'package:nyalcf/ui/models/FloatingActionButton.dart'; class PanelProxies extends StatelessWidget { - PanelProxies({required this.title}); + PanelProxies({super.key, required this.title}); - final UserController c = Get.find(); + final UserController uctr = Get.find(); final String title; @override Widget build(BuildContext context) { - final p_c = Get.put(ProxiesController(context: context)); + final pctr = Get.put(ProxiesController(context: context)); - p_c.load(c.user, c.token); + pctr.load(uctr.user, uctr.token); return Scaffold( appBar: AppBar( @@ -33,7 +33,7 @@ class PanelProxies extends StatelessWidget { icon: Obx(() => ClipRRect( borderRadius: BorderRadius.circular(500), child: Image.network( - '${c.avatar}', + '${uctr.avatar}', width: 35, ), )), @@ -43,12 +43,12 @@ class PanelProxies extends StatelessWidget { ), drawer: DrawerX(context: context).drawer(), body: Container( - margin: EdgeInsets.all(40.0), + margin: const EdgeInsets.all(40.0), child: ListView( children: [ ElevatedButton( - onPressed: () => {p_c.reload(c.user, c.token)}, - child: Row( + onPressed: () => {pctr.reload(uctr.user, uctr.token)}, + child: const Row( mainAxisSize: MainAxisSize.min, children: [Text('刷新'), Icon(Icons.refresh)], ), @@ -58,7 +58,7 @@ class PanelProxies extends StatelessWidget { children: [ DataTable( columnSpacing: 10.0, - columns: [ + columns: const [ DataColumn(label: Flexible(child: Text('名称'))), DataColumn(label: Flexible(child: Text('ID'))), DataColumn(label: Flexible(child: Text('节点'))), @@ -67,7 +67,7 @@ class PanelProxies extends StatelessWidget { DataColumn(label: Flexible(child: Text('端口'))), DataColumn(label: Flexible(child: Text('操作'))) ], - rows: p_c.proxiesListWidgets.value, + rows: pctr.proxiesListWidgets.value, ), ], ), diff --git a/lib/ui/views/setting/frpcSetting.dart b/lib/ui/views/setting/frpcSetting.dart index 12b5aef8..aa2e3fd4 100644 --- a/lib/ui/views/setting/frpcSetting.dart +++ b/lib/ui/views/setting/frpcSetting.dart @@ -5,66 +5,64 @@ import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; class FrpcSetting { FrpcSetting({required this.context}); - final context; + final BuildContext context; final fcs = FrpcConfigurationStorage(); - final FrpcSettingController ds_c = Get.find(); + final FrpcSettingController dsctr = Get.find(); Widget widget() { - ds_c.context = context; + dsctr.context = context; return Container( - margin: EdgeInsets.all(15.0), + margin: const EdgeInsets.all(15.0), child: ListView( children: [ - Obx(() => ds_c.frpc_download_tip.value), - Container( - child: Card( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ListTile( - leading: Icon(Icons.trip_origin), - title: Text('下载源镜像设置'), - ), - Container( - margin: - EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), - child: Obx( - () => Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: ListTile( - leading: Icon(Icons.auto_awesome), - title: Text('启用下载镜像源'), - ), - ), - Switch( - value: ds_c.frpc_download_use_mirror.value, - onChanged: (value) async { - fcs.setSettingsGitHubMirror(value); - ds_c.frpc_download_use_mirror.value = value; - }, + Obx(() => dsctr.frpcDownloadTip.value), + Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const ListTile( + leading: Icon(Icons.trip_origin), + title: Text('下载源镜像设置'), + ), + Container( + margin: + const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + child: Obx( + () => Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + const Expanded( + child: ListTile( + leading: Icon(Icons.auto_awesome), + title: Text('启用下载镜像源'), ), - ], - ), - /*/// TODO: 镜像选择 - /// 纵向 - Container( - margin: EdgeInsets.only(top: 10.0), - child: Row( - children: [ - /// 横向Container#1 - ], - ), - ),*/ - ], - ), + ), + Switch( + value: dsctr.frpcDownloadUseMirror.value, + onChanged: (value) async { + fcs.setSettingsGitHubMirror(value); + dsctr.frpcDownloadUseMirror.value = value; + }, + ), + ], + ), + /*/// TODO: 镜像选择 + /// 纵向 + Container( + margin: EdgeInsets.only(top: 10.0), + child: Row( + children: [ + /// 横向Container#1 + ], + ), + ),*/ + ], ), - ) - ], - ), + ), + ) + ], ), ), ], diff --git a/lib/ui/views/setting/injector.dart b/lib/ui/views/setting/injector.dart index ae8830be..646bca79 100644 --- a/lib/ui/views/setting/injector.dart +++ b/lib/ui/views/setting/injector.dart @@ -4,23 +4,22 @@ import 'package:nyalcf/controllers/frpcSettingController.dart'; import 'package:nyalcf/controllers/launcherSettingController.dart'; import 'package:nyalcf/ui/models/AppbarActions.dart'; import 'package:nyalcf/ui/models/FloatingActionButton.dart'; - -import 'frpcSetting.dart'; -import 'launcherSetting.dart'; +import 'package:nyalcf/ui/views/setting/frpcSetting.dart'; +import 'package:nyalcf/ui/views/setting/launcherSetting.dart'; class SettingInjector extends StatelessWidget { - SettingInjector({super.key, required this.title}); + const SettingInjector({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { - final FrpcSettingController dsf_c = + final FrpcSettingController fsctr = Get.put(FrpcSettingController(context: context)); - final DSettingLauncherController dsc_c = + final DSettingLauncherController dslctr = Get.put(DSettingLauncherController()); - dsf_c.load(); - dsc_c.load(); + fsctr.load(); + dslctr.load(); return DefaultTabController( length: 2, @@ -30,7 +29,7 @@ class SettingInjector extends StatelessWidget { style: const TextStyle(color: Colors.white)), actions: AppbarActionsX(context: context, setting: false).actions(), - bottom: TabBar( + bottom: const TabBar( tabs: [ Tab( icon: Icon(Icons.launch, color: Colors.white), diff --git a/lib/ui/views/setting/launcherSetting.dart b/lib/ui/views/setting/launcherSetting.dart index 5826b55b..72e703bf 100644 --- a/lib/ui/views/setting/launcherSetting.dart +++ b/lib/ui/views/setting/launcherSetting.dart @@ -5,175 +5,171 @@ import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart import 'package:url_launcher/url_launcher.dart'; class LauncherSetting { - final DSettingLauncherController ds_c = Get.find(); + final DSettingLauncherController dsctr = Get.find(); final lcs = LauncherConfigurationStorage(); Widget widget() { return Container( - margin: EdgeInsets.all(15.0), + margin: const EdgeInsets.all(15.0), child: ListView( children: [ - Container( - child: Card( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ListTile( - leading: Icon(Icons.color_lens), - title: Text('主题'), - ), - Container( - margin: - EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), - padding: EdgeInsets.only(left: 30.0, right: 50.0), - child: Obx( - () => Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - '自定义主题设置', - style: TextStyle( - color: Colors.grey.shade600, - ), + Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const ListTile( + leading: Icon(Icons.color_lens), + title: Text('主题'), + ), + Container( + margin: + const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + padding: const EdgeInsets.only(left: 30.0, right: 50.0), + child: Obx( + () => Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + '自定义主题设置', + style: TextStyle( + color: Colors.grey.shade600, ), - Row( - children: [ - Expanded( - child: ListTile( - leading: Icon(Icons.auto_awesome), - title: Text('自动设置主题'), - ), - ), - Switch( - value: ds_c.theme_auto.value, - onChanged: (value) async { - lcs.setThemeAuto(value); - lcs.save(); - ds_c.theme_auto.value = value; - ds_c.loadx(); - Get.forceAppUpdate(); - // ThemeControl.autoSet(); - }, + ), + Row( + children: [ + const Expanded( + child: ListTile( + leading: Icon(Icons.auto_awesome), + title: Text('自动设置主题'), ), - ], - ), - ds_c.switch_theme_dark.value, - Row( - children: [ - Expanded( - child: ListTile( - leading: Icon(Icons.colorize), - title: Text('浅色主题自定义主题色种子'), - ), + ), + Switch( + value: dsctr.themeAuto.value, + onChanged: (value) async { + lcs.setThemeAuto(value); + lcs.save(); + dsctr.themeAuto.value = value; + dsctr.loadx(); + Get.forceAppUpdate(); + // ThemeControl.autoSet(); + }, + ), + ], + ), + dsctr.switchThemeDark.value, + Row( + children: [ + const Expanded( + child: ListTile( + leading: Icon(Icons.colorize), + title: Text('浅色主题自定义主题色种子'), ), - SizedBox( - width: 200, - child: Container( - padding: EdgeInsets.only(bottom: 10.0), - child: TextField( - decoration: const InputDecoration( - labelText: '十六进制颜色', - ), - readOnly: true, + ), + SizedBox( + width: 200, + child: Container( + padding: const EdgeInsets.only(bottom: 10.0), + child: const TextField( + decoration: InputDecoration( + labelText: '十六进制颜色', ), + readOnly: true, ), ), - Switch( - value: ds_c.theme_light_seed_enable.value, - onChanged: null, - ), - ], - ), - ], - ), + ), + Switch( + value: dsctr.themeLightSeedEnable.value, + onChanged: null, + ), + ], + ), + ], ), - ) - ], - ), + ), + ) + ], ), ), - Container( - child: Card( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ListTile( - leading: Icon(Icons.bug_report), - title: Text('调试'), - ), - Container( - margin: - EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), - padding: EdgeInsets.only(left: 30.0, right: 50.0), - child: Obx( - () => Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - '启动器调试功能(目前没有任何用)', - style: TextStyle( - color: Colors.grey.shade600, - ), + Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const ListTile( + leading: Icon(Icons.bug_report), + title: Text('调试'), + ), + Container( + margin: + const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + padding: const EdgeInsets.only(left: 30.0, right: 50.0), + child: Obx( + () => Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + '启动器调试功能', + style: TextStyle( + color: Colors.grey.shade600, ), - Row( - children: [ - Expanded( - child: ListTile( - leading: Icon(Icons.file_open), - title: Text('开启 DEBUG 模式'), - ), - ), - Switch( - value: ds_c.debug_mode.value, - onChanged: (value) async { - lcs.setDebug(value); - lcs.save(); - ds_c.debug_mode.value = value; - }, + ), + Row( + children: [ + const Expanded( + child: ListTile( + leading: Icon(Icons.file_open), + title: Text('开启 DEBUG 模式'), ), - ], - ), - ], - ), + ), + Switch( + value: dsctr.debugMode.value, + onChanged: (value) async { + lcs.setDebug(value); + lcs.save(); + dsctr.debugMode.value = value; + }, + ), + ], + ), + ], ), - ) - ], - ), + ), + ) + ], ), ), Card( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - ListTile( + const ListTile( leading: Icon(Icons.info), title: Text('软件信息'), ), Container( margin: - EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), child: Obx( () => Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - SelectableText('通用软件名称:Nya LoCyanFrp! 乐青映射启动器'), - SelectableText('内部软件名称:${ds_c.app_name}'), - SelectableText('内部软件包名:${ds_c.app_package_name}'), - SelectableText('软件版本:${ds_c.app_version}'), - SelectableText('著作权信息:登记中'), + const SelectableText('通用软件名称:Nya LoCyanFrp! 乐青映射启动器'), + SelectableText('内部软件名称:${dsctr.appName}'), + SelectableText('内部软件包名:${dsctr.appPackageName}'), + SelectableText('软件版本:${dsctr.appVersion}'), + const SelectableText('著作权信息:登记中'), ], ), ), ), Container( - decoration: BoxDecoration( + decoration: const BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(15.0)), ), - padding: EdgeInsets.all(10.0), - margin: EdgeInsets.only( + padding: const EdgeInsets.all(10.0), + margin: const EdgeInsets.only( left: 10.0, right: 10.0, bottom: 10.0, top: 10.0), - child: Text( + child: const Text( 'Powered by Flutter framework.', style: TextStyle( color: Color.fromRGBO(57, 186, 255, 1.0), @@ -187,20 +183,20 @@ class LauncherSetting { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - ListTile( + const ListTile( leading: Icon(Icons.bug_report), title: Text('帮助我们做的更好'), ), Container( margin: - EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( + const Text( 'Nya LoCyanFrp! 是免费开源的,欢迎向我们提交BUG或新功能请求。您可以在GitHub上提交Issues来向我们反馈。'), TextButton( - child: ListTile( + child: const ListTile( leading: Icon(Icons.link), title: Text( 'https://github.com/Muska-Ami/NyaLCF/issues', @@ -215,7 +211,7 @@ class LauncherSetting { '发生错误', '无法打开网页,请检查设备是否存在WebView', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } }, diff --git a/lib/ui/views/tokenmode/panel.dart b/lib/ui/views/tokenmode/panel.dart index 712df4e3..aa131c1c 100644 --- a/lib/ui/views/tokenmode/panel.dart +++ b/lib/ui/views/tokenmode/panel.dart @@ -12,7 +12,7 @@ import 'package:nyalcf/ui/models/ProcessListDialog.dart'; import 'package:nyalcf/utils/frpc/ProcessManager.dart'; class TokenModePanel extends StatefulWidget { - TokenModePanel({super.key, required this.title}); + const TokenModePanel({super.key, required this.title}); final String title; @@ -29,8 +29,8 @@ class _TokenModePanelState extends State { final fcs = FrpcConfigurationStorage(); - final FrpcController f_c = Get.find(); - final ConsoleController c_c = Get.put(ConsoleController()); + final FrpcController fctr = Get.find(); + final ConsoleController cctr = Get.put(ConsoleController()); @override void dispose() { @@ -48,13 +48,13 @@ class _TokenModePanelState extends State { iconTheme: Theme.of(context).iconTheme, ), body: ListView( - padding: EdgeInsets.all(20.0), + padding: const EdgeInsets.all(20.0), children: [ Card( color: Colors.blue.shade100, child: Container( - margin: EdgeInsets.all(10.0), - child: Text( + margin: const EdgeInsets.all(10.0), + child: const Text( '提示:您正在使用Frp Token模式,如需使用完整版本,请登录LoCyanFrp账户喵~', style: TextStyle( color: Colors.blue, @@ -65,13 +65,13 @@ class _TokenModePanelState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('隧道ID'), + const Text('隧道ID'), Row( mainAxisSize: MainAxisSize.min, children: [ Container( width: 300, - margin: EdgeInsets.all(10.0), + margin: const EdgeInsets.all(10.0), child: TextField( decoration: const InputDecoration( labelText: '隧道ID', @@ -83,64 +83,71 @@ class _TokenModePanelState extends State { ), ElevatedButton( onPressed: () async { - final String? frp_token = await TokenModePrefs.getToken(); + final String? frpToken = await TokenModePrefs.getToken(); // 判断frp_token是否为空 - if (frp_token != null) if (proxyController.text != '') { - // 检测是否定义了环境变量 - if (f_c.custom_path == null) { - // 无环境变量已安装Frpc - if (fcs.getInstalledVersions().isNotEmpty) { + if (frpToken != null) { + if (proxyController.text != '') { + // 检测是否定义了环境变量 + if (fctr.customPath == null) { + // 无环境变量已安装Frpc + if (fcs + .getInstalledVersions() + .isNotEmpty) { + FrpcProcessManager().nwprcs( + frpToken: frpToken, + proxyId: int.parse(proxyController.text), + ); + Get.snackbar( + '启动命令已发出', + '请查看控制台确认是否启动成功', + snackPosition: SnackPosition.BOTTOM, + animationDuration: const Duration(milliseconds: 300), + ); + // 无环境变量未安装Frpc + } else { + Get.snackbar( + '笨..笨蛋!', + '你还没有安装Frpc!请先到 设置->FRPC 安装Frpc才能启动喵!', + snackPosition: SnackPosition.BOTTOM, + animationDuration: const Duration(milliseconds: 300), + ); + } + // 有环境变量未安装Frpc + } else if (await File(fctr.customPath!).exists()) { FrpcProcessManager().nwprcs( - frp_token: frp_token, - proxy_id: int.parse(proxyController.text), + frpcPath: fctr.customPath, + frpToken: frpToken, + proxyId: int.parse(proxyController.text), ); Get.snackbar( '启动命令已发出', '请查看控制台确认是否启动成功', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); - // 无环境变量未安装Frpc - } else + // 有环境变量未安装Frpc,但文件不存在 + } else { Get.snackbar( '笨..笨蛋!', - '你还没有安装Frpc!请先到 设置->FRPC 安装Frpc才能启动喵!', + '你的环境变量是无效哒!猫猫都要找晕啦!', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); - // 有环境变量未安装Frpc - } else if (await File(f_c.custom_path!).exists()) { - FrpcProcessManager().nwprcs( - frpc_path: f_c.custom_path, - frp_token: frp_token, - proxy_id: int.parse(proxyController.text), - ); - Get.snackbar( - '启动命令已发出', - '请查看控制台确认是否启动成功', - snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), - ); - // 有环境变量未安装Frpc,但文件不存在 - } else + } + } else { Get.snackbar( - '笨..笨蛋!', - '你的环境变量是无效哒!猫猫都要找晕啦!', + '发生错误', + '内部错误,请重新登录', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); - } else - Get.snackbar( - '发生错误', - '内部错误,请重新登录', - snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), - ); + } + } }, - child: Text('启动'), + child: const Text('启动'), ), Container( - margin: EdgeInsets.only(left: 70.0), + margin: const EdgeInsets.only(left: 70.0), child: Row( children: [ ElevatedButton( @@ -148,23 +155,23 @@ class _TokenModePanelState extends State { Get.dialog( ProcessListDialogX(context: context).build()); }, - child: Text('查看进程列表'), + child: const Text('查看进程列表'), ), - Container(margin: EdgeInsets.only(left: 10.0)), + Container(margin: const EdgeInsets.only(left: 10.0)), ElevatedButton( onPressed: () { FrpcProcessManager().killAll(); }, - child: Text( + style: ButtonStyle( + backgroundColor: + MaterialStateProperty.all(Colors.red), + ), + child: const Text( '关闭所有进程', style: TextStyle( color: Colors.white, ), ), - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all(Colors.red), - ), ), ], ), @@ -175,15 +182,15 @@ class _TokenModePanelState extends State { ), Obx( () => Card( - margin: EdgeInsets.all(20.0), + margin: const EdgeInsets.all(20.0), color: Colors.grey.shade900, child: SizedBox( width: Checkbox.width, height: 200.0, child: Container( - margin: EdgeInsets.all(10.0), + margin: const EdgeInsets.all(10.0), child: ListView( - children: f_c.process_out, + children: fctr.processOut, ), ), ), diff --git a/lib/utils/CPUArch.dart b/lib/utils/CPUArch.dart index d6c5b334..e4df3a14 100644 --- a/lib/utils/CPUArch.dart +++ b/lib/utils/CPUArch.dart @@ -4,8 +4,8 @@ import 'dart:io'; /// https://gist.github.com/corbindavenport/d04085e2ac42da303efbaccaa717f223 class CPUArch { // 获取当前CPU架构的函数 - static Future getCPUArchitecture() async { - var cpu; + static Future getCPUArchitecture() async { + String? cpu; if (Platform.isWindows) { cpu = Platform.environment['PROCESSOR_ARCHITECTURE']; // var cpu = envVars['PROCESSOR_ARCHITECTURE']; diff --git a/lib/utils/FileConfiguration.dart b/lib/utils/FileConfiguration.dart index 2f482993..99050fae 100644 --- a/lib/utils/FileConfiguration.dart +++ b/lib/utils/FileConfiguration.dart @@ -1,21 +1,21 @@ import 'dart:convert'; import 'dart:io'; -import 'package:nyalcf/utils/Logger.dart'; +//import 'package:nyalcf/utils/Logger.dart'; class FileConfiguration { FileConfiguration({ - this.file = null, + this.file, required this.handle, }); File? file; // Dart Dart 草你吗,定义File?传Future不报错 final String handle; - static Map tmp_data = {}; + static Map tmpData = {}; void initMap() { - tmp_data[handle] = Map(); + tmpData[handle] = {}; } /// 一堆B方法 /// 气死我里 @@ -48,7 +48,7 @@ class FileConfiguration { /// 设置值 void set(String node, dynamic value) { List nl = _parseNode(node); - dynamic last = tmp_data[handle]; // 初始化last为tmp_data的引用 + dynamic last = tmpData[handle]; // 初始化last为tmp_data的引用 String? n; for (int i = 0; i < nl.length; i++) { n = nl[i]; @@ -56,17 +56,17 @@ class FileConfiguration { // 更新最后一个节点的值 last[n] = value; } else { - if (last[n] == null || !(last[n] is Map)) { + if (last[n] == null || last[n] is! Map) { last[n] = {}; } // 移动到下一个节点 last = last[n]; } - Logger.debug('写入tmp_data状态值: ${tmp_data[handle]}'); - Logger.debug('写入迭代NODE: $n'); - Logger.debug('写入迭代LAST: $last'); + //Logger.debug('写入tmp_data状态值: ${tmp_data[handle]}'); + //Logger.debug('写入迭代NODE: $n'); + //Logger.debug('写入迭代LAST: $last'); } - Logger.debug('最终值(${n}): ${last}'); + //Logger.debug('最终值(${n}): ${last}'); } /// 获取值 @@ -77,66 +77,67 @@ class FileConfiguration { for (n in nl) { if (last != null) { last = last[n]; - Logger.debug('目标tmp_data状态值: ${tmp_data[handle]}'); - Logger.debug('读取迭代NODE: $n'); - Logger.debug('读取迭代LAST: $last'); + //Logger.debug('目标tmp_data状态值: ${tmp_data[handle]}'); + //Logger.debug('读取迭代NODE: $n'); + //Logger.debug('读取迭代LAST: $last'); } else { - last = tmp_data[handle][n]; - Logger.debug('目标tmp_data状态值: ${tmp_data[handle]}'); - Logger.debug('读取迭代NODE: $n'); - Logger.debug('读取迭代LAST: $last'); + last = tmpData[handle][n]; + //Logger.debug('目标tmp_data状态值: ${tmp_data[handle]}'); + //Logger.debug('读取迭代NODE: $n'); + //Logger.debug('读取迭代LAST: $last'); } } - Logger.debug('最终值(${n}): ${last}'); + //Logger.debug('最终值(${n}): ${last}'); return last; } /// 保存 Future save({ - File? file = null, + File? file, bool replace = false, }) async { File? fi = file ?? this.file; - Logger.debug('目标文件对象: $fi'); + //Logger.debug('目标文件对象: $fi'); if (fi != null) { if (!replace) { if (!(await fi.exists())) { if (!(await fi.exists())) await fi.create(); await fi.writeAsString(toString()); } else { - Logger.warn('File exist and replace is false, ignoring save action.'); + //Logger.warn('File exist and replace is false, ignoring save action.'); } } else { if (!(await fi.exists())) await fi.create(); await fi.writeAsString(toString()); } - } else + } else { throw UnimplementedError( 'No specified file selected.Please set a file to use save(); method!'); + } } /// 设置映射实体文件 - void setFile(File _file) { - file = _file; + void setFile(File file) { + this.file = file; } /// 设置映射实体文件(通过路径) - void setFilePath(String _path) { - file = File(_path); + void setFilePath(String path) { + file = File(path); } List _parseNode(String value) => value.split('.'); /// 转为 String @override - String toString() => json.encode(tmp_data[handle]); + String toString() => json.encode(tmpData[handle]); /// 转为 Map String - String toMapString() => tmp_data[handle].toString(); + String toMapString() => tmpData[handle].toString(); /// 从 String 导入 - fromString(String j) => tmp_data[handle] = json.decode(j); + fromString(String j) => tmpData[handle] = json.decode(j); /// 从 Map 导入 - fromMap(Map map) => tmp_data[handle] = map; + fromMap(Map map) => tmpData[handle] = map; } diff --git a/lib/utils/Logger.dart b/lib/utils/Logger.dart index 86a98bfc..c1dc09be 100644 --- a/lib/utils/Logger.dart +++ b/lib/utils/Logger.dart @@ -1,26 +1,26 @@ import 'dart:io'; import 'package:logger/logger.dart' as LoU; +import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart'; import 'package:nyalcf/utils/PathProvider.dart'; class Logger { - static final String? _s_path = PathProvider.appSupportPath; - - //static final lcs = LauncherConfigurationStorage(); + static final String? _supportPath = PathProvider.appSupportPath; + static final lcs = LauncherConfigurationStorage(); static get _fileOutPut async => - LoU.FileOutput(file: File('${_s_path}/run.log')); - static LoU.ConsoleOutput _consoleOutput = LoU.ConsoleOutput(); + LoU.FileOutput(file: File('$_supportPath/run.log')); + static final LoU.ConsoleOutput _consoleOutput = LoU.ConsoleOutput(); /// 重置日志文件 static clear() async { - final file = await File(('${_s_path}/run.log')); + final file = File(('$_supportPath/run.log')); if (await file.exists()) await file.delete(); } static get _logger async { - List multiOutput = [await _fileOutPut, await _consoleOutput]; - return await LoU.Logger( + List multiOutput = [await _fileOutPut, _consoleOutput]; + return LoU.Logger( filter: LogFilter(), printer: LoU.HybridPrinter( LoU.PrettyPrinter( @@ -35,7 +35,7 @@ class Logger { printTime: true, lineLength: 60, levelColors: { - LoU.Level.debug: LoU.AnsiColor.fg(126), + LoU.Level.debug: const LoU.AnsiColor.fg(126), }, methodCount: 0, errorMethodCount: null, @@ -62,20 +62,20 @@ class Logger { } static Future debug(s) async { - //if (lcs.getDebug()) { - (await _logger).d(s); - //} + if (lcs.getDebug()) { + (await _logger).d(s); + } } - static Future frpc_info(s) async { + static Future frpcInfo(s) async { await info('[FRPC][INFO]$s'); } - static Future frpc_warn(s) async { + static Future frpcWarn(s) async { await warn('[FRPC][WARN]$s'); } - static Future frpc_error(s) async { + static Future frpcError(s) async { await error('[FRPC][ERROR]$s'); } diff --git a/lib/utils/PathProvider.dart b/lib/utils/PathProvider.dart index 4b49400a..f1ed5f23 100644 --- a/lib/utils/PathProvider.dart +++ b/lib/utils/PathProvider.dart @@ -4,26 +4,22 @@ import 'package:nyalcf/utils/Logger.dart'; import 'package:path_provider/path_provider.dart'; class PathProvider { - static final _support_path = getApplicationSupportDirectory(); - static final _cache_path = getApplicationCacheDirectory(); + static final _supportPathAsync = getApplicationSupportDirectory(); + static final _cachePathAsync = getApplicationCacheDirectory(); /// 假的同步,实际上就是刚启动缓存成变量了 - static String? appCachePath = null; - static String? appSupportPath = null; + static String? appCachePath; + static String? appSupportPath; - /** - * 获取缓存目录 - */ + /// 获取缓存目录 static Future get _cachePath async { - String path = (await _cache_path).path; + String path = (await _cachePathAsync).path; return path; } - /** - * 获取数据存储目录 - */ + /// 获取数据存储目录 static Future get _supportPath async { - String path = (await _support_path).path; + String path = (await _supportPathAsync).path; return path; } @@ -32,18 +28,16 @@ class PathProvider { appSupportPath = await _supportPath; } - /** - * 移动文件夹 - */ + /// 移动文件夹 static void moveDirectory(Directory sourceDir, Directory targetDir) async { if (!await targetDir.exists()) { await targetDir.create(recursive: true); } - final sourceDirList = await sourceDir.list(); + final sourceDirList = sourceDir.list(); await sourceDirList.forEach((FileSystemEntity entity) async { String newPath = - targetDir.path + '/' + Uri.decodeFull(entity.uri.pathSegments.last); + '${targetDir.path}/${Uri.decodeFull(entity.uri.pathSegments.last)}'; Logger.debug(newPath); if (entity is File) { diff --git a/lib/utils/ThemeControl.dart b/lib/utils/ThemeControl.dart index 215f8a69..f214f9f0 100644 --- a/lib/utils/ThemeControl.dart +++ b/lib/utils/ThemeControl.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:get/get.dart'; +import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart'; import 'package:nyalcf/utils/Logger.dart'; class ThemeControl { - /** - * 设置主题为自动模式 - */ + static final lcs = LauncherConfigurationStorage(); + + /// 设置主题为自动模式 static void autoSet() { final bool isDarkMode = SchedulerBinding.instance.platformDispatcher.platformBrightness == @@ -14,31 +15,25 @@ class ThemeControl { switchDarkTheme(isDarkMode); } - /** - * 切换到暗色主题 - * @param value - 是否切换到暗色主题 - */ + /// 切换到暗色主题 static void switchDarkTheme(bool value) { if (value) { Get.changeTheme(dark); - Logger.info('切换到暗色主题 / ${value}'); + Logger.info('切换到暗色主题'); } else { Get.changeTheme(light); - Logger.info('切换到亮色主题 / ${value}'); + Logger.info('切换到亮色主题'); } } - /** - * 暗色主题设置 - */ + /// 暗色主题设置 static final dark = ThemeData( useMaterial3: true, fontFamily: 'HarmonyOS Sans', brightness: Brightness.dark, ); - /** - * 亮色主题设置 - */ + + /// 亮色主题设置 static final light = ThemeData( useMaterial3: true, fontFamily: 'HarmonyOS Sans', @@ -56,4 +51,19 @@ class ThemeControl { backgroundColor: Colors.pink.shade200, ), ); + static final custom = ThemeData( + useMaterial3: true, + fontFamily: 'HarmonyOS Sans', + colorSchemeSeed: colorFromHexCode(lcs.getThemeLightSeedValue()), + ); + + static colorFromHexCode(String hex) { + return Color( + int.parse( + hex.substring(0, 6), + radix: 16, + ) + + 0xFF000000, + ); + } } diff --git a/lib/utils/Updater.dart b/lib/utils/Updater.dart index 2ded72fd..aaeb576b 100644 --- a/lib/utils/Updater.dart +++ b/lib/utils/Updater.dart @@ -11,38 +11,38 @@ class Updater { final packageInfo = PackageInfo.fromPlatform(); /// 获取内部包版本 - packageInfo.then((pak_inf) { + packageInfo.then((pakInf) { final result = LauncherUpdateDio().getUpdate(); /// 获取远程源版本 - result.then((u_if) { - Logger.debug('${u_if?.version} | v${pak_inf.version}'); + result.then((uIf) { + Logger.debug('${uIf?.version} | v${pakInf.version}'); /// 比对是否一致 - if (u_if?.version != null && 'v${pak_inf.version}' != u_if?.version) { + if (uIf?.version != null && 'v${pakInf.version}' != uIf?.version) { /// 否 - Logger.info('New version: ${u_if?.version}'); + Logger.info('New version: ${uIf?.version}'); Get.dialog(AlertDialog( - icon: Icon(Icons.update), - title: Text('好耶!是新版本!'), + icon: const Icon(Icons.update), + title: const Text('好耶!是新版本!'), content: Column( mainAxisSize: MainAxisSize.min, children: [ - Text('当前版本:v${pak_inf.version}'), - Text('新版本:${u_if?.version}'), - Text('是否打开下载界面喵?'), + Text('当前版本:v${pakInf.version}'), + Text('新版本:${uIf?.version}'), + const Text('是否打开下载界面喵?'), ], ), actions: [ TextButton( - child: Text( + child: const Text( '取消', ), onPressed: () async { Get.close(0); }), TextButton( - child: Text( + child: const Text( '确定', ), onPressed: () async { @@ -52,7 +52,7 @@ class Updater { '发生错误', '无法打开网页,请检查设备是否存在WebView', snackPosition: SnackPosition.BOTTOM, - animationDuration: Duration(milliseconds: 300), + animationDuration: const Duration(milliseconds: 300), ); } else { Get.close(0); @@ -64,7 +64,7 @@ class Updater { } else { /// 是 Logger.info('You are running latest version.'); - Future.delayed(Duration(hours: 1), () { + Future.delayed(const Duration(hours: 1), () { startUp(); }); } diff --git a/lib/utils/frpc/Archive.dart b/lib/utils/frpc/Archive.dart index 04eb6cf6..4966c801 100644 --- a/lib/utils/frpc/Archive.dart +++ b/lib/utils/frpc/Archive.dart @@ -4,8 +4,8 @@ import 'package:archive/archive_io.dart'; import 'package:nyalcf/utils/PathProvider.dart'; class FrpcArchive { - static final _c_path = PathProvider.appCachePath; - static final _s_path = PathProvider.appSupportPath; + static final _cachePath = PathProvider.appCachePath; + static final _supportPath = PathProvider.appSupportPath; static Future unarchive({ required platform, @@ -15,17 +15,18 @@ class FrpcArchive { File f; /// 判定平台确定压缩包名称 - if (Platform.isWindows) - f = File('${_c_path}/frpc.zip'); - else - f = File('${_c_path}/frpc.tar.gz'); + if (Platform.isWindows) { + f = File('$_cachePath/frpc.zip'); + } else { + f = File('$_cachePath/frpc.tar.gz'); + } /// 确认 Frpc 是否存在 if (await f.exists()) { - extractFileToDisk(f.path, _c_path!); + extractFileToDisk(f.path, _cachePath!); final dir = Directory( - '${await _c_path}/frp_LoCyanFrp-${version}_${platform}_${arch}'); - PathProvider.moveDirectory(dir, Directory('${_s_path}/frpc/${version}')); + '$_cachePath/frp_LoCyanFrp-${version}_${platform}_$arch'); + PathProvider.moveDirectory(dir, Directory('$_supportPath/frpc/$version')); return true; } else { return false; diff --git a/lib/utils/frpc/ProcessManager.dart b/lib/utils/frpc/ProcessManager.dart index 4b2b6269..a2592182 100644 --- a/lib/utils/frpc/ProcessManager.dart +++ b/lib/utils/frpc/ProcessManager.dart @@ -9,69 +9,69 @@ import 'package:nyalcf/storages/stories/FrpcStoryStorage.dart'; import 'package:nyalcf/utils/Logger.dart'; class FrpcProcessManager { - final FrpcController f_c = Get.find(); - final ConsoleController c_c = Get.find(); + final FrpcController fctr = Get.find(); + final ConsoleController cctr = Get.find(); - final frpc_work_path = FrpcStoryStorage.getRunPath(); + final Future frpcWorkPath = FrpcStoryStorage.getRunPath(); void nwprcs({ - required String frp_token, - required int proxy_id, - String? frpc_path = null, + required String frpToken, + required int proxyId, + String? frpcPath, }) async { - if (!Platform.isWindows) { - Logger.info('*nix platform, change file permission'); + if (Platform.isLinux) { + Logger.info('Linux platform, change file permission'); await FrpcStoryStorage.setRunPermission(); } - final Map p_map = Map(); - List arguments = []; + final Map pMap = {}; + List arguments = []; - final conf_path = await ProxiesConfigurationStorage.getConfigPath(proxy_id); - if (conf_path != null) { - arguments = ['-c', conf_path]; + final String? confPath = await ProxiesConfigurationStorage.getConfigPath(proxyId); + if (confPath != null) { + arguments = ['-c', confPath]; } else { - arguments = [ + arguments = [ '-u', - frp_token, + frpToken, '-p', - proxy_id.toString(), + proxyId.toString(), ]; } - final process = await Process.start( - frpc_path ?? await FrpcStoryStorage.getFilePath(), + final Process process = await Process.start( + frpcPath ?? await FrpcStoryStorage.getFilePath(), arguments, workingDirectory: await FrpcStoryStorage.getRunPath(), ); - p_map['process'] = process; - p_map['proxy_id'] = proxy_id; - c_c.addProcess(p_map); + pMap['process'] = process; + pMap['proxy_id'] = proxyId; + cctr.addProcess(pMap); /// Process [stdout, stderr] - process.stdout.forEach((element) { - final regex = RegExp(r'\x1B\[[0-9;]*[mK]'); - final fmt_str = utf8.decode(element).trim().replaceAll(regex, ''); - if (fmt_str.contains('stopped') || fmt_str.contains('启动失败')) { - Logger.frpc_warn('[${proxy_id}] ${fmt_str}'); - f_c.appendWarnLog(fmt_str); + process.stdout.forEach((List element) { + final RegExp regex = RegExp(r'\x1B\[[0-9;]*[mK]'); + final String fmtStr = utf8.decode(element).trim().replaceAll(regex, ''); + if (fmtStr.contains('stopped') || fmtStr.contains('启动失败')) { + Logger.frpcWarn('[$proxyId] $fmtStr'); + fctr.appendWarnLog(fmtStr); process.kill(); - c_c.removeProcess(p_map); - } else if (fmt_str.contains('failed') || fmt_str.contains('err')) { - Logger.frpc_error('[${proxy_id}] ${fmt_str}'); - f_c.appendErrorLog(fmt_str); + cctr.removeProcess(pMap); + } else if (fmtStr.contains('failed') || fmtStr.contains('err')) { + Logger.frpcError('[$proxyId] $fmtStr'); + fctr.appendErrorLog(fmtStr); process.kill(); - c_c.removeProcess(p_map); + cctr.removeProcess(pMap); } else { - Logger.frpc_info('[${proxy_id}] ${fmt_str}'); - f_c.appendInfoLog(fmt_str); + Logger.frpcInfo('[$proxyId] $fmtStr'); + fctr.appendInfoLog(fmtStr); } }); - process.stderr.forEach((element) { - final fmt_str = utf8.decode(element).trim(); - Logger.frpc_error('[${proxy_id}] ${fmt_str}'); - f_c.appendErrorLog(fmt_str); + process.stderr.forEach((List element) { + final String fmtStr = utf8.decode(element).trim(); + Logger.frpcError('[$proxyId] $fmtStr'); + fctr.appendErrorLog(fmtStr); process.kill(); - c_c.removeProcess(p_map); + cctr.removeProcess(pMap); }); //print('Process length: ${process_list.length}'); @@ -79,23 +79,23 @@ class FrpcProcessManager { void killAll() { Logger.info('Killing all process'); - Logger.debug('Process length: ${c_c.process_list.length}'); - f_c.appendInfoLog('[SYSTEM][INFO] Killing all process...'); - c_c.process_list.forEach((element) { + Logger.debug('Process length: ${cctr.processList.length}'); + fctr.appendInfoLog('[SYSTEM][INFO] Killing all process...'); + for (Map element in cctr.processList) { kill(element); - }); - c_c.clearProcess(); + } + cctr.clearProcess(); Logger.info('All process killed'); - f_c.appendInfoLog('[SYSTEM][INFO] All process killed'); + fctr.appendInfoLog('[SYSTEM][INFO] All process killed'); } - void kill(prs) { + void kill(Map prs) { Logger.info('Killing frpc process, pid: ${prs['process'].pid}'); - f_c.appendInfoLog( + fctr.appendInfoLog( '[SYSTEM][INFO] Killing process, pid: ${prs['process'].pid}'); prs['process'].kill(); - c_c.removeProcess(prs); + cctr.removeProcess(prs); - Logger.debug('Process length: ${c_c.process_list.length}'); + Logger.debug('Process length: ${cctr.processList.length}'); } } diff --git a/lib/utils/network/dio/auth/loginAuth.dart b/lib/utils/network/dio/auth/loginAuth.dart index 03088d10..4963d1e0 100644 --- a/lib/utils/network/dio/auth/loginAuth.dart +++ b/lib/utils/network/dio/auth/loginAuth.dart @@ -9,9 +9,9 @@ class LoginAuth { Future requestLogin(user, password) async { FormData data = FormData.fromMap({'username': user, 'password': password}); try { - Logger.debug('Post login: ${user} / ${password}'); + Logger.debug('Post login: $user / $password'); final response = - await dio.post('${basicConfig.api_v2_url}/users/login', data: data); + await dio.post('${BasicDioConfig.api_v2_url}/users/login', data: data); Map responseJson = response.data; Logger.debug(responseJson); final resData = responseJson['data']; @@ -23,7 +23,7 @@ class LoginAuth { avatar: resData['avatar'], inbound: resData['inbound'], outbound: resData['outbound'], - frp_token: resData['frp_token'], + frpToken: resData['frp_token'], traffic: resData['traffic']); return userInfo; } else { diff --git a/lib/utils/network/dio/auth/registerAuth.dart b/lib/utils/network/dio/auth/registerAuth.dart index 2beee907..3b1e4aaf 100644 --- a/lib/utils/network/dio/auth/registerAuth.dart +++ b/lib/utils/network/dio/auth/registerAuth.dart @@ -18,9 +18,9 @@ class RegisterAuth { }); try { Logger.debug( - 'Post register: ${user} - ${email} / ${password} - ${confirmPassword} / ${verify}'); + 'Post register: $user - $email / $password - $confirmPassword / $verify'); final response = await dio - .post('${basicConfig.api_v2_url}/users/register', data: data); + .post('${BasicDioConfig.api_v2_url}/users/register', data: data); Map responseJson = response.data; Logger.debug(responseJson); final resData = responseJson['data']; @@ -37,18 +37,19 @@ class RegisterAuth { Future requestCode(email) async { try { - Logger.debug('Requesting email code, email: ${email}'); - Map params_map = Map(); - params_map['email'] = email; + Logger.debug('Requesting email code, email: $email'); + Map paramsMap = {}; + paramsMap['email'] = email; final response = await dio.get( - '${basicConfig.api_v2_url}/users/send', - queryParameters: params_map, + '${BasicDioConfig.api_v2_url}/users/send', + queryParameters: paramsMap, ); final resData = response.data; - if (resData['msg'] == 'success') + if (resData['msg'] == 'success') { return true; - else + } else { return resData['msg']; + } } catch (ex) { Logger.error(ex); return ex; diff --git a/lib/utils/network/dio/auth/userAuth.dart b/lib/utils/network/dio/auth/userAuth.dart index a35be663..d48e91c8 100644 --- a/lib/utils/network/dio/auth/userAuth.dart +++ b/lib/utils/network/dio/auth/userAuth.dart @@ -1,8 +1,7 @@ import 'package:dio/dio.dart'; import 'package:nyalcf/prefs/UserInfoPrefs.dart'; import 'package:nyalcf/utils/Logger.dart'; - -import '../basicConfig.dart'; +import 'package:nyalcf/utils/network/dio/basicConfig.dart'; class UserAuth { final dio = Dio(); @@ -10,12 +9,12 @@ class UserAuth { Future checkToken(token) async { try { Logger.info('Check token if is valid'); - Map params_map = Map(); - params_map['token'] = token; + Map paramsMap = {}; + paramsMap['token'] = token; final res = await dio.get( - '${basicConfig.api_v2_url}/check/token', - queryParameters: params_map, + '${BasicDioConfig.api_v2_url}/check/token', + queryParameters: paramsMap, ); Logger.debug(res.data); @@ -29,19 +28,19 @@ class UserAuth { Future refresh(token, username) async { try { Logger.info('Refresh user info'); - Map params_map = Map(); - params_map['username'] = username; + Map paramsMap = {}; + paramsMap['username'] = username; Options options = Options(); - Map options_map = Map(); - options_map['Content-Type'] = + Map optionsMap = {}; + optionsMap['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; - options_map['Authorization'] = 'Bearer $token'; - options = options.copyWith(headers: options_map); + optionsMap['Authorization'] = 'Bearer $token'; + options = options.copyWith(headers: optionsMap); final res = await dio.get( - '${basicConfig.api_v2_url}/users/info', - queryParameters: params_map, + '${BasicDioConfig.api_v2_url}/users/info', + queryParameters: paramsMap, options: options, ); final resData = res.data['data']; diff --git a/lib/utils/network/dio/basicConfig.dart b/lib/utils/network/dio/basicConfig.dart index 8dbb966c..df7036a9 100644 --- a/lib/utils/network/dio/basicConfig.dart +++ b/lib/utils/network/dio/basicConfig.dart @@ -1,10 +1,10 @@ -class basicConfig { - static final api_v1_url = 'https://api.locyanfrp.cn'; - static final api_v2_url = 'https://api-v2.locyanfrp.cn/api/v2'; - static final frpc_config_url = 'https://www.locyanfrp.cn/api'; - static final github_api_url = 'https://api-gh.1l1.icu'; - static final github_main_url = 'https://github.com'; - static final github_mirrors_url = +class BasicDioConfig { + static const api_v1_url = 'https://api.locyanfrp.cn'; + static const api_v2_url = 'https://api-v2.locyanfrp.cn/api/v2'; + static const frpc_config_url = 'https://www.locyanfrp.cn/api'; + static const github_api_url = 'https://api-gh.1l1.icu'; + static const github_main_url = 'https://github.com'; + static const github_mirrors_url = 'https://proxy-gh.1l1.icu/https://github.com'; // static final frpc_release_repo = 'LoCyan-Team/LoCyanFrpPureApp'; } diff --git a/lib/utils/network/dio/frpc/download.dart b/lib/utils/network/dio/frpc/download.dart index 2e9b62c7..1e7ebffd 100644 --- a/lib/utils/network/dio/frpc/download.dart +++ b/lib/utils/network/dio/frpc/download.dart @@ -5,7 +5,7 @@ import 'package:nyalcf/utils/Logger.dart'; class FrpcDownloadDio { final dio = Dio(); - final _c_path = PathProvider.appCachePath; + final _cachePath = PathProvider.appCachePath; /// 下载Frpc Future download({ @@ -16,35 +16,37 @@ class FrpcDownloadDio { required CancelToken cancelToken, required bool useMirror, }) async { - Logger.info('Start download: ${platform} | ${version} | ${arch}'); + Logger.info('Start download: $platform | $version | $arch'); try { - final download_basic_url; - if (useMirror) - download_basic_url = basicConfig.github_mirrors_url; - else - download_basic_url = basicConfig.github_main_url; + final String downloadBasicUrl; + if (useMirror) { + downloadBasicUrl = BasicDioConfig.github_mirrors_url; + } else { + downloadBasicUrl = BasicDioConfig.github_main_url; + } if (platform == 'windows') { Logger.debug('Windows, download zip'); return await dio.download( - '${download_basic_url}/LoCyan-Team/LoCyanFrpPureApp/releases/download/v${version}/frp_LoCyanFrp-${version}_${platform}_${arch}.zip', - '${_c_path}/frpc.zip', + '$downloadBasicUrl/LoCyan-Team/LoCyanFrpPureApp/releases/download/v$version/frp_LoCyanFrp-${version}_${platform}_$arch.zip', + '$_cachePath/frpc.zip', cancelToken: cancelToken, onReceiveProgress: progressCallback, ); } else { Logger.debug('Download tar.gz'); return await dio.download( - '${download_basic_url}/LoCyan-Team/LoCyanFrpPureApp/releases/download/v${version}/frp_LoCyanFrp-${version}_${platform}_${arch}.tar.gz', - '${_c_path}/frpc.tar.gz', + '$downloadBasicUrl/LoCyan-Team/LoCyanFrpPureApp/releases/download/v$version/frp_LoCyanFrp-${version}_${platform}_$arch.tar.gz', + '$_cachePath/frpc.tar.gz', cancelToken: cancelToken, onReceiveProgress: progressCallback, ); } } on DioException catch (e) { - if (cancelToken.isCancelled) + if (cancelToken.isCancelled) { return true; - else + } else { return e; + } } catch (e) { return e; } diff --git a/lib/utils/network/dio/launcher/update.dart b/lib/utils/network/dio/launcher/update.dart index 33dd2762..bb8a702c 100644 --- a/lib/utils/network/dio/launcher/update.dart +++ b/lib/utils/network/dio/launcher/update.dart @@ -9,13 +9,13 @@ class LauncherUpdateDio { Future getUpdate() async { try { final res = await dio.get( - '${basicConfig.github_api_url}/repos/Muska-Ami/NyaLCF/releases/latest'); + '${BasicDioConfig.github_api_url}/repos/Muska-Ami/NyaLCF/releases/latest'); final Map resData = res.data; // print(resData); return UpdateInfoModel( version: resData['name'], tag: resData['tag_name'], - download_url: resData['assets'], + downloadUrl: resData['assets'], ); } catch (e) { Logger.error(e); diff --git a/lib/utils/network/dio/other/announcement.dart b/lib/utils/network/dio/other/announcement.dart index 65e03a6b..79c78af4 100644 --- a/lib/utils/network/dio/other/announcement.dart +++ b/lib/utils/network/dio/other/announcement.dart @@ -1,7 +1,6 @@ import 'package:dio/dio.dart'; import 'package:nyalcf/utils/Logger.dart'; - -import '../basicConfig.dart'; +import 'package:nyalcf/utils/network/dio/basicConfig.dart'; class AnnouncementDio { final dio = Dio(); @@ -10,7 +9,7 @@ class AnnouncementDio { try { Logger.info('Get broadcast announcement'); final response = - await dio.get('${basicConfig.api_v1_url}/App/GetBroadCast'); + await dio.get('${BasicDioConfig.api_v1_url}/App/GetBroadCast'); Logger.debug(response); final Map resData = response.data; return resData['broadcast']; @@ -23,7 +22,7 @@ class AnnouncementDio { Future getCommon() async { try { Logger.info('Get common announcement'); - final response = await dio.get('${basicConfig.api_v1_url}/App'); + final response = await dio.get('${BasicDioConfig.api_v1_url}/App'); Logger.debug(response); final Map resData = response.data; return resData['ads']; diff --git a/lib/utils/network/dio/proxies/configuration.dart b/lib/utils/network/dio/proxies/configuration.dart index 5ddf2652..81623067 100644 --- a/lib/utils/network/dio/proxies/configuration.dart +++ b/lib/utils/network/dio/proxies/configuration.dart @@ -7,15 +7,15 @@ import 'package:nyalcf/utils/Logger.dart'; class ProxiesConfigurationDio { final dio = Dio(); - Future get(String frp_token, int proxy_id) async { + Future get(String frpToken, int proxyId) async { try { - Map params_map = Map(); - params_map['action'] = 'getcfg'; - params_map['token'] = frp_token; - params_map['id'] = proxy_id; + Map paramsMap = {}; + paramsMap['action'] = 'getcfg'; + paramsMap['token'] = frpToken; + paramsMap['id'] = proxyId; - final res = await dio.get('${basicConfig.frpc_config_url}', - queryParameters: params_map); + final res = await dio.get(BasicDioConfig.frpc_config_url, + queryParameters: paramsMap); try { final Map resData = jsonDecode(res.data); Logger.debug(res); diff --git a/lib/utils/network/dio/proxies/get.dart b/lib/utils/network/dio/proxies/get.dart index 56ad5c1a..a5167c55 100644 --- a/lib/utils/network/dio/proxies/get.dart +++ b/lib/utils/network/dio/proxies/get.dart @@ -8,21 +8,21 @@ class ProxiesGetDio { Future get(username, token) async { try { - Map params_map = Map(); - params_map['username'] = username; + Map paramsMap = {}; + paramsMap['username'] = username; Options options = Options(); - Map options_map = Map(); - options_map['Content-Type'] = + Map optionsMap = {}; + optionsMap['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; - options_map['Authorization'] = 'Bearer $token'; - options = options.copyWith(headers: options_map); + optionsMap['Authorization'] = 'Bearer $token'; + options = options.copyWith(headers: optionsMap); //print(options.headers?.keys); var response = await dio.get( - '${basicConfig.api_v2_url}/proxies/getlist', - queryParameters: params_map, + '${BasicDioConfig.api_v2_url}/proxies/getlist', + queryParameters: paramsMap, options: options, ); Map resJson = response.data; @@ -30,24 +30,24 @@ class ProxiesGetDio { Logger.debug(resData['proxies']); List> proxies = List.from(resData['proxies']); List list = []; - proxies.forEach((proxy) { + for (var proxy in proxies) { list.add(ProxyInfoModel( - proxy_name: proxy['proxy_name'], - use_compression: proxy['use_compression'], - local_ip: proxy['local_ip'], + proxyName: proxy['proxy_name'], + useCompression: proxy['use_compression'], + localIP: proxy['local_ip'], node: proxy['node'], - local_port: proxy['local_port'], + localPort: proxy['local_port'], // remote_port: int.parse(proxy['remote_port']), - remote_port: proxy['remote_port'], + remotePort: proxy['remote_port'], domain: proxy['domain'], icp: proxy['icp'], sk: proxy['sk'], id: proxy['id'], - proxy_type: proxy['proxy_type'], - use_encryption: proxy['use_encryption'], + proxyType: proxy['proxy_type'], + useEncryption: proxy['use_encryption'], status: proxy['status'], )); - }); + } return list; } catch (e) { Logger.error(e); diff --git a/pubspec.lock b/pubspec.lock index cdbd6dad..4ffe3f96 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -138,7 +138,7 @@ packages: source: hosted version: "3.1.1" crypto: - dependency: transitive + dependency: "direct main" description: name: crypto sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab @@ -199,7 +199,7 @@ packages: source: hosted version: "0.3.1" flutter_highlight: - dependency: transitive + dependency: "direct main" description: name: flutter_highlight sha256: "7b96333867aa07e122e245c033b8ad622e4e3a42a1a2372cbb098a2541d8782c" @@ -214,6 +214,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.13.1" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 + url: "https://pub.dev" + source: hosted + version: "3.0.1" flutter_markdown: dependency: "direct main" description: @@ -241,7 +249,7 @@ packages: source: hosted version: "4.6.6" highlight: - dependency: transitive + dependency: "direct main" description: name: highlight sha256: "5353a83ffe3e3eca7df0abfb72dcf3fa66cc56b953728e7113ad4ad88497cf21" @@ -304,6 +312,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.0" + lints: + dependency: transitive + description: + name: lints + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" + source: hosted + version: "3.0.0" logger: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 42214638..5328a4f3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -49,8 +49,12 @@ dependencies: logger: ^2.0.2+1 tray_manager: ^0.2.1 window_manager: ^0.3.8 + flutter_highlight: ^0.7.0 + highlight: ^0.7.0 + crypto: ^3.0.3 dev_dependencies: + flutter_lints: ^3.0.1 flutter_test: sdk: flutter From 825a9bfbce8b325b7322535788ae77b1352956a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Tue, 13 Feb 2024 19:21:26 +0800 Subject: [PATCH 04/10] [*]Fix bug:frpc process manager won't kill frpc when error with 'No connection could be made because the target machine actively refused it' --- lib/utils/frpc/ProcessManager.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/utils/frpc/ProcessManager.dart b/lib/utils/frpc/ProcessManager.dart index a2592182..520af002 100644 --- a/lib/utils/frpc/ProcessManager.dart +++ b/lib/utils/frpc/ProcessManager.dart @@ -26,7 +26,8 @@ class FrpcProcessManager { final Map pMap = {}; List arguments = []; - final String? confPath = await ProxiesConfigurationStorage.getConfigPath(proxyId); + final String? confPath = + await ProxiesConfigurationStorage.getConfigPath(proxyId); if (confPath != null) { arguments = ['-c', confPath]; } else { @@ -58,8 +59,11 @@ class FrpcProcessManager { cctr.removeProcess(pMap); } else if (fmtStr.contains('failed') || fmtStr.contains('err')) { Logger.frpcError('[$proxyId] $fmtStr'); + if (!fmtStr.contains( + 'No connection could be made because the target machine actively refused it')) { + process.kill(); + } fctr.appendErrorLog(fmtStr); - process.kill(); cctr.removeProcess(pMap); } else { Logger.frpcInfo('[$proxyId] $fmtStr'); From b6fa20e916701149519d420ff99c5253cc4e5c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Wed, 14 Feb 2024 10:16:25 +0800 Subject: [PATCH 05/10] =?UTF-8?q?[*]Fix=20bug:=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E9=80=BB=E8=BE=91=EF=BC=8C=E8=BF=9B=E4=B8=80?= =?UTF-8?q?=E6=AD=A5=E8=A7=84=E8=8C=83=E5=8C=96=E5=91=BD=E5=90=8D=E7=A9=BA?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ontroller.dart => console_controller.dart} | 2 +- lib/controllers/frpcController.dart | 6 +- ...ller.dart => frpc_setting_controller.dart} | 83 ++++++++-------- ....dart => launcher_setting_controller.dart} | 4 +- ...lController.dart => panel_controller.dart} | 0 ...ontroller.dart => proxies_controller.dart} | 31 +++--- ...erController.dart => user_controller.dart} | 4 +- ...nfoStorage.dart => user_info_storage.dart} | 7 +- lib/main.dart | 8 +- lib/main_window.dart | 8 +- ...rpcListModel.dart => frpc_list_model.dart} | 0 ...xyInfoModel.dart => proxy_info_model.dart} | 0 ...eInfoModel.dart => update_info_model.dart} | 0 ...serInfoModel.dart => user_info_model.dart} | 0 ...enModePrefs.dart => token_mode_prefs.dart} | 0 ...serInfoPrefs.dart => user_info_prefs.dart} | 4 +- ...e.dart => frpc_configuration_storage.dart} | 11 ++- ...rt => launcher_configuration_storage.dart} | 8 +- ...art => proxies_configuration_storage.dart} | 2 +- lib/storages/injector.dart | 4 +- ...iguration.dart => json_configuration.dart} | 10 +- ...ryStorage.dart => frpc_story_storage.dart} | 42 +++++---- lib/ui/models/FrpcDownloadTip.dart | 91 ------------------ ...AccountDialog.dart => account_dialog.dart} | 10 +- ...AppbarActions.dart => appbar_actions.dart} | 6 +- lib/ui/models/{Drawer.dart => drawer.dart} | 4 +- ...utton.dart => floating_action_button.dart} | 2 +- ... => frpc_configuration_editor_dialog.dart} | 10 +- ...dDialog.dart => frpc_download_dialog.dart} | 34 +++---- lib/ui/models/frpc_download_tip.dart | 94 +++++++++++++++++++ ...stDialog.dart => process_list_dialog.dart} | 2 +- .../{ToolDialog.dart => tool_dialog.dart} | 0 lib/ui/views/auth/login.dart | 10 +- lib/ui/views/auth/register.dart | 30 +++--- lib/ui/views/auth/tokenmode.dart | 6 +- lib/ui/views/home.dart | 12 +-- lib/ui/views/panel/console.dart | 14 +-- lib/ui/views/panel/home.dart | 14 +-- lib/ui/views/panel/proxies.dart | 10 +- .../{frpcSetting.dart => frpc_setting.dart} | 8 +- lib/ui/views/setting/injector.dart | 12 +-- ...cherSetting.dart => launcher_setting.dart} | 23 ++--- lib/ui/views/tokenmode/panel.dart | 65 ++++--------- lib/utils/{CPUArch.dart => cpu_arch.dart} | 0 ...iguration.dart => file_configuration.dart} | 1 + lib/utils/frpc/{Archive.dart => archive.dart} | 6 +- lib/utils/frpc/path_provider.dart | 18 ++++ ...ocessManager.dart => process_manager.dart} | 15 ++- ...StartUpLoader.dart => startup_loader.dart} | 0 lib/utils/{Logger.dart => logger.dart} | 4 +- .../auth/{loginAuth.dart => login_auth.dart} | 10 +- .../{registerAuth.dart => register_auth.dart} | 4 +- .../auth/{userAuth.dart => user_auth.dart} | 6 +- .../{basicConfig.dart => basic_config.dart} | 0 lib/utils/network/dio/frpc/download.dart | 6 +- lib/utils/network/dio/launcher/update.dart | 6 +- lib/utils/network/dio/other/announcement.dart | 4 +- .../network/dio/proxies/configuration.dart | 4 +- lib/utils/network/dio/proxies/get.dart | 6 +- .../{PathProvider.dart => path_provider.dart} | 2 +- .../{ThemeControl.dart => theme_control.dart} | 4 +- lib/utils/{Updater.dart => updater.dart} | 2 +- 62 files changed, 402 insertions(+), 387 deletions(-) rename lib/controllers/{consoleController.dart => console_controller.dart} (96%) rename lib/controllers/{frpcSettingController.dart => frpc_setting_controller.dart} (76%) rename lib/controllers/{launcherSettingController.dart => launcher_setting_controller.dart} (93%) rename lib/controllers/{panelController.dart => panel_controller.dart} (100%) rename lib/controllers/{proxiesController.dart => proxies_controller.dart} (87%) rename lib/controllers/{userController.dart => user_controller.dart} (91%) rename lib/io/{userInfoStorage.dart => user_info_storage.dart} (78%) rename lib/models/{FrpcListModel.dart => frpc_list_model.dart} (100%) rename lib/models/{ProxyInfoModel.dart => proxy_info_model.dart} (100%) rename lib/models/{UpdateInfoModel.dart => update_info_model.dart} (100%) rename lib/models/{UserInfoModel.dart => user_info_model.dart} (100%) rename lib/prefs/{TokenModePrefs.dart => token_mode_prefs.dart} (100%) rename lib/prefs/{UserInfoPrefs.dart => user_info_prefs.dart} (95%) rename lib/storages/configurations/{FrpcConfigurationStorage.dart => frpc_configuration_storage.dart} (70%) rename lib/storages/configurations/{LauncherConfigurationStorage.dart => launcher_configuration_storage.dart} (91%) rename lib/storages/configurations/{ProxiesConfigurationStorage.dart => proxies_configuration_storage.dart} (94%) rename lib/storages/{JsonConfiguration.dart => json_configuration.dart} (77%) rename lib/storages/stories/{FrpcStoryStorage.dart => frpc_story_storage.dart} (65%) delete mode 100644 lib/ui/models/FrpcDownloadTip.dart rename lib/ui/models/{AccountDialog.dart => account_dialog.dart} (87%) rename lib/ui/models/{AppbarActions.dart => appbar_actions.dart} (92%) rename lib/ui/models/{Drawer.dart => drawer.dart} (94%) rename lib/ui/models/{FloatingActionButton.dart => floating_action_button.dart} (91%) rename lib/ui/models/{FrpcConfigurationEditorDialog.dart => frpc_configuration_editor_dialog.dart} (88%) rename lib/ui/models/{FrpcDownloadDialog.dart => frpc_download_dialog.dart} (74%) create mode 100644 lib/ui/models/frpc_download_tip.dart rename lib/ui/models/{ProcessListDialog.dart => process_list_dialog.dart} (91%) rename lib/ui/models/{ToolDialog.dart => tool_dialog.dart} (100%) rename lib/ui/views/setting/{frpcSetting.dart => frpc_setting.dart} (89%) rename lib/ui/views/setting/{launcherSetting.dart => launcher_setting.dart} (92%) rename lib/utils/{CPUArch.dart => cpu_arch.dart} (100%) rename lib/utils/{FileConfiguration.dart => file_configuration.dart} (99%) rename lib/utils/frpc/{Archive.dart => archive.dart} (83%) create mode 100644 lib/utils/frpc/path_provider.dart rename lib/utils/frpc/{ProcessManager.dart => process_manager.dart} (88%) rename lib/utils/frpc/{StartUpLoader.dart => startup_loader.dart} (100%) rename lib/utils/{Logger.dart => logger.dart} (94%) rename lib/utils/network/dio/auth/{loginAuth.dart => login_auth.dart} (78%) rename lib/utils/network/dio/auth/{registerAuth.dart => register_auth.dart} (93%) rename lib/utils/network/dio/auth/{userAuth.dart => user_auth.dart} (90%) rename lib/utils/network/dio/{basicConfig.dart => basic_config.dart} (100%) rename lib/utils/{PathProvider.dart => path_provider.dart} (97%) rename lib/utils/{ThemeControl.dart => theme_control.dart} (92%) rename lib/utils/{Updater.dart => updater.dart} (98%) diff --git a/lib/controllers/consoleController.dart b/lib/controllers/console_controller.dart similarity index 96% rename from lib/controllers/consoleController.dart rename to lib/controllers/console_controller.dart index 0abb6bcd..3befc72a 100644 --- a/lib/controllers/consoleController.dart +++ b/lib/controllers/console_controller.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/utils/frpc/ProcessManager.dart'; +import 'package:nyalcf/utils/frpc/process_manager.dart'; /// 控制台 GetX 状态控制器 class ConsoleController extends GetxController { diff --git a/lib/controllers/frpcController.dart b/lib/controllers/frpcController.dart index b21b4c23..c5a66a3e 100644 --- a/lib/controllers/frpcController.dart +++ b/lib/controllers/frpcController.dart @@ -2,8 +2,8 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; -import 'package:nyalcf/storages/stories/FrpcStoryStorage.dart'; +import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; +import 'package:nyalcf/storages/stories/frpc_story_storage.dart'; class FrpcController extends GetxController { final FrpcConfigurationStorage fcs = FrpcConfigurationStorage(); @@ -26,7 +26,7 @@ class FrpcController extends GetxController { /// 版本号 RxString version = ''.obs; - String? get customPath => Platform.environment['NYA_LCF_FRPC_PATH']; + // String? get customPath => Platform.environment['NYA_LCF_FRPC_PATH']; /// 加载方法 load() async { diff --git a/lib/controllers/frpcSettingController.dart b/lib/controllers/frpc_setting_controller.dart similarity index 76% rename from lib/controllers/frpcSettingController.dart rename to lib/controllers/frpc_setting_controller.dart index 6e41116d..96eb45b4 100644 --- a/lib/controllers/frpcSettingController.dart +++ b/lib/controllers/frpc_setting_controller.dart @@ -3,11 +3,12 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart' hide Response; -import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; -import 'package:nyalcf/utils/Logger.dart'; -import 'package:nyalcf/ui/models/FrpcDownloadDialog.dart'; -import 'package:nyalcf/ui/models/FrpcDownloadTip.dart'; -import 'package:nyalcf/utils/CPUArch.dart'; +import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; +import 'package:nyalcf/utils/frpc/path_provider.dart'; +import 'package:nyalcf/utils/logger.dart'; +import 'package:nyalcf/ui/models/frpc_download_dialog.dart'; +import 'package:nyalcf/ui/models/frpc_download_tip.dart'; +import 'package:nyalcf/utils/cpu_arch.dart'; import 'package:nyalcf/utils/frpc/Archive.dart'; class FrpcSettingController extends GetxController { @@ -18,7 +19,7 @@ class FrpcSettingController extends GetxController { final FrpcConfigurationStorage fcs = FrpcConfigurationStorage(); String platform = ''; - String? get customPath => Platform.environment['NYA_LCF_FRPC_PATH']; + // String? get customPath => Platform.environment['NYA_LCF_FRPC_PATH']; Rx frpcDownloadTip = const Card().obs; var frpcDownloadArchList = >[ @@ -27,7 +28,6 @@ class FrpcSettingController extends GetxController { var frpcDownloadArch = 0.obs; var frpcDownloadProgress = 0.0.obs; var frpcDownloadShow = [].obs; - List _frpcDownloadedVersions = []; dynamic frpcDownloadCancel = false; var frpcDownloadUseMirror = false.obs; @@ -49,10 +49,8 @@ class FrpcSettingController extends GetxController { } void _loadTip() async { - _frpcDownloadedVersions = fcs.getInstalledVersions(); - if (_frpcDownloadedVersions.isEmpty || - (customPath != null && await File(customPath!).exists())) { - frpcDownloadTip.value = FrpcDownloadTip.tip(context: context); + if (await FrpcPathProvider.frpcPath == null) { + frpcDownloadTip.value = await FrpcDownloadTip.tip(context: context); } else { frpcDownloadTip.value = await FrpcDownloadTip.downloaded(context: context); @@ -90,35 +88,38 @@ class FrpcSettingController extends GetxController { });*/ Get.dialog(FrpcDownloadDialogX(context: context).unarchiving(), barrierDismissible: false); - Future.delayed(const Duration(seconds: 2), () async { - //延时执行 - final bool unarchive = await FrpcArchive.unarchive( - platform: platform, - arch: arch[frpcDownloadArch.value]['arch'], - version: fcs.getSettingsFrpcVersion(), - ); - if (unarchive) { - fcs.setSettingsFrpcVersion('0.51.3'); - fcs.addInstalledVersion('0.51.3'); - fcs.save(); - /**if (!Platform.isWindows) { + Future.delayed( + const Duration(seconds: 2), + () async { + //延时执行 + final bool unarchive = await FrpcArchive.unarchive( + platform: platform, + arch: arch[frpcDownloadArch.value]['arch'], + version: fcs.getSettingsFrpcVersion(), + ); + if (unarchive) { + fcs.setSettingsFrpcVersion('0.51.3'); + fcs.addInstalledVersion('0.51.3'); + fcs.save(); + /**if (!Platform.isWindows) { print('*nix platform, change file permission'); await FrpcManagerStorage.setRunPermission(); }*/ - _loadTip(); - } else { - Get.snackbar( - '解压 Frpc 时发生错误..呜呜..', - '请检查磁盘是否被塞满了..或者是已经安装了!受不了了呜呜呜...', - snackPosition: SnackPosition.BOTTOM, - animationDuration: const Duration(milliseconds: 300), - ); - } - - /// 关闭对话框 - Get.close(0); - Get.close(0); - },); + _loadTip(); + } else { + Get.snackbar( + '解压 Frpc 时发生错误..呜呜..', + '请检查磁盘是否被塞满了..或者是已经安装了!受不了了呜呜呜...', + snackPosition: SnackPosition.BOTTOM, + animationDuration: const Duration(milliseconds: 300), + ); + } + + /// 关闭对话框 + Get.close(0); + Get.close(0); + }, + ); } else { frpcDownloadShow.clear(); frpcDownloadShow.add(const Text( @@ -176,12 +177,12 @@ class FrpcSettingController extends GetxController { {'arch': 'arm64', 'name': 'arm64/armv8'}, ]); } - arch = arch.toList(); + this.arch = arch.toList(); /// 遍历构建 - for (var i = 0; i <= arch.length - 1; i++) { - dmil.add(_buildDMIWidget(version: arch[i]['name'], value: i)); - Logger.info(arch[i]); + for (var i = 0; i <= this.arch.length - 1; i++) { + dmil.add(_buildDMIWidget(version: this.arch[i]['name'], value: i)); + Logger.info(this.arch[i]); } return dmil; } diff --git a/lib/controllers/launcherSettingController.dart b/lib/controllers/launcher_setting_controller.dart similarity index 93% rename from lib/controllers/launcherSettingController.dart rename to lib/controllers/launcher_setting_controller.dart index f228ac15..ae479381 100644 --- a/lib/controllers/launcherSettingController.dart +++ b/lib/controllers/launcher_setting_controller.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart'; +import 'package:nyalcf/storages/configurations/launcher_configuration_storage.dart'; import 'package:package_info_plus/package_info_plus.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/utils/logger.dart'; class DSettingLauncherController extends GetxController { final lcs = LauncherConfigurationStorage(); diff --git a/lib/controllers/panelController.dart b/lib/controllers/panel_controller.dart similarity index 100% rename from lib/controllers/panelController.dart rename to lib/controllers/panel_controller.dart diff --git a/lib/controllers/proxiesController.dart b/lib/controllers/proxies_controller.dart similarity index 87% rename from lib/controllers/proxiesController.dart rename to lib/controllers/proxies_controller.dart index b1fd1fbb..42229291 100644 --- a/lib/controllers/proxiesController.dart +++ b/lib/controllers/proxies_controller.dart @@ -3,15 +3,16 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/storages/configurations/ProxiesConfigurationStorage.dart'; +import 'package:nyalcf/controllers/user_controller.dart'; +import 'package:nyalcf/storages/configurations/proxies_configuration_storage.dart'; +import 'package:nyalcf/utils/frpc/path_provider.dart'; import 'package:nyalcf/utils/network/dio/proxies/configuration.dart'; import 'package:nyalcf/utils/network/dio/proxies/get.dart'; -import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; -import 'package:nyalcf/models/ProxyInfoModel.dart'; -import 'package:nyalcf/ui/models/FrpcConfigurationEditorDialog.dart'; -import 'package:nyalcf/utils/Logger.dart'; -import 'package:nyalcf/utils/frpc/ProcessManager.dart'; +import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; +import 'package:nyalcf/models/proxy_info_model.dart'; +import 'package:nyalcf/ui/models/frpc_configuration_editor_dialog.dart'; +import 'package:nyalcf/utils/logger.dart'; +import 'package:nyalcf/utils/frpc/process_manager.dart'; import 'package:nyalcf/controllers/frpcController.dart'; /// 代理 GetX 状态控制器 @@ -63,8 +64,7 @@ class ProxiesController extends GetxController { DataCell(SelectableText(element.proxyType)), DataCell(SelectableText(element.localIP)), DataCell( - SelectableText( - '${element.localPort} -> ${element.remotePort}'), + SelectableText('${element.localPort} -> ${element.remotePort}'), ), DataCell( Row(children: await _buildActions(element)), @@ -101,9 +101,13 @@ class ProxiesController extends GetxController { icon: const Icon(Icons.play_circle), tooltip: '启动', onPressed: () async { - if (fcs.getInstalledVersions().isNotEmpty) { - FrpcProcessManager() - .nwprcs(frpToken: uctr.frpToken.value, proxyId: element.id); + final execPath = await FrpcPathProvider.frpcPath; + if (execPath != null) { + FrpcProcessManager().nwprcs( + frpToken: uctr.frpToken.value, + proxyId: element.id, + frpcPath: execPath, + ); Get.snackbar( '启动命令已发出', '请查看控制台确认是否启动成功', @@ -135,7 +139,8 @@ class ProxiesController extends GetxController { ); } - final fp = await ProxiesConfigurationStorage.getConfigPath(element.id); + final fp = + await ProxiesConfigurationStorage.getConfigPath(element.id); String text = ''; /// 判空 diff --git a/lib/controllers/userController.dart b/lib/controllers/user_controller.dart similarity index 91% rename from lib/controllers/userController.dart rename to lib/controllers/user_controller.dart index c2ced0f2..e2df39e6 100644 --- a/lib/controllers/userController.dart +++ b/lib/controllers/user_controller.dart @@ -1,6 +1,6 @@ import 'package:get/get.dart'; -import 'package:nyalcf/models/UserInfoModel.dart'; -import 'package:nyalcf/prefs/UserInfoPrefs.dart'; +import 'package:nyalcf/models/user_info_model.dart'; +import 'package:nyalcf/prefs/user_info_prefs.dart'; // 用户控制器 class UserController extends GetxController { diff --git a/lib/io/userInfoStorage.dart b/lib/io/user_info_storage.dart similarity index 78% rename from lib/io/userInfoStorage.dart rename to lib/io/user_info_storage.dart index f0ff47d9..0519ad92 100644 --- a/lib/io/userInfoStorage.dart +++ b/lib/io/user_info_storage.dart @@ -1,8 +1,8 @@ import 'dart:convert'; import 'dart:io'; -import 'package:nyalcf/models/UserInfoModel.dart'; -import 'package:nyalcf/utils/PathProvider.dart'; +import 'package:nyalcf/models/user_info_model.dart'; +import 'package:nyalcf/utils/path_provider.dart'; @deprecated class UserInfoStorage { @@ -11,8 +11,7 @@ class UserInfoStorage { /// 保存数据 static Future save(UserInfoModel data) async { final String writeData = jsonEncode(data); - await File('$_path/session.json') - .writeAsString(writeData, encoding: utf8); + await File('$_path/session.json').writeAsString(writeData, encoding: utf8); } /// 读取数据 diff --git a/lib/main.dart b/lib/main.dart index fad38898..1b731c00 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,8 +1,8 @@ import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:flutter/material.dart'; -import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart'; +import 'package:nyalcf/storages/configurations/launcher_configuration_storage.dart'; import 'package:nyalcf/storages/injector.dart'; -import 'package:nyalcf/utils/PathProvider.dart'; +import 'package:nyalcf/utils/path_provider.dart'; import 'package:nyalcf/main_tray.dart'; import 'package:nyalcf/main_window.dart'; import 'package:tray_manager/tray_manager.dart'; @@ -16,8 +16,8 @@ import 'package:nyalcf/ui/views/panel/home.dart'; import 'package:nyalcf/ui/views/panel/proxies.dart'; import 'package:nyalcf/ui/views/setting/injector.dart'; import 'package:nyalcf/ui/views/tokenmode/panel.dart'; -import 'package:nyalcf/utils/Logger.dart'; -import 'package:nyalcf/utils/Updater.dart'; +import 'package:nyalcf/utils/logger.dart'; +import 'package:nyalcf/utils/updater.dart'; import 'package:window_manager/window_manager.dart'; void main() async { diff --git a/lib/main_window.dart b/lib/main_window.dart index e68746cb..7f88e679 100644 --- a/lib/main_window.dart +++ b/lib/main_window.dart @@ -6,8 +6,8 @@ import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:nyalcf/main_tray.dart'; import 'package:nyalcf/protocol_activation.dart'; -import 'package:nyalcf/utils/Logger.dart'; -import 'package:nyalcf/utils/frpc/ProcessManager.dart'; +import 'package:nyalcf/utils/logger.dart'; +import 'package:nyalcf/utils/frpc/process_manager.dart'; import 'package:tray_manager/tray_manager.dart'; import 'package:window_manager/window_manager.dart'; @@ -35,6 +35,7 @@ class MainWindow { void callback(deepLink) { Logger.debug(deepLink); } + await ProtocolActivation.registerProtocolActivation(callback); // 显示主窗体 @@ -48,7 +49,8 @@ class MainWindow { appWindow.restore(); await Get.dialog(AlertDialog( title: const Text('关闭 Nya LoCyanFrp!'), - content: const Text('确定要关闭 Nya LoCyanFrp! 吗,要是 Frpc 没关掉猫猫会生气把 Frpc 一脚踹翻的哦!'), + content: + const Text('确定要关闭 Nya LoCyanFrp! 吗,要是 Frpc 没关掉猫猫会生气把 Frpc 一脚踹翻的哦!'), actions: [ TextButton( child: const Text( diff --git a/lib/models/FrpcListModel.dart b/lib/models/frpc_list_model.dart similarity index 100% rename from lib/models/FrpcListModel.dart rename to lib/models/frpc_list_model.dart diff --git a/lib/models/ProxyInfoModel.dart b/lib/models/proxy_info_model.dart similarity index 100% rename from lib/models/ProxyInfoModel.dart rename to lib/models/proxy_info_model.dart diff --git a/lib/models/UpdateInfoModel.dart b/lib/models/update_info_model.dart similarity index 100% rename from lib/models/UpdateInfoModel.dart rename to lib/models/update_info_model.dart diff --git a/lib/models/UserInfoModel.dart b/lib/models/user_info_model.dart similarity index 100% rename from lib/models/UserInfoModel.dart rename to lib/models/user_info_model.dart diff --git a/lib/prefs/TokenModePrefs.dart b/lib/prefs/token_mode_prefs.dart similarity index 100% rename from lib/prefs/TokenModePrefs.dart rename to lib/prefs/token_mode_prefs.dart diff --git a/lib/prefs/UserInfoPrefs.dart b/lib/prefs/user_info_prefs.dart similarity index 95% rename from lib/prefs/UserInfoPrefs.dart rename to lib/prefs/user_info_prefs.dart index c6b08bdb..f68a71cd 100644 --- a/lib/prefs/UserInfoPrefs.dart +++ b/lib/prefs/user_info_prefs.dart @@ -1,7 +1,7 @@ -import 'package:nyalcf/io/userInfoStorage.dart'; +import 'package:nyalcf/io/user_info_storage.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:nyalcf/models/UserInfoModel.dart'; +import 'package:nyalcf/models/user_info_model.dart'; class UserInfoPrefs { static Future setInfo(UserInfoModel userinfo) async { diff --git a/lib/storages/configurations/FrpcConfigurationStorage.dart b/lib/storages/configurations/frpc_configuration_storage.dart similarity index 70% rename from lib/storages/configurations/FrpcConfigurationStorage.dart rename to lib/storages/configurations/frpc_configuration_storage.dart index bb7f10a2..c91b0c84 100644 --- a/lib/storages/configurations/FrpcConfigurationStorage.dart +++ b/lib/storages/configurations/frpc_configuration_storage.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:nyalcf/storages/JsonConfiguration.dart'; +import 'package:nyalcf/storages/json_configuration.dart'; class FrpcConfigurationStorage extends JsonConfiguration { @override @@ -21,14 +21,17 @@ class FrpcConfigurationStorage extends JsonConfiguration { /// 使用的 Frpc 版本 String getSettingsFrpcVersion() => cfg.getString('settings.frpc_version'); - void setSettingsFrpcVersion(String value) => cfg.setString('settings.frpc_version', value); + void setSettingsFrpcVersion(String value) => + cfg.setString('settings.frpc_version', value); /// 使用镜像源 bool getSettingsGitHubMirror() => cfg.getBool('settings.github_mirror'); - void setSettingsGitHubMirror(bool value) => cfg.setBool('settings.github_mirror', value); + void setSettingsGitHubMirror(bool value) => + cfg.setBool('settings.github_mirror', value); /// 已安装的 Frpc 版本 - List getInstalledVersions() => cfg.getStringList('lists.frpc_installed_versions'); + List getInstalledVersions() => + cfg.getStringList('lists.frpc_installed_versions'); void addInstalledVersion(String value) { final List list = getInstalledVersions(); list.add(value); diff --git a/lib/storages/configurations/LauncherConfigurationStorage.dart b/lib/storages/configurations/launcher_configuration_storage.dart similarity index 91% rename from lib/storages/configurations/LauncherConfigurationStorage.dart rename to lib/storages/configurations/launcher_configuration_storage.dart index 85ae26ac..841a0075 100644 --- a/lib/storages/configurations/LauncherConfigurationStorage.dart +++ b/lib/storages/configurations/launcher_configuration_storage.dart @@ -2,8 +2,8 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -import 'package:nyalcf/storages/JsonConfiguration.dart'; -import 'package:nyalcf/utils/ThemeControl.dart'; +import 'package:nyalcf/storages/json_configuration.dart'; +import 'package:nyalcf/utils/theme_control.dart'; class LauncherConfigurationStorage extends JsonConfiguration { @override @@ -57,7 +57,9 @@ class LauncherConfigurationStorage extends JsonConfiguration { case false: return ThemeControl.light; } - } else if (darkEnable) {return ThemeControl.dark;} + } else if (darkEnable) { + return ThemeControl.dark; + } return ThemeControl.light; } } diff --git a/lib/storages/configurations/ProxiesConfigurationStorage.dart b/lib/storages/configurations/proxies_configuration_storage.dart similarity index 94% rename from lib/storages/configurations/ProxiesConfigurationStorage.dart rename to lib/storages/configurations/proxies_configuration_storage.dart index 13472fdc..b70df134 100644 --- a/lib/storages/configurations/ProxiesConfigurationStorage.dart +++ b/lib/storages/configurations/proxies_configuration_storage.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:nyalcf/utils/PathProvider.dart'; +import 'package:nyalcf/utils/path_provider.dart'; class ProxiesConfigurationStorage { static final _path = PathProvider.appSupportPath; diff --git a/lib/storages/injector.dart b/lib/storages/injector.dart index 71f3f218..99df6dc6 100644 --- a/lib/storages/injector.dart +++ b/lib/storages/injector.dart @@ -1,5 +1,5 @@ -import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; -import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart'; +import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; +import 'package:nyalcf/storages/configurations/launcher_configuration_storage.dart'; class StoragesInjector { static init() async { diff --git a/lib/storages/JsonConfiguration.dart b/lib/storages/json_configuration.dart similarity index 77% rename from lib/storages/JsonConfiguration.dart rename to lib/storages/json_configuration.dart index 97ed8e21..a5a2f59d 100644 --- a/lib/storages/JsonConfiguration.dart +++ b/lib/storages/json_configuration.dart @@ -2,8 +2,8 @@ import 'dart:convert'; import 'dart:io'; import 'package:crypto/crypto.dart'; -import 'package:nyalcf/utils/FileConfiguration.dart'; -import 'package:nyalcf/utils/PathProvider.dart'; +import 'package:nyalcf/utils/file_configuration.dart'; +import 'package:nyalcf/utils/path_provider.dart'; abstract class JsonConfiguration { var path = PathProvider.appSupportPath; @@ -18,9 +18,9 @@ abstract class JsonConfiguration { Future asyncInit() async => {}; FileConfiguration get cfg => FileConfiguration( - file: file, - handle: sha1.convert(utf8.encode(handle)).toString(), - ); + file: file, + handle: sha1.convert(utf8.encode(handle)).toString(), + ); /// 保存 void save() => cfg.save(replace: true); diff --git a/lib/storages/stories/FrpcStoryStorage.dart b/lib/storages/stories/frpc_story_storage.dart similarity index 65% rename from lib/storages/stories/FrpcStoryStorage.dart rename to lib/storages/stories/frpc_story_storage.dart index b6f0fdbb..39bd5fab 100644 --- a/lib/storages/stories/FrpcStoryStorage.dart +++ b/lib/storages/stories/frpc_story_storage.dart @@ -1,8 +1,9 @@ import 'dart:io'; -import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; -import 'package:nyalcf/utils/PathProvider.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; +import 'package:nyalcf/utils/frpc/path_provider.dart'; +import 'package:nyalcf/utils/path_provider.dart'; +import 'package:nyalcf/utils/logger.dart'; class FrpcStoryStorage { static final _supportPath = PathProvider.appSupportPath; @@ -13,19 +14,23 @@ class FrpcStoryStorage { } /// 获取Frpc文件 - static Future getFile() async { - return File(await getFilePath()); + static Future getFile() async { + final String? path = await getFilePath(); + if (path != null) return File(path); + return null; } /// 获取Frpc文件 - static Future getFilePath() async { + static Future getFilePath() async { final String name; if (Platform.isWindows) { name = 'frpc.exe'; } else { name = 'frpc'; } - return await getRunPath() + name; + final String path = await getRunPath() + name; + if (await File(path).exists()) return path; + return null; } /// 获取Frpc运行路径 @@ -69,14 +74,19 @@ class FrpcStoryStorage { static Future setRunPermission() async { Logger.info('Set run permission: ${await getFilePath()}'); - final process = await Process.run( - 'chmod', - [ - 'u+x', - await getFilePath(), - ], - ); - Logger.debug(process.stdout.toString()); - Logger.debug(process.stderr.toString()); + final execPath = await FrpcPathProvider.frpcPath; + if (execPath != null) { + final process = await Process.run( + 'chmod', + [ + 'u+x', + execPath, + ], + ); + Logger.debug(process.stdout.toString()); + Logger.debug(process.stderr.toString()); + } else { + throw UnimplementedError('No file provided.'); + } } } diff --git a/lib/ui/models/FrpcDownloadTip.dart b/lib/ui/models/FrpcDownloadTip.dart deleted file mode 100644 index 73f47f0c..00000000 --- a/lib/ui/models/FrpcDownloadTip.dart +++ /dev/null @@ -1,91 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:get/get.dart'; -import 'package:nyalcf/controllers/frpcSettingController.dart'; -import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; -import 'package:nyalcf/ui/models/FrpcDownloadDialog.dart'; - -class FrpcDownloadTip { - static final fcs = FrpcConfigurationStorage(); - static final FrpcSettingController fsctr = Get.find(); - - static Card tip({required context}) => Card( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const ListTile( - leading: Icon(Icons.warning), - title: Text('尚未安装任何版本的 Frpc'), - ), - Container( - margin: const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text('无法启动隧道了...呜呜...'), - Container( - margin: const EdgeInsets.only(top: 10.0), - child: Row( - children: [ - ElevatedButton( - onPressed: () async { - showDialog( - context: context, - builder: (context) { - return FrpcDownloadDialogX( - context: context) - .build(); - }); - }, - child: const Text('下载'), - ), - ], - ), - ), - ], - ), - ) - ], - ), - ); - - static Future downloaded({required context}) async => Card( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const ListTile( - leading: Icon(Icons.check_circle), - title: Text('可用的 Frpc 版本已安装!素晴らしい!'), - ), - Container( - margin: const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 10.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text('已安装版本列表:'), - Text(fcs.getInstalledVersions().toString()), - Text('已指定的 Frpc 文件路径:${fsctr.customPath ?? '无'}'), - ], - ), - ), - Container( - margin: const EdgeInsets.only(left: 20.0, bottom: 20.0), - child: Row( - children: [ - ElevatedButton( - onPressed: () async { - showDialog( - context: context, - builder: (context) { - return FrpcDownloadDialogX(context: context) - .build(); - }); - }, - child: const Text('重新下载'), - ), - ], - ), - ), - ], - ), - ); -} diff --git a/lib/ui/models/AccountDialog.dart b/lib/ui/models/account_dialog.dart similarity index 87% rename from lib/ui/models/AccountDialog.dart rename to lib/ui/models/account_dialog.dart index 75c64ec3..d8d7b103 100644 --- a/lib/ui/models/AccountDialog.dart +++ b/lib/ui/models/account_dialog.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/consoleController.dart'; -import 'package:nyalcf/controllers/panelController.dart'; -import 'package:nyalcf/controllers/proxiesController.dart'; -import 'package:nyalcf/io/userInfoStorage.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/controllers/console_controller.dart'; +import 'package:nyalcf/controllers/panel_controller.dart'; +import 'package:nyalcf/controllers/proxies_controller.dart'; +import 'package:nyalcf/io/user_info_storage.dart'; +import 'package:nyalcf/utils/logger.dart'; import 'package:url_launcher/url_launcher.dart'; class AccountDialogX { diff --git a/lib/ui/models/AppbarActions.dart b/lib/ui/models/appbar_actions.dart similarity index 92% rename from lib/ui/models/AppbarActions.dart rename to lib/ui/models/appbar_actions.dart index 1a7d7158..f2c8b812 100644 --- a/lib/ui/models/AppbarActions.dart +++ b/lib/ui/models/appbar_actions.dart @@ -1,14 +1,12 @@ import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/userController.dart'; +import 'package:nyalcf/controllers/user_controller.dart'; import 'package:nyalcf/main_window.dart'; class AppbarActionsX { AppbarActionsX( - {this.context, - this.append = const [], - this.setting = true}); + {this.context, this.append = const [], this.setting = true}); final UserController uctr = Get.find(); diff --git a/lib/ui/models/Drawer.dart b/lib/ui/models/drawer.dart similarity index 94% rename from lib/ui/models/Drawer.dart rename to lib/ui/models/drawer.dart index 279fc8c0..43cc10a7 100644 --- a/lib/ui/models/Drawer.dart +++ b/lib/ui/models/drawer.dart @@ -21,8 +21,8 @@ class DrawerX { child: Column(mainAxisSize: MainAxisSize.min, children: [ DecoratedBox( decoration: BoxDecoration( - color: - const Color.fromRGBO(255, 101, 160, 0.4196078431372549), + color: const Color.fromRGBO( + 255, 101, 160, 0.4196078431372549), borderRadius: BorderRadius.circular(50.0)), child: Center( child: Container( diff --git a/lib/ui/models/FloatingActionButton.dart b/lib/ui/models/floating_action_button.dart similarity index 91% rename from lib/ui/models/FloatingActionButton.dart rename to lib/ui/models/floating_action_button.dart index c21a7c94..840ac24b 100644 --- a/lib/ui/models/FloatingActionButton.dart +++ b/lib/ui/models/floating_action_button.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/ui/models/ToolDialog.dart'; +import 'package:nyalcf/ui/models/tool_dialog.dart'; class FloatingActionButtonX { Builder button() { diff --git a/lib/ui/models/FrpcConfigurationEditorDialog.dart b/lib/ui/models/frpc_configuration_editor_dialog.dart similarity index 88% rename from lib/ui/models/FrpcConfigurationEditorDialog.dart rename to lib/ui/models/frpc_configuration_editor_dialog.dart index 8863c8af..c3ff6b1d 100644 --- a/lib/ui/models/FrpcConfigurationEditorDialog.dart +++ b/lib/ui/models/frpc_configuration_editor_dialog.dart @@ -3,9 +3,9 @@ import 'package:flutter_code_editor/flutter_code_editor.dart'; import 'package:get/get.dart'; import 'package:highlight/languages/ini.dart'; import 'package:flutter_highlight/themes/monokai-sublime.dart'; -import 'package:nyalcf/controllers/proxiesController.dart'; -import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/storages/configurations/ProxiesConfigurationStorage.dart'; +import 'package:nyalcf/controllers/proxies_controller.dart'; +import 'package:nyalcf/controllers/user_controller.dart'; +import 'package:nyalcf/storages/configurations/proxies_configuration_storage.dart'; class FrpcConfigEditorDialogX { FrpcConfigEditorDialogX({ @@ -72,8 +72,8 @@ class FrpcConfigEditorDialogX { title: const Text('首次编辑,正在获取...'), children: [ Container( - margin: - const EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), + margin: const EdgeInsets.only( + left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), child: const Column( children: [ SizedBox( diff --git a/lib/ui/models/FrpcDownloadDialog.dart b/lib/ui/models/frpc_download_dialog.dart similarity index 74% rename from lib/ui/models/FrpcDownloadDialog.dart rename to lib/ui/models/frpc_download_dialog.dart index 61f541ae..669605e5 100644 --- a/lib/ui/models/FrpcDownloadDialog.dart +++ b/lib/ui/models/frpc_download_dialog.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/frpcSettingController.dart'; -import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; +import 'package:nyalcf/controllers/frpc_setting_controller.dart'; +import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; import 'package:nyalcf/utils/network/dio/frpc/download.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/utils/logger.dart'; class FrpcDownloadDialogX { FrpcDownloadDialogX({required this.context}); @@ -17,8 +17,8 @@ class FrpcDownloadDialogX { title: const Text('请选择一个合适的架构'), children: [ Container( - margin: - const EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), + margin: const EdgeInsets.only( + left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), child: Column( children: [ Text('猫猫翻遍了系统变量,识别到 CPU 架构为:${dsctr.cpuArch}'), @@ -26,7 +26,9 @@ class FrpcDownloadDialogX { value: dsctr.frpcDownloadArch.value, items: dsctr.frpcDownloadArchList, onChanged: (value) { - Logger.info('Selected arch: ${dsctr.arch[value]['arch']}'); + Logger.debug(dsctr.arch); + Logger.info( + 'Selected arch: ${dsctr.arch[value]['arch']}'); dsctr.frpcDownloadArch.value = value; }, )), @@ -38,12 +40,12 @@ class FrpcDownloadDialogX { /// 开始下载 Get.dialog(_downloading(), barrierDismissible: false); final res = await FrpcDownloadDio().download( - arch: dsctr.arch[dsctr.frpcDownloadArch.value]['arch'], - platform: dsctr.platform, - version: '0.51.3', - progressCallback: dsctr.downloadFrpcCallback, - cancelToken: dsctr.downloadCancelToken, - useMirror: fcs.getSettingsGitHubMirror(), + arch: dsctr.arch[dsctr.frpcDownloadArch.value]['arch'], + platform: dsctr.platform, + version: '0.51.3', + progressCallback: dsctr.downloadFrpcCallback, + cancelToken: dsctr.downloadCancelToken, + useMirror: fcs.getSettingsGitHubMirror(), ); dsctr.frpcDownloadCancel = res; dsctr.refreshDownloadShow(); @@ -62,8 +64,8 @@ class FrpcDownloadDialogX { title: const Text('正在下载...'), children: [ Container( - margin: - const EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), + margin: const EdgeInsets.only( + left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), child: Column( children: [ Obx(() => Column(children: dsctr.frpcDownloadShow.value)), @@ -96,8 +98,8 @@ class FrpcDownloadDialogX { ), children: [ Container( - margin: - const EdgeInsets.only(left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), + margin: const EdgeInsets.only( + left: 40.0, right: 40.0, bottom: 10.0, top: 5.0), child: const Column( children: [ SizedBox( diff --git a/lib/ui/models/frpc_download_tip.dart b/lib/ui/models/frpc_download_tip.dart new file mode 100644 index 00000000..11ed2339 --- /dev/null +++ b/lib/ui/models/frpc_download_tip.dart @@ -0,0 +1,94 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:nyalcf/controllers/frpc_setting_controller.dart'; +import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; +import 'package:nyalcf/ui/models/frpc_download_dialog.dart'; +import 'package:nyalcf/utils/frpc/path_provider.dart'; + +class FrpcDownloadTip { + static final fcs = FrpcConfigurationStorage(); + static final FrpcSettingController fsctr = Get.find(); + + static Future tip({required context}) async => Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const ListTile( + leading: Icon(Icons.warning), + title: Text('尚未安装任何版本的 Frpc'), + ), + Container( + margin: + const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text('无法启动隧道了...呜呜...'), + Text('Frpc 文件路径:${await FrpcPathProvider.frpcPath ?? '未找到'}'), + Container( + margin: const EdgeInsets.only(top: 10.0), + child: Row( + children: [ + ElevatedButton( + onPressed: () async { + showDialog( + context: context, + builder: (context) { + return FrpcDownloadDialogX(context: context) + .build(); + }); + }, + child: const Text('下载'), + ), + ], + ), + ), + ], + ), + ) + ], + ), + ); + + static Future downloaded({required context}) async => Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const ListTile( + leading: Icon(Icons.check_circle), + title: Text('可用的 Frpc 版本已安装!素晴らしい!'), + ), + Container( + margin: + const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 10.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text('已安装版本列表:'), + Text(fcs.getInstalledVersions().toString()), + Text('Frpc 文件路径:${await FrpcPathProvider.frpcPath ?? '未找到'}'), + ], + ), + ), + Container( + margin: const EdgeInsets.only(left: 20.0, bottom: 20.0), + child: Row( + children: [ + ElevatedButton( + onPressed: () async { + showDialog( + context: context, + builder: (context) { + return FrpcDownloadDialogX(context: context) + .build(); + }); + }, + child: const Text('重新下载'), + ), + ], + ), + ), + ], + ), + ); +} diff --git a/lib/ui/models/ProcessListDialog.dart b/lib/ui/models/process_list_dialog.dart similarity index 91% rename from lib/ui/models/ProcessListDialog.dart rename to lib/ui/models/process_list_dialog.dart index f3bcf7e9..d05689b5 100644 --- a/lib/ui/models/ProcessListDialog.dart +++ b/lib/ui/models/process_list_dialog.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/consoleController.dart'; +import 'package:nyalcf/controllers/console_controller.dart'; class ProcessListDialogX { ProcessListDialogX({required this.context}); diff --git a/lib/ui/models/ToolDialog.dart b/lib/ui/models/tool_dialog.dart similarity index 100% rename from lib/ui/models/ToolDialog.dart rename to lib/ui/models/tool_dialog.dart diff --git a/lib/ui/views/auth/login.dart b/lib/ui/views/auth/login.dart index 24ca47e3..7921bdb9 100644 --- a/lib/ui/views/auth/login.dart +++ b/lib/ui/views/auth/login.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/utils/network/dio/auth/loginAuth.dart'; -import 'package:nyalcf/models/UserInfoModel.dart'; -import 'package:nyalcf/prefs/UserInfoPrefs.dart'; -import 'package:nyalcf/ui/models/AppbarActions.dart'; -import 'package:nyalcf/ui/models/FloatingActionButton.dart'; +import 'package:nyalcf/utils/network/dio/auth/login_auth.dart'; +import 'package:nyalcf/models/user_info_model.dart'; +import 'package:nyalcf/prefs/user_info_prefs.dart'; +import 'package:nyalcf/ui/models/appbar_actions.dart'; +import 'package:nyalcf/ui/models/floating_action_button.dart'; class Login extends StatefulWidget { const Login({super.key, required this.title}); diff --git a/lib/ui/views/auth/register.dart b/lib/ui/views/auth/register.dart index e09f49d1..c1092e06 100644 --- a/lib/ui/views/auth/register.dart +++ b/lib/ui/views/auth/register.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/utils/network/dio/auth/loginAuth.dart'; -import 'package:nyalcf/utils/network/dio/auth/registerAuth.dart'; -import 'package:nyalcf/models/UserInfoModel.dart'; -import 'package:nyalcf/prefs/UserInfoPrefs.dart'; -import 'package:nyalcf/ui/models/AppbarActions.dart'; -import 'package:nyalcf/ui/models/FloatingActionButton.dart'; +import 'package:nyalcf/utils/network/dio/auth/login_auth.dart'; +import 'package:nyalcf/utils/network/dio/auth/register_auth.dart'; +import 'package:nyalcf/models/user_info_model.dart'; +import 'package:nyalcf/prefs/user_info_prefs.dart'; +import 'package:nyalcf/ui/models/appbar_actions.dart'; +import 'package:nyalcf/ui/models/floating_action_button.dart'; class Register extends StatefulWidget { const Register({super.key, required this.title}); @@ -136,8 +136,8 @@ class _RegisterState extends State { '正在请求', '正在请求发送验证码', snackPosition: SnackPosition.BOTTOM, - animationDuration: - const Duration(milliseconds: 300), + animationDuration: const Duration( + milliseconds: 300), ); final res = await RegisterAuth() .requestCode( @@ -150,7 +150,8 @@ class _RegisterState extends State { snackPosition: SnackPosition.BOTTOM, animationDuration: - const Duration(milliseconds: 300), + const Duration( + milliseconds: 300), ); } else { Get.snackbar( @@ -159,7 +160,8 @@ class _RegisterState extends State { snackPosition: SnackPosition.BOTTOM, animationDuration: - const Duration(milliseconds: 300), + const Duration( + milliseconds: 300), ); } } else { @@ -168,8 +170,8 @@ class _RegisterState extends State { '发送失败,原因:${res.toString()}', snackPosition: SnackPosition.BOTTOM, - animationDuration: - const Duration(milliseconds: 300), + animationDuration: const Duration( + milliseconds: 300), ); } } else { @@ -177,8 +179,8 @@ class _RegisterState extends State { '操作失败', '请输入邮箱', snackPosition: SnackPosition.BOTTOM, - animationDuration: - const Duration(milliseconds: 300), + animationDuration: const Duration( + milliseconds: 300), ); } }, diff --git a/lib/ui/views/auth/tokenmode.dart b/lib/ui/views/auth/tokenmode.dart index 18cc0f3b..91b55e7c 100644 --- a/lib/ui/views/auth/tokenmode.dart +++ b/lib/ui/views/auth/tokenmode.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/prefs/TokenModePrefs.dart'; -import 'package:nyalcf/ui/models/AppbarActions.dart'; -import 'package:nyalcf/ui/models/FloatingActionButton.dart'; +import 'package:nyalcf/prefs/token_mode_prefs.dart'; +import 'package:nyalcf/ui/models/appbar_actions.dart'; +import 'package:nyalcf/ui/models/floating_action_button.dart'; class TokenModeAuth extends StatefulWidget { const TokenModeAuth({super.key, required this.title}); diff --git a/lib/ui/views/home.dart b/lib/ui/views/home.dart index 6d37e270..4cf125d5 100644 --- a/lib/ui/views/home.dart +++ b/lib/ui/views/home.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/frpcController.dart'; -import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/ui/models/AppbarActions.dart'; -import 'package:nyalcf/utils/network/dio/auth/userAuth.dart'; -import 'package:nyalcf/io/userInfoStorage.dart'; -import 'package:nyalcf/models/UserInfoModel.dart'; -import 'package:nyalcf/ui/models/FloatingActionButton.dart'; +import 'package:nyalcf/controllers/user_controller.dart'; +import 'package:nyalcf/ui/models/appbar_actions.dart'; +import 'package:nyalcf/utils/network/dio/auth/user_auth.dart'; +import 'package:nyalcf/io/user_info_storage.dart'; +import 'package:nyalcf/models/user_info_model.dart'; +import 'package:nyalcf/ui/models/floating_action_button.dart'; class Home extends StatelessWidget { Home({super.key, required this.title}); diff --git a/lib/ui/views/panel/console.dart b/lib/ui/views/panel/console.dart index d2046d8d..849749f6 100644 --- a/lib/ui/views/panel/console.dart +++ b/lib/ui/views/panel/console.dart @@ -1,14 +1,14 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/consoleController.dart'; +import 'package:nyalcf/controllers/console_controller.dart'; import 'package:nyalcf/controllers/frpcController.dart'; -import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/ui/models/AccountDialog.dart'; -import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/controllers/user_controller.dart'; +import 'package:nyalcf/ui/models/account_dialog.dart'; +import 'package:nyalcf/ui/models/appbar_actions.dart'; import 'package:nyalcf/ui/models/Drawer.dart'; -import 'package:nyalcf/ui/models/FloatingActionButton.dart'; -import 'package:nyalcf/ui/models/ProcessListDialog.dart'; -import 'package:nyalcf/utils/frpc/ProcessManager.dart'; +import 'package:nyalcf/ui/models/floating_action_button.dart'; +import 'package:nyalcf/ui/models/process_list_dialog.dart'; +import 'package:nyalcf/utils/frpc/process_manager.dart'; class PanelConsole extends StatelessWidget { PanelConsole({super.key, required this.title}); diff --git a/lib/ui/views/panel/home.dart b/lib/ui/views/panel/home.dart index 339f67af..18faad3a 100644 --- a/lib/ui/views/panel/home.dart +++ b/lib/ui/views/panel/home.dart @@ -2,14 +2,14 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/consoleController.dart'; -import 'package:nyalcf/controllers/panelController.dart'; -import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/ui/models/AccountDialog.dart'; -import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/controllers/console_controller.dart'; +import 'package:nyalcf/controllers/panel_controller.dart'; +import 'package:nyalcf/controllers/user_controller.dart'; +import 'package:nyalcf/ui/models/account_dialog.dart'; +import 'package:nyalcf/ui/models/appbar_actions.dart'; import 'package:nyalcf/ui/models/Drawer.dart'; -import 'package:nyalcf/ui/models/FloatingActionButton.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/ui/models/floating_action_button.dart'; +import 'package:nyalcf/utils/logger.dart'; import 'package:url_launcher/url_launcher.dart'; class PanelHome extends StatelessWidget { diff --git a/lib/ui/views/panel/proxies.dart b/lib/ui/views/panel/proxies.dart index 30085f33..0556069a 100644 --- a/lib/ui/views/panel/proxies.dart +++ b/lib/ui/views/panel/proxies.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/proxiesController.dart'; -import 'package:nyalcf/controllers/userController.dart'; -import 'package:nyalcf/ui/models/AccountDialog.dart'; -import 'package:nyalcf/ui/models/AppbarActions.dart'; +import 'package:nyalcf/controllers/proxies_controller.dart'; +import 'package:nyalcf/controllers/user_controller.dart'; +import 'package:nyalcf/ui/models/account_dialog.dart'; +import 'package:nyalcf/ui/models/appbar_actions.dart'; import 'package:nyalcf/ui/models/Drawer.dart'; -import 'package:nyalcf/ui/models/FloatingActionButton.dart'; +import 'package:nyalcf/ui/models/floating_action_button.dart'; class PanelProxies extends StatelessWidget { PanelProxies({super.key, required this.title}); diff --git a/lib/ui/views/setting/frpcSetting.dart b/lib/ui/views/setting/frpc_setting.dart similarity index 89% rename from lib/ui/views/setting/frpcSetting.dart rename to lib/ui/views/setting/frpc_setting.dart index aa2e3fd4..eb272ad5 100644 --- a/lib/ui/views/setting/frpcSetting.dart +++ b/lib/ui/views/setting/frpc_setting.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/frpcSettingController.dart'; -import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; +import 'package:nyalcf/controllers/frpc_setting_controller.dart'; +import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; class FrpcSetting { FrpcSetting({required this.context}); @@ -25,8 +25,8 @@ class FrpcSetting { title: Text('下载源镜像设置'), ), Container( - margin: - const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + margin: const EdgeInsets.only( + left: 20.0, right: 20.0, bottom: 20.0), child: Obx( () => Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/ui/views/setting/injector.dart b/lib/ui/views/setting/injector.dart index 646bca79..4c310e1c 100644 --- a/lib/ui/views/setting/injector.dart +++ b/lib/ui/views/setting/injector.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/frpcSettingController.dart'; -import 'package:nyalcf/controllers/launcherSettingController.dart'; -import 'package:nyalcf/ui/models/AppbarActions.dart'; -import 'package:nyalcf/ui/models/FloatingActionButton.dart'; -import 'package:nyalcf/ui/views/setting/frpcSetting.dart'; -import 'package:nyalcf/ui/views/setting/launcherSetting.dart'; +import 'package:nyalcf/controllers/frpc_setting_controller.dart'; +import 'package:nyalcf/controllers/launcher_setting_controller.dart'; +import 'package:nyalcf/ui/models/appbar_actions.dart'; +import 'package:nyalcf/ui/models/floating_action_button.dart'; +import 'package:nyalcf/ui/views/setting/frpc_setting.dart'; +import 'package:nyalcf/ui/views/setting/launcher_setting.dart'; class SettingInjector extends StatelessWidget { const SettingInjector({super.key, required this.title}); diff --git a/lib/ui/views/setting/launcherSetting.dart b/lib/ui/views/setting/launcher_setting.dart similarity index 92% rename from lib/ui/views/setting/launcherSetting.dart rename to lib/ui/views/setting/launcher_setting.dart index 72e703bf..b5319389 100644 --- a/lib/ui/views/setting/launcherSetting.dart +++ b/lib/ui/views/setting/launcher_setting.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/launcherSettingController.dart'; -import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart'; +import 'package:nyalcf/controllers/launcher_setting_controller.dart'; +import 'package:nyalcf/storages/configurations/launcher_configuration_storage.dart'; import 'package:url_launcher/url_launcher.dart'; class LauncherSetting { @@ -22,8 +22,8 @@ class LauncherSetting { title: Text('主题'), ), Container( - margin: - const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + margin: const EdgeInsets.only( + left: 20.0, right: 20.0, bottom: 20.0), padding: const EdgeInsets.only(left: 30.0, right: 50.0), child: Obx( () => Column( @@ -99,8 +99,8 @@ class LauncherSetting { title: Text('调试'), ), Container( - margin: - const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + margin: const EdgeInsets.only( + left: 20.0, right: 20.0, bottom: 20.0), padding: const EdgeInsets.only(left: 30.0, right: 50.0), child: Obx( () => Column( @@ -146,8 +146,8 @@ class LauncherSetting { title: Text('软件信息'), ), Container( - margin: - const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + margin: const EdgeInsets.only( + left: 20.0, right: 20.0, bottom: 20.0), child: Obx( () => Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -188,8 +188,8 @@ class LauncherSetting { title: Text('帮助我们做的更好'), ), Container( - margin: - const EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), + margin: const EdgeInsets.only( + left: 20.0, right: 20.0, bottom: 20.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -211,7 +211,8 @@ class LauncherSetting { '发生错误', '无法打开网页,请检查设备是否存在WebView', snackPosition: SnackPosition.BOTTOM, - animationDuration: const Duration(milliseconds: 300), + animationDuration: + const Duration(milliseconds: 300), ); } }, diff --git a/lib/ui/views/tokenmode/panel.dart b/lib/ui/views/tokenmode/panel.dart index aa131c1c..230305fe 100644 --- a/lib/ui/views/tokenmode/panel.dart +++ b/lib/ui/views/tokenmode/panel.dart @@ -1,15 +1,14 @@ -import 'dart:io'; - import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/consoleController.dart'; +import 'package:nyalcf/controllers/console_controller.dart'; import 'package:nyalcf/controllers/frpcController.dart'; -import 'package:nyalcf/prefs/TokenModePrefs.dart'; -import 'package:nyalcf/storages/configurations/FrpcConfigurationStorage.dart'; -import 'package:nyalcf/ui/models/AppbarActions.dart'; -import 'package:nyalcf/ui/models/FloatingActionButton.dart'; -import 'package:nyalcf/ui/models/ProcessListDialog.dart'; -import 'package:nyalcf/utils/frpc/ProcessManager.dart'; +import 'package:nyalcf/prefs/token_mode_prefs.dart'; +import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; +import 'package:nyalcf/ui/models/appbar_actions.dart'; +import 'package:nyalcf/ui/models/floating_action_button.dart'; +import 'package:nyalcf/ui/models/process_list_dialog.dart'; +import 'package:nyalcf/utils/frpc/path_provider.dart'; +import 'package:nyalcf/utils/frpc/process_manager.dart'; class TokenModePanel extends StatefulWidget { const TokenModePanel({super.key, required this.title}); @@ -87,60 +86,30 @@ class _TokenModePanelState extends State { // 判断frp_token是否为空 if (frpToken != null) { if (proxyController.text != '') { - // 检测是否定义了环境变量 - if (fctr.customPath == null) { - // 无环境变量已安装Frpc - if (fcs - .getInstalledVersions() - .isNotEmpty) { - FrpcProcessManager().nwprcs( - frpToken: frpToken, - proxyId: int.parse(proxyController.text), - ); - Get.snackbar( - '启动命令已发出', - '请查看控制台确认是否启动成功', - snackPosition: SnackPosition.BOTTOM, - animationDuration: const Duration(milliseconds: 300), - ); - // 无环境变量未安装Frpc - } else { - Get.snackbar( - '笨..笨蛋!', - '你还没有安装Frpc!请先到 设置->FRPC 安装Frpc才能启动喵!', - snackPosition: SnackPosition.BOTTOM, - animationDuration: const Duration(milliseconds: 300), - ); - } - // 有环境变量未安装Frpc - } else if (await File(fctr.customPath!).exists()) { + final execPath = await FrpcPathProvider.frpcPath; + if (execPath != null) { FrpcProcessManager().nwprcs( - frpcPath: fctr.customPath, frpToken: frpToken, proxyId: int.parse(proxyController.text), + frpcPath: execPath, ); Get.snackbar( '启动命令已发出', '请查看控制台确认是否启动成功', snackPosition: SnackPosition.BOTTOM, - animationDuration: const Duration(milliseconds: 300), + animationDuration: + const Duration(milliseconds: 300), ); - // 有环境变量未安装Frpc,但文件不存在 + // 无环境变量未安装Frpc } else { Get.snackbar( '笨..笨蛋!', - '你的环境变量是无效哒!猫猫都要找晕啦!', + '你还没有安装Frpc!请先到 设置->FRPC 安装Frpc才能启动喵!', snackPosition: SnackPosition.BOTTOM, - animationDuration: const Duration(milliseconds: 300), + animationDuration: + const Duration(milliseconds: 300), ); } - } else { - Get.snackbar( - '发生错误', - '内部错误,请重新登录', - snackPosition: SnackPosition.BOTTOM, - animationDuration: const Duration(milliseconds: 300), - ); } } }, diff --git a/lib/utils/CPUArch.dart b/lib/utils/cpu_arch.dart similarity index 100% rename from lib/utils/CPUArch.dart rename to lib/utils/cpu_arch.dart diff --git a/lib/utils/FileConfiguration.dart b/lib/utils/file_configuration.dart similarity index 99% rename from lib/utils/FileConfiguration.dart rename to lib/utils/file_configuration.dart index 99050fae..56c7aecb 100644 --- a/lib/utils/FileConfiguration.dart +++ b/lib/utils/file_configuration.dart @@ -17,6 +17,7 @@ class FileConfiguration { void initMap() { tmpData[handle] = {}; } + /// 一堆B方法 /// 气死我里 /// String diff --git a/lib/utils/frpc/Archive.dart b/lib/utils/frpc/archive.dart similarity index 83% rename from lib/utils/frpc/Archive.dart rename to lib/utils/frpc/archive.dart index 4966c801..51f4c411 100644 --- a/lib/utils/frpc/Archive.dart +++ b/lib/utils/frpc/archive.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:archive/archive_io.dart'; -import 'package:nyalcf/utils/PathProvider.dart'; +import 'package:nyalcf/utils/path_provider.dart'; class FrpcArchive { static final _cachePath = PathProvider.appCachePath; @@ -24,8 +24,8 @@ class FrpcArchive { /// 确认 Frpc 是否存在 if (await f.exists()) { extractFileToDisk(f.path, _cachePath!); - final dir = Directory( - '$_cachePath/frp_LoCyanFrp-${version}_${platform}_$arch'); + final dir = + Directory('$_cachePath/frp_LoCyanFrp-${version}_${platform}_$arch'); PathProvider.moveDirectory(dir, Directory('$_supportPath/frpc/$version')); return true; } else { diff --git a/lib/utils/frpc/path_provider.dart b/lib/utils/frpc/path_provider.dart new file mode 100644 index 00000000..41dfb486 --- /dev/null +++ b/lib/utils/frpc/path_provider.dart @@ -0,0 +1,18 @@ +import 'dart:io'; + +import 'package:nyalcf/storages/stories/frpc_story_storage.dart'; + +class FrpcPathProvider { + static final Future frpcWorkPath = FrpcStoryStorage.getRunPath(); + static Future get frpcPath async { + final String? path; + final String? appFrpcPath = await FrpcStoryStorage.getFilePath(); + final String? envFrpcPath = Platform.environment['NYA_LCF_FRPC_PATH']; + if (envFrpcPath != null) { + path = envFrpcPath; + } else { + path = appFrpcPath; + } + return path; + } +} diff --git a/lib/utils/frpc/ProcessManager.dart b/lib/utils/frpc/process_manager.dart similarity index 88% rename from lib/utils/frpc/ProcessManager.dart rename to lib/utils/frpc/process_manager.dart index 520af002..94000306 100644 --- a/lib/utils/frpc/ProcessManager.dart +++ b/lib/utils/frpc/process_manager.dart @@ -2,22 +2,21 @@ import 'dart:convert'; import 'dart:io'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/consoleController.dart'; +import 'package:nyalcf/controllers/console_controller.dart'; import 'package:nyalcf/controllers/frpcController.dart'; -import 'package:nyalcf/storages/configurations/ProxiesConfigurationStorage.dart'; -import 'package:nyalcf/storages/stories/FrpcStoryStorage.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/storages/configurations/proxies_configuration_storage.dart'; +import 'package:nyalcf/storages/stories/frpc_story_storage.dart'; +import 'package:nyalcf/utils/frpc/path_provider.dart'; +import 'package:nyalcf/utils/logger.dart'; class FrpcProcessManager { final FrpcController fctr = Get.find(); final ConsoleController cctr = Get.find(); - final Future frpcWorkPath = FrpcStoryStorage.getRunPath(); - void nwprcs({ required String frpToken, required int proxyId, - String? frpcPath, + required String frpcPath, }) async { if (Platform.isLinux) { Logger.info('Linux platform, change file permission'); @@ -40,7 +39,7 @@ class FrpcProcessManager { } final Process process = await Process.start( - frpcPath ?? await FrpcStoryStorage.getFilePath(), + frpcPath, arguments, workingDirectory: await FrpcStoryStorage.getRunPath(), ); diff --git a/lib/utils/frpc/StartUpLoader.dart b/lib/utils/frpc/startup_loader.dart similarity index 100% rename from lib/utils/frpc/StartUpLoader.dart rename to lib/utils/frpc/startup_loader.dart diff --git a/lib/utils/Logger.dart b/lib/utils/logger.dart similarity index 94% rename from lib/utils/Logger.dart rename to lib/utils/logger.dart index c1dc09be..cff23f22 100644 --- a/lib/utils/Logger.dart +++ b/lib/utils/logger.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'package:logger/logger.dart' as LoU; -import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart'; -import 'package:nyalcf/utils/PathProvider.dart'; +import 'package:nyalcf/storages/configurations/launcher_configuration_storage.dart'; +import 'package:nyalcf/utils/path_provider.dart'; class Logger { static final String? _supportPath = PathProvider.appSupportPath; diff --git a/lib/utils/network/dio/auth/loginAuth.dart b/lib/utils/network/dio/auth/login_auth.dart similarity index 78% rename from lib/utils/network/dio/auth/loginAuth.dart rename to lib/utils/network/dio/auth/login_auth.dart index 4963d1e0..deefbedd 100644 --- a/lib/utils/network/dio/auth/loginAuth.dart +++ b/lib/utils/network/dio/auth/login_auth.dart @@ -1,7 +1,7 @@ import 'package:dio/dio.dart'; -import 'package:nyalcf/utils/Logger.dart'; -import 'package:nyalcf/models/UserInfoModel.dart'; -import 'package:nyalcf/utils/network/dio/basicConfig.dart'; +import 'package:nyalcf/utils/logger.dart'; +import 'package:nyalcf/models/user_info_model.dart'; +import 'package:nyalcf/utils/network/dio/basic_config.dart'; class LoginAuth { final dio = Dio(); @@ -10,8 +10,8 @@ class LoginAuth { FormData data = FormData.fromMap({'username': user, 'password': password}); try { Logger.debug('Post login: $user / $password'); - final response = - await dio.post('${BasicDioConfig.api_v2_url}/users/login', data: data); + final response = await dio + .post('${BasicDioConfig.api_v2_url}/users/login', data: data); Map responseJson = response.data; Logger.debug(responseJson); final resData = responseJson['data']; diff --git a/lib/utils/network/dio/auth/registerAuth.dart b/lib/utils/network/dio/auth/register_auth.dart similarity index 93% rename from lib/utils/network/dio/auth/registerAuth.dart rename to lib/utils/network/dio/auth/register_auth.dart index 3b1e4aaf..11399a55 100644 --- a/lib/utils/network/dio/auth/registerAuth.dart +++ b/lib/utils/network/dio/auth/register_auth.dart @@ -1,7 +1,7 @@ import 'package:dio/dio.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/utils/logger.dart'; -import 'package:nyalcf/utils/network/dio/basicConfig.dart'; +import 'package:nyalcf/utils/network/dio/basic_config.dart'; class RegisterAuth { final dio = Dio(); diff --git a/lib/utils/network/dio/auth/userAuth.dart b/lib/utils/network/dio/auth/user_auth.dart similarity index 90% rename from lib/utils/network/dio/auth/userAuth.dart rename to lib/utils/network/dio/auth/user_auth.dart index d48e91c8..69ad01d0 100644 --- a/lib/utils/network/dio/auth/userAuth.dart +++ b/lib/utils/network/dio/auth/user_auth.dart @@ -1,7 +1,7 @@ import 'package:dio/dio.dart'; -import 'package:nyalcf/prefs/UserInfoPrefs.dart'; -import 'package:nyalcf/utils/Logger.dart'; -import 'package:nyalcf/utils/network/dio/basicConfig.dart'; +import 'package:nyalcf/prefs/user_info_prefs.dart'; +import 'package:nyalcf/utils/logger.dart'; +import 'package:nyalcf/utils/network/dio/basic_config.dart'; class UserAuth { final dio = Dio(); diff --git a/lib/utils/network/dio/basicConfig.dart b/lib/utils/network/dio/basic_config.dart similarity index 100% rename from lib/utils/network/dio/basicConfig.dart rename to lib/utils/network/dio/basic_config.dart diff --git a/lib/utils/network/dio/frpc/download.dart b/lib/utils/network/dio/frpc/download.dart index 1e7ebffd..a7106d11 100644 --- a/lib/utils/network/dio/frpc/download.dart +++ b/lib/utils/network/dio/frpc/download.dart @@ -1,7 +1,7 @@ import 'package:dio/dio.dart'; -import 'package:nyalcf/utils/network/dio/basicConfig.dart'; -import 'package:nyalcf/utils/PathProvider.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/utils/network/dio/basic_config.dart'; +import 'package:nyalcf/utils/path_provider.dart'; +import 'package:nyalcf/utils/logger.dart'; class FrpcDownloadDio { final dio = Dio(); diff --git a/lib/utils/network/dio/launcher/update.dart b/lib/utils/network/dio/launcher/update.dart index bb8a702c..045a45b7 100644 --- a/lib/utils/network/dio/launcher/update.dart +++ b/lib/utils/network/dio/launcher/update.dart @@ -1,7 +1,7 @@ import 'package:dio/dio.dart'; -import 'package:nyalcf/utils/network/dio/basicConfig.dart'; -import 'package:nyalcf/models/UpdateInfoModel.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/utils/network/dio/basic_config.dart'; +import 'package:nyalcf/models/update_info_model.dart'; +import 'package:nyalcf/utils/logger.dart'; class LauncherUpdateDio { final dio = Dio(); diff --git a/lib/utils/network/dio/other/announcement.dart b/lib/utils/network/dio/other/announcement.dart index 79c78af4..ca7639fd 100644 --- a/lib/utils/network/dio/other/announcement.dart +++ b/lib/utils/network/dio/other/announcement.dart @@ -1,6 +1,6 @@ import 'package:dio/dio.dart'; -import 'package:nyalcf/utils/Logger.dart'; -import 'package:nyalcf/utils/network/dio/basicConfig.dart'; +import 'package:nyalcf/utils/logger.dart'; +import 'package:nyalcf/utils/network/dio/basic_config.dart'; class AnnouncementDio { final dio = Dio(); diff --git a/lib/utils/network/dio/proxies/configuration.dart b/lib/utils/network/dio/proxies/configuration.dart index 81623067..b8a67f28 100644 --- a/lib/utils/network/dio/proxies/configuration.dart +++ b/lib/utils/network/dio/proxies/configuration.dart @@ -1,8 +1,8 @@ import 'dart:convert'; import 'package:dio/dio.dart'; -import 'package:nyalcf/utils/network/dio/basicConfig.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/utils/network/dio/basic_config.dart'; +import 'package:nyalcf/utils/logger.dart'; class ProxiesConfigurationDio { final dio = Dio(); diff --git a/lib/utils/network/dio/proxies/get.dart b/lib/utils/network/dio/proxies/get.dart index a5167c55..e3463ca3 100644 --- a/lib/utils/network/dio/proxies/get.dart +++ b/lib/utils/network/dio/proxies/get.dart @@ -1,7 +1,7 @@ import 'package:dio/dio.dart'; -import 'package:nyalcf/utils/network/dio/basicConfig.dart'; -import 'package:nyalcf/models/ProxyInfoModel.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/utils/network/dio/basic_config.dart'; +import 'package:nyalcf/models/proxy_info_model.dart'; +import 'package:nyalcf/utils/logger.dart'; class ProxiesGetDio { final dio = Dio(); diff --git a/lib/utils/PathProvider.dart b/lib/utils/path_provider.dart similarity index 97% rename from lib/utils/PathProvider.dart rename to lib/utils/path_provider.dart index f1ed5f23..65c968fc 100644 --- a/lib/utils/PathProvider.dart +++ b/lib/utils/path_provider.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/utils/logger.dart'; import 'package:path_provider/path_provider.dart'; class PathProvider { diff --git a/lib/utils/ThemeControl.dart b/lib/utils/theme_control.dart similarity index 92% rename from lib/utils/ThemeControl.dart rename to lib/utils/theme_control.dart index f214f9f0..8c0025a4 100644 --- a/lib/utils/ThemeControl.dart +++ b/lib/utils/theme_control.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/storages/configurations/LauncherConfigurationStorage.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/storages/configurations/launcher_configuration_storage.dart'; +import 'package:nyalcf/utils/logger.dart'; class ThemeControl { static final lcs = LauncherConfigurationStorage(); diff --git a/lib/utils/Updater.dart b/lib/utils/updater.dart similarity index 98% rename from lib/utils/Updater.dart rename to lib/utils/updater.dart index aaeb576b..a9a6f08e 100644 --- a/lib/utils/Updater.dart +++ b/lib/utils/updater.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/utils/network/dio/launcher/update.dart'; -import 'package:nyalcf/utils/Logger.dart'; +import 'package:nyalcf/utils/logger.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:url_launcher/url_launcher.dart'; From 353be49800f8eba79a22bca2c23166f35009caae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Wed, 14 Feb 2024 10:23:31 +0800 Subject: [PATCH 06/10] [*]Unknown bug? --- lib/controllers/frpc_setting_controller.dart | 80 ++++---------------- lib/ui/models/frpc_download_dialog.dart | 1 + 2 files changed, 14 insertions(+), 67 deletions(-) diff --git a/lib/controllers/frpc_setting_controller.dart b/lib/controllers/frpc_setting_controller.dart index 96eb45b4..c1754d99 100644 --- a/lib/controllers/frpc_setting_controller.dart +++ b/lib/controllers/frpc_setting_controller.dart @@ -28,7 +28,7 @@ class FrpcSettingController extends GetxController { var frpcDownloadArch = 0.obs; var frpcDownloadProgress = 0.0.obs; var frpcDownloadShow = [].obs; - dynamic frpcDownloadCancel = false; + bool frpcDownloadCancel = false; var frpcDownloadUseMirror = false.obs; var frpcVersion = ''.obs; @@ -64,76 +64,22 @@ class FrpcSettingController extends GetxController { } void refreshDownloadShow() async { - if (frpcDownloadCancel is bool) { - if (frpcDownloadCancel) { - frpcDownloadShow.clear(); - frpcDownloadShow.add(const Text( - '下载取消', - style: TextStyle(color: Colors.orange), - )); - frpcDownloadCancel = false; - downloadCancelToken = CancelToken(); - } else { - frpcDownloadShow.clear(); - frpcDownloadShow.add(LinearProgressIndicator( - value: frpcDownloadProgress.value, - )); - } - } else if (frpcDownloadCancel is Response) { - Get.close(0); - /*await showDialog( - context: context, - builder: (context) { - return FrpcDownloadDialogX(context: context).unarchiving(); - });*/ - Get.dialog(FrpcDownloadDialogX(context: context).unarchiving(), - barrierDismissible: false); - Future.delayed( - const Duration(seconds: 2), - () async { - //延时执行 - final bool unarchive = await FrpcArchive.unarchive( - platform: platform, - arch: arch[frpcDownloadArch.value]['arch'], - version: fcs.getSettingsFrpcVersion(), - ); - if (unarchive) { - fcs.setSettingsFrpcVersion('0.51.3'); - fcs.addInstalledVersion('0.51.3'); - fcs.save(); - /**if (!Platform.isWindows) { - print('*nix platform, change file permission'); - await FrpcManagerStorage.setRunPermission(); - }*/ - _loadTip(); - } else { - Get.snackbar( - '解压 Frpc 时发生错误..呜呜..', - '请检查磁盘是否被塞满了..或者是已经安装了!受不了了呜呜呜...', - snackPosition: SnackPosition.BOTTOM, - animationDuration: const Duration(milliseconds: 300), - ); - } - - /// 关闭对话框 - Get.close(0); - Get.close(0); - }, - ); - } else { + if (frpcDownloadCancel) { + Logger.debug('Download cancelled.'); frpcDownloadShow.clear(); frpcDownloadShow.add(const Text( - '发生错误', - style: TextStyle(color: Colors.red), + '下载取消', + style: TextStyle(color: Colors.orange), + )); + frpcDownloadCancel = false; + downloadCancelToken = CancelToken(); + } else { + frpcDownloadShow.clear(); + frpcDownloadShow.add(LinearProgressIndicator( + value: frpcDownloadProgress.value, )); - Get.snackbar( - '下载 Frpc 时发生错误..呜呜..', - frpcDownloadCancel.toString(), - snackPosition: SnackPosition.BOTTOM, - animationDuration: const Duration(milliseconds: 300), - ); } - } + } /// 构建Arch列表 List> _buildArchDMIWidgetList() { diff --git a/lib/ui/models/frpc_download_dialog.dart b/lib/ui/models/frpc_download_dialog.dart index 669605e5..4713f15d 100644 --- a/lib/ui/models/frpc_download_dialog.dart +++ b/lib/ui/models/frpc_download_dialog.dart @@ -74,6 +74,7 @@ class FrpcDownloadDialogX { ElevatedButton( onPressed: () async { dsctr.downloadCancelToken.cancel(); + dsctr.refreshDownloadShow(); Get.close(0); }, child: const Text('取消'), From 7b2985a435a1ad561139b9810e1af8dc7a8b35cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Wed, 14 Feb 2024 10:26:17 +0800 Subject: [PATCH 07/10] [*]Dart fix --- lib/controllers/frpcController.dart | 1 - lib/controllers/frpc_setting_controller.dart | 2 -- lib/io/user_info_storage.dart | 2 +- lib/utils/frpc/process_manager.dart | 1 - 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/controllers/frpcController.dart b/lib/controllers/frpcController.dart index c5a66a3e..33c0b201 100644 --- a/lib/controllers/frpcController.dart +++ b/lib/controllers/frpcController.dart @@ -1,4 +1,3 @@ -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; diff --git a/lib/controllers/frpc_setting_controller.dart b/lib/controllers/frpc_setting_controller.dart index c1754d99..40cf86f4 100644 --- a/lib/controllers/frpc_setting_controller.dart +++ b/lib/controllers/frpc_setting_controller.dart @@ -6,10 +6,8 @@ import 'package:get/get.dart' hide Response; import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; import 'package:nyalcf/utils/frpc/path_provider.dart'; import 'package:nyalcf/utils/logger.dart'; -import 'package:nyalcf/ui/models/frpc_download_dialog.dart'; import 'package:nyalcf/ui/models/frpc_download_tip.dart'; import 'package:nyalcf/utils/cpu_arch.dart'; -import 'package:nyalcf/utils/frpc/Archive.dart'; class FrpcSettingController extends GetxController { FrpcSettingController({required this.context}); diff --git a/lib/io/user_info_storage.dart b/lib/io/user_info_storage.dart index 0519ad92..0d4b82cb 100644 --- a/lib/io/user_info_storage.dart +++ b/lib/io/user_info_storage.dart @@ -17,7 +17,7 @@ class UserInfoStorage { /// 读取数据 static Future read() async { try { - final String result = await File('${await _path}/session.json') + final String result = await File('$_path/session.json') .readAsString(encoding: utf8); return UserInfoModel.fromJson(jsonDecode(result)); } catch (e) { diff --git a/lib/utils/frpc/process_manager.dart b/lib/utils/frpc/process_manager.dart index 94000306..06748c09 100644 --- a/lib/utils/frpc/process_manager.dart +++ b/lib/utils/frpc/process_manager.dart @@ -6,7 +6,6 @@ import 'package:nyalcf/controllers/console_controller.dart'; import 'package:nyalcf/controllers/frpcController.dart'; import 'package:nyalcf/storages/configurations/proxies_configuration_storage.dart'; import 'package:nyalcf/storages/stories/frpc_story_storage.dart'; -import 'package:nyalcf/utils/frpc/path_provider.dart'; import 'package:nyalcf/utils/logger.dart'; class FrpcProcessManager { From ea8e33bb2c74cee3d36566da3e9f2440df2d12d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Wed, 14 Feb 2024 10:36:49 +0800 Subject: [PATCH 08/10] [*]Fix build for linux --- ...pcController.dart => frpc_controller.dart} | 0 lib/controllers/panel_controller.dart | 4 ++-- lib/controllers/proxies_controller.dart | 2 +- lib/ui/views/home.dart | 2 +- lib/ui/views/panel/console.dart | 4 ++-- lib/ui/views/panel/home.dart | 4 ++-- lib/ui/views/panel/proxies.dart | 2 +- lib/ui/views/tokenmode/panel.dart | 2 +- lib/utils/frpc/process_manager.dart | 2 +- lib/utils/logger.dart | 24 +++++++++---------- 10 files changed, 23 insertions(+), 23 deletions(-) rename lib/controllers/{frpcController.dart => frpc_controller.dart} (100%) diff --git a/lib/controllers/frpcController.dart b/lib/controllers/frpc_controller.dart similarity index 100% rename from lib/controllers/frpcController.dart rename to lib/controllers/frpc_controller.dart diff --git a/lib/controllers/panel_controller.dart b/lib/controllers/panel_controller.dart index 9d322d91..3ab46259 100644 --- a/lib/controllers/panel_controller.dart +++ b/lib/controllers/panel_controller.dart @@ -3,10 +3,10 @@ import 'package:nyalcf/utils/network/dio/other/announcement.dart'; class DPanelController extends GetxController { var announcement = '喵喵喵?正在请求捏'.obs; - var announcement_common = '喵喵喵?正在请求捏'.obs; + var announcementCommon = '喵喵喵?正在请求捏'.obs; load() async { announcement.value = await AnnouncementDio().getBroadcast(); - announcement_common.value = await AnnouncementDio().getCommon(); + announcementCommon.value = await AnnouncementDio().getCommon(); } } diff --git a/lib/controllers/proxies_controller.dart b/lib/controllers/proxies_controller.dart index 42229291..35eda12f 100644 --- a/lib/controllers/proxies_controller.dart +++ b/lib/controllers/proxies_controller.dart @@ -13,7 +13,7 @@ import 'package:nyalcf/models/proxy_info_model.dart'; import 'package:nyalcf/ui/models/frpc_configuration_editor_dialog.dart'; import 'package:nyalcf/utils/logger.dart'; import 'package:nyalcf/utils/frpc/process_manager.dart'; -import 'package:nyalcf/controllers/frpcController.dart'; +import 'package:nyalcf/controllers/frpc_controller.dart'; /// 代理 GetX 状态控制器 class ProxiesController extends GetxController { diff --git a/lib/ui/views/home.dart b/lib/ui/views/home.dart index 4cf125d5..3a99658e 100644 --- a/lib/ui/views/home.dart +++ b/lib/ui/views/home.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controllers/frpcController.dart'; +import 'package:nyalcf/controllers/frpc_controller.dart'; import 'package:nyalcf/controllers/user_controller.dart'; import 'package:nyalcf/ui/models/appbar_actions.dart'; import 'package:nyalcf/utils/network/dio/auth/user_auth.dart'; diff --git a/lib/ui/views/panel/console.dart b/lib/ui/views/panel/console.dart index 849749f6..3943273b 100644 --- a/lib/ui/views/panel/console.dart +++ b/lib/ui/views/panel/console.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/console_controller.dart'; -import 'package:nyalcf/controllers/frpcController.dart'; +import 'package:nyalcf/controllers/frpc_controller.dart'; import 'package:nyalcf/controllers/user_controller.dart'; import 'package:nyalcf/ui/models/account_dialog.dart'; import 'package:nyalcf/ui/models/appbar_actions.dart'; -import 'package:nyalcf/ui/models/Drawer.dart'; +import 'package:nyalcf/ui/models/drawer.dart'; import 'package:nyalcf/ui/models/floating_action_button.dart'; import 'package:nyalcf/ui/models/process_list_dialog.dart'; import 'package:nyalcf/utils/frpc/process_manager.dart'; diff --git a/lib/ui/views/panel/home.dart b/lib/ui/views/panel/home.dart index 18faad3a..30fa2241 100644 --- a/lib/ui/views/panel/home.dart +++ b/lib/ui/views/panel/home.dart @@ -7,7 +7,7 @@ import 'package:nyalcf/controllers/panel_controller.dart'; import 'package:nyalcf/controllers/user_controller.dart'; import 'package:nyalcf/ui/models/account_dialog.dart'; import 'package:nyalcf/ui/models/appbar_actions.dart'; -import 'package:nyalcf/ui/models/Drawer.dart'; +import 'package:nyalcf/ui/models/drawer.dart'; import 'package:nyalcf/ui/models/floating_action_button.dart'; import 'package:nyalcf/utils/logger.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -170,7 +170,7 @@ class PanelHome extends StatelessWidget { launchUrl(Uri.parse(url)); } }, - data: '${dpctr.announcement_common}')))) + data: '${dpctr.announcementCommon}')))) ], ), ), diff --git a/lib/ui/views/panel/proxies.dart b/lib/ui/views/panel/proxies.dart index 0556069a..d12d9fc4 100644 --- a/lib/ui/views/panel/proxies.dart +++ b/lib/ui/views/panel/proxies.dart @@ -4,7 +4,7 @@ import 'package:nyalcf/controllers/proxies_controller.dart'; import 'package:nyalcf/controllers/user_controller.dart'; import 'package:nyalcf/ui/models/account_dialog.dart'; import 'package:nyalcf/ui/models/appbar_actions.dart'; -import 'package:nyalcf/ui/models/Drawer.dart'; +import 'package:nyalcf/ui/models/drawer.dart'; import 'package:nyalcf/ui/models/floating_action_button.dart'; class PanelProxies extends StatelessWidget { diff --git a/lib/ui/views/tokenmode/panel.dart b/lib/ui/views/tokenmode/panel.dart index 230305fe..a42d185a 100644 --- a/lib/ui/views/tokenmode/panel.dart +++ b/lib/ui/views/tokenmode/panel.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/console_controller.dart'; -import 'package:nyalcf/controllers/frpcController.dart'; +import 'package:nyalcf/controllers/frpc_controller.dart'; import 'package:nyalcf/prefs/token_mode_prefs.dart'; import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; import 'package:nyalcf/ui/models/appbar_actions.dart'; diff --git a/lib/utils/frpc/process_manager.dart b/lib/utils/frpc/process_manager.dart index 06748c09..6772eff9 100644 --- a/lib/utils/frpc/process_manager.dart +++ b/lib/utils/frpc/process_manager.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'package:get/get.dart'; import 'package:nyalcf/controllers/console_controller.dart'; -import 'package:nyalcf/controllers/frpcController.dart'; +import 'package:nyalcf/controllers/frpc_controller.dart'; import 'package:nyalcf/storages/configurations/proxies_configuration_storage.dart'; import 'package:nyalcf/storages/stories/frpc_story_storage.dart'; import 'package:nyalcf/utils/logger.dart'; diff --git a/lib/utils/logger.dart b/lib/utils/logger.dart index cff23f22..742ec8ba 100644 --- a/lib/utils/logger.dart +++ b/lib/utils/logger.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:logger/logger.dart' as LoU; +import 'package:logger/logger.dart' as log_u; import 'package:nyalcf/storages/configurations/launcher_configuration_storage.dart'; import 'package:nyalcf/utils/path_provider.dart'; @@ -9,8 +9,8 @@ class Logger { static final lcs = LauncherConfigurationStorage(); static get _fileOutPut async => - LoU.FileOutput(file: File('$_supportPath/run.log')); - static final LoU.ConsoleOutput _consoleOutput = LoU.ConsoleOutput(); + log_u.FileOutput(file: File('$_supportPath/run.log')); + static final log_u.ConsoleOutput _consoleOutput = log_u.ConsoleOutput(); /// 重置日志文件 static clear() async { @@ -19,29 +19,29 @@ class Logger { } static get _logger async { - List multiOutput = [await _fileOutPut, _consoleOutput]; - return LoU.Logger( + List multiOutput = [await _fileOutPut, _consoleOutput]; + return log_u.Logger( filter: LogFilter(), - printer: LoU.HybridPrinter( - LoU.PrettyPrinter( + printer: log_u.HybridPrinter( + log_u.PrettyPrinter( printEmojis: false, printTime: true, methodCount: 0, lineLength: 60, errorMethodCount: null, ), - debug: LoU.PrettyPrinter( + debug: log_u.PrettyPrinter( printEmojis: false, printTime: true, lineLength: 60, levelColors: { - LoU.Level.debug: const LoU.AnsiColor.fg(126), + log_u.Level.debug: const log_u.AnsiColor.fg(126), }, methodCount: 0, errorMethodCount: null, ), ), - output: LoU.MultiOutput(multiOutput), + output: log_u.MultiOutput(multiOutput), ); } @@ -88,9 +88,9 @@ class Logger { } } -class LogFilter extends LoU.LogFilter { +class LogFilter extends log_u.LogFilter { @override - bool shouldLog(LoU.LogEvent event) { + bool shouldLog(log_u.LogEvent event) { return true; } } From ea96a7052841b35d8f4a643230fc605759c130fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Wed, 14 Feb 2024 10:44:22 +0800 Subject: [PATCH 09/10] =?UTF-8?q?[*]Feat:=20warning=20when=20frpc=20stdout?= =?UTF-8?q?=20'=E6=97=A0=E6=B3=95=E8=BF=9E=E6=8E=A5'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/frpc/process_manager.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/frpc/process_manager.dart b/lib/utils/frpc/process_manager.dart index 6772eff9..4ced3b00 100644 --- a/lib/utils/frpc/process_manager.dart +++ b/lib/utils/frpc/process_manager.dart @@ -50,7 +50,7 @@ class FrpcProcessManager { process.stdout.forEach((List element) { final RegExp regex = RegExp(r'\x1B\[[0-9;]*[mK]'); final String fmtStr = utf8.decode(element).trim().replaceAll(regex, ''); - if (fmtStr.contains('stopped') || fmtStr.contains('启动失败')) { + if (fmtStr.contains('stopped') || fmtStr.contains('启动失败') || fmtStr.contains('无法连接')) { Logger.frpcWarn('[$proxyId] $fmtStr'); fctr.appendWarnLog(fmtStr); process.kill(); From a0423755ef0914c03c26fd197082c70d01fc430f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Wed, 14 Feb 2024 11:35:58 +0800 Subject: [PATCH 10/10] [*]Fix frpc download --- lib/controllers/frpc_setting_controller.dart | 84 +++++++++++++++++--- 1 file changed, 71 insertions(+), 13 deletions(-) diff --git a/lib/controllers/frpc_setting_controller.dart b/lib/controllers/frpc_setting_controller.dart index 40cf86f4..68c15b63 100644 --- a/lib/controllers/frpc_setting_controller.dart +++ b/lib/controllers/frpc_setting_controller.dart @@ -4,6 +4,8 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart' hide Response; import 'package:nyalcf/storages/configurations/frpc_configuration_storage.dart'; +import 'package:nyalcf/ui/models/frpc_download_dialog.dart'; +import 'package:nyalcf/utils/frpc/archive.dart'; import 'package:nyalcf/utils/frpc/path_provider.dart'; import 'package:nyalcf/utils/logger.dart'; import 'package:nyalcf/ui/models/frpc_download_tip.dart'; @@ -26,7 +28,7 @@ class FrpcSettingController extends GetxController { var frpcDownloadArch = 0.obs; var frpcDownloadProgress = 0.0.obs; var frpcDownloadShow = [].obs; - bool frpcDownloadCancel = false; + dynamic frpcDownloadCancel = false; var frpcDownloadUseMirror = false.obs; var frpcVersion = ''.obs; @@ -62,22 +64,78 @@ class FrpcSettingController extends GetxController { } void refreshDownloadShow() async { - if (frpcDownloadCancel) { - Logger.debug('Download cancelled.'); - frpcDownloadShow.clear(); - frpcDownloadShow.add(const Text( - '下载取消', - style: TextStyle(color: Colors.orange), - )); - frpcDownloadCancel = false; - downloadCancelToken = CancelToken(); + if (frpcDownloadCancel is bool) { + if (frpcDownloadCancel) { + Logger.debug('Download cancelled.'); + frpcDownloadShow.clear(); + frpcDownloadShow.add(const Text( + '下载取消', + style: TextStyle(color: Colors.orange), + )); + frpcDownloadCancel = false; + downloadCancelToken = CancelToken(); + } else { + frpcDownloadShow.clear(); + frpcDownloadShow.add(LinearProgressIndicator( + value: frpcDownloadProgress.value, + )); + } + } else if (frpcDownloadCancel is Response) { + Get.close(0); + /*await showDialog( + context: context, + builder: (context) { + return FrpcDownloadDialogX(context: context).unarchiving(); + });*/ + Get.dialog(FrpcDownloadDialogX(context: context).unarchiving(), + barrierDismissible: false); + Future.delayed( + const Duration(seconds: 2), + () async { + //延时执行 + final bool unarchive = await FrpcArchive.unarchive( + platform: platform, + arch: arch[frpcDownloadArch.value]['arch'], + version: fcs.getSettingsFrpcVersion(), + ); + if (unarchive) { + fcs.setSettingsFrpcVersion('0.51.3'); + fcs.addInstalledVersion('0.51.3'); + fcs.save(); + /**if (!Platform.isWindows) { + print('*nix platform, change file permission'); + await FrpcManagerStorage.setRunPermission(); + }*/ + _loadTip(); + } else { + Get.snackbar( + '解压 Frpc 时发生错误..呜呜..', + '请检查磁盘是否被塞满了..或者是已经安装了!受不了了呜呜呜...', + snackPosition: SnackPosition.BOTTOM, + animationDuration: const Duration(milliseconds: 300), + ); + Get.close(0); + } + + /// 关闭对话框 + Get.close(0); + Get.close(0); + }, + ); } else { frpcDownloadShow.clear(); - frpcDownloadShow.add(LinearProgressIndicator( - value: frpcDownloadProgress.value, + frpcDownloadShow.add(Text( + '发生错误${frpcDownloadCancel.error}', + style: const TextStyle(color: Colors.red), )); + Get.snackbar( + '下载 Frpc 时发生错误..呜呜..', + frpcDownloadCancel.toString(), + snackPosition: SnackPosition.BOTTOM, + animationDuration: const Duration(milliseconds: 300), + ); } - } + } /// 构建Arch列表 List> _buildArchDMIWidgetList() {