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
This commit is contained in:
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -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
|
||||
|
||||
@@ -155,6 +155,8 @@ abstract final class GithubIds {
|
||||
'nickgirga',
|
||||
'xxnuo',
|
||||
'sunnysu0608',
|
||||
'Staten-Wang',
|
||||
'alterkeyy'
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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<void> _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<void> _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();
|
||||
}
|
||||
|
||||
|
||||
Submodule packages/fl_lib updated: c54bdbb351...e757cd36c3
Reference in New Issue
Block a user