Skip to content

Commit

Permalink
[+*]Refactor ProcessManager to FrpcProcessManager & FrpcArchive & for…
Browse files Browse the repository at this point in the history
…mat code
  • Loading branch information
Muska-Ami committed Dec 24, 2023
1 parent 8f43a00 commit 56c44dd
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 49 deletions.
1 change: 0 additions & 1 deletion lib/controller/dsetting.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyalcf/io/frpcManagerStorage.dart';

class DSettingController extends GetxController {
var _frpc_version = ''.obs;
Expand Down
3 changes: 2 additions & 1 deletion lib/controller/proxies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class ProxiesController extends GetxController {
IconButton(
icon: Icon(Icons.play_circle),
onPressed: () => {
ProcessManager().nwprcs(frp_token: c.frp_token.value, proxy_id: element.id)
FrpcProcessManager().nwprcs(
frp_token: c.frp_token.value, proxy_id: element.id)
},
),
IconButton(
Expand Down
35 changes: 21 additions & 14 deletions lib/dio/frpc/download.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:nyalcf/dio/basicConfig.dart';
import 'package:nyalcf/model/FrpcList.dart';
import 'package:nyalcf/util/FileIO.dart';

class FrpcDownloadDio {
Expand All @@ -21,18 +18,28 @@ class FrpcDownloadDio {
*/

Future<dynamic> download(
{required String arch,
required String platform,
required ProgressCallback progressCallback,
required CancelToken cancelToken,
String proxy = ''}) async {
/// 下载Frpc
Future<dynamic> download({
required String arch,
required String platform,
required ProgressCallback progressCallback,
required CancelToken cancelToken,
String proxy = '',
}) async {
try {
return await dio.download(
'${proxy + basicConfig.github_main_url}/LoCyan-Team/LoCyanFrpPureApp/releases/download/v0.51.3/frp_LoCyanFrp-0.51.3_windows_amd64.zip',
'${FileIO.cache_path}/frpc.zip',
cancelToken: cancelToken,
onReceiveProgress: progressCallback);
if (platform == 'windows') {
return await dio.download(
'${proxy + basicConfig.github_main_url}/LoCyan-Team/LoCyanFrpPureApp/releases/download/v0.51.3/frp_LoCyanFrp-0.51.3_${platform}_${arch}.zip',
'${FileIO.cache_path}/frpc.zip',
cancelToken: cancelToken,
onReceiveProgress: progressCallback);
} else {
return await dio.download(
'${proxy + basicConfig.github_main_url}/LoCyan-Team/LoCyanFrpPureApp/releases/download/v0.51.3/frp_LoCyanFrp-0.51.3_${platform}_${arch}.tar.gz',
'${FileIO.cache_path}/frpc.tar.gz',
cancelToken: cancelToken,
onReceiveProgress: progressCallback);
}
} on DioException {
if (cancelToken.isCancelled)
return true;
Expand Down
3 changes: 2 additions & 1 deletion lib/io/frpcManagerStorage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ 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 get infoJson async {
final infoString = File('${await _path}/info.json').readAsString();
return jsonDecode(await infoString);
Expand Down Expand Up @@ -74,5 +76,4 @@ class FrpcManagerStorage {
print(versions);
return versions;
}

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

}
class SettingStorage {}
2 changes: 1 addition & 1 deletion lib/ui/model/AppbarActions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class AppbarActionsX {
style: TextStyle(color: Colors.red),
),
onPressed: () {
ProcessManager().killAll();
FrpcProcessManager().killAll();
Navigator.pop(context, true);
},
),
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/panel/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class PanelConsole extends StatelessWidget {
),
ElevatedButton(
onPressed: () {
ProcessManager().killAll();
FrpcProcessManager().killAll();
},
child: Text('关闭所有进程',
style: TextStyle(
Expand Down
11 changes: 7 additions & 4 deletions lib/ui/setting/frpcmanager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ class FrpcManagerSX {
)
],
),
Obx(() => Text('当前代理:${ds_c.github_proxy_url}', style: TextStyle(
color: Colors.grey,
fontStyle: FontStyle.italic,
),)),
Obx(() => Text(
'当前代理:${ds_c.github_proxy_url}',
style: TextStyle(
color: Colors.grey,
fontStyle: FontStyle.italic,
),
)),
ElevatedButton(onPressed: null, child: Text('保存'))
],
),
Expand Down
24 changes: 24 additions & 0 deletions lib/util/FileIO.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:path_provider/path_provider.dart';

class FileIO {
Expand All @@ -23,4 +25,26 @@ class FileIO {
print('Get support path: $path');
return path;
}

/**
* 移动文件夹
*/
static void moveDirectory(Directory sourceDir, Directory targetDir) {
if (!targetDir.existsSync()) {
targetDir.createSync(recursive: true);
}

sourceDir.listSync().forEach((FileSystemEntity entity) {
String newPath = targetDir.path + '/' + entity.uri.pathSegments.last;

if (entity is File) {
File newFile = File(newPath);
entity.renameSync(newFile.path);
} else if (entity is Directory) {
Directory newDir = Directory(newPath);
moveDirectory(entity, newDir);
entity.deleteSync();
}
});
}
}
35 changes: 35 additions & 0 deletions lib/util/frpc/Archive.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'dart:io';

import 'package:archive/archive_io.dart';
import 'package:nyalcf/util/FileIO.dart';

class FrpcArchive {
static final _c_path = FileIO.cache_path;
static final _s_path = FileIO.support_path;

static bool unarchive({
required platform,
required arch,
required version,
}) {
File f;
_c_path.then((c_path) {
if (Platform.isWindows)
f = File('${c_path}/frpc.zip');
else
f = File('${c_path}/frpc.tar.gz');
if (f.existsSync()) {
extractFileToDisk(f.path, c_path);
_s_path.then((s_path) {
final dir = Directory(
'${c_path}/frp_LoCyanFrp-${version}_${platform}_${arch}');
FileIO.moveDirectory(dir, Directory('${s_path}/frpc/${version}'));
return true;
});
} else {
return false;
}
});
return false;
}
}
3 changes: 1 addition & 2 deletions lib/util/frpc/ProcessManager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import 'package:get/get.dart';
import 'package:nyalcf/controller/frpc.dart';
import 'package:nyalcf/io/frpcManagerStorage.dart';

class ProcessManager {

class FrpcProcessManager {
final FrpcController f_c = Get.find();

final List<Process> process_list = <Process>[];
Expand Down
42 changes: 21 additions & 21 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
dependency: "direct main"
description:
name: archive
sha256: "7b875fd4a20b165a3084bd2d210439b22ebc653f21cea4842729c0c30c82596b"
Expand All @@ -29,26 +29,26 @@ packages:
dependency: "direct main"
description:
name: bitsdojo_window
sha256: "1118bc1cd16e6f358431ca4473af57cc1b287d2ceab46dfab6d59a9463160622"
sha256: "88ef7765dafe52d97d7a3684960fb5d003e3151e662c18645c1641c22b873195"
url: "https://pub.dev"
source: hosted
version: "0.1.5"
version: "0.1.6"
bitsdojo_window_linux:
dependency: transitive
description:
name: bitsdojo_window_linux
sha256: d3804a30315fcbb43b28acc86d1180ce0be22c0c738ad2da9e5ade4d8dbd9655
sha256: "9519c0614f98be733e0b1b7cb15b827007886f6fe36a4fb62cf3d35b9dd578ab"
url: "https://pub.dev"
source: hosted
version: "0.1.3"
version: "0.1.4"
bitsdojo_window_macos:
dependency: transitive
description:
name: bitsdojo_window_macos
sha256: d2a9886c74516c5b84c1dd65ab8ee5d1c52055b265ebf0e7d664dee28366b521
sha256: f7c5be82e74568c68c5b8449e2c5d8fd12ec195ecd70745a7b9c0f802bb0268f
url: "https://pub.dev"
source: hosted
version: "0.1.3"
version: "0.1.4"
bitsdojo_window_platform_interface:
dependency: transitive
description:
Expand All @@ -61,10 +61,10 @@ packages:
dependency: transitive
description:
name: bitsdojo_window_windows
sha256: "8766a40aac84a6d7bdcaa716b24997e028fc9a9a1800495fc031721fd5a22ed0"
sha256: fa982cf61ede53f483e50b257344a1c250af231a3cdc93a7064dd6dc0d720b68
url: "https://pub.dev"
source: hosted
version: "0.1.5"
version: "0.1.6"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -332,10 +332,10 @@ packages:
dependency: transitive
description:
name: petitparser
sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
url: "https://pub.dev"
source: hosted
version: "5.4.0"
version: "6.0.2"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -404,10 +404,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_web
sha256: d762709c2bbe80626ecc819143013cc820fa49ca5e363620ee20a8b15a3e3daf
sha256: "7b15ffb9387ea3e237bb7a66b8a23d2147663d391cafc5c8f37b2e7b4bde5d21"
url: "https://pub.dev"
source: hosted
version: "2.2.1"
version: "2.2.2"
shared_preferences_windows:
dependency: transitive
description:
Expand Down Expand Up @@ -529,10 +529,10 @@ packages:
dependency: transitive
description:
name: url_launcher_web
sha256: "7fd2f55fe86cea2897b963e864dc01a7eb0719ecc65fcef4c1cc3d686d718bb2"
sha256: "7286aec002c8feecc338cc33269e96b73955ab227456e9fb2a91f7fab8a358e9"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "2.2.2"
url_launcher_windows:
dependency: transitive
description:
Expand Down Expand Up @@ -561,10 +561,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: a6f0236dbda0f63aa9a25ad1ff9a9d8a4eaaa5012da0dc59d21afdb1dc361ca4
sha256: b0f37db61ba2f2e9b7a78a1caece0052564d1bc70668156cf3a29d676fe4e574
url: "https://pub.dev"
source: hosted
version: "3.1.4"
version: "5.1.1"
xdg_directories:
dependency: transitive
description:
Expand All @@ -577,10 +577,10 @@ packages:
dependency: transitive
description:
name: xml
sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84"
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
url: "https://pub.dev"
source: hosted
version: "6.3.0"
version: "6.5.0"
yaml:
dependency: transitive
description:
Expand All @@ -590,5 +590,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.13.0"
dart: ">=3.2.0 <4.0.0"
flutter: ">=3.16.0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
shared_preferences: ^2.2.2
get: ^4.6.6
flutter_markdown: ^0.6.18+2
archive: ^3.4.9

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 56c44dd

Please sign in to comment.