new: remember pwd in mem

This commit is contained in:
lollipopkit
2024-03-10 19:15:24 -06:00
parent 5e9f0bf8a1
commit f187bc6ccf
17 changed files with 62 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ import 'package:choice/choice.dart';
import 'package:flutter/material.dart';
import 'package:toolbox/core/extension/context/common.dart';
import 'package:toolbox/core/extension/context/locale.dart';
import 'package:toolbox/data/res/store.dart';
import 'package:toolbox/view/widget/choice_chip.dart';
import 'package:toolbox/view/widget/tag.dart';
@@ -57,17 +58,27 @@ extension DialogX on BuildContext {
}
}
Future<String?> showPwdDialog(
static final _recoredPwd = <String, String>{};
Future<String?> showPwdDialog({
String? user,
) async {
required String hostId,
void Function()? onCorrectPwd,
}) async {
if (!mounted) return null;
return await showRoundDialog<String>(
title: Text(user ?? l10n.pwd),
child: Input(
controller: TextEditingController(text: _recoredPwd[hostId]),
autoFocus: true,
type: TextInputType.visiblePassword,
obscureText: true,
onSubmitted: (val) => pop(val.trim()),
onSubmitted: (val) {
pop(val);
if (Stores.setting.rememberPwdInMem.fetch()) {
_recoredPwd[hostId] = val;
}
},
label: l10n.pwd,
),
);

View File

@@ -67,6 +67,7 @@ extension SSHClientX on SSHClient {
_OnStdout? onStderr,
_OnStdin? stdin,
bool redirectToBash = false, // not working yet. do not use
required String id,
}) async {
var isRequestingPwd = false;
final session = await exec(
@@ -80,7 +81,7 @@ extension SSHClientX on SSHClient {
isRequestingPwd = true;
final user = Miscs.pwdRequestWithUserReg.firstMatch(data)?.group(1);
if (context == null) return;
final pwd = await context.showPwdDialog(user);
final pwd = await context.showPwdDialog(user: user, hostId: id);
if (pwd == null || pwd.isEmpty) {
session.kill(SSHSignal.INT);
} else {

View File

@@ -28,6 +28,7 @@ class ContainerProvider extends ChangeNotifier {
ContainerErr? error;
String? runLog;
ContainerType type;
bool sudo = false;
ContainerProvider({
required this.client,
@@ -71,8 +72,7 @@ class ContainerProvider extends ChangeNotifier {
}
Future<void> refresh({bool isAuto = false}) async {
final sudo =
await _requiresSudo() && Stores.setting.containerTrySudo.fetch();
sudo = await _requiresSudo() && Stores.setting.containerTrySudo.fetch();
/// If sudo is required and auto refresh is enabled, skip the refresh.
/// Or this will ask for pwd again and again.
@@ -88,6 +88,7 @@ class ContainerProvider extends ChangeNotifier {
)),
context: context,
onStdout: (data, _) => raw = '$raw$data',
id: hostId,
);
/// Code 127 means command not found
@@ -204,13 +205,14 @@ class ContainerProvider extends ChangeNotifier {
runLog = '';
final errs = <String>[];
final code = await client?.execWithPwd(
_wrap(cmd),
_wrap(sudo ? 'sudo -S $cmd' : cmd),
context: context,
onStdout: (data, _) {
runLog = '$runLog$data';
notifyListeners();
},
onStderr: (data, _) => errs.add(data),
id: hostId,
);
runLog = null;
notifyListeners();

View File

@@ -255,6 +255,10 @@ class SettingStore extends PersistentStore {
late final termCursor =
property('termCursor', TerminalCursorType.block.index);
/// Remerber pwd in memory
/// Used for [DialogX.showPwdDialog]
late final rememberPwdInMem = property('rememberPwdInMem', true);
// Never show these settings for users
//
// ------BEGIN------

View File

@@ -193,6 +193,8 @@
"pwd": "Passwort",
"read": "Lesen",
"reboot": "Neustart",
"rememberPwdInMem": "Passwort im Speicher behalten",
"rememberPwdInMemTip": "Für Container, Aufhängen usw.",
"remotePath": "Entfernte Pfade",
"rename": "Umbenennen",
"reportBugsOnGithubIssue": "Bitte Bugs auf {url} melden",

View File

@@ -193,6 +193,8 @@
"pwd": "Password",
"read": "Read",
"reboot": "Reboot",
"rememberPwdInMem": "Remember password in memory",
"rememberPwdInMemTip": "Used for containers, suspending, etc.",
"remotePath": "Remote path",
"rename": "Rename",
"reportBugsOnGithubIssue": "Please report bugs on {url}",

View File

@@ -193,6 +193,8 @@
"pwd": "Contraseña",
"read": "Leer",
"reboot": "Reiniciar",
"rememberPwdInMem": "Recordar contraseña en la memoria",
"rememberPwdInMemTip": "Utilizado para contenedores, suspensión, etc.",
"remotePath": "Ruta remota",
"rename": "Renombrar",
"reportBugsOnGithubIssue": "Por favor, informa los problemas en {url}",

View File

@@ -193,6 +193,8 @@
"pwd": "Mot de passe",
"read": "Lire",
"reboot": "Redémarrer",
"rememberPwdInMem": "Mémoriser le mot de passe en mémoire",
"rememberPwdInMemTip": "Utilisé pour les conteneurs, la suspension, etc.",
"remotePath": "Chemin distant",
"rename": "Renommer",
"reportBugsOnGithubIssue": "Veuillez signaler les bogues sur {url}",

View File

@@ -193,6 +193,8 @@
"pwd": "Kata sandi",
"read": "Baca",
"reboot": "Reboot",
"rememberPwdInMem": "Ingat kata sandi di dalam memori",
"rememberPwdInMemTip": "Digunakan untuk kontainer, menangguhkan, dll.",
"remotePath": "Jalur jarak jauh",
"rename": "Ganti nama",
"reportBugsOnGithubIssue": "Harap laporkan bug di {url}",

View File

@@ -193,6 +193,8 @@
"pwd": "パスワード",
"read": "読み取り",
"reboot": "再起動",
"rememberPwdInMem": "メモリにパスワードを記憶する",
"rememberPwdInMemTip": "コンテナ、一時停止などに使用されます。",
"remotePath": "リモートパス",
"rename": "名前を変更",
"reportBugsOnGithubIssue": "{url}で問題を報告してください",

View File

@@ -193,6 +193,8 @@
"pwd": "Senha",
"read": "Leitura",
"reboot": "Reiniciar",
"rememberPwdInMem": "Lembrar senha na memória",
"rememberPwdInMemTip": "Usado para contêineres, suspensão, etc.",
"remotePath": "Caminho remoto",
"rename": "Renomear",
"reportBugsOnGithubIssue": "Por favor, reporte problemas em {url}",

View File

@@ -193,6 +193,8 @@
"pwd": "пароль",
"read": "чтение",
"reboot": "перезагрузка",
"rememberPwdInMem": "Запомнить пароль в памяти",
"rememberPwdInMemTip": "Используется для контейнеров, приостановки и т. д.",
"remotePath": "удаленный путь",
"rename": "переименовать",
"reportBugsOnGithubIssue": "Пожалуйста, сообщайте о проблемах на {url}",

View File

@@ -193,6 +193,8 @@
"pwd": "密码",
"read": "读",
"reboot": "重启",
"rememberPwdInMem": "在内存中记住密码",
"rememberPwdInMemTip": "用于容器、挂起等",
"remotePath": "远端路径",
"rename": "重命名",
"reportBugsOnGithubIssue": "请到 {url} 提交问题",

View File

@@ -193,6 +193,8 @@
"pwd": "密碼",
"read": "读",
"reboot": "重启",
"rememberPwdInMem": "在記憶體中記住密碼",
"rememberPwdInMemTip": "用於容器、暫停等",
"remotePath": "遠端路徑",
"rename": "重命名",
"reportBugsOnGithubIssue": "請到 {url} 提交問題",

View File

@@ -261,6 +261,7 @@ class _ServerPageState extends State<ServerPage>
srv.client?.execWithPwd(
ShellFunc.suspend.exec,
context: context,
id: srv.id,
);
},
typ: l10n.suspend,
@@ -274,6 +275,7 @@ class _ServerPageState extends State<ServerPage>
func: () => srv.client?.execWithPwd(
ShellFunc.shutdown.exec,
context: context,
id: srv.id,
),
typ: l10n.shutdown,
name: srv.spi.name,
@@ -286,6 +288,7 @@ class _ServerPageState extends State<ServerPage>
func: () => srv.client?.execWithPwd(
ShellFunc.reboot.exec,
context: context,
id: srv.id,
),
typ: l10n.reboot,
name: srv.spi.name,

View File

@@ -1048,6 +1048,7 @@ class _SettingPageState extends State<SettingPage> {
return ExpandTile(
title: Text(l10n.more),
children: [
_buildRememberPwdInMem(),
_buildTextScaler(),
_buildPreferTemperatureDeviceList(),
_buildKeepStatusWhenErr(),
@@ -1081,4 +1082,12 @@ class _SettingPageState extends State<SettingPage> {
},
);
}
Widget _buildRememberPwdInMem() {
return ListTile(
title: Text(l10n.rememberPwdInMem),
subtitle: Text(l10n.rememberPwdInMemTip, style: UIs.textGrey),
trailing: StoreSwitch(prop: _setting.rememberPwdInMem),
);
}
}

View File

@@ -245,7 +245,11 @@ Future<void> _onPkg(BuildContext context, ServerPrivateInfo spi) async {
fn: () async {
final updateCmd = pkg.update;
if (updateCmd != null) {
await client.execWithPwd(updateCmd, context: context);
await client.execWithPwd(
updateCmd,
context: context,
id: spi.id,
);
}
},
barrierDismiss: true,