From 0420793e21487f3bd603a24da54cee022475f5e0 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Mon, 28 Aug 2023 18:08:26 +0800 Subject: [PATCH] new: edit `settings` in json --- .dart_tool/flutter_gen/gen_l10n/l10n.dart | 6 ++ .dart_tool/flutter_gen/gen_l10n/l10n_de.dart | 3 + .dart_tool/flutter_gen/gen_l10n/l10n_en.dart | 3 + .dart_tool/flutter_gen/gen_l10n/l10n_id.dart | 3 + .dart_tool/flutter_gen/gen_l10n/l10n_zh.dart | 6 ++ lib/data/model/app/net_view.dart | 22 +++++++ lib/l10n/app_de.arb | 1 + lib/l10n/app_en.arb | 1 + lib/l10n/app_id.arb | 1 + lib/l10n/app_zh.arb | 1 + lib/l10n/app_zh_tw.arb | 1 + lib/view/page/home.dart | 63 ++++++++++---------- lib/view/page/setting/entry.dart | 3 +- 13 files changed, 83 insertions(+), 31 deletions(-) diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n.dart b/.dart_tool/flutter_gen/gen_l10n/l10n.dart index 953f2c33..6f8b91d2 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n.dart @@ -158,6 +158,12 @@ abstract class S { /// **'Alter url'** String get alterUrl; + /// No description provided for @atOwnRisk. + /// + /// In en, this message translates to: + /// **'At your own risk !'** + String get atOwnRisk; + /// No description provided for @attention. /// /// In en, this message translates to: diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_de.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_de.dart index c58120d6..20c020c3 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_de.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_de.dart @@ -34,6 +34,9 @@ class SDe extends S { @override String get alterUrl => 'Url ändern'; + @override + String get atOwnRisk => 'Auf eigene Gefahr !'; + @override String get attention => 'Achtung'; diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart index 7645e0af..5e7fd968 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart @@ -34,6 +34,9 @@ class SEn extends S { @override String get alterUrl => 'Alter url'; + @override + String get atOwnRisk => 'At your own risk !'; + @override String get attention => 'Attention'; diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_id.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_id.dart index e9e3e0fe..9bb75b93 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_id.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_id.dart @@ -34,6 +34,9 @@ class SId extends S { @override String get alterUrl => 'Alter url'; + @override + String get atOwnRisk => 'Dengan risiko Anda sendiri'; + @override String get attention => 'Perhatian'; diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart index 7b147198..d2f2ba45 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart @@ -34,6 +34,9 @@ class SZh extends S { @override String get alterUrl => '备选链接'; + @override + String get atOwnRisk => '如果了解不多,请不要继续!'; + @override String get attention => '注意'; @@ -754,6 +757,9 @@ class SZhTw extends SZh { @override String get alterUrl => '備選鏈接'; + @override + String get atOwnRisk => '如果了解不多,請不要繼續!'; + @override String get attention => '注意'; diff --git a/lib/data/model/app/net_view.dart b/lib/data/model/app/net_view.dart index 209659f2..32609bee 100644 --- a/lib/data/model/app/net_view.dart +++ b/lib/data/model/app/net_view.dart @@ -43,6 +43,28 @@ enum NetViewType { ); } } + + int toJson() { + switch (this) { + case NetViewType.conn: + return 0; + case NetViewType.speed: + return 1; + case NetViewType.traffic: + return 2; + } + } + + static NetViewType fromJson(int json) { + switch (json) { + case 0: + return NetViewType.conn; + case 2: + return NetViewType.traffic; + default: + return NetViewType.speed; + } + } } class NetViewData { diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 71678588..55268e41 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -10,6 +10,7 @@ "all": "Alle", "alreadyLastDir": "Bereits im letzten Verzeichnis.", "alterUrl": "Url ändern", + "atOwnRisk": "Auf eigene Gefahr !", "attention": "Achtung", "auto": "System folgen", "autoCheckUpdate": "Aktualisierung automatisch prüfen", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 61ae8337..52ca2617 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -10,6 +10,7 @@ "all": "All", "alreadyLastDir": "Already in last directory.", "alterUrl": "Alter url", + "atOwnRisk": "At your own risk !", "attention": "Attention", "auto": "Auto", "autoCheckUpdate": "Auto check update", diff --git a/lib/l10n/app_id.arb b/lib/l10n/app_id.arb index aff7a0e6..4f9842af 100644 --- a/lib/l10n/app_id.arb +++ b/lib/l10n/app_id.arb @@ -10,6 +10,7 @@ "all": "Semua", "alreadyLastDir": "Sudah di direktori terakhir.", "alterUrl": "Alter url", + "atOwnRisk": "Dengan risiko Anda sendiri", "attention": "Perhatian", "auto": "Auto", "autoCheckUpdate": "Periksa pembaruan otomatis", diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index d31c7bde..4ca344c4 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -10,6 +10,7 @@ "all": "所有", "alreadyLastDir": "已经是最上层目录了", "alterUrl": "备选链接", + "atOwnRisk": "如果了解不多,请不要继续!", "attention": "注意", "auto": "自动", "autoCheckUpdate": "自动检查更新", diff --git a/lib/l10n/app_zh_tw.arb b/lib/l10n/app_zh_tw.arb index 56174083..3191cf93 100644 --- a/lib/l10n/app_zh_tw.arb +++ b/lib/l10n/app_zh_tw.arb @@ -10,6 +10,7 @@ "all": "所有", "alreadyLastDir": "已經是最上層目錄了", "alterUrl": "備選鏈接", + "atOwnRisk": "如果了解不多,請不要繼續!", "attention": "注意", "auto": "自動", "autoCheckUpdate": "自動檢查更新", diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index 775adc87..9d9545e9 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -233,36 +233,7 @@ class _HomePageState extends State leading: const Icon(Icons.settings), title: Text(_s.setting), onTap: () => AppRoute.setting().go(context), - onLongPress: () async { - final map = _setting.toJson(); - final go = await showRoundDialog( - context: context, - child: Text(_s.attention), - actions: [ - TextButton( - onPressed: () => context.pop(true), - child: Text( - _s.ok, - style: const TextStyle(color: Colors.red), - ), - ), - ], - ); - if (go != true) { - return; - } - - /// Encode [map] to String with indent `\t` - final text = const JsonEncoder.withIndent('\t').convert(map); - final result = await AppRoute.editor( - text: text, - langCode: 'json', - ).go(context); - if (result == null) { - return; - } - _setting.box.putAll(json.decode(result) as Map); - }, + onLongPress: _onLongPressSetting, ), ListTile( leading: const Icon(Icons.vpn_key), @@ -383,4 +354,36 @@ class _HomePageState extends State homeWidgetChannel.invokeMethod('update'); } } + + Future _onLongPressSetting() async { + final go = await showRoundDialog( + context: context, + title: Text(_s.attention), + child: Text(_s.atOwnRisk), + actions: [ + TextButton( + onPressed: () => context.pop(true), + child: Text( + _s.ok, + style: const TextStyle(color: Colors.red), + ), + ), + ], + ); + if (go != true) { + return; + } + + /// Encode [map] to String with indent `\t` + final map = _setting.toJson(); + final text = jsonEncoder.convert(map); + final result = await AppRoute.editor( + text: text, + langCode: 'json', + ).go(context); + if (result == null) { + return; + } + _setting.box.putAll(json.decode(result) as Map); + } } diff --git a/lib/view/page/setting/entry.dart b/lib/view/page/setting/entry.dart index ce625bf8..f7ce145d 100644 --- a/lib/view/page/setting/entry.dart +++ b/lib/view/page/setting/entry.dart @@ -194,7 +194,8 @@ class _SettingPageState extends State { _buildFont(), _buildTermFontSize(), _buildSSHVirtualKeyAutoOff(), - _buildKeyboardType(), + // Use hardware keyboard on desktop, so there is no need to set it + if (isMobile) _buildKeyboardType(), _buildSSHVirtKeys(), _buildSftpRmrfDir(), ].map((e) => RoundRectCard(e)).toList(),