diff --git a/assets/translation.json b/assets/translation.json index a3bae80..74402e2 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -129,7 +129,10 @@ "Move favorite after reading": "阅读后移动收藏", "Are you sure you want to delete this folder?" : "确定要删除这个收藏夹吗?", "Import from file": "从文件导入", - "Failed to import": "导入失败" + "Failed to import": "导入失败", + "Cache Limit": "缓存限制", + "Set Cache Limit": "设置缓存限制", + "Size in MB": "大小(MB)" }, "zh_TW": { "Home": "首頁", @@ -261,6 +264,9 @@ "Move favorite after reading": "閱讀後移動收藏", "Are you sure you want to delete this folder?" : "確定要刪除這個收藏夾嗎?", "Import from file": "從文件匯入", - "Failed to import": "匯入失敗" + "Failed to import": "匯入失敗", + "Cache Limit": "緩存限制", + "Set Cache Limit": "設置緩存限制", + "Size in MB": "大小(MB)" } } \ No newline at end of file diff --git a/lib/foundation/appdata.dart b/lib/foundation/appdata.dart index e8f75f0..7a083c9 100644 --- a/lib/foundation/appdata.dart +++ b/lib/foundation/appdata.dart @@ -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) { diff --git a/lib/init.dart b/lib/init.dart index 6d63e3a..a4262d1 100644 --- a/lib/init.dart +++ b/lib/init.dart @@ -22,5 +22,5 @@ Future init() async { await ComicSource.init(); await LocalManager().init(); await TagsTranslation.readData(); - CacheManager(); + CacheManager().setLimitSize(appdata.settings['cacheSize']); } \ No newline at end of file diff --git a/lib/pages/settings/app.dart b/lib/pages/settings/app.dart index 5752687..571b869 100644 --- a/lib/pages/settings/app.dart +++ b/lib/pages/settings/app.dart @@ -25,8 +25,8 @@ class _AppSettingsState extends State { 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 { 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,