new: clipboard backup (#263)

This commit is contained in:
lollipopkit
2024-02-01 11:57:18 +08:00
parent 3093230400
commit 3d5ce4b863
16 changed files with 127 additions and 28 deletions

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 732;
static const String engine = "3.16.8";
static const String buildAt = "2024-01-30 11:53:52";
static const int modifications = 3;
static const int build = 734;
static const String engine = "3.16.9";
static const String buildAt = "2024-02-01 11:26:59";
static const int modifications = 5;
static const int script = 36;
}

View File

@@ -31,6 +31,7 @@
"chooseFontFile": "Schriftart auswählen",
"choosePrivateKey": "Private key auswählen",
"clear": "Entfernen",
"clipboard": "Zwischenablage",
"close": "Schließen",
"cmd": "Command",
"collapseUI": "Zusammenbrechen",

View File

@@ -31,6 +31,7 @@
"chooseFontFile": "Choose a font file",
"choosePrivateKey": "Choose private key",
"clear": "Clear",
"clipboard": "Clipboard",
"close": "Close",
"cmd": "Command",
"collapseUI": "Collapse",

View File

@@ -31,6 +31,7 @@
"chooseFontFile": "Choisir un fichier de police",
"choosePrivateKey": "Choisir la clé privée",
"clear": "Effacer",
"clipboard": "presse-papiers",
"close": "Fermer",
"cmd": "Commande",
"collapseUI": "обвал",

View File

@@ -31,6 +31,7 @@
"chooseFontFile": "Pilih file font",
"choosePrivateKey": "Pilih Kunci Pribadi",
"clear": "Jernih",
"clipboard": "papan klip",
"close": "Menutup",
"cmd": "Memerintah",
"collapseUI": "Runtuh",

View File

@@ -31,6 +31,7 @@
"chooseFontFile": "选择字体文件",
"choosePrivateKey": "选择私钥",
"clear": "清除",
"clipboard": "剪切板",
"close": "关闭",
"cmd": "命令",
"collapseUI": "折叠",

View File

@@ -31,6 +31,7 @@
"chooseFontFile": "選擇字體文件",
"choosePrivateKey": "選擇私鑰",
"clear": "清除",
"clipboard": "剪切板",
"close": "關閉",
"cmd": "命令",
"collapseUI": "折疊",

View File

@@ -47,6 +47,7 @@ class BackupPage extends StatelessWidget {
if (isMacOS || isIOS) _buildIcloud(context),
_buildWebdav(context),
_buildFile(context),
_buildClipboard(context),
],
);
}
@@ -188,6 +189,31 @@ class BackupPage extends StatelessWidget {
);
}
Widget _buildClipboard(BuildContext context) {
return CardX(
child: ExpandTile(
leading: const Icon(Icons.content_paste),
title: Text(l10n.clipboard),
children: [
ListTile(
title: Text(l10n.backup),
trailing: const Icon(Icons.save),
onTap: () async {
final path = await Backup.backup();
Shares.copy(await File(path).readAsString());
context.showSnackBar(l10n.success);
},
),
ListTile(
trailing: const Icon(Icons.restore),
title: Text(l10n.restore),
onTap: () async => _onTapClipboardRestore(context),
),
],
),
);
}
Future<void> _onTapFileRestore(BuildContext context) async {
final path = await pickOneFile();
if (path == null) return;
@@ -353,4 +379,47 @@ class BackupPage extends StatelessWidget {
Webdav.changeClient(urlCtrl.text, userCtrl.text, pwdCtrl.text);
}
}
void _onTapClipboardRestore(BuildContext context) async {
final text = await Shares.paste();
if (text == null || text.isEmpty) {
context.showSnackBar(l10n.fieldMustNotEmpty);
return;
}
try {
context.showLoadingDialog();
final backup =
await Computer.shared.start(Backup.fromJsonString, text.trim());
if (backupFormatVersion != backup.version) {
context.showSnackBar(l10n.backupVersionNotMatch);
return;
}
await context.showRoundDialog(
title: Text(l10n.restore),
child: Text(l10n.askContinue(
'${l10n.restore} ${l10n.backup}(${backup.date})',
)),
actions: [
TextButton(
onPressed: () => context.pop(),
child: Text(l10n.cancel),
),
TextButton(
onPressed: () async {
await backup.restore(force: true);
context.pop();
},
child: Text(l10n.ok),
),
],
);
} catch (e, trace) {
Loggers.app.warning('Import backup failed', e, trace);
context.showSnackBar(e.toString());
} finally {
context.pop();
}
}
}