Skip to content

Commit

Permalink
Merge pull request #8 from Muska-Ami/dev
Browse files Browse the repository at this point in the history
Push dev to main
  • Loading branch information
Muska-Ami authored Dec 30, 2023
2 parents 875378d + 7bb467e commit 1c0c355
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 121 deletions.
47 changes: 6 additions & 41 deletions lib/controller/dsetting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:nyalcf/io/frpcManagerStorage.dart';
import 'package:nyalcf/model/FrpcConfig.dart';
import 'package:nyalcf/prefs/SettingPrefs.dart';
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';
Expand All @@ -26,6 +27,7 @@ class DSettingController extends GetxController {
var frpc_download_arch = 0.obs;
var frpc_download_progress = 0.0.obs;
var frpc_download_show = <Widget>[].obs;
var _frpc_downloaded_versions = [];
dynamic frpc_download_cancel = false;

var frpc_version = ''.obs;
Expand All @@ -36,7 +38,6 @@ class DSettingController extends GetxController {

var github_proxy = ''.obs;

var _frpc_downloaded_versions = [];
var cpu_arch = ''.obs;

load() async {
Expand All @@ -55,46 +56,9 @@ class DSettingController extends GetxController {
void _load_tip() async {
_frpc_downloaded_versions = await FrpcManagerStorage.downloadedVersions;
if (_frpc_downloaded_versions.length == 0) {
frpc_download_tip.value = Container(
child: Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
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: <Widget>[
Text('无法启动隧道了...呜呜...'),
Container(
margin: EdgeInsets.only(top: 10.0),
child: Row(
children: <Widget>[
ElevatedButton(
onPressed: () async {
showDialog(
context: context,
builder: (context) {
return FrpcDownloadDialogX(context: context)
.build();
});
},
child: Text('下载'),
),
],
),
),
],
),
)
],
),
),
);
frpc_download_tip.value = FrpcDownloadTip.tip(context: context);
} else {
frpc_download_tip.value = await FrpcDownloadTip.downloaded(context: context);
}
}

