Skip to content

Commit

Permalink
new: compatibility of Chinese Android safe keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Mar 13, 2024
1 parent 150c8f0 commit 3747e2f
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 110 deletions.
18 changes: 8 additions & 10 deletions lib/data/store/setting.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:toolbox/core/persistant_store.dart';
import 'package:toolbox/core/utils/platform/base.dart';
import 'package:toolbox/data/model/app/menu/server_func.dart';
import 'package:xterm/ui.dart';

import '../model/app/net_view.dart';
import '../res/default.dart';
Expand Down Expand Up @@ -128,10 +126,10 @@ class SettingStore extends PersistentStore {
// 1,
// );

late final keyboardType = property(
'keyboardType',
TextInputType.text.index,
);
// late final keyboardType = property(
// 'keyboardType',
// TextInputType.text.index,
// );

late final sshVirtKeys = listProperty(
'sshVirtKeys',
Expand Down Expand Up @@ -251,10 +249,6 @@ class SettingStore extends PersistentStore {
/// when building traffic view on server tab
late final ignoreLocalNet = property('ignoreLocalNetIface', true);

/// Index of terminal cursor type
late final termCursor =
property('termCursor', TerminalCursorType.block.index);

/// Remerber pwd in memory
/// Used for [DialogX.showPwdDialog]
late final rememberPwdInMem = property('rememberPwdInMem', true);
Expand All @@ -263,6 +257,10 @@ class SettingStore extends PersistentStore {
/// 0: follow app theme, 1: light, 2: dark
late final termTheme = property('termTheme', 0);

/// Compatiablity for Chinese Android.
/// Set it to true, if you use Safe Keyboard on Chinese Android
late final cnKeyboardComp = property('cnKeyboardComp', false);

// Never show these settings for users
//
// ------BEGIN------
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"clipboard": "Zwischenablage",
"close": "Schließen",
"cmd": "Command",
"cnKeyboardComp": "Kompatibilität mit chinesischem Android",
"cnKeyboardCompTip": "Wenn das Terminal ein sicheres Tastenfeld öffnet, können Sie es aktivieren.",
"collapseUI": "Zusammenbrechen",
"collapseUITip": "Ob lange Listen in der Benutzeroberfläche standardmäßig eingeklappt werden sollen oder nicht",
"conn": "Verbindung",
Expand Down Expand Up @@ -125,8 +127,6 @@
"keepStatusWhenErr": "Den letzten Serverstatus beibehalten",
"keepStatusWhenErrTip": "Nur im Fehlerfall während der Ausführung des Skripts",
"keyAuth": "Schlüsselauthentifzierung",
"keyboardCompatibility": "Mögliche Verbesserungen bei der Kompatibilität der Eingabemethoden",
"keyboardType": "Tastatur Typ",
"language": "Sprache",
"languageName": "Deutsch",
"lastTry": "Letzter Versuch",
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"clipboard": "Clipboard",
"close": "Close",
"cmd": "Command",
"cnKeyboardComp": "Compatibility with Chinese Android",
"cnKeyboardCompTip": "If the terminal pops up a secure keyboard, you can enable it.",
"collapseUI": "Collapse",
"collapseUITip": "Whether to collapse long lists present in the UI by default",
"conn": "Connection",
Expand Down Expand Up @@ -125,8 +127,6 @@
"keepStatusWhenErr": "Preserve the last server state",
"keepStatusWhenErrTip": "Only in the event of an error during script execution",
"keyAuth": "Key Auth",
"keyboardCompatibility": "Possible to improve input method compatibility",
"keyboardType": "Keyborad type",
"language": "Language",
"languageName": "English",
"lastTry": "Last try",
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"clipboard": "Portapapeles",
"close": "Cerrar",
"cmd": "Comando",
"cnKeyboardComp": "Compatibilidad con Android chino",
"cnKeyboardCompTip": "Si el terminal muestra un teclado seguro, puedes activarlo.",
"collapseUI": "Colapsar",
"collapseUITip": "¿Colapsar por defecto las listas largas en la UI?",
"conn": "Conectar",
Expand Down Expand Up @@ -125,8 +127,6 @@
"keepStatusWhenErr": "Mantener el estado anterior del servidor",
"keepStatusWhenErrTip": "Solo aplica cuando hay errores al ejecutar scripts",
"keyAuth": "Autenticación con llave",
"keyboardCompatibility": "Puede mejorar la compatibilidad del teclado",
"keyboardType": "Tipo de teclado",
"language": "Idioma",
"languageName": "Español",
"lastTry": "Último intento",
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"clipboard": "presse-papiers",
"close": "Fermer",
"cmd": "Commande",
"cnKeyboardComp": " Compatibilité avec Android chinois",
"cnKeyboardCompTip": "Si le terminal affiche un clavier sécurisé, vous pouvez l'activer.",
"collapseUI": "обвал",
"collapseUITip": "Réduction ou non des longues listes présentes dans l'interface utilisateur par défaut",
"conn": "Connexion",
Expand Down Expand Up @@ -125,8 +127,6 @@
"keepStatusWhenErr": "Conserver le dernier état du serveur",
"keepStatusWhenErrTip": "Uniquement en cas d'erreur lors de l'exécution du script",
"keyAuth": "Authentification par clé",
"keyboardCompatibility": "Possibilité d'améliorer la compatibilité avec les méthodes de saisie",
"keyboardType": "Type de clavier",
"language": "Langue",
"languageName": "Français",
"lastTry": "Dernier essai",
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"clipboard": "papan klip",
"close": "Menutup",
"cmd": "Memerintah",
"cnKeyboardComp": "Kompatibilitas dengan Android China",
"cnKeyboardCompTip": "Jika terminal munculkan keyboard aman, Anda bisa mengaktifkannya.",
"collapseUI": "Runtuh",
"collapseUITip": "Apakah akan menciutkan daftar panjang yang ada di UI secara default atau tidak",
"conn": "Koneksi",
Expand Down Expand Up @@ -125,8 +127,6 @@
"keepStatusWhenErr": "Menyimpan status server terakhir",
"keepStatusWhenErrTip": "Hanya ketika terjadi kesalahan saat menjalankan skrip",
"keyAuth": "Auth kunci",
"keyboardCompatibility": "Mungkin untuk meningkatkan kompatibilitas metode input",
"keyboardType": "Tipe Keyborad",
"language": "Bahasa",
"languageName": "Indonesia",
"lastTry": "Percobaan terakhir",
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"clipboard": "クリップボード",
"close": "閉じる",
"cmd": "コマンド",
"cnKeyboardComp": "中国のAndroidとの互換性",
"cnKeyboardCompTip": "ターミナルがセキュアキーボードを表示した場合、それを有効にできます。",
"collapseUI": "UIを折りたたむ",
"collapseUITip": "UIの長いリストをデフォルトで折りたたむかどうか",
"conn": "接続",
Expand Down Expand Up @@ -125,8 +127,6 @@
"keepStatusWhenErr": "エラー時に前回のサーバーステータスを保持",
"keepStatusWhenErrTip": "スクリプトの実行エラーに限ります",
"keyAuth": "キー認証",
"keyboardCompatibility": "入力法の互換性を向上させる可能性があります",
"keyboardType": "キーボードタイプ",
"language": "言語",
"languageName": "日本語",
"lastTry": "最後の試み",
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"clipboard": "Área de transferência",
"close": "Fechar",
"cmd": "Comando",
"cnKeyboardComp": "Compatibilidade com Android chinês",
"cnKeyboardCompTip": "Se o terminal abrir um teclado seguro, você pode ativá-lo.",
"collapseUI": "Colapsar",
"collapseUITip": "Deve colapsar listas longas na UI por padrão?",
"conn": "Conectar",
Expand Down Expand Up @@ -125,8 +127,6 @@
"keepStatusWhenErr": "Manter o status anterior do servidor",
"keepStatusWhenErrTip": "Limitado a erros de execução de scripts",
"keyAuth": "Autenticação por chave",
"keyboardCompatibility": "Pode melhorar a compatibilidade do teclado",
"keyboardType": "Tipo de teclado",
"language": "Idioma",
"languageName": "Português",
"lastTry": "Última tentativa",
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"clipboard": "буфер обмена",
"close": "закрыть",
"cmd": "команда",
"cnKeyboardComp": "Совместимость с китайским Android",
"cnKeyboardCompTip": "Если терминал отображает безопасную клавиатуру, вы можете ее активировать.",
"collapseUI": "свернуть",
"collapseUITip": "Свернуть длинные списки в UI по умолчанию",
"conn": "подключение",
Expand Down Expand Up @@ -125,8 +127,6 @@
"keepStatusWhenErr": "Сохранять статус сервера при ошибке",
"keepStatusWhenErrTip": "Применимо только в случае ошибки выполнения скрипта",
"keyAuth": "аутентификация по ключу",
"keyboardCompatibility": "может улучшить совместимость с клавиатурой",
"keyboardType": "тип клавиатуры",
"language": "язык",
"languageName": "Русский",
"lastTry": "последняя попытка",
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"clipboard": "剪切板",
"close": "关闭",
"cmd": "命令",
"cnKeyboardComp": "中国Android兼容性",
"cnKeyboardCompTip": "如果终端弹出安全键盘,可以开启",
"collapseUI": "折叠",
"collapseUITip": "是否默认折叠UI中存在的长列表",
"conn": "连接",
Expand Down Expand Up @@ -125,8 +127,6 @@
"keepStatusWhenErr": "保留上次的服务器状态",
"keepStatusWhenErrTip": "仅限于执行脚本出错",
"keyAuth": "密钥认证",
"keyboardCompatibility": "可能会改善输入法兼容性",
"keyboardType": "键盘类型",
"language": "语言",
"languageName": "简体中文",
"lastTry": "最后尝试",
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_zh_tw.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"clipboard": "剪切板",
"close": "關閉",
"cmd": "命令",
"cnKeyboardComp": "中國Android兼容性",
"cnKeyboardCompTip": "如果終端彈出安全鍵盤,您可以啟用它。",
"collapseUI": "折疊",
"collapseUITip": "是否預設折疊UI中存在的長列表",
"conn": "連接",
Expand Down Expand Up @@ -125,8 +127,6 @@
"keepStatusWhenErr": "保留上次的伺服器狀態",
"keepStatusWhenErrTip": "仅在执行脚本时出错时",
"keyAuth": "密鑰認證",
"keyboardCompatibility": "可能會改善輸入法兼容性",
"keyboardType": "鍵盤類型",
"language": "語言",
"languageName": "繁體中文",
"lastTry": "最後嘗試",
Expand Down
69 changes: 5 additions & 64 deletions lib/view/page/setting/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:toolbox/core/extension/colorx.dart';
import 'package:toolbox/core/extension/context/common.dart';
import 'package:toolbox/core/extension/context/locale.dart';
import 'package:toolbox/core/extension/context/snackbar.dart';
import 'package:toolbox/core/extension/enum.dart';
import 'package:toolbox/core/extension/locale.dart';
import 'package:toolbox/core/extension/context/dialog.dart';
import 'package:toolbox/core/extension/stringx.dart';
Expand All @@ -18,7 +17,6 @@ import 'package:toolbox/data/res/provider.dart';
import 'package:toolbox/data/res/rebuild.dart';
import 'package:toolbox/data/res/store.dart';
import 'package:toolbox/view/widget/expand_tile.dart';
import 'package:xterm/ui.dart';

import '../../../core/persistant_store.dart';
import '../../../core/route.dart';
Expand Down Expand Up @@ -173,10 +171,9 @@ class _SettingPageState extends State<SettingPage> {
_buildTermTheme(),
_buildFont(),
_buildTermFontSize(),
_buildTermCursor(),
_buildSSHVirtualKeyAutoOff(),
// Use hardware keyboard on desktop, so there is no need to set it
if (isMobile) _buildKeyboardType(),
if (isAndroid) _buildCNKeyboardComp(),
if (isMobile) _buildSSHVirtKeys(),
].map((e) => CardX(child: e)).toList(),
);
Expand Down Expand Up @@ -656,43 +653,11 @@ class _SettingPageState extends State<SettingPage> {
// );
// }

Widget _buildKeyboardType() {
const List<String> names = <String>[
'text',
'multiline',
'number',
'phone',
'datetime',
'emailAddress',
'url',
'visiblePassword',
'name',
'address',
'none',
];
Widget _buildCNKeyboardComp() {
return ListTile(
title: Text(l10n.keyboardType),
subtitle: Text(l10n.keyboardCompatibility, style: UIs.textGrey),
trailing: ValueListenableBuilder(
valueListenable: _setting.keyboardType.listenable(),
builder: (_, val, __) => Text(
names[val],
style: UIs.text15,
),
),
onTap: () async {
if (names.length != TextInputType.values.length) {
// This notify me to update the code
context.showSnackBar('names.length != TextInputType.values.length');
}
final selected = await context.showPickSingleDialog(
items: names,
initial: names.fromIndex(_setting.keyboardType.fetch()),
);
if (selected != null) {
_setting.keyboardType.put(names.indexOf(selected));
}
},
title: Text(l10n.cnKeyboardComp),
subtitle: Text(l10n.cnKeyboardCompTip, style: UIs.textGrey),
trailing: StoreSwitch(prop: _setting.cnKeyboardComp),
);
}

Expand Down Expand Up @@ -1060,30 +1025,6 @@ class _SettingPageState extends State<SettingPage> {
);
}

Widget _buildTermCursor() {
return ListTile(
title: Text(l10n.cursorType),
trailing: ValueListenableBuilder(
valueListenable: _setting.termCursor.listenable(),
builder: (_, val, __) => Text(
TerminalCursorType.values.fromIndex(val).name,
style: UIs.text15,
),
),
onTap: () async {
final selected = await context.showPickSingleDialog(
items: TerminalCursorType.values,
name: (p0) => p0.name,
initial:
TerminalCursorType.values.fromIndex(_setting.termCursor.fetch()),
);
if (selected != null) {
_setting.termCursor.put(selected.index);
}
},
);
}

Widget _buildRememberPwdInMem() {
return ListTile(
title: Text(l10n.rememberPwdInMem),
Expand Down
18 changes: 3 additions & 15 deletions lib/view/page/ssh/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
late MediaQueryData _media;
late TerminalStyle _terminalStyle;
late TerminalTheme _terminalTheme;
late TextInputType _keyboardType;
double _virtKeyWidth = 0;
double _virtKeysHeight = 0;
late final TerminalCursorType _termCursor;

bool _isDark = false;
Timer? _virtKeyLongPressTimer;
Expand Down Expand Up @@ -138,13 +136,13 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
child: TerminalView(
_terminal,
controller: _terminalController,
keyboardType: _keyboardType,
keyboardType: TextInputType.emailAddress,
enableSuggestions: Stores.setting.cnKeyboardComp.fetch(),
textStyle: _terminalStyle,
theme: _terminalTheme,
deleteDetection: false,
deleteDetection: isMobile,
autofocus: true,
keyboardAppearance: _isDark ? Brightness.dark : Brightness.light,
cursorType: _termCursor,
showToolbar: isMobile,
viewOffset: Offset(
2 * _horizonPadding,
Expand Down Expand Up @@ -484,16 +482,6 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
);

_terminalStyle = TerminalStyle.fromTextStyle(textStyle);
_keyboardType = TextInputType.values[Stores.setting.keyboardType.fetch()];

final termCursor = Stores.setting.termCursor.fetch();
_termCursor = () {
try {
return TerminalCursorType.values[termCursor];
} catch (_) {
return TerminalCursorType.block;
}
}();
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ packages:
description:
path: "."
ref: master
resolved-ref: b81b303040729b866f844dd46b25c9f6be582962
resolved-ref: ee64dc1541a18f513856de0f554d8227fdbf29da
url: "https://github.com/lollipopkit/xterm.dart"
source: git
version: "4.0.0"
Expand Down

0 comments on commit 3747e2f

Please sign in to comment.