From eab195eaa07b98988d5c1da6e5d0e1a14022ffdd 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, 2 Jan 2024 15:02:02 +0800 Subject: [PATCH 1/7] =?UTF-8?q?[*+]=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=A0=B7=E5=BC=8F=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=8F=8D=E9=A6=88=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/model/ToolDialog.dart | 33 +++++++++++++++++---------- lib/ui/panel/home.dart | 18 ++++++++++----- lib/ui/setting/launcher.dart | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/lib/ui/model/ToolDialog.dart b/lib/ui/model/ToolDialog.dart index e0b51d2f..70c7c7ac 100644 --- a/lib/ui/model/ToolDialog.dart +++ b/lib/ui/model/ToolDialog.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:get/get.dart'; import 'package:url_launcher/url_launcher.dart'; class ToolDialogX { @@ -15,10 +16,12 @@ class ToolDialogX { onPressed: () async { const url = 'https://www.locyanfrp.cn'; if (!await launchUrl(Uri.parse(url))) { - const snackBar = SnackBar( - content: Text('无法打开网页,请检查设备是否存在WebView'), + Get.snackbar( + '发生错误', + '无法打开网页,请检查设备是否存在WebView', + snackPosition: SnackPosition.BOTTOM, + animationDuration: Duration(milliseconds: 300), ); - ScaffoldMessenger.of(context).showSnackBar(snackBar); } }), SimpleDialogOption( @@ -26,10 +29,12 @@ class ToolDialogX { onPressed: () async { const url = 'https://dashboard.locyanfrp.cn'; if (!await launchUrl(Uri.parse(url))) { - const snackBar = SnackBar( - content: Text('无法打开网页,请检查设备是否存在WebView'), + Get.snackbar( + '发生错误', + '无法打开网页,请检查设备是否存在WebView', + snackPosition: SnackPosition.BOTTOM, + animationDuration: Duration(milliseconds: 300), ); - ScaffoldMessenger.of(context).showSnackBar(snackBar); } }), SimpleDialogOption( @@ -37,10 +42,12 @@ class ToolDialogX { onPressed: () async { const url = 'https://preview.locyanfrp.cn'; if (!await launchUrl(Uri.parse(url))) { - const snackBar = SnackBar( - content: Text('无法打开网页,请检查设备是否存在WebView'), + Get.snackbar( + '发生错误', + '无法打开网页,请检查设备是否存在WebView', + snackPosition: SnackPosition.BOTTOM, + animationDuration: Duration(milliseconds: 300), ); - ScaffoldMessenger.of(context).showSnackBar(snackBar); } }), SimpleDialogOption( @@ -48,10 +55,12 @@ class ToolDialogX { onPressed: () async { const url = 'https://xn--v6qw21h0gd43u.xn--fiqs8s/'; if (!await launchUrl(Uri.parse(url))) { - const snackBar = SnackBar( - content: Text('无法打开网页,请检查设备是否存在WebView'), + Get.snackbar( + '发生错误', + '无法打开网页,请检查设备是否存在WebView', + snackPosition: SnackPosition.BOTTOM, + animationDuration: Duration(milliseconds: 300), ); - ScaffoldMessenger.of(context).showSnackBar(snackBar); } }), ], diff --git a/lib/ui/panel/home.dart b/lib/ui/panel/home.dart index 08a9e427..191ca783 100644 --- a/lib/ui/panel/home.dart +++ b/lib/ui/panel/home.dart @@ -115,9 +115,12 @@ class PanelHome extends StatelessWidget { child: Column(children: [ Text('Frp Token'), ElevatedButton( - onPressed: () { - Clipboard.setData(ClipboardData( - text: c.frp_token.value)); + onPressed: () async { + Clipboard.setData( + ClipboardData( + text: c.frp_token.value, + ), + ); ScaffoldMessenger.of(context) .showSnackBar(SnackBar( content: Text('已复制'), @@ -129,9 +132,12 @@ class PanelHome extends StatelessWidget { child: Column(children: [ Text('Token'), ElevatedButton( - onPressed: () { - Clipboard.setData(ClipboardData( - text: c.token.value)); + onPressed: () async { + Clipboard.setData( + ClipboardData( + text: c.token.value, + ), + ); ScaffoldMessenger.of(context) .showSnackBar(SnackBar( content: Text('已复制'), diff --git a/lib/ui/setting/launcher.dart b/lib/ui/setting/launcher.dart index af02d5f3..0c64b970 100644 --- a/lib/ui/setting/launcher.dart +++ b/lib/ui/setting/launcher.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controller/dsetting.dart'; +import 'package:url_launcher/url_launcher.dart'; class LauncherSX { final DSettingController ds_c = Get.find(); @@ -52,6 +53,48 @@ class LauncherSX { ], ), ), + 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), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Nya LoCyanFrp! 是免费开源的,欢迎向我们提交BUG或新功能请求。您可以在GitHub上提交Issues来向我们反馈。'), + TextButton( + child: ListTile( + leading: Icon(Icons.link), + title: Text( + 'https://github.com/Muska-Ami/NyaLCF/issues', + style: TextStyle(color: Colors.pink), + ), + ), + onPressed: () async { + const url = 'https://github.com/Muska-Ami/NyaLCF/issues'; + if (!await launchUrl(Uri.parse(url))) { + Get.snackbar( + '发生错误', + '无法打开网页,请检查设备是否存在WebView', + snackPosition: SnackPosition.BOTTOM, + animationDuration: Duration(milliseconds: 300), + ); + } + }, + ), + ], + ), + ), + ], + ), + ), ], ), ); From ef7a169e03681c08815cb30f74f4930c992b805c 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, 8 Jan 2024 00:30:34 +0800 Subject: [PATCH 2/7] =?UTF-8?q?[*]=E4=BF=AE=E5=A4=8D=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=8F=B0=E8=BF=9B=E7=A8=8B=E5=88=97=E8=A1=A8=E4=B8=8D=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E5=88=B7=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controller/dconsole.dart | 1 + lib/ui/panel/console.dart | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/controller/dconsole.dart b/lib/controller/dconsole.dart index 57dd9673..9f149cea 100644 --- a/lib/controller/dconsole.dart +++ b/lib/controller/dconsole.dart @@ -50,6 +50,7 @@ class ConsoleController extends GetxController { onPressed: () { /// 杀死进程 FrpcProcessManager().kill(element); + load(); }, ), ), diff --git a/lib/ui/panel/console.dart b/lib/ui/panel/console.dart index ae3b85a0..df755de1 100644 --- a/lib/ui/panel/console.dart +++ b/lib/ui/panel/console.dart @@ -69,8 +69,7 @@ class PanelConsole extends StatelessWidget { children: [ ElevatedButton( onPressed: () { - Get.dialog( - ProcessListDialogX(context: context).build()); + Get.dialog(ProcessListDialogX(context: context).build()); }, child: Text('查看进程列表'), ), From 6635a5672845824fa69c08c78a2951e03fc4ea5c 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, 8 Jan 2024 14:05:16 +0800 Subject: [PATCH 3/7] =?UTF-8?q?[*]=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=B8=A4=E4=B8=AA=E6=9C=AA?= =?UTF-8?q?=E5=81=9A=E7=9A=84=E9=80=89=E9=A1=B9=20#9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/setting/launcher.dart | 60 +++++++++++++++++++++++++++++++++++- pubspec.yaml | 2 +- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/lib/ui/setting/launcher.dart b/lib/ui/setting/launcher.dart index 0c64b970..bc934899 100644 --- a/lib/ui/setting/launcher.dart +++ b/lib/ui/setting/launcher.dart @@ -11,6 +11,63 @@ class LauncherSX { margin: 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: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: ListTile( + leading: Icon(Icons.dark_mode), + title: Text('深色主题'), + ), + ), + Switch(value: false, onChanged: null), + ], + ), + Row( + children: [ + Expanded( + child: ListTile( + leading: Icon(Icons.dark_mode), + title: Text('浅色主题自定义主题色种子'), + ), + ), + SizedBox( + width: 200, + child: Container( + padding: EdgeInsets.only(bottom: 10.0), + child: TextField( + decoration: const InputDecoration( + labelText: '十六进制颜色', + ), + readOnly: true, + ), + ), + ), + Switch(value: false, onChanged: null), + ], + ), + ], + ), + ) + ], + ), + ), + ), Card( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -78,7 +135,8 @@ class LauncherSX { ), ), onPressed: () async { - const url = 'https://github.com/Muska-Ami/NyaLCF/issues'; + const url = + 'https://github.com/Muska-Ami/NyaLCF/issues'; if (!await launchUrl(Uri.parse(url))) { Get.snackbar( '发生错误', diff --git a/pubspec.yaml b/pubspec.yaml index 645aaccf..9ec07b84 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.0+rc1 +version: 0.1.0 environment: sdk: '>=3.1.5 <4.0.0' From fe0b017ce44e039e0ba82d7e9988cf72c56d5d2d 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, 8 Jan 2024 14:08:46 +0800 Subject: [PATCH 4/7] =?UTF-8?q?[*]=E6=9B=B4=E6=94=B9README=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=B8=AA=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++-- lib/ui/setting/launcher.dart | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2a334e01..abae874f 100644 --- a/README.md +++ b/README.md @@ -24,15 +24,16 @@ An unoffical LoCyanFrp launcher. - [x] 注册 - [x] 自动登录 - [ ] Frpc管理 -- [x] *进程管理器 +- [x] 进程管理器 - [x] Token复制 - [x] 隧道信息展示 - [x] 隧道启动 - [x] 高级启动 -- [x] *控制台 +- [x] 控制台 - [ ] 隧道编辑 - [x] 公告 - [x] 通知 +- [ ] 暗色主题 ## Repo stats diff --git a/lib/ui/setting/launcher.dart b/lib/ui/setting/launcher.dart index bc934899..a183ef13 100644 --- a/lib/ui/setting/launcher.dart +++ b/lib/ui/setting/launcher.dart @@ -42,7 +42,7 @@ class LauncherSX { children: [ Expanded( child: ListTile( - leading: Icon(Icons.dark_mode), + leading: Icon(Icons.colorize), title: Text('浅色主题自定义主题色种子'), ), ), From dae02546aa8909bec7d7853d8caf46813e7bd98e 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, 9 Jan 2024 23:35:05 +0800 Subject: [PATCH 5/7] [+]Feature: dark theme #9 --- lib/controller/dsetting.dart | 8 +-- lib/io/frpcManagerStorage.dart | 4 +- lib/io/settingStorage.dart | 55 ++++++++++++++++++- lib/main.dart | 55 +++++++++++++++---- lib/model/Setting.dart | 34 ++++++++++++ ...ettingPrefs.dart => FrpcSettingPrefs.dart} | 31 ++++++----- lib/prefs/LauncherSettingPrefs.dart | 23 ++++++++ lib/ui/model/FrpcDownloadTip.dart | 4 +- lib/ui/setting/launcher.dart | 11 ++++ 9 files changed, 189 insertions(+), 36 deletions(-) create mode 100644 lib/model/Setting.dart rename lib/prefs/{SettingPrefs.dart => FrpcSettingPrefs.dart} (55%) create mode 100644 lib/prefs/LauncherSettingPrefs.dart diff --git a/lib/controller/dsetting.dart b/lib/controller/dsetting.dart index 58881230..2d57cb4c 100644 --- a/lib/controller/dsetting.dart +++ b/lib/controller/dsetting.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart' hide Response; import 'package:nyalcf/io/frpcManagerStorage.dart'; import 'package:nyalcf/model/FrpcConfig.dart'; -import 'package:nyalcf/prefs/SettingPrefs.dart'; +import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; import 'package:nyalcf/ui/model/FrpcDownloadDialog.dart'; import 'package:nyalcf/ui/model/FrpcDownloadTip.dart'; import 'package:nyalcf/util/CPUArch.dart'; @@ -100,11 +100,11 @@ class DSettingController extends GetxController { version: '0.51.3', ); if (unarchive) { - SettingPrefs.setFrpcDownloadedVersionsInfo('0.51.3'); + FrpcSettingPrefs.setFrpcDownloadedVersionsInfo('0.51.3'); FrpcManagerStorage.save( FrpcConfig( - settings: (await SettingPrefs.getFrpcInfo()).settings, - lists: (await SettingPrefs.getFrpcInfo()).lists), + settings: (await FrpcSettingPrefs.getFrpcInfo()).settings, + lists: (await FrpcSettingPrefs.getFrpcInfo()).lists), ); /**if (!Platform.isWindows) { print('*nix platform, change file permission'); diff --git a/lib/io/frpcManagerStorage.dart b/lib/io/frpcManagerStorage.dart index c244eec9..662c9b1e 100644 --- a/lib/io/frpcManagerStorage.dart +++ b/lib/io/frpcManagerStorage.dart @@ -2,7 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:nyalcf/model/FrpcConfig.dart'; -import 'package:nyalcf/prefs/SettingPrefs.dart'; +import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; import 'package:nyalcf/util/FileIO.dart'; class FrpcManagerStorage { @@ -22,7 +22,7 @@ class FrpcManagerStorage { } } - static Future get _info async => SettingPrefs.getFrpcInfo(); + static Future get _info async => FrpcSettingPrefs.getFrpcInfo(); static void init() { _path.then((path) { diff --git a/lib/io/settingStorage.dart b/lib/io/settingStorage.dart index 24bcd287..14156dc6 100644 --- a/lib/io/settingStorage.dart +++ b/lib/io/settingStorage.dart @@ -1 +1,54 @@ -class SettingStorage {} +import 'dart:convert'; +import 'dart:io'; + +import 'package:nyalcf/model/Setting.dart'; +import 'package:nyalcf/util/FileIO.dart'; + +class SettingStorage { + static final _path = FileIO.support_path; + + static void init() { + _path.then((path) { + if (!Directory(path).existsSync()) Directory(path).createSync(); + final infoF = File('${path}/settings.json'); + if (!infoF.existsSync()) { + Map json = { + 'theme': { + 'auto': true, + 'dark': { + 'enable': false, + }, + 'light': { + 'seed': { + 'enable': false, + 'value': '66ccff', + }, + } + }, + }; + infoF.writeAsStringSync(jsonEncode(json)); + } + }); + } + + /// 保存数据 + static Future save(Setting data) async { + final String write_data = jsonEncode(data); + await File('${await _path}/settings.json') + .writeAsString(write_data, encoding: utf8); + } + + /// 读取数据 + static Setting? read() { + try { + _path.then((path) { + final String result = File('${path}/settings.json') + .readAsStringSync(encoding: utf8); + return Setting.fromJson(jsonDecode(result)); + }); + } catch (e) { + return null; + } + return null; + } +} diff --git a/lib/main.dart b/lib/main.dart index 4ffed715..d94c2ec2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,8 +1,11 @@ import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/scheduler.dart'; import 'package:get/get.dart'; import 'package:nyalcf/controller/user.dart'; import 'package:nyalcf/io/frpcManagerStorage.dart'; +import 'package:nyalcf/io/settingStorage.dart'; +import 'package:nyalcf/model/Setting.dart'; import 'package:nyalcf/ui/auth/login.dart'; import 'package:nyalcf/ui/auth/register.dart'; import 'package:nyalcf/ui/home.dart'; @@ -24,17 +27,54 @@ void main() { }); } +final Setting? _settings = SettingStorage.read(); + class App extends StatelessWidget { const App({super.key}); final title = 'Nya LoCyanFrp!'; - // This widget is the root of your application. + /// This widget is the root of your application. @override Widget build(BuildContext context) { - // 初始化Frpc配置 + /// 初始化配置文件 + SettingStorage.init(); FrpcManagerStorage.init(); + ThemeData _theme_data; + + final bool isDarkMode = (Theme.of(context).brightness == Brightness.dark || + Theme.of(context).colorScheme.brightness == Brightness.dark) || + SchedulerBinding.instance.platformDispatcher.platformBrightness == Brightness.dark || + MediaQuery.of(context).platformBrightness == Brightness.dark; + + print('dark mode: ${isDarkMode}'); + + /// 判定是否需要切换暗色主题 + if (((_settings?.theme_auto ?? true) && isDarkMode) || + (_settings?.theme_dark ?? false)) { + _theme_data = ThemeData.dark(useMaterial3: true); + } else if ((_settings?.theme_light_seed_enable ?? false)) { + _theme_data = ThemeData( + useMaterial3: true, + fontFamily: 'HarmonyOS Sans', + colorScheme: ColorScheme.fromSeed( + seedColor: + Color('0x${_settings?.theme_light_seed ?? '66ccff'}' as int), + )); + } else { + _theme_data = ThemeData( + useMaterial3: true, + fontFamily: 'HarmonyOS Sans', + colorScheme: ColorScheme.fromSeed( + seedColor: Colors.pink.shade300, + ).copyWith( + primary: Colors.pink.shade500, + secondary: Colors.pink.shade400, + ), + ); + } + Get.put(UserController()); return GetMaterialApp( title: 'Nya LoCyanFrp!', @@ -47,16 +87,7 @@ class App extends StatelessWidget { '/panel/console': (context) => PanelConsole(title: title), '/setting': (context) => SettingInjector(title: title), }, - theme: ThemeData( - useMaterial3: true, - fontFamily: 'HarmonyOS Sans', - colorScheme: ColorScheme.fromSeed( - seedColor: Colors.pink.shade300, - ).copyWith( - primary: Colors.pink.shade500, - secondary: Colors.pink.shade400, - ), - ), + theme: _theme_data, ); } } diff --git a/lib/model/Setting.dart b/lib/model/Setting.dart new file mode 100644 index 00000000..64f25026 --- /dev/null +++ b/lib/model/Setting.dart @@ -0,0 +1,34 @@ +class Setting { + Setting({ + required this.theme_auto, + required this.theme_dark, + required this.theme_light_seed_enable, + required this.theme_light_seed, + }); + + final theme_auto; + final theme_dark; + final theme_light_seed_enable; + final theme_light_seed; + + Map toJson() => { + 'theme': { + 'auto': theme_auto, + 'dark': { + 'enable': theme_dark, + }, + 'light': { + 'seed': { + 'enable': theme_light_seed_enable, + 'value': theme_light_seed, + }, + } + }, + }; + + Setting.fromJson(Map json) + : theme_auto = json['theme']['auto'], + theme_dark = json['theme']['dark']['enable'], + theme_light_seed = json['theme']['light']['seed']['value'], + theme_light_seed_enable = json['theme']['light']['seed']['enable']; +} diff --git a/lib/prefs/SettingPrefs.dart b/lib/prefs/FrpcSettingPrefs.dart similarity index 55% rename from lib/prefs/SettingPrefs.dart rename to lib/prefs/FrpcSettingPrefs.dart index 6cd4c3a6..b7b11b12 100644 --- a/lib/prefs/SettingPrefs.dart +++ b/lib/prefs/FrpcSettingPrefs.dart @@ -2,14 +2,14 @@ import 'package:nyalcf/io/frpcManagerStorage.dart'; import 'package:nyalcf/model/FrpcConfig.dart'; import 'package:shared_preferences/shared_preferences.dart'; -class SettingPrefs { +class FrpcSettingPrefs { static Future setFrpcInfo(FrpcConfig frpcinfo) async { SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setString('setting@frpc_version', frpcinfo.frpc_version); - prefs.setStringList( - 'list@frpc_downloaded_versions', frpcinfo.frpc_downloaded_versions); - prefs.setString('setting@github_proxy', frpcinfo.github_proxy); - prefs.setStringList('list@github_proxies', frpcinfo.github_proxies); + prefs.setString('frpc@setting@frpc_version', frpcinfo.frpc_version); + prefs.setStringList('frpc@list@frpc_downloaded_versions', + frpcinfo.frpc_downloaded_versions); + prefs.setString('frpc@setting@github_proxy', frpcinfo.github_proxy); + prefs.setStringList('frpc@list@github_proxies', frpcinfo.github_proxies); } static Future setFrpcDownloadedVersionsInfo(String version) async { @@ -17,16 +17,17 @@ class SettingPrefs { final newlist = (await getFrpcInfo()).lists['frpc_downloaded_versions'] ?? []; newlist.add(version); - prefs.setStringList('list@frpc_downloaded_versions', newlist); + prefs.setStringList('frpc@list@frpc_downloaded_versions', newlist); } static Future getFrpcInfo() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - final s_frpc_version = prefs.getString('setting@frpc_version') ?? ''; + final s_frpc_version = prefs.getString('frpc@setting@frpc_version') ?? ''; final l_frpc_downloaded_versions = - prefs.getStringList('list@frpc_downloaded_versions') ?? []; - final s_github_proxy = prefs.getString('setting@github_proxy') ?? ''; - final l_github_proxies = prefs.getStringList('list@github_proxies') ?? []; + prefs.getStringList('frpc@list@frpc_downloaded_versions') ?? []; + final s_github_proxy = prefs.getString('frpc@setting@github_proxy') ?? ''; + final l_github_proxies = + prefs.getStringList('frpc@list@github_proxies') ?? []; final Map settings = Map(); settings['frpc_version'] = s_frpc_version; @@ -39,8 +40,8 @@ class SettingPrefs { return FrpcConfig(settings: settings, lists: lists); } - static Future refresh() async => { - if (await FrpcManagerStorage.read() != null) - setFrpcInfo((await FrpcManagerStorage.read())!) - }; + static Future refresh() async { + final res = await FrpcManagerStorage.read(); + if (res != null) setFrpcInfo(res); + } } diff --git a/lib/prefs/LauncherSettingPrefs.dart b/lib/prefs/LauncherSettingPrefs.dart new file mode 100644 index 00000000..bdbc2873 --- /dev/null +++ b/lib/prefs/LauncherSettingPrefs.dart @@ -0,0 +1,23 @@ +import 'package:nyalcf/io/settingStorage.dart'; +import 'package:nyalcf/model/Setting.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +class LauncherSettingPrefs { + static Future setFrpcInfo(Setting frpcinfo) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + } + + /*static Future getFrpcInfo() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + + return Setting( + + ); + }*/ + + static Future refresh() async { + final res = await SettingStorage.read(); + if (res != null) + setFrpcInfo(res); + } +} diff --git a/lib/ui/model/FrpcDownloadTip.dart b/lib/ui/model/FrpcDownloadTip.dart index 1d4a3e88..3e6d62ad 100644 --- a/lib/ui/model/FrpcDownloadTip.dart +++ b/lib/ui/model/FrpcDownloadTip.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:nyalcf/prefs/SettingPrefs.dart'; +import 'package:nyalcf/prefs/FrpcSettingPrefs.dart'; import 'FrpcDownloadDialog.dart'; @@ -60,7 +60,7 @@ class FrpcDownloadTip { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('已安装版本列表:'), - Text((await SettingPrefs.getFrpcInfo()) + Text((await FrpcSettingPrefs.getFrpcInfo()) .lists['frpc_downloaded_versions'] .toString()), ], diff --git a/lib/ui/setting/launcher.dart b/lib/ui/setting/launcher.dart index a183ef13..c3251c22 100644 --- a/lib/ui/setting/launcher.dart +++ b/lib/ui/setting/launcher.dart @@ -27,6 +27,17 @@ class LauncherSX { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + Row( + children: [ + Expanded( + child: ListTile( + leading: Icon(Icons.auto_awesome), + title: Text('自动设置主题'), + ), + ), + Switch(value: false, onChanged: null), + ], + ), Row( children: [ Expanded( From 878892541d82002912157c99e518db9481fdde00 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, 9 Jan 2024 23:52:59 +0800 Subject: [PATCH 6/7] [+]Broken changes: split dsetting.dart, add LauncherSettingPrefs.dart prefs --- .../{dsetting.dart => dsettingfrpc.dart} | 14 ++--------- lib/controller/dsettinglauncher.dart | 17 +++++++++++++ lib/prefs/LauncherSettingPrefs.dart | 24 ++++++++++++++----- lib/ui/model/FrpcDownloadDialog.dart | 4 ++-- lib/ui/setting/frpcmanager.dart | 4 ++-- lib/ui/setting/injector.dart | 11 +++++---- lib/ui/setting/launcher.dart | 4 ++-- 7 files changed, 50 insertions(+), 28 deletions(-) rename lib/controller/{dsetting.dart => dsettingfrpc.dart} (93%) create mode 100644 lib/controller/dsettinglauncher.dart diff --git a/lib/controller/dsetting.dart b/lib/controller/dsettingfrpc.dart similarity index 93% rename from lib/controller/dsetting.dart rename to lib/controller/dsettingfrpc.dart index 2d57cb4c..80f7c7a4 100644 --- a/lib/controller/dsetting.dart +++ b/lib/controller/dsettingfrpc.dart @@ -10,10 +10,9 @@ import 'package:nyalcf/ui/model/FrpcDownloadDialog.dart'; import 'package:nyalcf/ui/model/FrpcDownloadTip.dart'; import 'package:nyalcf/util/CPUArch.dart'; import 'package:nyalcf/util/frpc/Archive.dart'; -import 'package:package_info_plus/package_info_plus.dart'; -class DSettingController extends GetxController { - DSettingController({required this.context}); +class DSettingFrpcController extends GetxController { + DSettingFrpcController({required this.context}); final context; List> arch = >[]; @@ -32,20 +31,11 @@ class DSettingController extends GetxController { var frpc_version = ''.obs; - var app_name = ''.obs; - var app_version = ''.obs; - var app_package_name = ''.obs; - var github_proxy = ''.obs; var cpu_arch = ''.obs; load() async { - final packageInfo = await PackageInfo.fromPlatform(); - app_name.value = packageInfo.appName; - app_version.value = packageInfo.version; - app_package_name.value = packageInfo.packageName; - cpu_arch.value = await CPUArch.getCPUArchitecture(); frpc_version.value = await FrpcManagerStorage.usingVersion; diff --git a/lib/controller/dsettinglauncher.dart b/lib/controller/dsettinglauncher.dart new file mode 100644 index 00000000..177419b0 --- /dev/null +++ b/lib/controller/dsettinglauncher.dart @@ -0,0 +1,17 @@ +import 'package:get/get.dart'; +import 'package:package_info_plus/package_info_plus.dart'; + +class DSettingLauncherController extends GetxController { + + var app_name = ''.obs; + var app_version = ''.obs; + var app_package_name = ''.obs; + + load() async { + final packageInfo = await PackageInfo.fromPlatform(); + app_name.value = packageInfo.appName; + app_version.value = packageInfo.version; + app_package_name.value = packageInfo.packageName; + } + +} diff --git a/lib/prefs/LauncherSettingPrefs.dart b/lib/prefs/LauncherSettingPrefs.dart index bdbc2873..6620a705 100644 --- a/lib/prefs/LauncherSettingPrefs.dart +++ b/lib/prefs/LauncherSettingPrefs.dart @@ -3,21 +3,33 @@ import 'package:nyalcf/model/Setting.dart'; import 'package:shared_preferences/shared_preferences.dart'; class LauncherSettingPrefs { - static Future setFrpcInfo(Setting frpcinfo) async { + static Future setFrpcInfo(Setting data) async { SharedPreferences prefs = await SharedPreferences.getInstance(); + prefs.setString('setting@theme@auto', data.theme_auto); + prefs.setString('setting@theme@dark@enable', data.theme_dark); + prefs.setString( + 'setting@theme@light@seed@enable', data.theme_light_seed_enable); + prefs.setString('setting@theme@light@seed@value', data.theme_light_seed); } - /*static Future getFrpcInfo() async { + static Future getFrpcInfo() async { SharedPreferences prefs = await SharedPreferences.getInstance(); + final theme_auto = prefs.getString('setting@theme@auto'); + final theme_dark = prefs.getString('setting@theme@dark@enable'); + final theme_light_seed_enable = + prefs.getString('setting@theme@light@seed@enable'); + final theme_light_seed = prefs.getString('setting@theme@light@seed@value'); return Setting( - + theme_auto: theme_auto, + theme_dark: theme_dark, + theme_light_seed: theme_light_seed, + theme_light_seed_enable: theme_light_seed_enable, ); - }*/ + } static Future refresh() async { final res = await SettingStorage.read(); - if (res != null) - setFrpcInfo(res); + if (res != null) setFrpcInfo(res); } } diff --git a/lib/ui/model/FrpcDownloadDialog.dart b/lib/ui/model/FrpcDownloadDialog.dart index dbf6166c..7c84e706 100644 --- a/lib/ui/model/FrpcDownloadDialog.dart +++ b/lib/ui/model/FrpcDownloadDialog.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controller/dsetting.dart'; +import 'package:nyalcf/controller/dsettingfrpc.dart'; import 'package:nyalcf/dio/frpc/download.dart'; class FrpcDownloadDialogX { FrpcDownloadDialogX({required this.context}); - final DSettingController ds_c = Get.find(); + final DSettingFrpcController ds_c = Get.find(); final context; Widget build() { diff --git a/lib/ui/setting/frpcmanager.dart b/lib/ui/setting/frpcmanager.dart index 7a2cfc06..37475862 100644 --- a/lib/ui/setting/frpcmanager.dart +++ b/lib/ui/setting/frpcmanager.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controller/dsetting.dart'; +import 'package:nyalcf/controller/dsettingfrpc.dart'; class FrpcManagerSX { - final DSettingController ds_c = Get.find(); + final DSettingFrpcController ds_c = Get.find(); Widget widget() { return Container( diff --git a/lib/ui/setting/injector.dart b/lib/ui/setting/injector.dart index dbdc7b84..4fcd1f8d 100644 --- a/lib/ui/setting/injector.dart +++ b/lib/ui/setting/injector.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controller/dsetting.dart'; +import 'package:nyalcf/controller/dsettingfrpc.dart'; +import 'package:nyalcf/controller/dsettinglauncher.dart'; import 'package:nyalcf/ui/model/AppbarActions.dart'; import 'package:nyalcf/ui/model/FloatingActionButton.dart'; @@ -14,9 +15,11 @@ class SettingInjector extends StatelessWidget { @override Widget build(BuildContext context) { - final DSettingController ds_c = - Get.put(DSettingController(context: context)); - ds_c.load(); + final DSettingFrpcController dsf_c = + Get.put(DSettingFrpcController(context: context)); + final DSettingLauncherController dsc_c = Get.put(DSettingLauncherController()); + dsf_c.load(); + dsc_c.load(); return DefaultTabController( length: 2, diff --git a/lib/ui/setting/launcher.dart b/lib/ui/setting/launcher.dart index c3251c22..4f0e7aaf 100644 --- a/lib/ui/setting/launcher.dart +++ b/lib/ui/setting/launcher.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:nyalcf/controller/dsetting.dart'; +import 'package:nyalcf/controller/dsettinglauncher.dart'; import 'package:url_launcher/url_launcher.dart'; class LauncherSX { - final DSettingController ds_c = Get.find(); + final DSettingLauncherController ds_c = Get.find(); Widget widget() { return Container( From 94ef7fcea87ed550ded9a923d3ebc58636f261d5 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, 10 Jan 2024 01:16:15 +0800 Subject: [PATCH 7/7] [*]Fix theme settings show --- lib/controller/dsettinglauncher.dart | 14 ++++- lib/io/settingStorage.dart | 11 ++-- lib/main.dart | 27 +++++--- lib/model/Setting.dart | 8 +-- lib/prefs/LauncherSettingPrefs.dart | 40 +++++++----- lib/ui/panel/console.dart | 3 +- lib/ui/setting/injector.dart | 3 +- lib/ui/setting/launcher.dart | 94 +++++++++++++++------------- 8 files changed, 120 insertions(+), 80 deletions(-) diff --git a/lib/controller/dsettinglauncher.dart b/lib/controller/dsettinglauncher.dart index 177419b0..6324a885 100644 --- a/lib/controller/dsettinglauncher.dart +++ b/lib/controller/dsettinglauncher.dart @@ -1,17 +1,27 @@ import 'package:get/get.dart'; +import 'package:nyalcf/prefs/LauncherSettingPrefs.dart'; import 'package:package_info_plus/package_info_plus.dart'; class DSettingLauncherController extends GetxController { - var app_name = ''.obs; var app_version = ''.obs; var app_package_name = ''.obs; + var theme_auto = false.obs; + var theme_dark = false.obs; + var theme_light_seed = ''.obs; + var theme_light_seed_enable = 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; - } + final settings = await LauncherSettingPrefs.getInfo(); + theme_auto.value = settings.theme_auto; + theme_dark.value = settings.theme_dark; + theme_light_seed.value = settings.theme_light_seed; + theme_light_seed_enable.value = settings.theme_light_seed_enable; + } } diff --git a/lib/io/settingStorage.dart b/lib/io/settingStorage.dart index 14156dc6..adc478b9 100644 --- a/lib/io/settingStorage.dart +++ b/lib/io/settingStorage.dart @@ -39,16 +39,13 @@ class SettingStorage { } /// 读取数据 - static Setting? read() { + static Future read() async { try { - _path.then((path) { - final String result = File('${path}/settings.json') - .readAsStringSync(encoding: utf8); - return Setting.fromJson(jsonDecode(result)); - }); + final String result = + File('${await _path}/settings.json').readAsStringSync(encoding: utf8); + return Setting.fromJson(jsonDecode(result)); } catch (e) { return null; } - return null; } } diff --git a/lib/main.dart b/lib/main.dart index d94c2ec2..c7c83dce 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,6 +6,7 @@ import 'package:nyalcf/controller/user.dart'; import 'package:nyalcf/io/frpcManagerStorage.dart'; import 'package:nyalcf/io/settingStorage.dart'; import 'package:nyalcf/model/Setting.dart'; +import 'package:nyalcf/prefs/LauncherSettingPrefs.dart'; import 'package:nyalcf/ui/auth/login.dart'; import 'package:nyalcf/ui/auth/register.dart'; import 'package:nyalcf/ui/home.dart'; @@ -14,7 +15,14 @@ import 'package:nyalcf/ui/panel/home.dart'; import 'package:nyalcf/ui/panel/proxies.dart'; import 'package:nyalcf/ui/setting/injector.dart'; -void main() { +Setting? _settings = null; + +void main() async { + /// 初始化配置文件 + SettingStorage.init(); + FrpcManagerStorage.init(); + _settings = await SettingStorage.read(); + runApp(const App()); doWhenWindowReady(() { @@ -27,8 +35,6 @@ void main() { }); } -final Setting? _settings = SettingStorage.read(); - class App extends StatelessWidget { const App({super.key}); @@ -37,15 +43,20 @@ class App extends StatelessWidget { /// This widget is the root of your application. @override Widget build(BuildContext context) { - /// 初始化配置文件 - SettingStorage.init(); - FrpcManagerStorage.init(); + LauncherSettingPrefs.setInfo(_settings ?? + Setting( + theme_auto: true, + theme_dark: false, + theme_light_seed_enable: false, + theme_light_seed: '66ccff', + )); ThemeData _theme_data; final bool isDarkMode = (Theme.of(context).brightness == Brightness.dark || - Theme.of(context).colorScheme.brightness == Brightness.dark) || - SchedulerBinding.instance.platformDispatcher.platformBrightness == Brightness.dark || + Theme.of(context).colorScheme.brightness == Brightness.dark) || + SchedulerBinding.instance.platformDispatcher.platformBrightness == + Brightness.dark || MediaQuery.of(context).platformBrightness == Brightness.dark; print('dark mode: ${isDarkMode}'); diff --git a/lib/model/Setting.dart b/lib/model/Setting.dart index 64f25026..f751b273 100644 --- a/lib/model/Setting.dart +++ b/lib/model/Setting.dart @@ -6,10 +6,10 @@ class Setting { required this.theme_light_seed, }); - final theme_auto; - final theme_dark; - final theme_light_seed_enable; - final theme_light_seed; + final bool theme_auto; + final bool theme_dark; + final bool theme_light_seed_enable; + final String theme_light_seed; Map toJson() => { 'theme': { diff --git a/lib/prefs/LauncherSettingPrefs.dart b/lib/prefs/LauncherSettingPrefs.dart index 6620a705..c584ab02 100644 --- a/lib/prefs/LauncherSettingPrefs.dart +++ b/lib/prefs/LauncherSettingPrefs.dart @@ -3,33 +3,45 @@ import 'package:nyalcf/model/Setting.dart'; import 'package:shared_preferences/shared_preferences.dart'; class LauncherSettingPrefs { - static Future setFrpcInfo(Setting data) async { + static Future setInfo(Setting data) async { SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setString('setting@theme@auto', data.theme_auto); - prefs.setString('setting@theme@dark@enable', data.theme_dark); - prefs.setString( - 'setting@theme@light@seed@enable', data.theme_light_seed_enable); + prefs.setString('setting@theme@auto', data.theme_auto.toString()); + prefs.setString('setting@theme@dark@enable', data.theme_dark.toString()); + prefs.setString('setting@theme@light@seed@enable', + data.theme_light_seed_enable.toString()); prefs.setString('setting@theme@light@seed@value', data.theme_light_seed); } - static Future getFrpcInfo() async { + static Future getInfo() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - final theme_auto = prefs.getString('setting@theme@auto'); - final theme_dark = prefs.getString('setting@theme@dark@enable'); + final theme_auto = prefs.getString('setting@theme@auto') ?? 'true'; + final theme_dark = prefs.getString('setting@theme@dark@enable') ?? 'false'; final theme_light_seed_enable = - prefs.getString('setting@theme@light@seed@enable'); - final theme_light_seed = prefs.getString('setting@theme@light@seed@value'); + prefs.getString('setting@theme@light@seed@enable') ?? 'false'; + final theme_light_seed = + prefs.getString('setting@theme@light@seed@value') ?? ''; return Setting( - theme_auto: theme_auto, - theme_dark: theme_dark, + theme_auto: theme_auto.toBoolean(), + theme_dark: theme_dark.toBoolean(), theme_light_seed: theme_light_seed, - theme_light_seed_enable: theme_light_seed_enable, + theme_light_seed_enable: theme_light_seed_enable.toBoolean(), ); } static Future refresh() async { final res = await SettingStorage.read(); - if (res != null) setFrpcInfo(res); + if (res != null) setInfo(res); + } +} + +extension on String { + bool toBoolean() { + print(this); + return (this.toLowerCase() == 'true' || this.toLowerCase() == '1') + ? true + : (this.toLowerCase() == 'false' || this.toLowerCase() == '0' + ? false + : throw UnsupportedError); } } diff --git a/lib/ui/panel/console.dart b/lib/ui/panel/console.dart index df755de1..ae3b85a0 100644 --- a/lib/ui/panel/console.dart +++ b/lib/ui/panel/console.dart @@ -69,7 +69,8 @@ class PanelConsole extends StatelessWidget { children: [ ElevatedButton( onPressed: () { - Get.dialog(ProcessListDialogX(context: context).build()); + Get.dialog( + ProcessListDialogX(context: context).build()); }, child: Text('查看进程列表'), ), diff --git a/lib/ui/setting/injector.dart b/lib/ui/setting/injector.dart index 4fcd1f8d..50291b5a 100644 --- a/lib/ui/setting/injector.dart +++ b/lib/ui/setting/injector.dart @@ -17,7 +17,8 @@ class SettingInjector extends StatelessWidget { Widget build(BuildContext context) { final DSettingFrpcController dsf_c = Get.put(DSettingFrpcController(context: context)); - final DSettingLauncherController dsc_c = Get.put(DSettingLauncherController()); + final DSettingLauncherController dsc_c = + Get.put(DSettingLauncherController()); dsf_c.load(); dsc_c.load(); diff --git a/lib/ui/setting/launcher.dart b/lib/ui/setting/launcher.dart index 4f0e7aaf..b1e2a7e8 100644 --- a/lib/ui/setting/launcher.dart +++ b/lib/ui/setting/launcher.dart @@ -24,55 +24,63 @@ class LauncherSX { margin: EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0), padding: EdgeInsets.only(left: 30.0, right: 50.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: ListTile( - leading: Icon(Icons.auto_awesome), - title: Text('自动设置主题'), + child: Obx( + () => Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: ListTile( + leading: Icon(Icons.auto_awesome), + title: Text('自动设置主题'), + ), ), - ), - Switch(value: false, onChanged: null), - ], - ), - Row( - children: [ - Expanded( - child: ListTile( - leading: Icon(Icons.dark_mode), - title: Text('深色主题'), + Switch( + value: ds_c.theme_auto.value, + onChanged: null), + ], + ), + Row( + children: [ + Expanded( + child: ListTile( + leading: Icon(Icons.dark_mode), + title: Text('深色主题'), + ), ), - ), - Switch(value: false, onChanged: null), - ], - ), - Row( - children: [ - Expanded( - child: ListTile( - leading: Icon(Icons.colorize), - title: Text('浅色主题自定义主题色种子'), + Switch( + value: ds_c.theme_dark.value, + onChanged: null), + ], + ), + Row( + children: [ + 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: '十六进制颜色', + SizedBox( + width: 200, + child: Container( + padding: EdgeInsets.only(bottom: 10.0), + child: TextField( + decoration: const InputDecoration( + labelText: '十六进制颜色', + ), + readOnly: true, ), - readOnly: true, ), ), - ), - Switch(value: false, onChanged: null), - ], - ), - ], + Switch( + value: ds_c.theme_light_seed_enable.value, + onChanged: null), + ], + ), + ], + ), ), ) ],