opt.: l10n & fix: write script (#514)
This commit is contained in:
@@ -83,9 +83,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
if (s == null) {
|
||||
return Scaffold(
|
||||
appBar: const CustomAppBar(),
|
||||
body: Center(
|
||||
child: Text(l10n.noClient),
|
||||
),
|
||||
body: Center(child: Text(libL10n.empty)),
|
||||
);
|
||||
}
|
||||
return _buildMainPage(s);
|
||||
@@ -123,7 +121,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
|
||||
CustomAppBar _buildAppBar(Server si) {
|
||||
return CustomAppBar(
|
||||
title: Text(si.spi.name, style: UIs.text18),
|
||||
title: Text(si.spi.name),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
@@ -484,7 +482,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
child: Text(l10n.close),
|
||||
child: Text(libL10n.close),
|
||||
)
|
||||
],
|
||||
);
|
||||
@@ -528,7 +526,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
child: Text(l10n.close),
|
||||
child: Text(libL10n.close),
|
||||
)
|
||||
],
|
||||
);
|
||||
@@ -605,18 +603,10 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
Widget _buildNetView(ServerStatus ss) {
|
||||
final ns = ss.netSpeed;
|
||||
final children = <Widget>[];
|
||||
if (ns.devices.isEmpty) {
|
||||
children.add(Center(
|
||||
child: Text(
|
||||
l10n.noInterface,
|
||||
style: UIs.text13Grey,
|
||||
),
|
||||
));
|
||||
} else {
|
||||
final devices = ns.devices;
|
||||
devices.sort(_netSortType.value.getSortFunc(ns));
|
||||
children.addAll(devices.map((e) => _buildNetSpeedItem(ns, e)));
|
||||
}
|
||||
final devices = ns.devices;
|
||||
devices.sort(_netSortType.value.getSortFunc(ns));
|
||||
children.addAll(devices.map((e) => _buildNetSpeedItem(ns, e)));
|
||||
|
||||
return CardX(
|
||||
child: ExpandTile(
|
||||
leading: Icon(ServerDetailCards.net.icon, size: 17),
|
||||
@@ -870,7 +860,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
child: Text(l10n.close),
|
||||
child: Text(libL10n.close),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -92,7 +92,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
|
||||
PreferredSizeWidget _buildAppBar() {
|
||||
return CustomAppBar(
|
||||
title: Text(l10n.edit, style: UIs.text18),
|
||||
title: Text(libL10n.edit),
|
||||
actions: widget.spi != null ? [_buildDelBtn()] : null,
|
||||
);
|
||||
}
|
||||
@@ -101,22 +101,20 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
return IconButton(
|
||||
onPressed: () {
|
||||
context.showRoundDialog(
|
||||
title: l10n.attention,
|
||||
title: libL10n.attention,
|
||||
child: StatefulBuilder(builder: (ctx, setState) {
|
||||
return Text(l10n.askContinue(
|
||||
'${l10n.delete} ${l10n.server}(${widget.spi!.name})',
|
||||
return Text(libL10n.askContinue(
|
||||
'${libL10n.delete} ${l10n.server}(${widget.spi!.name})',
|
||||
));
|
||||
}),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
context.pop();
|
||||
Pros.server.delServer(widget.spi!.id);
|
||||
context.pop(true);
|
||||
},
|
||||
child: Text(l10n.ok, style: UIs.textRed),
|
||||
),
|
||||
],
|
||||
actions: Btn.ok(
|
||||
onTap: (c) async {
|
||||
context.pop();
|
||||
Pros.server.delServer(widget.spi!.id);
|
||||
context.pop(true);
|
||||
},
|
||||
red: true,
|
||||
).toList,
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.delete),
|
||||
@@ -132,8 +130,8 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
type: TextInputType.text,
|
||||
node: _nameFocus,
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_ipFocus),
|
||||
hint: l10n.exampleName,
|
||||
label: l10n.name,
|
||||
hint: libL10n.example,
|
||||
label: libL10n.name,
|
||||
icon: BoxIcons.bx_rename,
|
||||
obscureText: false,
|
||||
autoCorrect: true,
|
||||
@@ -164,7 +162,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
type: TextInputType.text,
|
||||
node: _usernameFocus,
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_alterUrlFocus),
|
||||
label: l10n.user,
|
||||
label: libL10n.user,
|
||||
icon: Icons.account_box,
|
||||
hint: 'root',
|
||||
suggestion: false,
|
||||
@@ -266,7 +264,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
});
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(l10n.addPrivateKey),
|
||||
title: Text(libL10n.add),
|
||||
contentPadding: padding,
|
||||
trailing: const Padding(
|
||||
padding: EdgeInsets.only(right: 13),
|
||||
@@ -331,7 +329,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
Input(
|
||||
controller: _preferTempDevCtrl,
|
||||
type: TextInputType.text,
|
||||
label: l10n.deviceName,
|
||||
label: libL10n.device,
|
||||
icon: MingCute.low_temperature_line,
|
||||
hint: 'nvme-pci-0400',
|
||||
suggestion: false,
|
||||
@@ -421,7 +419,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
).cardx,
|
||||
ListTile(
|
||||
leading: const Icon(MingCute.doc_line),
|
||||
title: Text(l10n.doc),
|
||||
title: Text(libL10n.doc),
|
||||
trailing: const Icon(Icons.open_in_new, size: 17),
|
||||
onTap: () => l10n.customCmdDocUrl.launch(),
|
||||
).cardx,
|
||||
@@ -494,7 +492,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
)
|
||||
.toList();
|
||||
children.add(ListTile(
|
||||
title: Text(l10n.clear),
|
||||
title: Text(libL10n.clear),
|
||||
trailing: const Icon(Icons.clear),
|
||||
onTap: () => _jumpServer.value = null,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 17),
|
||||
@@ -513,31 +511,31 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
|
||||
void _onSave() async {
|
||||
if (_ipController.text.isEmpty) {
|
||||
context.showSnackBar(l10n.plzEnterHost);
|
||||
context.showSnackBar('${libL10n.empty} ${l10n.host}');
|
||||
return;
|
||||
}
|
||||
|
||||
if (_keyIdx.value == null && _passwordController.text.isEmpty) {
|
||||
final cancel = await context.showRoundDialog<bool>(
|
||||
title: l10n.attention,
|
||||
child: Text(l10n.askContinue(l10n.useNoPwd)),
|
||||
title: libL10n.attention,
|
||||
child: Text(libL10n.askContinue(l10n.useNoPwd)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(false),
|
||||
child: Text(l10n.ok),
|
||||
child: Text(libL10n.ok),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => context.pop(true),
|
||||
child: Text(l10n.cancel),
|
||||
child: Text(libL10n.cancel),
|
||||
)
|
||||
],
|
||||
);
|
||||
if (cancel != false) {
|
||||
return;
|
||||
}
|
||||
if (cancel != false) return;
|
||||
}
|
||||
|
||||
// If [_pubKeyIndex] is -1, it means that the user has not selected
|
||||
if (_keyIdx.value == -1) {
|
||||
context.showSnackBar(l10n.plzSelectKey);
|
||||
context.showSnackBar(libL10n.empty);
|
||||
return;
|
||||
}
|
||||
if (_usernameController.text.isEmpty) {
|
||||
@@ -568,7 +566,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
if (wol != null) {
|
||||
final wolValidation = wol.validate();
|
||||
if (!wolValidation.$2) {
|
||||
context.showSnackBar('${l10n.failed}: ${wolValidation.$1}');
|
||||
context.showSnackBar('${libL10n.fail}: ${wolValidation.$1}');
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -608,7 +606,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
onTap: () {
|
||||
context.showRoundDialog(
|
||||
title: l10n.attention,
|
||||
title: libL10n.attention,
|
||||
child: SimpleMarkdown(data: l10n.writeScriptTip),
|
||||
actions: [Btn.ok()],
|
||||
);
|
||||
@@ -618,7 +616,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
children: [
|
||||
const Icon(Icons.tips_and_updates, size: 15, color: Colors.grey),
|
||||
UIs.width13,
|
||||
Text(l10n.attention, style: UIs.textGrey)
|
||||
Text(libL10n.attention, style: UIs.textGrey)
|
||||
],
|
||||
).paddingSymmetric(horizontal: 13, vertical: 3),
|
||||
),
|
||||
|
||||
@@ -106,7 +106,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
child: FloatingActionButton(
|
||||
heroTag: 'addServer',
|
||||
onPressed: () => AppRoutes.serverEdit().go(context),
|
||||
tooltip: l10n.addAServer,
|
||||
tooltip: libL10n.add,
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
@@ -141,10 +141,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
return Consumer<ServerProvider>(builder: (_, pro, __) {
|
||||
if (pro.serverOrder.isEmpty) {
|
||||
return Center(
|
||||
child: Text(
|
||||
l10n.serverTabEmpty,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
child: Text(libL10n.empty, textAlign: TextAlign.center),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -190,10 +187,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
}
|
||||
if (pro.serverOrder.isEmpty) {
|
||||
return Center(
|
||||
child: Text(
|
||||
l10n.serverTabEmpty,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
child: Text(libL10n.empty, textAlign: TextAlign.center),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -348,19 +342,20 @@ class _ServerPageState extends State<ServerPage>
|
||||
}
|
||||
|
||||
List<Widget> _buildFlippedCard(Server srv) {
|
||||
const textStyle = TextStyle(color: Colors.grey);
|
||||
final children = [
|
||||
Btn.column(
|
||||
onTap: (_) => _askFor(
|
||||
func: () async {
|
||||
if (Stores.setting.showSuspendTip.fetch()) {
|
||||
await context.showRoundDialog(
|
||||
title: l10n.attention,
|
||||
title: libL10n.attention,
|
||||
child: Text(l10n.suspendTip),
|
||||
);
|
||||
Stores.setting.showSuspendTip.put(false);
|
||||
}
|
||||
srv.client?.execWithPwd(
|
||||
ShellFunc.suspend.exec,
|
||||
ShellFunc.suspend.exec(srv.spi.id),
|
||||
context: context,
|
||||
id: srv.id,
|
||||
);
|
||||
@@ -368,39 +363,43 @@ class _ServerPageState extends State<ServerPage>
|
||||
typ: l10n.suspend,
|
||||
name: srv.spi.name,
|
||||
),
|
||||
icon: const Icon(Icons.stop),
|
||||
icon: const Icon(Icons.stop, color: Colors.grey),
|
||||
text: l10n.suspend,
|
||||
textStyle: textStyle,
|
||||
),
|
||||
Btn.column(
|
||||
onTap: (_) => _askFor(
|
||||
func: () => srv.client?.execWithPwd(
|
||||
ShellFunc.shutdown.exec,
|
||||
ShellFunc.shutdown.exec(srv.spi.id),
|
||||
context: context,
|
||||
id: srv.id,
|
||||
),
|
||||
typ: l10n.shutdown,
|
||||
name: srv.spi.name,
|
||||
),
|
||||
icon: const Icon(Icons.power_off),
|
||||
icon: const Icon(Icons.power_off, color: Colors.grey),
|
||||
text: l10n.shutdown,
|
||||
textStyle: textStyle,
|
||||
),
|
||||
Btn.column(
|
||||
onTap: (_) => _askFor(
|
||||
func: () => srv.client?.execWithPwd(
|
||||
ShellFunc.reboot.exec,
|
||||
ShellFunc.reboot.exec(srv.spi.id),
|
||||
context: context,
|
||||
id: srv.id,
|
||||
),
|
||||
typ: l10n.reboot,
|
||||
name: srv.spi.name,
|
||||
),
|
||||
icon: const Icon(Icons.restart_alt),
|
||||
icon: const Icon(Icons.restart_alt, color: Colors.grey),
|
||||
text: l10n.reboot,
|
||||
textStyle: textStyle,
|
||||
),
|
||||
Btn.column(
|
||||
onTap: (_) => AppRoutes.serverEdit(spi: srv.spi).go(context),
|
||||
icon: const Icon(Icons.edit),
|
||||
text: l10n.edit,
|
||||
icon: const Icon(Icons.edit, color: Colors.grey),
|
||||
text: libL10n.edit,
|
||||
textStyle: textStyle,
|
||||
)
|
||||
];
|
||||
|
||||
@@ -445,7 +444,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
|
||||
Widget _buildServerCardTitle(Server s) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7),
|
||||
padding: const EdgeInsets.only(left: 7, right: 13),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@@ -497,15 +496,15 @@ class _ServerPageState extends State<ServerPage>
|
||||
),
|
||||
ServerConn.disconnected => (
|
||||
const Icon(
|
||||
BoxIcons.bx_link,
|
||||
size: 21,
|
||||
MingCute.link_3_line,
|
||||
size: 19,
|
||||
color: Colors.grey,
|
||||
),
|
||||
() => Pros.server.refresh(spi: s.spi)
|
||||
),
|
||||
ServerConn.finished => (
|
||||
const Icon(
|
||||
BoxIcons.bx_unlink,
|
||||
MingCute.unlink_2_line,
|
||||
size: 17,
|
||||
color: Colors.grey,
|
||||
),
|
||||
@@ -535,15 +534,14 @@ class _ServerPageState extends State<ServerPage>
|
||||
|
||||
Widget _buildTopRightText(Server s) {
|
||||
final hasErr = s.conn == ServerConn.failed && s.status.err != null;
|
||||
final str = s.getTopRightStr(s.spi);
|
||||
if (str == null) return UIs.placeholder;
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (!hasErr) return;
|
||||
_showFailReason(s.status);
|
||||
},
|
||||
child: Text(
|
||||
s.getTopRightStr(s.spi),
|
||||
style: UIs.text13Grey,
|
||||
),
|
||||
child: Text(str, style: UIs.text13Grey),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -552,15 +550,15 @@ class _ServerPageState extends State<ServerPage>
|
||||
${ss.err?.solution ?? l10n.unknown}
|
||||
|
||||
```sh
|
||||
${ss.err?.message ?? l10n.unknownError}
|
||||
${ss.err?.message ?? 'null'}
|
||||
''';
|
||||
context.showRoundDialog(
|
||||
title: l10n.error,
|
||||
title: libL10n.error,
|
||||
child: SingleChildScrollView(child: SimpleMarkdown(data: md)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Pfs.copy(md),
|
||||
child: Text(l10n.copy),
|
||||
child: Text(libL10n.copy),
|
||||
)
|
||||
],
|
||||
);
|
||||
@@ -692,17 +690,14 @@ ${ss.err?.message ?? l10n.unknownError}
|
||||
required String name,
|
||||
}) {
|
||||
context.showRoundDialog(
|
||||
title: l10n.attention,
|
||||
child: Text(l10n.askContinue('$typ ${l10n.server}($name)')),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
func();
|
||||
},
|
||||
child: Text(l10n.ok),
|
||||
),
|
||||
],
|
||||
title: libL10n.attention,
|
||||
child: Text(libL10n.askContinue('$typ ${l10n.server}($name)')),
|
||||
actions: Btn.ok(
|
||||
onTap: (c) {
|
||||
context.pop();
|
||||
func();
|
||||
},
|
||||
).toList,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -750,3 +745,60 @@ class _CardStatus {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension _ServerX on Server {
|
||||
String? getTopRightStr(ServerPrivateInfo spi) {
|
||||
switch (conn) {
|
||||
case ServerConn.disconnected:
|
||||
return null;
|
||||
case ServerConn.finished:
|
||||
// Highest priority of temperature display
|
||||
final cmdTemp = () {
|
||||
final val = status.customCmds['server_card_top_right'];
|
||||
if (val == null) return null;
|
||||
// This returned value is used on server card top right, so it should
|
||||
// be a single line string.
|
||||
return val.split('\n').lastOrNull;
|
||||
}();
|
||||
final temperatureVal = () {
|
||||
// Second priority
|
||||
final preferTempDev = spi.custom?.preferTempDev;
|
||||
if (preferTempDev != null) {
|
||||
final preferTemp = status.sensors
|
||||
.firstWhereOrNull((e) => e.device == preferTempDev)
|
||||
?.summary
|
||||
?.split(' ')
|
||||
.firstOrNull;
|
||||
if (preferTemp != null) {
|
||||
return double.tryParse(preferTemp.replaceFirst('°C', ''));
|
||||
}
|
||||
}
|
||||
// Last priority
|
||||
final temp = status.temps.first;
|
||||
if (temp != null) {
|
||||
return temp;
|
||||
}
|
||||
return null;
|
||||
}();
|
||||
final upTime = status.more[StatusCmdType.uptime];
|
||||
final items = [
|
||||
cmdTemp ??
|
||||
(temperatureVal != null
|
||||
? '${temperatureVal.toStringAsFixed(1)}°C'
|
||||
: null),
|
||||
upTime
|
||||
];
|
||||
final str = items.where((e) => e != null && e.isNotEmpty).join(' | ');
|
||||
if (str.isEmpty) return libL10n.empty;
|
||||
return str;
|
||||
case ServerConn.loading:
|
||||
return null;
|
||||
case ServerConn.connected:
|
||||
return null;
|
||||
case ServerConn.connecting:
|
||||
return null;
|
||||
case ServerConn.failed:
|
||||
return status.err != null ? l10n.viewErr : libL10n.fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user