Skip to content

Commit

Permalink
config editing feature added
Browse files Browse the repository at this point in the history
  • Loading branch information
simiooo committed Aug 14, 2024
1 parent c924dae commit 6cbd0cc
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 172 deletions.
40 changes: 8 additions & 32 deletions lib/utils/quincy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Quincy {
String? runtimePath;
Timer? _timer;
String? runtimeName;
String? password;
String configPath;
int? pid;
QuincyRuntimeStatus status = QuincyRuntimeStatus.stoped;
Expand All @@ -31,7 +30,6 @@ class Quincy {
Quincy({
this.runtimePath,
required this.configPath,
this.password,
}) {
create();
}
Expand Down Expand Up @@ -120,35 +118,11 @@ class Quincy {
throw const FileNotFoundException("No excutable file found");
}
}
// if (Platform.isLinux) {
// if (password == null) {
// throw Exception("Password is empty, please set the password");
// }
// var chmod =
// await Process.start('sudo', ['-S', 'chmod', '755', runtimePath!]);

// // Close the stdin to indicate end of input
// await chmod.stdin.close();
// initLogs(chmod);
// initErrorLogs(chmod);

// var exitCode = await chmod.exitCode;
// if(exitCode != 0) {
// throw Exception("could not chmod to $runtimePath");
// }
// var runtime = await Process.start(
// "echo",
// [password!,"|",'sudo',"-S", runtimePath!, '--config-path', configPath],
// );

// runtime.stdin.writeln(password);
// await runtime.stdin.close();
// } else {

runtime = await Process.start(
runtimePath!,
['--config-path', configPath],
);
// }

status = QuincyRuntimeStatus.active;
initLogs(runtime);
Expand Down Expand Up @@ -203,14 +177,16 @@ class Quincy {
}

stop() async {
return runtime?.kill(ProcessSignal.sigstop);
var result = runtime?.kill();
logs.add(removeAnsiEscapeCodes("Stop Quincy normally"));
for (var cb in logHandlerList) {
cb(logs, errorLogs);
}
return result;
}

restart() async {
var res = runtime?.kill(ProcessSignal.sigstop) ?? false;
// if (!res) {
// throw Exception("Failed to kill process");
// }
var res = stop();
await create();
}

Expand Down
62 changes: 42 additions & 20 deletions lib/widgets/config_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ import 'dart:math';
import 'package:easy_localization/easy_localization.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart'
hide IconButton, showDialog, Divider, Colors,FilledButton;
hide IconButton, showDialog, Divider, Colors, FilledButton;
import 'package:quincy_sui/utils/quincy.dart';
import 'package:quincy_sui/widgets/config_form.dart';
import 'package:toml/toml.dart';

class ConfigDisplay extends StatelessWidget {
Map<String, dynamic> content = {};
TomlDocument doc;
void Function(String key)? onDelete;
void Function() onUpdatePassword;
Quincy? runtime;
void Function(TomlDocument doc)? onChanged;
String path;
void Function(TomlDocument doc, String path)? onConnect;
void Function(TomlDocument doc, String path)? onDisconnect;
ConfigDisplay(
{Key? key,
this.runtime,
this.onDelete,
required this.onUpdatePassword,
required this.content,
required this.path,
this.onConnect,
this.onChanged,
this.onDisconnect,
required this.doc})
: super(key: key);

Expand Down Expand Up @@ -51,12 +54,22 @@ class ConfigDisplay extends StatelessWidget {
if (runtime == null) {
return;
}
runtime?.stop();
if (onDisconnect == null) {
return;
}
onDisconnect!(doc, path);
}),
SizedBox(
width: 12,
),
Button(child: Text(context.tr('编辑')), onPressed: () {}),
Button(
child: Text(context.tr('编辑')),
onPressed: () {
if (onChanged == null) {
return;
}
onChanged!(doc);
}),
];
} else if (runtime?.status == QuincyRuntimeStatus.failed) {
return [
Expand All @@ -71,7 +84,14 @@ class ConfigDisplay extends StatelessWidget {
SizedBox(
width: 12,
),
Button(child: Text(context.tr('编辑')), onPressed: () {}),
Button(
child: Text(context.tr('编辑')),
onPressed: () {
if (onChanged == null) {
return;
}
onChanged!(doc);
}),
];
} else {
return [
Expand All @@ -86,7 +106,14 @@ class ConfigDisplay extends StatelessWidget {
SizedBox(
width: 12,
),
Button(child: Text(context.tr('编辑')), onPressed: () {}),
Button(
child: Text(context.tr('编辑')),
onPressed: () {
if (onChanged == null) {
return;
}
onChanged!(doc);
}),
];
}
}
Expand Down Expand Up @@ -185,12 +212,14 @@ class ConfigDisplay extends StatelessWidget {
height: 24,
),
SelectableText("${context.tr("认证类型")} : UsersFile"),
SelectableText("${context.tr('用户名')} : ${content["authentication"]["username"]}"),
SelectableText(
"${context.tr('用户名')} : ${content["authentication"]["username"]}"),
// SelectableText("密码 : ${content["authentication"]["password"]}"),
SelectableText("${context.tr('密码')} : ********"),
SelectableText(
"${context.tr('信任证书' )}: ${content["authentication"]["trusted_certificates"]}"),
SelectableText("${context.tr('路由')} : ${content["network"]["routes"]}"),
"${context.tr('信任证书')}: ${content["authentication"]["trusted_certificates"]}"),
SelectableText(
"${context.tr('路由')} : ${content["network"]["routes"]}"),
SizedBox(
height: 16,
),
Expand All @@ -207,7 +236,8 @@ class ConfigDisplay extends StatelessWidget {
"${context.tr('发送帧大小')} : ${content["connection"]["send_buffer_size"]}"),
SelectableText(
"${context.tr('接收帧大小')} : ${content["connection"]["recv_buffer_size"]}"),
SelectableText("${context.tr('日志级别')} : ${content["log"]["level"]}"),
SelectableText(
"${context.tr('日志级别')} : ${content["log"]["level"]}"),
SizedBox(
height: 24,
),
Expand All @@ -220,16 +250,8 @@ class ConfigDisplay extends StatelessWidget {
SizedBox(
width: 16,
),
// Platform.isLinux ? Button(child: Text('Update Sudo Password'), onPressed: () {
// if(onUpdatePassword == null) {
// return;
// }
// onUpdatePassword();
// }) : Container(),
IconButton(
icon: Icon(
color: Colors.red,
Icons.delete),
icon: Icon(color: Colors.red, Icons.delete),
onPressed: () {
if (onDelete == null) {
return;
Expand Down
Loading

0 comments on commit 6cbd0cc

Please sign in to comment.