From 35328448797bf48ebc9f411f1ffd7afcf4f4b774 Mon Sep 17 00:00:00 2001 From: GT610 <79314033+GT-610@users.noreply.github.com> Date: Sat, 28 Mar 2026 11:23:39 +0800 Subject: [PATCH] fix(ssh): Fixed the logic for handling font paths (#1093) * fix(ssh): Fixed the logic for handling font paths Correctly handles font filenames to avoid duplicate file extensions. Also optimized the logic for copying font files to ensure path accuracy. Add an issue participant * fix (Settings): Fixed the font clearing feature and added cache cleanup On the SSH settings page, we fixed an issue where the font clearing feature failed to clear the cache and added logic to clear cached font files. Additionally, we changed the clearing operation to run asynchronously to ensure the page closes only after the operation is complete. * fix: Check if the component has been mounted before popping the context Avoid calling `context.pop()` when the component is unmounted, which causes an exception --- .gitmodules | 2 +- lib/data/res/github_id.dart | 2 ++ lib/view/page/setting/entries/ssh.dart | 28 +++++++++++++++++++------- packages/fl_lib | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.gitmodules b/.gitmodules index 4cbe8e47..56e043b0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,7 +9,7 @@ [submodule "fl_lib"] path = packages/fl_lib url = https://github.com/lollipopkit/fl_lib - branch = before-sqlite + branch = main [submodule "fl_build"] path = packages/fl_build url = https://github.com/lppcg/fl_build.git diff --git a/lib/data/res/github_id.dart b/lib/data/res/github_id.dart index 5c15ff10..f1fb3ae9 100644 --- a/lib/data/res/github_id.dart +++ b/lib/data/res/github_id.dart @@ -155,6 +155,8 @@ abstract final class GithubIds { 'nickgirga', 'xxnuo', 'sunnysu0608', + 'Staten-Wang', + 'alterkeyy' }; } diff --git a/lib/view/page/setting/entries/ssh.dart b/lib/view/page/setting/entries/ssh.dart index 38eeffa5..37ed0be9 100644 --- a/lib/view/page/setting/entries/ssh.dart +++ b/lib/view/page/setting/entries/ssh.dart @@ -283,7 +283,7 @@ extension _SSH on _AppSettingsPageState { leading: const Icon(MingCute.font_fill), title: Text(libL10n.font), trailing: _setting.fontPath.listenable().listenVal((val) { - final fontName = val.getFileName(); + final fontName = val.getFileName(withoutExtension: true); return Text(fontName ?? libL10n.empty, style: UIs.text15); }), onTap: () { @@ -292,9 +292,10 @@ extension _SSH on _AppSettingsPageState { actions: [ TextButton(onPressed: () async => await _pickFontFile(), child: Text(libL10n.file)), TextButton( - onPressed: () { + onPressed: () async { + await _clearCachedFont(); _setting.fontPath.delete(); - context.pop(); + if (mounted) context.pop(); RNodes.app.notify(); }, child: Text(libL10n.clear), @@ -305,6 +306,15 @@ extension _SSH on _AppSettingsPageState { ); } + Future _clearCachedFont() async { + final oldFontPath = _setting.fontPath.fetch(); + if (oldFontPath.isEmpty || !oldFontPath.startsWith(Paths.font)) return; + final oldFile = File(oldFontPath); + if (await oldFile.exists()) { + await oldFile.delete(); + } + } + Future _pickFontFile() async { final path = await Pfs.pickFilePath(); if (path == null) return; @@ -314,13 +324,17 @@ extension _SSH on _AppSettingsPageState { _setting.fontPath.put(path); await FontUtils.loadFrom(path); } else { + await _clearCachedFont(); + final fontFile = File(path); - await fontFile.copy(Paths.font); - _setting.fontPath.put(Paths.font); - await FontUtils.loadFrom(Paths.font); + final fontName = path.getFileName(); + final fontPath = Paths.font.joinPath(fontName ?? 'font.ttf'); + await fontFile.copy(fontPath); + _setting.fontPath.put(fontPath); + await FontUtils.loadFrom(fontPath); } - context.pop(); + if (mounted) context.pop(); RNodes.app.notify(); } diff --git a/packages/fl_lib b/packages/fl_lib index c54bdbb3..e757cd36 160000 --- a/packages/fl_lib +++ b/packages/fl_lib @@ -1 +1 @@ -Subproject commit c54bdbb351cd3243a1eb2285b40f7a0165f32bc9 +Subproject commit e757cd36c3ed5847322c834a36ffd3d26788c6db