Skip to content

Commit

Permalink
Merge pull request #180 from Muska-Ami/dev
Browse files Browse the repository at this point in the history
Update GUI to v0.2.1+2
  • Loading branch information
Muska-Ami authored Sep 4, 2024
2 parents 16ec091 + e73fe43 commit 8d4f3da
Show file tree
Hide file tree
Showing 31 changed files with 726 additions and 742 deletions.
32 changes: 3 additions & 29 deletions RELEASE_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
使用方法请参考 NyaLCF Wiki 食用~ [Wiki](https://docs-nyalcf.1l1.icu)

**Breaking changes: 本版本修改了启动器包名,需要手动迁移配置文件位置**
****

请参照 [如何重置启动器](https://docs-nyalcf.1l1.icu/gui/chang-jian-wen-ti-jie-da#q-ru-he-zhong-zhi-qi-dong-qi) 找到您的数据目录,并将 `moe.xmcn.nyanana` 文件夹改名为 `moe.muska.ami`,造成不便请谅解。

此外,要使用 LoCyan Mirrors 镜像源,请修改你的 `frpc.json` :

```json
{
// ...
"lists": {
// ...
"frpc_download_mirrors": [
// ...
{
"name": "LoCyan Mirrors",
"id": "locyan-mirror",
// 将这里的 github-releases 改成 github-release
// 请不要把注释粘进去
"format": "https://mirrors.locyan.cn/github-release/{owner}/{repo}/{release_name}/frp_LoCyanFrp-{version_pure}_{platform}_{arch}.{suffix}"
}
]
}
}

```

[//]: # (应用户需求,Nya LoCyanFrp! 开始开发 CLI 版本,欢迎使用和反馈问题!)

## 更新日志

### GUI

- 更改了包名
- 修复写错了一个镜像信息
- 添加了自动滚动
- 修改了一些放错了位置的逻辑
- 移除多余的类定义

### CLI

Expand Down
38 changes: 19 additions & 19 deletions nyalcf_gui/nyalcf_core_extend/lib/utils/frpc/process_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class FrpcProcessManager {
// procesList.add();
// pMap['process'] = process;
// pMap['proxy_id'] = proxyId;
_cCtr.addProcess(process);
_fCtr.addProcess(process);
} catch (e, st) {
// 检测是否被拦截
if (e.toString().contains('包含病毒或潜在的垃圾软件')) {
Get.dialog(DefenderDialogX().build());
Get.dialog(defenderDialog());
}
Logger.error(e, t: st);
}
Expand All @@ -71,9 +71,9 @@ class FrpcProcessManager {
processInstance.stderr.forEach((List<int> element) {
final String fmtStr = utf8.decode(element).trim();
Logger.frpcError(proxyId, fmtStr);
_fCtr.appendErrorLog(fmtStr);
_cCtr.appendErrorLog(fmtStr);
process!.process.kill();
_cCtr.removeProcess(process);
_fCtr.removeProcess(process);
});
}

Expand All @@ -88,22 +88,22 @@ class FrpcProcessManager {
!str.contains('重连失败')) {
// 启动失败
Logger.frpcWarn(process.proxyId, str);
_fCtr.appendWarnLog(str);
_cCtr.appendWarnLog(str);
process.process.kill();
_cCtr.removeProcess(process);
_fCtr.removeProcess(process);
} else if (str.contains('[E]') || str.contains('failed')) {
// Frpc 错误
Logger.frpcError(process.proxyId, str);
_fCtr.appendErrorLog(str);
_cCtr.appendErrorLog(str);
// 例外
if (!str.contains(
'No connection could be made because the target machine actively refused it')) {
process.process.kill();
_cCtr.removeProcess(process);
_fCtr.removeProcess(process);
}
} else {
Logger.frpcInfo(process.proxyId, str);
_fCtr.appendInfoLog(str);
_cCtr.appendInfoLog(str);
}
final List<Map<String, String>> errorList = [
{
Expand All @@ -130,36 +130,36 @@ class FrpcProcessManager {
];
for (Map<String, String> error in errorList) {
if (str.contains(error['key']!)) {
_fCtr.appendSystemInfoLog('提示:${error['info']}');
_cCtr.appendSystemInfoLog('提示:${error['info']}');
}
}
}

void killAll() {
Logger.info('Killing all process');
Logger.debug('Process length: ${ConsoleController.processList.length}');
_fCtr.appendSystemInfoLog('Killing all process...');
Logger.debug('Process length: ${FrpcController.processList.length}');
_cCtr.appendSystemInfoLog('Killing all process...');
try {
var allList = [];
allList.addAll(ConsoleController.processList);
allList.addAll(FrpcController.processList);
for (var element in allList) {
kill(element);
}
_cCtr.clearProcess();
_fCtr.clearProcess();
} catch (e, st) {
_fCtr.appendSystemErrorLog('Killing all process error: $e');
_cCtr.appendSystemErrorLog('Killing all process error: $e');
Logger.error(e, t: st);
}
Logger.info('All process killed');
_fCtr.appendSystemInfoLog('All process killed');
_cCtr.appendSystemInfoLog('All process killed');
}

void kill(ProcessModel prs) {
Logger.info('Killing frpc process, pid: ${prs.process.pid}');
_fCtr.appendSystemInfoLog('Killing process, pid: ${prs.process.pid}');
_cCtr.appendSystemInfoLog('Killing process, pid: ${prs.process.pid}');
prs.process.kill();
_cCtr.removeProcess(prs);
_fCtr.removeProcess(prs);

Logger.debug('Process length: ${ConsoleController.processList.length}');
Logger.debug('Process length: ${FrpcController.processList.length}');
}
}
153 changes: 132 additions & 21 deletions nyalcf_gui/nyalcf_ui/lib/controllers/console_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,156 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'package:nyalcf_core_extend/utils/frpc/process_manager.dart';
import 'package:nyalcf_ui/views/panel/console.dart';
import 'package:nyalcf_core/models/process_model.dart';
import 'package:nyalcf_ui/controllers/frpc_controller.dart';

/// 控制台 GetX 状态控制器
class ConsoleController extends GetxController {
/// UI组件列表
var widgets = <DataRow>[].obs;
static var processListWidget = <Widget>[].obs;

/// 进程管理列表
static var processList = <ProcessModel>[].obs;
var autoScroll = true.obs;

/// 添加进程
void addProcess(ProcessModel process) {
processList.add(process);
processList.refresh();
PanelConsole.buildProcessListWidget();
/// 过滤后的输出文本
RxList<SelectableText> processOut = <SelectableText>[
const SelectableText(
'[SYSTEM] Welcome to frpc console.',
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
)
].obs;

/// 追加信息日志
void appendInfoLog(String element) {
/// 如果输出文本长度超过500,则移除第一条文本
if (processOut.length >= 500) processOut.remove(processOut.first);

/// 添加信息日志文本
processOut.add(
SelectableText(
'[FRPC][INFO] $element',
style: const TextStyle(
color: Colors.teal,
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
),
);

/// 刷新输出文本
processOut.refresh();
}

/// 添加进程
void removeProcess(ProcessModel process) {
processList.remove(process);
processList.refresh();
PanelConsole.buildProcessListWidget();
/// 追加警告日志
void appendWarnLog(String element) {
/// 如果输出文本长度超过500,则移除第一条文本
if (processOut.length >= 500) processOut.remove(processOut.first);

/// 添加警告日志文本
processOut.add(
SelectableText(
'[FRPC][WARN] $element',
style: const TextStyle(
color: Colors.orange,
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
),
);

/// 刷新输出文本
processOut.refresh();
}

/// 清空进程
/// 请将进程全部结束后再运行此方法,此方法不会结束进程
void clearProcess() {
processList.clear();
processList.refresh();
load();
PanelConsole.buildProcessListWidget();
/// 追加错误日志
void appendErrorLog(String element) {
/// 如果输出文本长度超过500,则移除第一条文本
if (processOut.length >= 500) processOut.remove(processOut.first);

/// 添加错误日志文本
processOut.add(
SelectableText(
'[FRPC][ERROR] $element',
style: const TextStyle(
color: Colors.red,
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
),
);

/// 刷新输出文本
processOut.refresh();
}

void appendSystemInfoLog(String element) {
/// 如果输出文本长度超过500,则移除第一条文本
if (processOut.length >= 500) processOut.remove(processOut.first);

/// 添加警告日志文本
processOut.add(
SelectableText(
'[SYSTEM][INFO] $element',
style: TextStyle(
color: Colors.tealAccent[400],
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
),
);

/// 刷新输出文本
processOut.refresh();
}

void appendSystemWarnLog(String element) {
/// 如果输出文本长度超过500,则移除第一条文本
if (processOut.length >= 500) processOut.remove(processOut.first);

/// 添加信息日志文本
processOut.add(
SelectableText(
'[SYSTEM][WARN] $element',
style: TextStyle(
color: Colors.orangeAccent[400],
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
),
);

/// 刷新输出文本
processOut.refresh();
}

void appendSystemErrorLog(String element) {
/// 如果输出文本长度超过500,则移除第一条文本
if (processOut.length >= 500) processOut.remove(processOut.first);

/// 添加错误日志文本
processOut.add(
SelectableText(
'[SYSTEM][ERROR] $element',
style: TextStyle(
color: Colors.redAccent[400],
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
),
);

/// 刷新输出文本
processOut.refresh();
}

/// 加载进程管理信息
load() {
widgets.value = <DataRow>[];
for (ProcessModel element in processList) {
for (ProcessModel element in FrpcController.processList) {
final Process process = element.process;
final int proxyId = element.proxyId;

Expand Down
Loading

0 comments on commit 8d4f3da

Please sign in to comment.