Skip to content

Commit

Permalink
[+]Frpc console log & startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Dec 22, 2023
1 parent 078f53f commit 2d2ef36
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 51 deletions.
Binary file added asset/font/Droid_Sans_Mono.ttf
Binary file not shown.
56 changes: 56 additions & 0 deletions lib/controller/frpc.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyalcf/io/frpcManagerStorage.dart';
import 'package:nyalcf/util/FileIO.dart';

class FrpcController extends GetxController {
final _support_path = FileIO.support_path;
var exist = false.obs;
var process_out = <SelectableText>[
SelectableText(
'[SYSTEM] Welcome to frpc console.',
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
)
].obs;
var version = ''.obs;

load() async {
Expand All @@ -23,4 +34,49 @@ class FrpcController extends GetxController {
final Map<String, dynamic> settingJson = jsonDecode(await setting);
return settingJson['use_version'];
}

void appendInfoLog(element) {
if (process_out.length >= 500) process_out.remove(process_out.first);
process_out.add(
SelectableText(
'[FRPC][INFO] $element',
style: TextStyle(
color: Colors.teal,
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
),
);
process_out.refresh();
}

void appendWarnLog(element) {
if (process_out.length >= 500) process_out.remove(process_out.first);
process_out.add(
SelectableText(
'[FRPC][WARN] $element',
style: TextStyle(
color: Colors.orange,
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
),
);
process_out.refresh();
}

void appendErrorLog(element) {
if (process_out.length >= 500) process_out.remove(process_out.first);
process_out.add(
SelectableText(
'[FRPC][ERROR] $element',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.w200,
fontFamily: 'Droid Sans Mono',
),
),
);
process_out.refresh();
}
}
21 changes: 3 additions & 18 deletions lib/controller/proxies.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyalcf/controller/user.dart';
import 'package:nyalcf/dio/proxies/get.dart';
import 'package:nyalcf/io/frpcManagerStorage.dart';
import 'package:nyalcf/model/ProxyInfo.dart';
import 'package:nyalcf/util/frpc/ProcessManager.dart';

import 'frpc.dart';

Expand Down Expand Up @@ -54,21 +52,8 @@ class ProxiesController extends GetxController {
children: [
IconButton(
icon: Icon(Icons.play_circle),
onPressed: () async {
var runner = await Process.start(
await FrpcManagerStorage.getFilePath('0.51.3'),
[
'-u',
c.frp_token.value,
'-p',
element.id.toString(),
],
workingDirectory:
await FrpcManagerStorage.getRunPath('0.51.3'),

);
stdout.addStream(runner.stdout);
stderr.addStream(runner.stderr);
onPressed: () => {
ProcessManager().nwprcs(frp_token: c.frp_token.value, proxy_id: element.id)
},
),
IconButton(
Expand Down
45 changes: 21 additions & 24 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,26 @@ class App extends StatelessWidget {

Get.put(UserController());
return GetMaterialApp(
title: 'Nya LoCyanFrp!',
routes: {
'/': (context) => Home(title: title),
'/login': (context) => Login(title: title),
'/register': (context) => Register(title: title),
'/panel/home': (context) => PanelHome(title: title),
'/panel/proxies': (context) => PanelProxies(title: title),
'/panel/console': (context) => PanelConsole(title: title),
'/setting': (context) => SettingInjector(title: title),
},
theme: ThemeData(
useMaterial3: true,
fontFamily: 'HarmonyOS Sans',
iconButtonTheme: IconButtonThemeData(
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all(
Colors.white
)
)
),
colorScheme: ColorScheme.fromSeed(seedColor: Colors.pink.shade300)
.copyWith(
primary: Colors.pink.shade500,
secondary: Colors.pink.shade400)));
title: 'Nya LoCyanFrp!',
routes: {
'/': (context) => Home(title: title),
'/login': (context) => Login(title: title),
'/register': (context) => Register(title: title),
'/panel/home': (context) => PanelHome(title: title),
'/panel/proxies': (context) => PanelProxies(title: title),
'/panel/console': (context) => PanelConsole(title: title),
'/setting': (context) => SettingInjector(title: title),
},
theme: ThemeData(
useMaterial3: true,
fontFamily: 'HarmonyOS Sans',
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.pink.shade300,
).copyWith(
primary: Colors.pink.shade500,
secondary: Colors.pink.shade400,
),
),
);
}
}
37 changes: 28 additions & 9 deletions lib/ui/panel/console.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyalcf/controller/frpc.dart';
import 'package:nyalcf/controller/user.dart';
import 'package:nyalcf/ui/model/AccountDialog.dart';
import 'package:nyalcf/ui/model/AppbarActions.dart';
Expand All @@ -11,6 +12,7 @@ class PanelConsole extends StatelessWidget {
PanelConsole({super.key, required this.title});

final UserController c = Get.find();
final FrpcController f_c = Get.find();
final String title;

@override
Expand Down Expand Up @@ -42,15 +44,32 @@ class PanelConsole extends StatelessWidget {
),
drawer: DrawerX(context: context).drawer(),
body: Center(
child: ListView(children: [
Text('这里还什么都没有,不过你可以为这里贡献一下ww~'),
ElevatedButton(
onPressed: () {
launchUrl(Uri.parse('https://github.com/Muska-Ami/NyaLCF'));
},
child: SelectableText('https://github.com/Muska-Ami/NyaLCF'),
),
]),
child: ListView(
children: [
Obx(
() => Card(
margin: EdgeInsets.all(20.0),
child: SizedBox(
width: Checkbox.width,
height: 340.0,
child: Container(
margin: EdgeInsets.all(10.0),
child: ListView(
children: f_c.process_out,
),
),
),
),
),
Text('这里还是只读视图,不过你可以为这里贡献一下ww~'),
ElevatedButton(
onPressed: () {
launchUrl(Uri.parse('https://github.com/Muska-Ami/NyaLCF'));
},
child: SelectableText('https://github.com/Muska-Ami/NyaLCF'),
),
],
),
),
floatingActionButton: FloatingActionButtonX().button());
}
Expand Down
47 changes: 47 additions & 0 deletions lib/util/frpc/ProcessManager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:convert';
import 'dart:io';

import 'package:get/get.dart';
import 'package:nyalcf/controller/frpc.dart';
import 'package:nyalcf/io/frpcManagerStorage.dart';

class ProcessManager {

final FrpcController f_c = Get.find();

final frpc_work_path = FrpcManagerStorage.getRunPath('0.51.3');

void nwprcs({
required String frp_token,
required int proxy_id,
}) async {
final process = await Process.start(
await FrpcManagerStorage.getFilePath('0.51.3'),
[
'-u',
frp_token,
'-p',
proxy_id.toString(),
],
workingDirectory: await FrpcManagerStorage.getRunPath('0.51.3'),
);
// Process [stdout, stderr]
process.stdout.forEach((element) {
final fmt_str = utf8.decode(element).trim();
if (fmt_str.contains('stopped') || fmt_str.contains('启动失败')) {
print('[${proxy_id}][FRPC][WARN] ${fmt_str}');
f_c.appendWarnLog(fmt_str);
process.kill();
} else {
print('[${proxy_id}][FRPC][INFO] ${fmt_str}');
f_c.appendInfoLog(fmt_str);
}
});
process.stderr.forEach((element) {
final fmt_str = utf8.decode(element).trim();
print('[${proxy_id}][FRPC][ERROR] ${fmt_str}');
f_c.appendErrorLog(fmt_str);
process.kill();
});
}
}
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ flutter:
weight: 400
- asset: asset/font/HarmonyOS_Sans_SC_Bold.ttf
weight: 700
- family: "Droid Sans Mono"
fonts:
- asset: asset/font/Droid_Sans_Mono.ttf
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
Expand Down

0 comments on commit 2d2ef36

Please sign in to comment.