limit cache size

This commit is contained in:
nyne
2024-10-28 16:43:19 +08:00
parent 26ddfd6134
commit 66f96a580c
4 changed files with 33 additions and 5 deletions

View File

@@ -108,6 +108,7 @@ class _Settings {
'enableTapToTurnPages': true,
'enablePageAnimation': true,
'language': 'system', // system, zh-CN, zh-TW, en-US
'cacheSize': 2048, // in MB
};
operator [](String key) {

View File

@@ -22,5 +22,5 @@ Future<void> init() async {
await ComicSource.init();
await LocalManager().init();
await TagsTranslation.readData();
CacheManager();
CacheManager().setLimitSize(appdata.settings['cacheSize']);
}

View File

@@ -25,8 +25,8 @@ class _AppSettingsState extends State<AppSettings> {
title: "Set New Storage Path".tl,
actionTitle: "Set".tl,
callback: () async {
if(App.isIOS) {
context.showMessage(message: "Not supported on iOS".tl);
if (App.isMobile) {
context.showMessage(message: "Not supported".tl);
return;
}
var result = await selectDirectory();
@@ -65,6 +65,27 @@ class _AppSettingsState extends State<AppSettings> {
setState(() {});
},
).toSliver(),
_CallbackSetting(
title: "Cache Limit".tl,
subtitle: "${appdata.settings['cacheSize']} MB",
callback: () {
showInputDialog(
context: context,
title: "Set Cache Limit".tl,
hintText: "Size in MB".tl,
inputValidator: RegExp(r"^\d+$"),
onConfirm: (value) {
appdata.settings['cacheSize'] = int.parse(value);
appdata.saveData();
setState(() {});
CacheManager()
.setLimitSize(appdata.settings['cacheSize'] * 1024 * 1024);
return null;
},
);
},
actionTitle: 'Set'.tl,
).toSliver(),
_SettingPartTitle(
title: "Log".tl,
icon: Icons.error_outline,