Skip to content

Commit

Permalink
[+]Better console & process killer
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Dec 23, 2023
1 parent 60a4c2c commit 6cdaf41
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ An unoffical LoCyanFrp launcher.
- [ ] Frpc管理
- [x] Frp Token复制
- [x] 隧道信息展示
- [ ] 隧道启动
- [x] 隧道启动
- [x] 控制台
- [ ] 隧道编辑
- [x] 公告

Expand Down
31 changes: 24 additions & 7 deletions lib/ui/panel/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:nyalcf/ui/model/AccountDialog.dart';
import 'package:nyalcf/ui/model/AppbarActions.dart';
import 'package:nyalcf/ui/model/Drawer.dart';
import 'package:nyalcf/ui/model/FloatingActionButton.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:nyalcf/util/frpc/ProcessManager.dart';

class PanelConsole extends StatelessWidget {
PanelConsole({super.key, required this.title});
Expand Down Expand Up @@ -49,6 +49,7 @@ class PanelConsole extends StatelessWidget {
Obx(
() => Card(
margin: EdgeInsets.all(20.0),
color: Colors.grey.shade900,
child: SizedBox(
width: Checkbox.width,
height: 340.0,
Expand All @@ -61,12 +62,28 @@ class PanelConsole extends StatelessWidget {
),
),
),
Text('这里还是只读视图,不过你可以为这里贡献一下ww~'),
ElevatedButton(
onPressed: () {
launchUrl(Uri.parse('https://github.com/Muska-Ami/NyaLCF'));
},
child: SelectableText('https://github.com/Muska-Ami/NyaLCF'),
Container(
margin: EdgeInsets.only(left: 20.0, right: 20.0),
child: Row(
children: [
ElevatedButton(
onPressed: () {},
child: Text('查看进程列表'),
),
ElevatedButton(
onPressed: () {
ProcessManager().killAll();
},
child: Text('关闭所有进程',
style: TextStyle(
color: Colors.white,
)),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.red),
),
),
],
),
),
],
),
Expand Down
20 changes: 20 additions & 0 deletions lib/util/frpc/ProcessManager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,36 @@ class ProcessManager {
print('[${proxy_id}][FRPC][WARN] ${fmt_str}');
f_c.appendWarnLog(fmt_str);
process.kill();
process_list.remove(process);
} else {
print('[${proxy_id}][FRPC][INFO] ${fmt_str}');
f_c.appendInfoLog(fmt_str);
}

//print('Process length: ${process_list.length}');
});
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();
process_list.remove(process);
});

//print('Process length: ${process_list.length}');
}

void killAll() {
print('Killing all process');
print('Process length: ${process_list.length}');
f_c.appendInfoLog('[SYSTEM][INFO] Killing all process...');
process_list.forEach((element) {
print('Killing frpc process, pid: ${element.pid}');
f_c.appendInfoLog('[SYSTEM][INFO] Killing process, pid: ${element.pid}');
element.kill();
process_list.remove(element);
});

print('Process length: ${process_list.length}');
}
}

0 comments on commit 6cdaf41

Please sign in to comment.