Skip to content

Commit

Permalink
[+*]fix load & better icon & frpc utils(unfinished)
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Dec 20, 2023
1 parent 3308905 commit 008ac20
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 24 deletions.
18 changes: 16 additions & 2 deletions lib/controller/dsetting.dart
Original file line number Diff line number Diff line change
@@ -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 = <DropdownMenuItem>[].obs;
var frpc_version_value = 0.obs;

load() {
frpc_version_widgets.value = <DropdownMenuItem>[
load() async {
final versions = await FrpcManagerStorage.versionList;
final list = _buildDMIWidgetList(versions);
frpc_version_widgets.value = //list;
<DropdownMenuItem>[
DropdownMenuItem(
child: Text('0.51.3'),
value: 0,
Expand All @@ -28,6 +32,16 @@ class DSettingController extends GetxController {
//await FrpcDownloadDio()(arch: 'amd64', platform: 'windows', progressCallback: () {}, cancelToken: ct);
//}

/// 构建选项列表
List<DropdownMenuItem> _buildDMIWidgetList(List<String> versions) {
final List<DropdownMenuItem> dmil = <DropdownMenuItem>[];
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(
Expand Down
19 changes: 8 additions & 11 deletions lib/controller/frpc.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<String> 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<String, dynamic> settingJson = jsonDecode(await setting);
return settingJson['use_version'];
}
}
1 change: 0 additions & 1 deletion lib/io/frpcManager.dart

This file was deleted.

33 changes: 33 additions & 0 deletions lib/io/frpcManagerStorage.dart
Original file line number Diff line number Diff line change
@@ -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<String> get _path async {
return '${await _s_path}/frpc';
}

static init() {
Map<String, dynamic> json = Map();
json['versions'] = <String>[];
}

/// 获取Frpc文件
static Future<File> getFile(String version) async {
final name;
if (Platform.isWindows) name = 'frpc.exe'; else name = 'frpc';
return File('${_path}/${version}/${name}');
}

/// 获取已安装版本列表
static Future<List<String>> get versionList async {
final infoString = File('${await _path}/info.json').readAsString();
final infoJson = jsonDecode(await infoString);
final versions = infoJson['versions'];
print(versions);
return versions;
}

}
3 changes: 3 additions & 0 deletions lib/io/settingStorage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class SettingStorage {

}
27 changes: 19 additions & 8 deletions lib/ui/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,32 @@ 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 {
User? userinfo = await UserInfoStorage.read();
if (userinfo != null) {
if (await CheckDio().checkToken(userinfo.token)) {
w.value = <Widget>[];
Get.snackbar(
'欢迎回来',
'已经自动登录啦~',
snackPosition: SnackPosition.BOTTOM,
animationDuration: Duration(milliseconds: 300),
);
Get.toNamed('/panel/home');
} else {
Get.snackbar(
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/model/AccountDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AccountDialogX {
children: <Widget>[
SimpleDialogOption(
child: const ListTile(
leading: Icon(Icons.transit_enterexit),
leading: Icon(Icons.redo),
title: Text('退出登录'),
),
onPressed: () async {
Expand All @@ -32,7 +32,7 @@ class AccountDialogX {
}),
SimpleDialogOption(
child: const ListTile(
leading: Icon(Icons.headset),
leading: Icon(Icons.face),
title: Text('编辑头像'),
),
onPressed: () async {
Expand Down
2 changes: 2 additions & 0 deletions lib/util/FileIO.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class FileIO {
static Future<String> get cache_path async {
String path = '';
await _cache_path.then((value) => path = value.path);
print('Get cache path $path');
return path;
}

Expand All @@ -19,6 +20,7 @@ class FileIO {
static Future<String> get support_path async {
String path = '';
await _support_path.then((value) => path = value.path);
print('Get support path: $path');
return path;
}
}

0 comments on commit 008ac20

Please sign in to comment.