new: delete scripts when delete server

This commit is contained in:
lollipopkit
2023-11-07 18:10:38 +08:00
parent e80f6d4cc2
commit 2133302397
17 changed files with 117 additions and 56 deletions

View File

@@ -11,7 +11,7 @@ class SecureStore {
SecureStore._();
static const _secureStorage = FlutterSecureStorage();
static HiveAesCipher? _cipher;
static const _hiveKey = 'hive_key';

View File

@@ -16,8 +16,8 @@ enum ShellFunc {
suspend,
;
static const _serverBoxDir = '.config/server_box';
static const _scriptFileName = 'mobile_v${BuildData.script}.sh';
static const _srvBoxDir = '.config/server_box';
static const _scriptFile = 'mobile_v${BuildData.script}.sh';
/// Issue #159
///
@@ -26,15 +26,15 @@ enum ShellFunc {
/// So different version of app can run at the same time.
///
/// **Can't** use it in SFTP, because SFTP can't recognize `$HOME`
static String getShellPath(String home) =>
'$home/$_serverBoxDir/$_scriptFileName';
static String getShellPath(String home) => '$home/$_srvBoxDir/$_scriptFile';
static final _installShellPath = getShellPath(_homeVar);
static const srvBoxDir = '$_homeVar/$_srvBoxDir';
static const _installShellPath = '$_homeVar/$_srvBoxDir/$_scriptFile';
/// Issue #168
/// Use `sh` for compatibility
static final installShellCmd = """
mkdir -p $_homeVar/$_serverBoxDir
mkdir -p $_homeVar/$_srvBoxDir
cat << 'EOF' > $_installShellPath
${ShellFunc.allScript}
EOF

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 630;
static const int build = 634;
static const String engine = "3.13.8";
static const String buildAt = "2023-11-02 13:45:05";
static const int modifications = 1;
static const String buildAt = "2023-11-03 22:14:11";
static const int modifications = 2;
static const int script = 25;
}

View File

@@ -45,6 +45,7 @@
"decode": "Decode",
"decompress": "Dekomprimieren",
"delete": "Löschen",
"deleteScripts": "Gleichzeitiges Löschen von Server-Skripten",
"deleteServers": "Batch-Löschung von Servern",
"dirEmpty": "Stelle sicher, dass der Ordner leer ist.",
"disabled": "Behinderte",

View File

@@ -45,6 +45,7 @@
"decode": "Decode",
"decompress": "Decompress",
"delete": "Delete",
"deleteScripts": "Delete server scripts at the same time",
"deleteServers": "Batch delete servers",
"dirEmpty": "Make sure dir is empty.",
"disabled": "Disabled",

View File

@@ -45,6 +45,7 @@
"decode": "Membaca sandi",
"decompress": "Dekompresi",
"delete": "Menghapus",
"deleteScripts": "Menghapus skrip server secara bersamaan",
"deleteServers": "Penghapusan server secara batch",
"dirEmpty": "Pastikan dir kosong.",
"disabled": "Dengan disabilitas",

View File

@@ -45,6 +45,7 @@
"decode": "解码",
"decompress": "解压缩",
"delete": "删除",
"deleteScripts": "同时删除服务器脚本",
"deleteServers": "批量删除服务器",
"dirEmpty": "请确保文件夹为空",
"disabled": "已禁用",

View File

@@ -45,6 +45,7 @@
"decode": "解碼",
"decompress": "解壓縮",
"delete": "刪除",
"deleteScripts": "同時刪除服務器腳本",
"deleteServers": "批量刪除服務器",
"dirEmpty": "請確保文件夾為空",
"disabled": "已禁用",

View File

@@ -96,7 +96,7 @@ class _HomePageState extends State<HomePage>
BgRunMC.moveToBg();
}
} else {
Pros.server.setDisconnected();
//Pros.server.setDisconnected();
Pros.server.stopAutoRefresh();
}
break;

View File

@@ -4,6 +4,7 @@ import 'package:toolbox/core/extension/context/common.dart';
import 'package:toolbox/core/extension/context/dialog.dart';
import 'package:toolbox/core/extension/context/locale.dart';
import 'package:toolbox/core/extension/context/snackbar.dart';
import 'package:toolbox/data/model/app/shell_func.dart';
import 'package:toolbox/data/res/provider.dart';
import 'package:toolbox/view/widget/expand_tile.dart';
@@ -107,31 +108,59 @@ class _ServerEditPageState extends State<ServerEditPage> {
}
PreferredSizeWidget _buildAppBar() {
final delBtn = IconButton(
onPressed: () {
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.askContinue(
'${l10n.delete} ${l10n.server}(${widget.spi!.name})',
)),
actions: [
TextButton(
onPressed: () {
Pros.server.delServer(widget.spi!.id);
context.pop();
context.pop(true);
},
child: Text(l10n.ok, style: UIs.textRed),
),
],
);
},
icon: const Icon(Icons.delete),
);
final actions = widget.spi != null ? [delBtn] : null;
return CustomAppBar(
title: Text(l10n.edit, style: UIs.textSize18),
actions: actions,
actions: widget.spi != null
? [
IconButton(
onPressed: () {
var delScripts = false;
context.showRoundDialog(
title: Text(l10n.attention),
child: StatefulBuilder(builder: (ctx, setState) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(l10n.askContinue(
'${l10n.delete} ${l10n.server}(${widget.spi!.name})',
)),
UIs.height13,
Row(
children: [
Checkbox(
value: delScripts,
onChanged: (_) => setState(
() => delScripts = !delScripts,
),
),
Text(l10n.deleteScripts),
],
)
],
);
}),
actions: [
TextButton(
onPressed: () async {
if (delScripts) {
const cmd =
'rm ${ShellFunc.srvBoxDir}/mobile_v*.sh';
await widget.spi?.server?.client?.run(cmd);
}
Pros.server.delServer(widget.spi!.id);
context.pop();
context.pop(true);
},
child: Text(l10n.ok, style: UIs.textRed),
),
],
);
},
icon: const Icon(Icons.delete),
),
]
: null,
);
}