Skip to content

Commit

Permalink
feat: disable letter cache (#446)
Browse files Browse the repository at this point in the history
Fixes #445
  • Loading branch information
lollipopkit authored Jul 3, 2024
1 parent 4430045 commit 6e428c9
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 68 deletions.
41 changes: 13 additions & 28 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,21 @@ class MyApp extends StatelessWidget {
themeMode: themeMode,
theme: light,
darkTheme: tMode < 3 ? dark : dark.toAmoled,
home: _buildAppContent(ctx),
);
}

Widget _buildAppContent(BuildContext ctx) {
//if (Pros.app.isWearOS) return const WearHome();
return const _AppContent(
intro: _IntroPage(),
child: HomePage(),
);
}
}
home: Builder(
builder: (context) {
context.setLibL10n();
final appL10n = AppLocalizations.of(context);
if (appL10n != null) l10n = appL10n;

/// It's used for init settings related to [BuildContext]
final class _AppContent extends StatelessWidget {
final Widget child;
final Widget intro;
final intros = _IntroPage.builders;
if (intros.isNotEmpty) {
return _IntroPage(intros);
}

const _AppContent({required this.child, required this.intro});

@override
Widget build(BuildContext context) {
context.setLibL10n();
final appL10n = AppLocalizations.of(context);
if (appL10n != null) l10n = appL10n;

final showIntro = Stores.setting.showIntro.fetch();
if (showIntro) return intro;

return child;
return const HomePage();
},
),
);
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/data/store/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ class SettingStore extends PersistentStore {
/// Format: {width}x{height}
late final windowSize = property('windowSize', '');

late final showIntro = property('showIntro', true);
late final introVer = property('introVer', 0);

late final letterCache = property('letterCache', false);

// Never show these settings for users
//
Expand Down
66 changes: 43 additions & 23 deletions lib/intro.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
part of 'app.dart';

final class _IntroPage extends StatelessWidget {
const _IntroPage();
final List<IntroPageBuilder> pages;

static final _setting = Stores.setting;
static const _kIconSize = 23.0;
static const _introListPad = EdgeInsets.symmetric(horizontal: 17);
const _IntroPage(this.pages);

static const _builders = {
1: _buildAppSettings,
2: _buildRecommended,
1006: _buildTermLetterCache,
};

@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, cons) {
final padTop = cons.maxHeight * .2;
final padTop = cons.maxHeight * .16;
final pages_ = pages.map((e) => e(context, padTop)).toList();
return IntroPage(
pages: [
_buildAppSettings(context, padTop),
_buildRecommended(context, padTop),
],
pages: pages_,
onDone: (ctx) {
Stores.setting.showIntro.put(false);
Stores.setting.introVer.put(BuildData.build);
Navigator.of(ctx).pushReplacement(
MaterialPageRoute(builder: (_) => const HomePage()),
);
Expand All @@ -28,12 +30,29 @@ final class _IntroPage extends StatelessWidget {
);
}

Widget _buildRecommended(BuildContext context, double padTop) {
static Widget _buildTermLetterCache(BuildContext context, double padTop) {
return ListView(
padding: _introListPad,
children: [
SizedBox(height: padTop),
IntroPage.title(icon: BoxIcons.bxs_terminal, big: true),
SizedBox(height: padTop),
ListTile(
leading: const Icon(Bootstrap.input_cursor),
title: Text(l10n.letterCache),
subtitle: Text(l10n.letterCacheTip, style: UIs.textGrey),
trailing: StoreSwitch(prop: _setting.letterCache),
).cardx,
],
);
}

static Widget _buildRecommended(BuildContext context, double padTop) {
return ListView(
padding: _introListPad,
children: [
SizedBox(height: padTop),
const Icon(Bootstrap.stars, size: 35),
IntroPage.title(icon: Bootstrap.stars, big: true),
SizedBox(height: padTop),
ListTile(
leading: const Icon(MingCute.delete_2_fill),
Expand All @@ -57,12 +76,12 @@ final class _IntroPage extends StatelessWidget {
);
}

Widget _buildAppSettings(BuildContext ctx, double padTop) {
static Widget _buildAppSettings(BuildContext ctx, double padTop) {
return ListView(
padding: _introListPad,
children: [
SizedBox(height: padTop),
_buildTitle(l10n.init, big: true),
IntroPage.title(text: l10n.init, big: true),
SizedBox(height: padTop),
ListTile(
leading: const Icon(IonIcons.language),
Expand Down Expand Up @@ -94,14 +113,15 @@ final class _IntroPage extends StatelessWidget {
);
}

Widget _buildTitle(String text, {bool big = false}) {
return Center(
child: Text(
text,
style: big
? const TextStyle(fontSize: 41, fontWeight: FontWeight.w500)
: UIs.textGrey,
),
);
static List<IntroPageBuilder> get builders {
final storedVer = _setting.introVer.fetch();
return _builders.entries
.where((e) => e.key > storedVer)
.map((e) => e.value)
.toList();
}

static final _setting = Stores.setting;
static const _kIconSize = 23.0;
static const _introListPad = EdgeInsets.symmetric(horizontal: 17);
}
3 changes: 2 additions & 1 deletion lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "Decode",
"decompress": "Dekomprimieren",
"delete": "Löschen",
"deleteScripts": "Gleichzeitiges Löschen von Server-Skripten",
"deleteServers": "Batch-Löschung von Servern",
"deviceName": "Gerätename",
"dirEmpty": "Stelle sicher, dass der Ordner leer ist.",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "Deutsch",
"lastTry": "Letzter Versuch",
"launchPage": "Startseite",
"letterCache": "Buchstaben-Caching",
"letterCacheTip": "Empfohlen zu aktivieren, aber die Aktivierung verhindert die Eingabe von CJK (Chinesisch, Japanisch, Koreanisch) Zeichen",
"license": "Lizenzen",
"light": "Hell",
"loadingFiles": "Lädt Dateien...",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "Decode",
"decompress": "Decompress",
"delete": "Delete",
"deleteScripts": "Delete server scripts at the same time",
"deleteServers": "Batch delete servers",
"deviceName": "Device name",
"dirEmpty": "Make sure the folder is empty.",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "English",
"lastTry": "Last try",
"launchPage": "Launch page",
"letterCache": "Letter caching",
"letterCacheTip": "Recommended to enable, but enabling it prevents the input of CJK (Chinese, Japanese, Korean) characters",
"license": "License",
"light": "Light",
"loadingFiles": "Loading files...",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "Decodificar",
"decompress": "Descomprimir",
"delete": "Eliminar",
"deleteScripts": "Eliminar scripts del servidor simultáneamente",
"deleteServers": "Eliminar servidores en lote",
"deviceName": "Nombre del dispositivo",
"dirEmpty": "Asegúrate de que el directorio esté vacío",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "Español",
"lastTry": "Último intento",
"launchPage": "Página de lanzamiento",
"letterCache": "Caché de letras",
"letterCacheTip": "Se recomienda activar, pero al activarlo se impide la introducción de caracteres CJK (chino, japonés, coreano)",
"license": "Licencia de código abierto",
"light": "Claro",
"loadingFiles": "Cargando directorio...",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "Décoder",
"decompress": "Décompresser",
"delete": "Supprimer",
"deleteScripts": "Supprimer les scripts du serveur en même temps",
"deleteServers": "Supprimer des serveurs en lot",
"deviceName": "Nom de l'appareil",
"dirEmpty": "Assurez-vous que le répertoire est vide.",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "Français",
"lastTry": "Dernière tentative",
"launchPage": "Page de lancement",
"letterCache": "Mise en cache des lettres",
"letterCacheTip": "Recommandé à activer, mais son activation empêche la saisie de caractères CJK (chinois, japonais, coréen)",
"license": "Licence",
"light": "Clair",
"loadingFiles": "Chargement des fichiers...",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "Membaca sandi",
"decompress": "Dekompresi",
"delete": "Menghapus",
"deleteScripts": "Menghapus skrip server secara bersamaan",
"deleteServers": "Penghapusan server secara batch",
"deviceName": "Nama perangkat",
"dirEmpty": "Pastikan dir kosong.",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "Indonesia",
"lastTry": "Percobaan terakhir",
"launchPage": "Halaman peluncuran",
"letterCache": "Caching huruf",
"letterCacheTip": "Disarankan untuk diaktifkan, tetapi mengaktifkannya mencegah input karakter CJK (Cina, Jepang, Korea)",
"license": "Lisensi",
"light": "Terang",
"loadingFiles": "Memuat file ...",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "デコード",
"decompress": "解凍",
"delete": "削除",
"deleteScripts": "サーバースクリプトも削除",
"deleteServers": "サーバーを一括削除",
"deviceName": "デバイス名",
"dirEmpty": "フォルダーが空であることを確認してください",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "日本語",
"lastTry": "最後の試み",
"launchPage": "起動ページ",
"letterCache": "文字キャッシング",
"letterCacheTip": "有効化を推奨しますが、有効にするとCJK(中国語、日本語、韓国語)の文字の入力ができなくなります",
"license": "オープンソースライセンス",
"light": "ライト",
"loadingFiles": "ディレクトリを読み込んでいます...",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_nl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "Decoderen",
"decompress": "Decomprimeren",
"delete": "Verwijderen",
"deleteScripts": "Verwijder tegelijkertijd serverscripts",
"deleteServers": "Servers batchgewijs verwijderen",
"deviceName": "Apparaatnaam",
"dirEmpty": "Zorg ervoor dat de map leeg is.",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "Nederlands",
"lastTry": "Laatste poging",
"launchPage": "Startpagina",
"letterCache": "Lettercaching",
"letterCacheTip": "Aanbevolen om in te schakelen, maar bij inschakeling wordt de invoer van CJK (Chinees, Japans, Koreaans) tekens voorkomen",
"license": "Licentie",
"light": "Licht",
"loadingFiles": "Bestanden laden...",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "Decodificar",
"decompress": "Descomprimir",
"delete": "Excluir",
"deleteScripts": "Excluir scripts do servidor simultaneamente",
"deleteServers": "Excluir servidores em lote",
"deviceName": "Nome do dispositivo",
"dirEmpty": "Certifique-se de que a pasta está vazia",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "Português",
"lastTry": "Última tentativa",
"launchPage": "Página de lançamento",
"letterCache": "Cache de letras",
"letterCacheTip": "Recomendado para ativar, mas a ativação impede a entrada de caracteres CJK (chinês, japonês, coreano)",
"license": "Licença de código aberto",
"light": "Claro",
"loadingFiles": "Carregando diretórios...",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "декодировать",
"decompress": "разархивировать",
"delete": "удалить",
"deleteScripts": "удалить скрипты с сервера",
"deleteServers": "удалить серверы пакетно",
"deviceName": "Название устройства",
"dirEmpty": "Пожалуйста, убедитесь, что папка пуста",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "Русский",
"lastTry": "последняя попытка",
"launchPage": "стартовая страница",
"letterCache": "Кэширование букв",
"letterCacheTip": "Рекомендуется включить, но его активация препятствует вводу символов CJK (китайский, японский, корейский)",
"license": "лицензия",
"light": "светлая",
"loadingFiles": "Загрузка файлов...",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "解码",
"decompress": "解压缩",
"delete": "删除",
"deleteScripts": "同时删除服务器脚本",
"deleteServers": "批量删除服务器",
"deviceName": "设备名",
"dirEmpty": "请确保文件夹为空",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "简体中文",
"lastTry": "最后尝试",
"launchPage": "启动页",
"letterCache": "输入法字符缓存",
"letterCacheTip": "推荐开启,但是开启后无法输入 CJK 等文字",
"license": "开源许可证",
"light": "亮",
"loadingFiles": "正在加载目录。。。",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_zh_tw.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"decode": "解碼",
"decompress": "解壓縮",
"delete": "刪除",
"deleteScripts": "同時刪除伺服器腳本",
"deleteServers": "批量刪除伺服器",
"deviceName": "設備名",
"dirEmpty": "請確保資料夾為空",
Expand Down Expand Up @@ -154,6 +153,8 @@
"languageName": "繁體中文",
"lastTry": "最後嘗試",
"launchPage": "啓動頁",
"letterCache": "输入法字符緩存",
"letterCacheTip": "推薦開啟,但是開啟後無法輸入CJK(中文、日文、韓文)等文字",
"license": "開源許可證",
"light": "亮",
"loadingFiles": "正在加載目錄...",
Expand Down
13 changes: 13 additions & 0 deletions lib/view/page/setting/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildSSH() {
return Column(
children: [
_buildLetterCache(),
_buildSSHWakeLock(),
_buildTermTheme(),
_buildFont(),
Expand Down Expand Up @@ -1178,4 +1179,16 @@ class _SettingPageState extends State<SettingPage> {
trailing: StoreSwitch(prop: _setting.betaTest),
);
}

Widget _buildLetterCache() {
return ListTile(
leading: const Icon(Bootstrap.input_cursor),
title: Text(l10n.letterCache),
subtitle: Text(
'${l10n.letterCacheTip}\n${l10n.needRestart}',
style: UIs.textGrey,
),
trailing: StoreSwitch(prop: _setting.letterCache),
);
}
}
Loading

0 comments on commit 6e428c9

Please sign in to comment.