diff --git a/lib/controller/dsetting.dart b/lib/controller/dsetting.dart index 4d899958..4957eb31 100644 --- a/lib/controller/dsetting.dart +++ b/lib/controller/dsetting.dart @@ -1,13 +1,17 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:nyalcf/io/frpcManagerStorage.dart'; class DSettingController extends GetxController { var _frpc_version = ''.obs; var frpc_version_widgets = [].obs; var frpc_version_value = 0.obs; - load() { - frpc_version_widgets.value = [ + load() async { + final versions = await FrpcManagerStorage.versionList; + final list = _buildDMIWidgetList(versions); + frpc_version_widgets.value = //list; + [ DropdownMenuItem( child: Text('0.51.3'), value: 0, @@ -28,6 +32,16 @@ class DSettingController extends GetxController { //await FrpcDownloadDio()(arch: 'amd64', platform: 'windows', progressCallback: () {}, cancelToken: ct); //} + /// 构建选项列表 + List _buildDMIWidgetList(List versions) { + final List dmil = []; + for (var i = 0; i > versions.length - 1; i++) { + dmil.add(_buildDMIWidget(version: versions[i], value: i)); + } + return dmil; + } + + /// 构建选项 DropdownMenuItem _buildDMIWidget( {required String version, required int value}) { return DropdownMenuItem( diff --git a/lib/controller/frpc.dart b/lib/controller/frpc.dart index 5dd9ee5e..c78c1a20 100644 --- a/lib/controller/frpc.dart +++ b/lib/controller/frpc.dart @@ -1,6 +1,8 @@ +import 'dart:convert'; import 'dart:io'; import 'package:get/get.dart'; +import 'package:nyalcf/io/frpcManagerStorage.dart'; import 'package:nyalcf/util/FileIO.dart'; class FrpcController extends GetxController { @@ -9,21 +11,16 @@ class FrpcController extends GetxController { var version = ''.obs; load() async { - exist.value = await file().exists(); + exist.value = await file.exists(); } /// 获取Frpc文件对象 - File file() { - String path = ''; - _support_path.then((value) { - path = value + '/frpc/${version}/frpc'; - }); - if (Platform.isWindows) path += '.exe'; - return File(path); - } + get file => FrpcManagerStorage.getFile(version.value); Future getVersion() async { - String path = await _support_path + '/frpc/frpc_info.json'; - return await File(path).readAsString(); + String path = await _support_path + '/setting/frpc.json'; + final setting = File(path).readAsString(); + final Map settingJson = jsonDecode(await setting); + return settingJson['use_version']; } } diff --git a/lib/io/frpcManager.dart b/lib/io/frpcManager.dart deleted file mode 100644 index 8b137891..00000000 --- a/lib/io/frpcManager.dart +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/io/frpcManagerStorage.dart b/lib/io/frpcManagerStorage.dart new file mode 100644 index 00000000..780f4334 --- /dev/null +++ b/lib/io/frpcManagerStorage.dart @@ -0,0 +1,33 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:nyalcf/util/FileIO.dart'; + +class FrpcManagerStorage { + static final _s_path = FileIO.support_path; + static Future get _path async { + return '${await _s_path}/frpc'; + } + + static init() { + Map json = Map(); + json['versions'] = []; + } + + /// 获取Frpc文件 + static Future getFile(String version) async { + final name; + if (Platform.isWindows) name = 'frpc.exe'; else name = 'frpc'; + return File('${_path}/${version}/${name}'); + } + + /// 获取已安装版本列表 + static Future> get versionList async { + final infoString = File('${await _path}/info.json').readAsString(); + final infoJson = jsonDecode(await infoString); + final versions = infoJson['versions']; + print(versions); + return versions; + } + +} diff --git a/lib/io/settingStorage.dart b/lib/io/settingStorage.dart new file mode 100644 index 00000000..66ac758c --- /dev/null +++ b/lib/io/settingStorage.dart @@ -0,0 +1,3 @@ +class SettingStorage { + +} \ No newline at end of file diff --git a/lib/ui/home.dart b/lib/ui/home.dart index 677c8722..2fcb9f32 100644 --- a/lib/ui/home.dart +++ b/lib/ui/home.dart @@ -49,14 +49,19 @@ class _HC extends GetxController { '欢迎使用Nya LoCyanFrp! Launcher', style: TextStyle(fontSize: 30), ), - const Text('にゃ~にゃ~,请选择一项操作'), - SizedBox( - height: 22.0, - width: 22.0, - child: CircularProgressIndicator( - strokeWidth: 2, - ), - ) + const Text('にゃ~にゃ~,检测到保存数据,正在校验以自动登录'), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: 22.0, + width: 22.0, + child: CircularProgressIndicator( + strokeWidth: 2, + ), + ), + ], + ), ].obs; load() async { @@ -64,6 +69,12 @@ class _HC extends GetxController { if (userinfo != null) { if (await CheckDio().checkToken(userinfo.token)) { w.value = []; + Get.snackbar( + '欢迎回来', + '已经自动登录啦~', + snackPosition: SnackPosition.BOTTOM, + animationDuration: Duration(milliseconds: 300), + ); Get.toNamed('/panel/home'); } else { Get.snackbar( diff --git a/lib/ui/model/AccountDialog.dart b/lib/ui/model/AccountDialog.dart index 58b00ea4..eddd24f5 100644 --- a/lib/ui/model/AccountDialog.dart +++ b/lib/ui/model/AccountDialog.dart @@ -14,7 +14,7 @@ class AccountDialogX { children: [ SimpleDialogOption( child: const ListTile( - leading: Icon(Icons.transit_enterexit), + leading: Icon(Icons.redo), title: Text('退出登录'), ), onPressed: () async { @@ -32,7 +32,7 @@ class AccountDialogX { }), SimpleDialogOption( child: const ListTile( - leading: Icon(Icons.headset), + leading: Icon(Icons.face), title: Text('编辑头像'), ), onPressed: () async { diff --git a/lib/util/FileIO.dart b/lib/util/FileIO.dart index 0484d073..87a6821b 100644 --- a/lib/util/FileIO.dart +++ b/lib/util/FileIO.dart @@ -10,6 +10,7 @@ class FileIO { static Future get cache_path async { String path = ''; await _cache_path.then((value) => path = value.path); + print('Get cache path $path'); return path; } @@ -19,6 +20,7 @@ class FileIO { static Future get support_path async { String path = ''; await _support_path.then((value) => path = value.path); + print('Get support path: $path'); return path; } }