new & opt.

- new: support suspend and WOL #172
- opt.: `execWithPwd` when cancel
- opt.: extentions
This commit is contained in:
lollipopkit
2023-09-25 18:51:14 +08:00
parent df84aeb8b2
commit 4d06a52e99
45 changed files with 251 additions and 176 deletions

View File

@@ -58,7 +58,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
if (widget.spi?.pubKeyId == null) {
_passwordController.text = widget.spi?.pwd ?? '';
} else {
_keyIdx.value = Providers.key.pkis.indexWhere(
_keyIdx.value = Pros.key.pkis.indexWhere(
(e) => e.id == widget.spi!.pubKeyId,
);
}
@@ -115,7 +115,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
actions: [
TextButton(
onPressed: () {
Providers.server.delServer(widget.spi!.id);
Pros.server.delServer(widget.spi!.id);
context.pop();
context.pop(true);
},
@@ -183,8 +183,8 @@ class _ServerEditPageState extends State<ServerEditPage> {
TagEditor(
tags: _tags,
onChanged: (p0) => _tags = p0,
allTags: [...Providers.server.tags],
onRenameTag: Providers.server.renameTag,
allTags: [...Pros.server.tags],
onRenameTag: Pros.server.renameTag,
),
_buildAuth(),
ListTile(
@@ -357,7 +357,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
user: _usernameController.text,
pwd: _passwordController.text.isEmpty ? null : _passwordController.text,
pubKeyId: _keyIdx.value != null
? Providers.key.pkis.elementAt(_keyIdx.value!).id
? Pros.key.pkis.elementAt(_keyIdx.value!).id
: null,
tags: _tags,
alterUrl: _altUrlController.text.isEmpty ? null : _altUrlController.text,
@@ -365,9 +365,9 @@ class _ServerEditPageState extends State<ServerEditPage> {
);
if (widget.spi == null) {
Providers.server.addServer(spi);
Pros.server.addServer(spi);
} else {
Providers.server.updateServer(widget.spi!, spi);
Pros.server.updateServer(widget.spi!, spi);
}
context.pop();

View File

@@ -92,8 +92,7 @@ class _ServerPageState extends State<ServerPage>
return child;
}
return RefreshIndicator(
onRefresh: () async =>
await Providers.server.refreshData(onlyFailed: true),
onRefresh: () async => await Pros.server.refreshData(onlyFailed: true),
child: child,
);
}
@@ -245,22 +244,42 @@ class _ServerPageState extends State<ServerPage>
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
onPressed: () => srv.client?.execWithPwd(
ShellFunc.shutdown.cmd,
context: context,
),
icon: const Icon(Icons.power_off),
onPressed: () async {
if (Stores.first.showSuspendTip.fetch()) {
await context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.suspendTip),
);
Stores.first.showSuspendTip.put(false);
}
srv.client?.execWithPwd(
ShellFunc.suspend.exec,
context: context,
);
},
icon: const Icon(Icons.stop),
tooltip: 'Suspend',
),
IconButton(
onPressed: () => srv.client?.execWithPwd(
ShellFunc.reboot.cmd,
ShellFunc.shutdown.exec,
context: context,
),
icon: const Icon(Icons.refresh),
icon: const Icon(Icons.power_off),
tooltip: 'Shutdown',
),
IconButton(
onPressed: () => srv.client?.execWithPwd(
ShellFunc.reboot.exec,
context: context,
),
icon: const Icon(Icons.restart_alt),
tooltip: 'Reboot',
),
IconButton(
onPressed: () => AppRoute.serverEdit(spi: srv.spi).go(context),
icon: const Icon(Icons.edit),
tooltip: l10n.edit,
)
],
)
@@ -305,7 +324,7 @@ class _ServerPageState extends State<ServerPage>
Widget? rightCorner;
if (!(spi.autoConnect ?? true) && cs == ServerState.disconnected) {
rightCorner = InkWell(
onTap: () => Providers.server.refreshData(spi: spi),
onTap: () => Pros.server.refreshData(spi: spi),
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 7),
child: Icon(
@@ -456,8 +475,8 @@ class _ServerPageState extends State<ServerPage>
@override
Future<void> afterFirstLayout(BuildContext context) async {
await GetIt.I.allReady();
await Providers.server.load();
Providers.server.startAutoRefresh();
await Pros.server.load();
Pros.server.startAutoRefresh();
}
List<String> _filterServers(ServerProvider pro) => pro.serverOrder