Skip to content

Commit

Permalink
GUI: Refactor reference object name
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Jul 20, 2024
1 parent 86ddfbb commit 22f883f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
7 changes: 7 additions & 0 deletions nyalcf_cli/lib/utils/process_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import 'package:nyalcf_core/models/process_model.dart';
class ProcessManager {
static final List<ProcessModel> processList = [];

/// 添加进程
static void addProcess(ProcessModel process) {
processList.add(process);
}

/// 添加进程
static void removeProcess(ProcessModel process) {
processList.remove(process);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DeepLinkExecutor {
final frpToken = data[0], proxyId = int.parse(data[1]);
final frpcPath = await FrpcPathProvider().frpcPath;
if (frpcPath != null) {
FrpcProcessManager().nwprcs(
FrpcProcessManager().newProcess(
frpToken: frpToken,
proxyId: proxyId,
frpcPath: frpcPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import 'package:nyalcf_ui/models/defender_dialog.dart';
class FrpcProcessManager {
final _fss = FrpcStorage();
final FrpcController _fCtr = Get.find();
final ConsoleController cctr = Get.find();
final ConsoleController _cCtr = Get.find();

void nwprcs({
void newProcess({
required String frpToken,
required int proxyId,
required String frpcPath,
Expand Down Expand Up @@ -52,7 +52,7 @@ class FrpcProcessManager {
// procesList.add();
// pMap['process'] = process;
// pMap['proxy_id'] = proxyId;
cctr.addProcess(process);
_cCtr.addProcess(process);
} catch (e, st) {
// 检测是否被拦截
if (e.toString().contains('包含病毒或潜在的垃圾软件')) {
Expand All @@ -73,7 +73,7 @@ class FrpcProcessManager {
Logger.frpcError(proxyId, fmtStr);
_fCtr.appendErrorLog(fmtStr);
process!.process.kill();
cctr.removeProcess(process);
_cCtr.removeProcess(process);
});
}

Expand All @@ -90,7 +90,7 @@ class FrpcProcessManager {
Logger.frpcWarn(process.proxyId, str);
_fCtr.appendWarnLog(str);
process.process.kill();
cctr.removeProcess(process);
_cCtr.removeProcess(process);
} else if (str.contains('[E]') || str.contains('failed')) {
// Frpc 错误
Logger.frpcError(process.proxyId, str);
Expand All @@ -99,7 +99,7 @@ class FrpcProcessManager {
if (!str.contains(
'No connection could be made because the target machine actively refused it')) {
process.process.kill();
cctr.removeProcess(process);
_cCtr.removeProcess(process);
}
} else {
Logger.frpcInfo(process.proxyId, str);
Expand Down Expand Up @@ -145,7 +145,7 @@ class FrpcProcessManager {
for (var element in allList) {
kill(element);
}
cctr.clearProcess();
_cCtr.clearProcess();
} catch (e, st) {
_fCtr.appendSystemErrorLog('Killing all process error: $e');
Logger.error(e, t: st);
Expand All @@ -158,7 +158,7 @@ class FrpcProcessManager {
Logger.info('Killing frpc process, pid: ${prs.process.pid}');
_fCtr.appendSystemInfoLog('Killing process, pid: ${prs.process.pid}');
prs.process.kill();
cctr.removeProcess(prs);
_cCtr.removeProcess(prs);

Logger.debug('Process length: ${ConsoleController.processList.length}');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FrpcStartUpLoader {
if (execPath != null) {
for (var proxy in proxiesList) {
Logger.info('Starting proxy: $proxy');
pm.nwprcs(
pm.newProcess(
frpToken: uc.frpToken.value,
proxyId: proxy,
frpcPath: execPath,
Expand Down
9 changes: 5 additions & 4 deletions nyalcf_gui/nyalcf_ui/lib/controllers/console_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ class ConsoleController extends GetxController {
static var processList = <ProcessModel>[].obs;

/// 添加进程
addProcess(ProcessModel process) {
void addProcess(ProcessModel process) {
processList.add(process);
processList.refresh();
PanelConsole.buildProcessListWidget();
}

/// 移除进程
removeProcess(ProcessModel process) {
/// 添加进程
void removeProcess(ProcessModel process) {
processList.remove(process);
processList.refresh();
PanelConsole.buildProcessListWidget();
}

/// 清空进程
clearProcess() {
/// 请将进程全部结束后再运行此方法,此方法不会结束进程
void clearProcess() {
processList.clear();
processList.refresh();
load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class ProxiesController extends GetxController {
onPressed: () async {
final execPath = await FrpcPathProvider().frpcPath;
if (execPath != null) {
FrpcProcessManager().nwprcs(
FrpcProcessManager().newProcess(
frpToken: _uCtr.frpToken.value,
proxyId: element.id,
frpcPath: execPath,
Expand Down
2 changes: 1 addition & 1 deletion nyalcf_gui/nyalcf_ui/lib/views/tokenmode/panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class _TokenModePanelState extends State {
);
return;
}
FrpcProcessManager().nwprcs(
FrpcProcessManager().newProcess(
frpToken: frpToken,
proxyId: proxyId,
frpcPath: execPath,
Expand Down

0 comments on commit 22f883f

Please sign in to comment.