opt.: seq settings (#273)

This commit is contained in:
lollipopkit
2024-02-15 16:44:41 +08:00
parent 2c79c25436
commit e20adee0e2
8 changed files with 139 additions and 125 deletions

View File

@@ -28,6 +28,7 @@ abstract final class ICloud {
String? localPath,
}) async {
final completer = Completer<ICloudErr?>();
try {
await ICloudStorage.upload(
containerId: _containerId,
filePath: localPath ?? '${await Paths.doc}/$relativePath',
@@ -42,6 +43,11 @@ abstract final class ICloud {
);
},
);
} catch (e, s) {
_logger.warning('Upload $relativePath failed', e, s);
completer.complete(ICloudErr(type: ICloudErrType.generic, message: '$e'));
}
return completer.future;
}
@@ -52,10 +58,14 @@ abstract final class ICloud {
}
static Future<void> delete(String relativePath) async {
try {
await ICloudStorage.delete(
containerId: _containerId,
relativePath: relativePath,
);
} catch (e, s) {
_logger.warning('Delete $relativePath failed', e, s);
}
}
/// Download file from iCloud

View File

@@ -4,6 +4,7 @@ abstract final class GithubIds {
// Thanks
// If you want to change your Github ID, please open an issue.
static const contributors = <GhId>{
'PaperCube',
'its-tom',
'azkadev',
'kalashnikov',
@@ -57,5 +58,6 @@ abstract final class GithubIds {
'bxoooooo',
'KatharsisKing',
'mervinniu',
'L-Super',
};
}

View File

@@ -100,7 +100,7 @@ class SettingStore extends PersistentStore {
late final termFontSize = property('termFontSize', 13.0);
// Locale
late final locale = property<String>('locale', '');
late final locale = property('locale', '');
// SSH virtual key (ctrl | alt) auto turn off
late final sshVirtualKeyAutoOff = property('sshVirtualKeyAutoOff', true);

View File

@@ -39,7 +39,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage> {
late FocusScopeNode _focusScope;
Widget? _loading;
final _loading = ValueNotifier<Widget?>(null);
@override
void initState() {
@@ -134,9 +134,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage> {
return;
}
FocusScope.of(context).unfocus();
setState(() {
_loading = UIs.centerSizedLoading;
});
_loading.value = UIs.centerSizedLoading;
try {
final decrypted = await Computer.shared.start(decyptPem, [key, pwd]);
final pki = PrivateKeyInfo(id: name, key: decrypted);
@@ -149,9 +147,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage> {
context.showSnackBar(e.toString());
rethrow;
} finally {
setState(() {
_loading = null;
});
_loading.value = null;
}
context.pop();
},
@@ -219,7 +215,10 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage> {
icon: Icons.password,
),
SizedBox(height: MediaQuery.of(context).size.height * 0.1),
_loading ?? UIs.placeholder,
ValueListenableBuilder(
valueListenable: _loading,
builder: (_, val, __) => val ?? UIs.placeholder,
),
],
);
}

View File

@@ -227,7 +227,7 @@ class _SettingPageState extends State<SettingPage> {
_buildSSHVirtualKeyAutoOff(),
// Use hardware keyboard on desktop, so there is no need to set it
if (isMobile) _buildKeyboardType(),
_buildSSHVirtKeys(),
if (isMobile) _buildSSHVirtKeys(),
].map((e) => CardX(child: e)).toList(),
);
}

View File

@@ -17,6 +17,8 @@ class ServerDetailOrderPage extends StatefulWidget {
}
class _ServerDetailOrderPageState extends State<ServerDetailOrderPage> {
final prop = Stores.setting.detailCardOrder;
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -28,11 +30,10 @@ class _ServerDetailOrderPageState extends State<ServerDetailOrderPage> {
}
Widget _buildBody() {
final keys_ = Stores.setting.detailCardOrder.fetch();
final keys = <String>[];
for (final key in keys_) {
keys.add(key);
}
return ValueListenableBuilder(
valueListenable: prop.listenable(),
builder: (_, vals, __) {
final keys = List<String>.from(vals);
final disabled =
Defaults.detailCardOrder.where((e) => !keys.contains(e)).toList();
final allKeys = [...keys, ...disabled];
@@ -55,8 +56,9 @@ class _ServerDetailOrderPageState extends State<ServerDetailOrderPage> {
context.showSnackBar(l10n.disabled);
return;
}
keys.moveByItem(keys, o, n, property: Stores.setting.detailCardOrder);
setState(() {});
keys.moveByItem(keys, o, n, property: prop);
},
);
},
);
}
@@ -75,8 +77,7 @@ class _ServerDetailOrderPageState extends State<ServerDetailOrderPage> {
} else {
keys.remove(key);
}
Stores.setting.detailCardOrder.put(keys);
setState(() {});
prop.put(keys);
},
);
}

View File

@@ -17,6 +17,8 @@ class ServerFuncBtnsOrderPage extends StatefulWidget {
}
class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {
final prop = Stores.setting.serverFuncBtns;
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -28,11 +30,10 @@ class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {
}
Widget _buildBody() {
final keys_ = Stores.setting.serverFuncBtns.fetch();
final keys = <int>[];
for (final key in keys_) {
keys.add(key);
}
return ValueListenableBuilder(
valueListenable: prop.listenable(),
builder: (_, vals, __) {
final keys = List<int>.from(vals);
final disabled = ServerFuncBtn.values
.map((e) => e.index)
.where((e) => !keys.contains(e))
@@ -57,8 +58,9 @@ class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {
context.showSnackBar(l10n.disabled);
return;
}
keys.moveByItem(keys, o, n, property: Stores.setting.serverFuncBtns);
setState(() {});
keys.moveByItem(keys, o, n, property: prop);
},
);
},
);
}
@@ -82,8 +84,7 @@ class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {
} else {
keys.remove(key);
}
Stores.setting.serverFuncBtns.put(keys);
setState(() {});
prop.put(keys);
},
);
}

View File

@@ -18,6 +18,8 @@ class SSHVirtKeySettingPage extends StatefulWidget {
}
class _SSHVirtKeySettingPageState extends State<SSHVirtKeySettingPage> {
final prop = Stores.setting.sshVirtKeys;
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -29,11 +31,10 @@ class _SSHVirtKeySettingPageState extends State<SSHVirtKeySettingPage> {
}
Widget _buildBody() {
final keys_ = Stores.setting.sshVirtKeys.fetch();
final keys = <int>[];
for (final key in keys_) {
keys.add(key);
}
return ValueListenableBuilder(
valueListenable: prop.listenable(),
builder: (_, vals, __) {
final keys = List<int>.from(vals);
final disabled = VirtKey.values
.map((e) => e.index)
.where((e) => !keys.contains(e))
@@ -61,8 +62,9 @@ class _SSHVirtKeySettingPageState extends State<SSHVirtKeySettingPage> {
context.showSnackBar(l10n.disabled);
return;
}
keys.moveByItem(keys, o, n, property: Stores.setting.sshVirtKeys);
setState(() {});
keys.moveByItem(keys, o, n, property: prop);
},
);
},
);
}
@@ -93,8 +95,7 @@ class _SSHVirtKeySettingPageState extends State<SSHVirtKeySettingPage> {
} else {
keys.remove(key);
}
Stores.setting.sshVirtKeys.put(keys);
setState(() {});
prop.put(keys);
},
);
}