Skip to content

Commit

Permalink
[Fix] unused custom cache root
Browse files Browse the repository at this point in the history
  • Loading branch information
canxin121 committed Nov 10, 2024
1 parent 1790a01 commit b91346d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
33 changes: 23 additions & 10 deletions lib/common_pages/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,13 @@ class StorageConfigPage extends StatefulWidget {

class StorageConfigPageState extends State<StorageConfigPage>
with WidgetsBindingObserver {
String StoragePath = "";

@override
void initState() {
super.initState();
StoragePath =
globalConfig.getStorageFolder(documentFolder: globalDocumentPath);
WidgetsBinding.instance.addObserver(this);
}

Expand Down Expand Up @@ -480,20 +484,23 @@ class StorageConfigPageState extends State<StorageConfigPage>

await moveCacheData(
documentPath: globalDocumentPath,
newCustomCacheRoot: newCustomCacheRoot);
newCustomCacheRoot: newCustomCacheRoot,
oldCustomCacheRoot: globalConfig.storageConfig.customCacheRoot);
} else {
if (mounted) {
await showWaitDialog(context, isDesktop, "正在清理旧数据中,稍后将自动退出应用以应用更改");
}
await delOldCacheData(documentPath: globalDocumentPath);
await delOldCacheData(
documentPath: globalDocumentPath,
oldCustomCacheRoot: globalConfig.storageConfig.customCacheRoot);
}

globalConfig.storageConfig.customCacheRoot = newCustomCacheRoot;
await globalConfig.save(documentFolder: globalDocumentPath);

if (mounted) {
context.findAncestorStateOfType<SettingPageState>()?.refresh();
}
setState(() {
StoragePath =
globalConfig.getStorageFolder(documentFolder: globalDocumentPath);
});
} finally {
if (mounted) {
popPage(context, isDesktop);
Expand Down Expand Up @@ -557,8 +564,7 @@ class StorageConfigPageState extends State<StorageConfigPage>
alignment: Alignment.centerRight,
height: 50,
child: Text(
globalConfig.getStorageFolder(
documentFolder: globalDocumentPath),
StoragePath,
style: TextStyle(color: textColor)
.useSystemChineseFont(),
))),
Expand Down Expand Up @@ -914,7 +920,9 @@ class StorageConfigPageState extends State<StorageConfigPage>
if (confirm == null || !confirm) return;
try {
await delOldCacheData(
documentPath: globalDocumentPath);
documentPath: globalDocumentPath,
oldCustomCacheRoot: globalConfig
.storageConfig.customCacheRoot);
LogToast.success("清理空间", "清理缓存成功",
"[storageConfig.clearCache] success");
} catch (e) {
Expand Down Expand Up @@ -1093,6 +1101,8 @@ class ExternalApiConfigPageState extends State<ExternalApiConfigPage>
var externalApi =
await ExternalApiConfig.fromPath(
path: filePath,
customCacheRoot: globalConfig
.storageConfig.customCacheRoot,
documentFolder: globalDocumentPath);

globalConfig.externalApi = externalApi;
Expand Down Expand Up @@ -1137,7 +1147,10 @@ class ExternalApiConfigPageState extends State<ExternalApiConfigPage>
var externalApi =
await ExternalApiConfig.fromUrl(
url: link,
documentFolder: globalDocumentPath);
documentFolder: globalDocumentPath,
customCacheRoot: globalConfig
.storageConfig.customCacheRoot);

globalConfig.externalApi = externalApi;
await globalConfig.save(
documentFolder: globalDocumentPath);
Expand Down
1 change: 1 addition & 0 deletions lib/desktop/comps/music_agg_comp/music_agg_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ class OptionsCellState extends State<OptionsCell> {
hasCacheMusic(
name: widget.musicAgg.name,
artists: widget.musicAgg.artist,
customCacheRoot: globalConfig.storageConfig.customCacheRoot,
documentFolder: globalDocumentPath)
.then((value) {
if (mounted) {
Expand Down
1 change: 1 addition & 0 deletions lib/mobile/comps/music_agg_comp/music_agg_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class MobileMusicAggregatorListItemState
bool cacheStatus = await hasCacheMusic(
name: widget.musicAgg.name,
artists: widget.musicAgg.artist,
customCacheRoot: globalConfig.storageConfig.customCacheRoot,
documentFolder: globalDocumentPath);
if (mounted) {
setState(() {
Expand Down
1 change: 1 addition & 0 deletions lib/pulldown_menus/music_aggregator_pulldown_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Future<void> showMusicAggregatorMenu(
hasCache = await hasCacheMusic(
name: musicAgg.name,
artists: musicAgg.artist,
customCacheRoot: globalConfig.storageConfig.customCacheRoot,
documentFolder: globalDocumentPath);
if (!context.mounted) return;
menuItems = _musicAggregetorPullDownItems(
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/cache_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ ExtendedImage imageWithCache(
}

String? uri =
_getFileCacheWithUriWrapper(url, picCacheFolder, cacheNow: enableCache);
_getFileCacheWithUriWrapper(url, picCacheFolder, cacheNow: enableCache,);

if (uri.startsWith("http")) {
return ExtendedImage.network(
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/music_api_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ Future<void> delMusicCache(
}) async {
if (!await rust_api_music_cache.hasCacheMusic(
documentFolder: globalDocumentPath,
customCacheRoot: globalConfig.storageConfig.customCacheRoot,
name: musicAggregator.name,
artists: musicAggregator.artist)) {
return;
Expand Down Expand Up @@ -247,6 +248,7 @@ Future<void> cacheMusicContainer(MusicContainer musicContainer,
{bool hasCache = false}) async {
if (await rust_api_music_cache.hasCacheMusic(
documentFolder: globalDocumentPath,
customCacheRoot: globalConfig.storageConfig.customCacheRoot,
name: musicContainer.musicAggregator.name,
artists: musicContainer.musicAggregator.artist)) {
return;
Expand All @@ -264,7 +266,8 @@ Future<void> cacheMusicContainer(MusicContainer musicContainer,
artists: musicContainer.musicAggregator.artist,
playinfo: musicContainer.playinfo!,
lyric: musicContainer.lyric,
documentFolder: globalDocumentPath);
documentFolder: globalDocumentPath,
customCacheRoot: globalConfig.storageConfig.customCacheRoot);

musicAggregatorCacheController
.add((true, musicContainer.musicAggregator.identity()));
Expand Down

0 comments on commit b91346d

Please sign in to comment.