Expand Down Expand Up @@ -143,6 +107,7 @@ class DSettingController extends GetxController {
if (!Platform.isWindows) {
await FrpcManagerStorage.setRunPermission();
}
_load_tip();
} else {
Get.snackbar(
'解压 Frpc 时发生错误..呜呜..',
Expand Down
34 changes: 21 additions & 13 deletions lib/io/frpcManagerStorage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:nyalcf/model/FrpcConfig.dart';
import 'package:nyalcf/prefs/SettingPrefs.dart';
import 'package:nyalcf/util/FileIO.dart';

class FrpcManagerStorage {
Expand All @@ -11,7 +12,7 @@ class FrpcManagerStorage {
return '${await _s_path}/frpc';
}

static Future<FrpcConfig?> get _info async {
static Future<FrpcConfig?> read() async {
try {
final String result =
await File('${await _path}/info.json').readAsString(encoding: utf8);
Expand All @@ -21,19 +22,26 @@ class FrpcManagerStorage {
}
}

static Future<FrpcConfig> get _info async => SettingPrefs.getFrpcInfo();

static void init() {
_path.then((path) {
if (!Directory(path).existsSync()) Directory(path).createSync();
final infoF = File('${path}/info.json');
if (!infoF.existsSync()) {
Map<String, dynamic> json = Map();
json['settings']['frpc_version'] = '';
json['settings']['github_proxy'] = <String>[];
json['lists']['frpc_downloaded_versions'] = <String>[];
json['lists']['github_proxies'] = <String>[
'https://mirror.ghproxy.com/',
'https://ghproxy.com/',
];
Map<String, dynamic> json = {
'settings': {
'frpc_version': '',
'github_proxy': <String>[],
},
'lists': {
'frpc_downloaded_versions': <String>[],
'github_proxies': <String>[
'https://mirror.ghproxy.com/',
'https://ghproxy.com/',
],
},
};
infoF.writeAsStringSync(jsonEncode(json));
}
});
Expand Down Expand Up @@ -63,25 +71,25 @@ class FrpcManagerStorage {

/// 获取正在使用的版本
static Future<String> get usingVersion async {
final version = (await _info)?.frpc_version ?? '';
final version = (await _info).frpc_version;
return version;
}

/// 自定义GitHub代理列表
static Future<List<String>> get proxies async {
final url = (await _info)?.github_proxies ?? [];
final url = (await _info).github_proxies;
return url;
}

/// GitHub代理
static Future<String> get proxyUrl async {
final url = (await _info)?.github_proxy ?? '';
final url = (await _info).github_proxy;
return url;
}

/// 获取已安装版本列表
static Future<List<String>> get downloadedVersions async {
final versions = (await _info)?.frpc_downloaded_versions ?? [];
final versions = (await _info).frpc_downloaded_versions;
print(versions);
return versions;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/prefs/SettingPrefs.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:nyalcf/io/frpcManagerStorage.dart';
import 'package:nyalcf/model/FrpcConfig.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand All @@ -13,10 +14,10 @@ class SettingPrefs {

static Future<void> setFrpcDownloadedVersionsInfo(String version) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final newlist = (await getFrpcInfo()).lists['frpc_downloaded_versions'] ?? [];
final newlist =
(await getFrpcInfo()).lists['frpc_downloaded_versions'] ?? [];
newlist.add(version);
prefs.setStringList(
'list@frpc_downloaded_versions', newlist);
prefs.setStringList('list@frpc_downloaded_versions', newlist);
}

static Future<FrpcConfig> getFrpcInfo() async {
Expand All @@ -37,4 +38,6 @@ class SettingPrefs {

return FrpcConfig(settings: settings, lists: lists);
}

static Future<void> refresh() async => { if (await FrpcManagerStorage.read() != null) setFrpcInfo((await FrpcManagerStorage.read())!)};
}
73 changes: 73 additions & 0 deletions lib/ui/model/FrpcDownloadTip.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import 'package:nyalcf/prefs/SettingPrefs.dart';

import 'FrpcDownloadDialog.dart';

class FrpcDownloadTip {

static Container tip({required context}) => Container(
child: Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
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: <Widget>[
Text('无法启动隧道了...呜呜...'),
Container(
margin: EdgeInsets.only(top: 10.0),
child: Row(
children: <Widget>[
ElevatedButton(
onPressed: () async {
showDialog(
context: context,
builder: (context) {
return FrpcDownloadDialogX(context: context)
.build();
});
},
child: Text('下载'),
),
],
),
),
],
),
)
],
),
),
);

static Future<Container> downloaded({required context}) async => Container(
child: Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ListTile(
leading: Icon(Icons.check_circle),
title: Text('可用的 Frpc 版本已安装!素晴らしい!'),
),
Container(
margin: EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('已安装版本列表:'),
Text((await SettingPrefs.getFrpcInfo()).lists['frpc_downloaded_versions'].toString()),
],
),
)
],
),
),
);

}
64 changes: 0 additions & 64 deletions lib/ui/setting/frpcmanager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,70 +11,6 @@ class FrpcManagerSX {
child: ListView(
children: <Widget>[
Obx(() => ds_c.frpc_download_tip.value),

/*
Card(
child: Row(
children: [
Expanded(
child: ListTile(
leading: Icon(Icons.cabin),
title: Text('Frpc版本'),
),
),
Container(
width: 80,
margin: EdgeInsets.only(right: 25.0),
child: Obx(
() => DropdownButton(
value: ds_c.frpc_version_value.value,
items: ds_c.frpc_version_widgets,
onChanged: (v) {
ds_c.frpc_version_value.value = v;
},
),
),
)
],
),
),
Card(
child: Column(
children: [
Row(
children: [
Expanded(
child: ListTile(
leading: Icon(Icons.cabin),
title: Text('GitHub下载源代理设置'),
),
),
Container(
width: 80,
margin: EdgeInsets.only(right: 25.0),
child: Obx(
() => DropdownButton(
value: ds_c.github_proxy_url_value.value,
items: ds_c.github_proxy_widgets,
onChanged: (v) {
ds_c.github_proxy_url_value.value = v;
},
),
),
)
],
),
Obx(() => Text(
'当前代理:${ds_c.github_proxy_url}',
style: TextStyle(
color: Colors.grey,
fontStyle: FontStyle.italic,
),
)),
ElevatedButton(onPressed: null, child: Text('保存'))
],
),
),*/
],
),
);
Expand Down

0 comments on commit 1c0c355

Please sign in to comment.