new: fast poweroff | reboot (#119)

This commit is contained in:
lollipopkit
2023-08-31 12:36:40 -06:00
parent 28660b82ef
commit acaec6e2d8
2 changed files with 77 additions and 44 deletions

View File

@@ -6,10 +6,9 @@ import '../model/app/net_view.dart';
import '../res/default.dart'; import '../res/default.dart';
class SettingStore extends PersistentStore { class SettingStore extends PersistentStore {
// ------BEGIN------ // ------BEGIN------
// These settings are not displayed in the settings page // These settings are not displayed in the settings page
// You can edit them in the settings json editor (by long press the settings // You can edit them in the settings json editor (by long press the settings
// item in the drawer of the server tab page) // item in the drawer of the server tab page)
/// Discussion #146 /// Discussion #146

View File

@@ -38,6 +38,8 @@ class _ServerPageState extends State<ServerPage>
late SettingStore _settingStore; late SettingStore _settingStore;
late S _s; late S _s;
final _flipedCardIds = <String>{};
String? _tag; String? _tag;
bool _useDoubleColumn = false; bool _useDoubleColumn = false;
@@ -189,10 +191,16 @@ class _ServerPageState extends State<ServerPage>
_showFailReason(si.status); _showFailReason(si.status);
} }
}, },
onLongPress: () => AppRoute.serverEdit(spi: si.spi).go(context), onLongPress: () => setState(() {
if (_flipedCardIds.contains(si.spi.id)) {
_flipedCardIds.remove(si.spi.id);
} else {
_flipedCardIds.add(si.spi.id);
}
}),
child: Padding( child: Padding(
padding: const EdgeInsets.all(13), padding: const EdgeInsets.all(13),
child: _buildRealServerCard(si.status, si.state, si.spi), child: _buildRealServerCard(si),
), ),
), ),
); );
@@ -207,51 +215,21 @@ class _ServerPageState extends State<ServerPage>
); );
} }
Widget _buildRealServerCard( Widget _buildRealServerCard(Server srv) {
ServerStatus ss, final title = _buildServerCardTitle(srv.status, srv.state, srv.spi);
ServerState cs, final List<Widget> children = [title];
ServerPrivateInfo spi, if (srv.state != ServerState.finished) {
) { // Do nothing
final rootDisk = findRootDisk(ss.disk); } else if (_flipedCardIds.contains(srv.spi.id)) {
late final List<Widget> children; children.addAll(_buildFlipedCard(srv));
if (cs != ServerState.finished) {
children = [
_buildServerCardTitle(ss, cs, spi),
];
} else { } else {
children = [ children.addAll(_buildNormalCard(srv.status, srv.spi));
_buildServerCardTitle(ss, cs, spi),
height13,
Padding(
padding: const EdgeInsets.symmetric(horizontal: 13),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_wrapWithSizedbox(_buildPercentCircle(ss.cpu.usedPercent())),
_wrapWithSizedbox(_buildPercentCircle(ss.mem.usedPercent * 100)),
_wrapWithSizedbox(_buildNet(ss)),
_wrapWithSizedbox(_buildIOData(
'Total:\n${rootDisk?.size}',
'Used:\n${rootDisk?.usedPercent}%',
)),
],
),
),
height13,
if (_settingStore.moveOutServerTabFuncBtns.fetch() &&
// Discussion #146
!_settingStore.serverTabUseOldUI.fetch())
SizedBox(
height: 27,
child: ServerFuncBtns(spi: spi, s: _s),
),
];
} }
return AnimatedContainer( return AnimatedContainer(
duration: const Duration(milliseconds: 377), duration: const Duration(milliseconds: 377),
curve: Curves.fastEaseInToSlowEaseOut, curve: Curves.fastEaseInToSlowEaseOut,
height: _calcCardHeight(cs), height: _calcCardHeight(srv.state, srv.spi.id),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
@@ -261,6 +239,59 @@ class _ServerPageState extends State<ServerPage>
); );
} }
List<Widget> _buildFlipedCard(Server srv) {
return [
height13,
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
onPressed: () => srv.client?.run('shutdown -h now'),
icon: const Icon(Icons.power_off),
),
IconButton(
onPressed: () => srv.client?.run('reboot'),
icon: const Icon(Icons.refresh),
),
IconButton(
onPressed: () => AppRoute.serverEdit(spi: srv.spi).go(context),
icon: const Icon(Icons.edit),
)
],
)
];
}
List<Widget> _buildNormalCard(ServerStatus ss, ServerPrivateInfo spi) {
final rootDisk = findRootDisk(ss.disk);
return [
height13,
Padding(
padding: const EdgeInsets.symmetric(horizontal: 13),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_wrapWithSizedbox(_buildPercentCircle(ss.cpu.usedPercent())),
_wrapWithSizedbox(_buildPercentCircle(ss.mem.usedPercent * 100)),
_wrapWithSizedbox(_buildNet(ss)),
_wrapWithSizedbox(_buildIOData(
'Total:\n${rootDisk?.size}',
'Used:\n${rootDisk?.usedPercent}%',
)),
],
),
),
height13,
if (_settingStore.moveOutServerTabFuncBtns.fetch() &&
// Discussion #146
!_settingStore.serverTabUseOldUI.fetch())
SizedBox(
height: 27,
child: ServerFuncBtns(spi: spi, s: _s),
),
];
}
Widget _buildServerCardTitle( Widget _buildServerCardTitle(
ServerStatus ss, ServerStatus ss,
ServerState cs, ServerState cs,
@@ -450,10 +481,13 @@ class _ServerPageState extends State<ServerPage>
} }
} }
double _calcCardHeight(ServerState cs) { double _calcCardHeight(ServerState cs, String id) {
if (cs != ServerState.finished) { if (cs != ServerState.finished) {
return 23.0; return 23.0;
} }
if (_flipedCardIds.contains(id)) {
return 77.0;
}
if (_settingStore.moveOutServerTabFuncBtns.fetch() && if (_settingStore.moveOutServerTabFuncBtns.fetch() &&
// Discussion #146 // Discussion #146
!_settingStore.serverTabUseOldUI.fetch()) { !_settingStore.serverTabUseOldUI.fetch()) {