new & opt.

- new: support suspend and WOL #172
- opt.: `execWithPwd` when cancel
- opt.: extentions
This commit is contained in:
lollipopkit
2023-09-25 18:51:14 +08:00
parent df84aeb8b2
commit 4d06a52e99
45 changed files with 251 additions and 176 deletions

View File

@@ -18,6 +18,7 @@ enum ShellFunc {
process,
shutdown,
reboot,
suspend,
;
String get flag {
@@ -32,6 +33,8 @@ enum ShellFunc {
return 'sd';
case ShellFunc.reboot:
return 'r';
case ShellFunc.suspend:
return 'sp';
}
}
@@ -51,10 +54,12 @@ enum ShellFunc {
return 'ShutDown';
case ShellFunc.reboot:
return 'Reboot';
case ShellFunc.suspend:
return 'Suspend';
}
}
String get cmd {
String get _cmd {
switch (this) {
case ShellFunc.status:
return '''
@@ -96,6 +101,13 @@ if [ "\$userId" = "0" ]; then
\treboot
else
\tsudo -S reboot
fi''';
case ShellFunc.suspend:
return '''
if [ "\$userId" = "0" ]; then
\tsystemctl suspend
else
\tsudo -S systemctl suspend
fi''';
}
}
@@ -123,7 +135,7 @@ userId=\$(id -u)
for (final func in values) {
sb.write('''
${func.name}() {
${func.cmd.split('\n').map((e) => '\t$e').join('\n')}
${func._cmd.split('\n').map((e) => '\t$e').join('\n')}
}
''');