Skip to content

Commit

Permalink
opt.: seq settings (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Feb 15, 2024
1 parent 2c79c25 commit e20adee
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 125 deletions.
46 changes: 28 additions & 18 deletions lib/core/utils/sync/icloud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,26 @@ abstract final class ICloud {
String? localPath,
}) async {
final completer = Completer<ICloudErr?>();
await ICloudStorage.upload(
containerId: _containerId,
filePath: localPath ?? '${await Paths.doc}/$relativePath',
destinationRelativePath: relativePath,
onProgress: (stream) {
stream.listen(
null,
onDone: () => completer.complete(null),
onError: (e) => completer.complete(
ICloudErr(type: ICloudErrType.generic, message: '$e'),
),
);
},
);
try {
await ICloudStorage.upload(
containerId: _containerId,
filePath: localPath ?? '${await Paths.doc}/$relativePath',
destinationRelativePath: relativePath,
onProgress: (stream) {
stream.listen(
null,
onDone: () => completer.complete(null),
onError: (e) => completer.complete(
ICloudErr(type: ICloudErrType.generic, message: '$e'),
),
);
},
);
} catch (e, s) {
_logger.warning('Upload $relativePath failed', e, s);
completer.complete(ICloudErr(type: ICloudErrType.generic, message: '$e'));
}

return completer.future;
}

Expand All @@ -52,10 +58,14 @@ abstract final class ICloud {
}

static Future<void> delete(String relativePath) async {
await ICloudStorage.delete(
containerId: _containerId,
relativePath: relativePath,
);
try {
await ICloudStorage.delete(
containerId: _containerId,
relativePath: relativePath,
);
} catch (e, s) {
_logger.warning('Delete $relativePath failed', e, s);
}
}

/// Download file from iCloud
Expand Down
2 changes: 2 additions & 0 deletions lib/data/res/github_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -57,5 +58,6 @@ abstract final class GithubIds {
'bxoooooo',
'KatharsisKing',
'mervinniu',
'L-Super',
};
}
2 changes: 1 addition & 1 deletion lib/data/store/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions lib/view/page/private_key/edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage> {

late FocusScopeNode _focusScope;

Widget? _loading;
final _loading = ValueNotifier<Widget?>(null);

@override
void initState() {
Expand Down Expand Up @@ -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);
Expand All @@ -149,9 +147,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage> {
context.showSnackBar(e.toString());
rethrow;
} finally {
setState(() {
_loading = null;
});
_loading.value = null;
}
context.pop();
},
Expand Down Expand Up @@ -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,
),
],
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/view/page/setting/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
Expand Down
61 changes: 31 additions & 30 deletions lib/view/page/setting/seq/srv_detail_seq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -28,36 +30,36 @@ class _ServerDetailOrderPageState extends State<ServerDetailOrderPage> {
}

Widget _buildBody() {
final keys_ = Stores.setting.detailCardOrder.fetch();
final keys = <String>[];
for (final key in keys_) {
keys.add(key);
}
final disabled =
Defaults.detailCardOrder.where((e) => !keys.contains(e)).toList();
final allKeys = [...keys, ...disabled];
return ReorderableListView.builder(
padding: const EdgeInsets.all(7),
itemBuilder: (_, idx) {
final key = allKeys[idx];
return CardX(
key: ValueKey(idx),
child: ListTile(
title: Text(key),
leading: _buildCheckBox(keys, key, idx, idx < keys.length),
trailing: isDesktop ? null : const Icon(Icons.drag_handle),
),
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];
return ReorderableListView.builder(
padding: const EdgeInsets.all(7),
itemBuilder: (_, idx) {
final key = allKeys[idx];
return CardX(
key: ValueKey(idx),
child: ListTile(
title: Text(key),
leading: _buildCheckBox(keys, key, idx, idx < keys.length),
trailing: isDesktop ? null : const Icon(Icons.drag_handle),
),
);
},
itemCount: allKeys.length,
onReorder: (o, n) {
if (o >= keys.length || n >= keys.length) {
context.showSnackBar(l10n.disabled);
return;
}
keys.moveByItem(keys, o, n, property: prop);
},
);
},
itemCount: allKeys.length,
onReorder: (o, n) {
if (o >= keys.length || n >= keys.length) {
context.showSnackBar(l10n.disabled);
return;
}
keys.moveByItem(keys, o, n, property: Stores.setting.detailCardOrder);
setState(() {});
},
);
}

Expand All @@ -75,8 +77,7 @@ class _ServerDetailOrderPageState extends State<ServerDetailOrderPage> {
} else {
keys.remove(key);
}
Stores.setting.detailCardOrder.put(keys);
setState(() {});
prop.put(keys);
},
);
}
Expand Down
65 changes: 33 additions & 32 deletions lib/view/page/setting/seq/srv_func_seq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -28,38 +30,38 @@ class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {
}

Widget _buildBody() {
final keys_ = Stores.setting.serverFuncBtns.fetch();
final keys = <int>[];
for (final key in keys_) {
keys.add(key);
}
final disabled = ServerFuncBtn.values
.map((e) => e.index)
.where((e) => !keys.contains(e))
.toList();
final allKeys = [...keys, ...disabled];
return ReorderableListView.builder(
padding: const EdgeInsets.all(7),
itemBuilder: (_, idx) {
final key = allKeys[idx];
return CardX(
key: ValueKey(idx),
child: ListTile(
title: Text(ServerFuncBtn.values[key].toStr),
leading: _buildCheckBox(keys, key, idx, idx < keys.length),
trailing: isDesktop ? null : const Icon(Icons.drag_handle),
),
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))
.toList();
final allKeys = [...keys, ...disabled];
return ReorderableListView.builder(
padding: const EdgeInsets.all(7),
itemBuilder: (_, idx) {
final key = allKeys[idx];
return CardX(
key: ValueKey(idx),
child: ListTile(
title: Text(ServerFuncBtn.values[key].toStr),
leading: _buildCheckBox(keys, key, idx, idx < keys.length),
trailing: isDesktop ? null : const Icon(Icons.drag_handle),
),
);
},
itemCount: allKeys.length,
onReorder: (o, n) {
if (o >= keys.length || n >= keys.length) {
context.showSnackBar(l10n.disabled);
return;
}
keys.moveByItem(keys, o, n, property: prop);
},
);
},
itemCount: allKeys.length,
onReorder: (o, n) {
if (o >= keys.length || n >= keys.length) {
context.showSnackBar(l10n.disabled);
return;
}
keys.moveByItem(keys, o, n, property: Stores.setting.serverFuncBtns);
setState(() {});
},
);
}

Expand All @@ -82,8 +84,7 @@ class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {
} else {
keys.remove(key);
}
Stores.setting.serverFuncBtns.put(keys);
setState(() {});
prop.put(keys);
},
);
}
Expand Down
Loading

0 comments on commit e20adee

Please sign in to comment.