From d95fcd8b002c7a4d50f6a1c5a37e06e6de3c0612 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Fri, 27 Feb 2026 00:50:52 +0800 Subject: [PATCH] add cache management page --- src/consts/cache.ts | 5 + src/core/cache.ts | 7 + src/lib/cache.ts | 156 +++++++++++++++++ src/lib/ui/common.ts | 35 ---- src/locales/de.json | 10 ++ src/locales/en.json | 10 ++ src/locales/es.json | 10 ++ src/locales/fr.json | 10 ++ src/locales/helpers.ts | 26 +++ src/locales/it.json | 10 ++ src/locales/ja.json | 10 ++ src/locales/kn.json | 10 ++ src/locales/ko.json | 10 ++ src/locales/nl.json | 10 ++ src/locales/pt_BR.json | 10 ++ src/locales/ru.json | 10 ++ src/locales/sl.json | 10 ++ src/locales/ta.json | 10 ++ src/locales/th.json | 10 ++ src/locales/tr.json | 10 ++ src/locales/uk.json | 10 ++ src/locales/vi.json | 10 ++ src/locales/zh_Hans.json | 10 ++ src/locales/zh_Hant.json | 10 ++ src/router/mobile.ts | 6 + src/stores/exchangeRates.ts | 15 ++ src/views/base/AboutPageBase.ts | 4 +- src/views/desktop/app/AppSettingsPage.vue | 15 +- .../tabs/AppBrowserCacheSettingTab.vue | 161 ++++++++++++++++++ src/views/mobile/SettingsPage.vue | 1 + .../settings/BrowserCacheSettingPage.vue | 103 +++++++++++ 31 files changed, 685 insertions(+), 39 deletions(-) create mode 100644 src/consts/cache.ts create mode 100644 src/core/cache.ts create mode 100644 src/lib/cache.ts create mode 100644 src/views/desktop/app/settings/tabs/AppBrowserCacheSettingTab.vue create mode 100644 src/views/mobile/settings/BrowserCacheSettingPage.vue diff --git a/src/consts/cache.ts b/src/consts/cache.ts new file mode 100644 index 00000000..93a22ed7 --- /dev/null +++ b/src/consts/cache.ts @@ -0,0 +1,5 @@ +export const SW_PRECACHE_CACHE_NAME_PREFIX: string = 'workbox-precache-v2-'; +export const SW_RUNTIME_CACHE_NAME_PREFIX: string = 'workbox-runtime-'; +export const SW_ASSETS_CACHE_NAME: string = 'ezbookkeeping-assets-cache'; +export const SW_CODE_CACHE_NAME: string = 'ezbookkeeping-code-cache'; +export const SW_MAP_CACHE_NAME: string = 'ezbookkeeping-map-cache'; diff --git a/src/core/cache.ts b/src/core/cache.ts new file mode 100644 index 00000000..b6300ad9 --- /dev/null +++ b/src/core/cache.ts @@ -0,0 +1,7 @@ +export interface BrowserCacheStatistics { + readonly totalCacheSize: number; + readonly codeCacheSize: number; + readonly assetsCacheSize: number; + readonly mapCacheSize: number; + readonly othersCacheSize: number; +} diff --git a/src/lib/cache.ts b/src/lib/cache.ts new file mode 100644 index 00000000..abd7bcd5 --- /dev/null +++ b/src/lib/cache.ts @@ -0,0 +1,156 @@ +import type { + BrowserCacheStatistics +} from '@/core/cache.ts'; + +import { + SW_PRECACHE_CACHE_NAME_PREFIX, + SW_RUNTIME_CACHE_NAME_PREFIX, + SW_ASSETS_CACHE_NAME, + SW_CODE_CACHE_NAME, + SW_MAP_CACHE_NAME +} from '@/consts/cache.ts'; + +import { isFunction, isObject, isNumber } from './common.ts'; +import logger from './logger.ts'; + +function findFirstCacheName(prefix: string): Promise { + if (!window.caches) { + logger.error('caches API is not supported in this browser'); + return Promise.reject(new Error('caches API is not supported')); + } + + return window.caches.keys().then(cacheNames => { + for (const cacheName of cacheNames) { + if (cacheName.startsWith(prefix)) { + return cacheName; + } + } + + throw new Error(`cache with prefix "${prefix}" not found`); + }); +} + +async function getCacheTotalSize(cacheName: string): Promise { + if (!window.caches) { + logger.error('caches API is not supported in this browser'); + return Promise.reject(new Error('caches API is not supported')); + } + + const cache = await window.caches.open(cacheName); + const requests = await cache.keys(); + let totalSize = 0; + + for (const request of requests) { + try { + const response = await cache.match(request); + + if (response && response.headers) { + const contentLength = response.headers.get('content-length'); + + if (contentLength) { + const size = parseInt(contentLength, 10); + + if (Number.isFinite(size)) { + totalSize += size; + } + } + } + } catch (ex) { + logger.warn(`failed to get size for request ${request.url} in cache ${cacheName}`, ex); + } + } + + return totalSize; +} + +export function loadBrowserCacheStatistics(): Promise { + return new Promise((resolve, reject) => { + const caches = window.caches; + + if (!caches) { + logger.error('caches API is not supported in this browser'); + reject(new Error('caches API is not supported in this browser')); + return; + } + + return Promise.all([ + navigator && navigator.storage && isFunction(navigator.storage.estimate) ? navigator.storage.estimate() : Promise.resolve(undefined), + findFirstCacheName(SW_PRECACHE_CACHE_NAME_PREFIX).then(cacheName => getCacheTotalSize(cacheName)).catch(() => 0), + findFirstCacheName(SW_RUNTIME_CACHE_NAME_PREFIX).then(cacheName => getCacheTotalSize(cacheName)).catch(() => 0), + getCacheTotalSize(SW_CODE_CACHE_NAME), + getCacheTotalSize(SW_ASSETS_CACHE_NAME), + getCacheTotalSize(SW_MAP_CACHE_NAME) + ]).then(([storageEstimate, precacheCacheSize, runtimeCacheSize, codeCacheSize, assetsCacheSize, mapCacheSize]) => { + let totalCacheSize: number = 0; + + if (storageEstimate) { + const cachesUsage = 'usageDetails' in storageEstimate + && isObject(storageEstimate.usageDetails) + && 'caches' in storageEstimate.usageDetails + ? storageEstimate.usageDetails.caches : undefined; + + if (isNumber(cachesUsage)) { + totalCacheSize = cachesUsage; + } else if (isNumber(storageEstimate.usage)) { + totalCacheSize = storageEstimate.usage; + } + } + + if (totalCacheSize < 1) { + totalCacheSize = precacheCacheSize + runtimeCacheSize + codeCacheSize + assetsCacheSize + mapCacheSize; + } + + let othersCacheSize: number = totalCacheSize - precacheCacheSize - runtimeCacheSize - codeCacheSize - assetsCacheSize - mapCacheSize; + + if (othersCacheSize < 0) { + othersCacheSize = 0; + } + + resolve({ + totalCacheSize: totalCacheSize, + codeCacheSize: codeCacheSize + runtimeCacheSize, + assetsCacheSize: assetsCacheSize + precacheCacheSize, + mapCacheSize: mapCacheSize, + othersCacheSize: othersCacheSize + }); + }).catch(error => { + logger.error("failed to clear cache", error); + reject(error); + }); + }); +} + +export function clearAllBrowserCaches(): Promise { + if (!window.caches) { + logger.error('caches API is not supported in this browser'); + return Promise.reject(); + } + + return new Promise((resolve, reject) => { + window.caches.keys().then(cacheNames => { + const promises = []; + + for (const cacheName of cacheNames) { + promises.push(window.caches.delete(cacheName).then(success => { + if (success) { + logger.info(`cache "${cacheName}" cleared successfully`); + return Promise.resolve(cacheName); + } else { + logger.warn(`failed to clear cache "${cacheName}"`); + return Promise.reject(cacheName); + } + })); + } + + Promise.all(promises).then(() => { + logger.info("all caches cleared successfully"); + resolve(); + }).catch(() => { + resolve(); + }); + }).catch(error => { + logger.warn("failed to clear cache", error); + reject(error); + }); + }); +} diff --git a/src/lib/ui/common.ts b/src/lib/ui/common.ts index 1bb775a9..c904e467 100644 --- a/src/lib/ui/common.ts +++ b/src/lib/ui/common.ts @@ -245,38 +245,3 @@ export function compressJpgImage(file: File, maxWidth: number, maxHeight: number reader.readAsDataURL(file); }); } - -export function clearBrowserCaches(): Promise { - if (!window.caches) { - logger.error('caches API is not supported in this browser'); - return Promise.reject(); - } - - return new Promise((resolve, reject) => { - window.caches.keys().then(cacheNames => { - const promises = []; - - for (const cacheName of cacheNames) { - promises.push(window.caches.delete(cacheName).then(success => { - if (success) { - logger.info(`cache "${cacheName}" cleared successfully`); - return Promise.resolve(cacheName); - } else { - logger.warn(`failed to clear cache "${cacheName}"`); - return Promise.reject(cacheName); - } - })); - } - - Promise.all(promises).then(() => { - logger.info("all caches cleared successfully"); - resolve(); - }).catch(() => { - resolve(); - }); - }).catch(error => { - logger.warn("failed to clear cache", error); - reject(error); - }); - }); -} diff --git a/src/locales/de.json b/src/locales/de.json index 84260753..85739d11 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Unable to retrieve user synchronized application settings", "Unable to update user synchronized application settings": "Unable to update user synchronized application settings", "Unable to disable user synchronized application settings": "Unable to disable user synchronized application settings", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Sind Sie sicher, dass Sie sich erneut anmelden möchten?", "Exchange Rates Data": "Wechselkursdaten", "User Custom": "User Custom", diff --git a/src/locales/en.json b/src/locales/en.json index 2b63dcbd..ed6c706b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Unable to retrieve user synchronized application settings", "Unable to update user synchronized application settings": "Unable to update user synchronized application settings", "Unable to disable user synchronized application settings": "Unable to disable user synchronized application settings", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Are you sure you want to re-login?", "Exchange Rates Data": "Exchange Rates Data", "User Custom": "User Custom", diff --git a/src/locales/es.json b/src/locales/es.json index 3d237cb9..2d4788e1 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Unable to retrieve user synchronized application settings", "Unable to update user synchronized application settings": "Unable to update user synchronized application settings", "Unable to disable user synchronized application settings": "Unable to disable user synchronized application settings", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "¿Seguro que deseas volver a iniciar sesión?", "Exchange Rates Data": "Tipos de Cambio", "User Custom": "User Custom", diff --git a/src/locales/fr.json b/src/locales/fr.json index 4a094a20..9153aee5 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Impossible de récupérer les paramètres d'application synchronisés de l'utilisateur", "Unable to update user synchronized application settings": "Impossible de mettre à jour les paramètres d'application synchronisés de l'utilisateur", "Unable to disable user synchronized application settings": "Impossible de désactiver les paramètres d'application synchronisés de l'utilisateur", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Êtes-vous sûr de vouloir vous reconnecter ?", "Exchange Rates Data": "Données de taux de change", "User Custom": "Personnalisé utilisateur", diff --git a/src/locales/helpers.ts b/src/locales/helpers.ts index a0291585..8f4d5079 100644 --- a/src/locales/helpers.ts +++ b/src/locales/helpers.ts @@ -2100,6 +2100,31 @@ export function useI18n() { return formatPercent(value, precision, lowPrecisionValue, numberFormatOptions); } + function getFormattedVolume(value: number, precision?: number, unit?: 'KiB' | 'MiB'): string { + const numberFormatOptions = getNumberFormatOptions({}); + let displayUnit = unit || 'B'; + + if (unit === 'KiB') { + value = value / 1024.0; + } else if (unit === 'MiB') { + value = value / 1024.0 / 1024.0; + } else { + displayUnit = 'B'; + + if (value >= 1024.0) { + value = value / 1024.0; + displayUnit = 'KiB'; + } + + if (value >= 1024.0) { + value = value / 1024.0; + displayUnit = 'MiB'; + } + } + + return formatNumber(value, numberFormatOptions, precision) + ' ' + displayUnit; + } + function getFormattedExchangeRateAmount(value: number, numeralSystem?: NumeralSystem): string { const numberFormatOptions = getNumberFormatOptions({ numeralSystem }); return formatExchangeRateAmount(value, numberFormatOptions); @@ -2505,6 +2530,7 @@ export function useI18n() { formatNumberToWesternArabicNumerals: (value: number, precision?: number) => getFormattedNumber(value, NumeralSystem.WesternArabicNumerals, precision), formatPercentToLocalizedNumerals: (value: number, precision: number, lowPrecisionValue: string) => getFormattedPercentValue(value, precision, lowPrecisionValue), formatPercentToWesternArabicNumerals: (value: number, precision: number, lowPrecisionValue: string) => getFormattedPercentValue(value, precision, lowPrecisionValue, NumeralSystem.WesternArabicNumerals), + formatVolumeToLocalizedNumerals: getFormattedVolume, formatExchangeRateAmountToWesternArabicNumerals: (value: number) => getFormattedExchangeRateAmount(value, NumeralSystem.WesternArabicNumerals), appendDigitGroupingSymbolAndDecimalSeparator: (value: string) => appendDigitGroupingSymbolAndDecimalSeparator(value, getNumberFormatOptions({})), getAdaptiveAmountRate, diff --git a/src/locales/it.json b/src/locales/it.json index 77fc3d50..faaf780e 100644 --- a/src/locales/it.json +++ b/src/locales/it.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Unable to retrieve user synchronized application settings", "Unable to update user synchronized application settings": "Unable to update user synchronized application settings", "Unable to disable user synchronized application settings": "Unable to disable user synchronized application settings", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Sei sicuro di voler accedere di nuovo?", "Exchange Rates Data": "Dati tassi di cambio", "User Custom": "User Custom", diff --git a/src/locales/ja.json b/src/locales/ja.json index 62f6f274..302e0705 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Unable to retrieve user synchronized application settings", "Unable to update user synchronized application settings": "Unable to update user synchronized application settings", "Unable to disable user synchronized application settings": "Unable to disable user synchronized application settings", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "再ログインしますか?", "Exchange Rates Data": "為替レートデータ", "User Custom": "User Custom", diff --git a/src/locales/kn.json b/src/locales/kn.json index 95cd8c3d..50aa1f58 100644 --- a/src/locales/kn.json +++ b/src/locales/kn.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "ಬಳಕೆದಾರರ ಸಿಂಕ್ ಮಾಡಿದ ಅಪ್ಲಿಕೇಶನ್ ಸೆಟ್ಟಿಂಗ್ಸ್ ಪಡೆಯಲು ಸಾಧ್ಯವಾಗಿಲ್ಲ", "Unable to update user synchronized application settings": "ಬಳಕೆದಾರರ ಸಿಂಕ್ ಮಾಡಿದ ಅಪ್ಲಿಕೇಶನ್ ಸೆಟ್ಟಿಂಗ್ಸ್ ನವೀಕರಿಸಲು ಸಾಧ್ಯವಾಗಿಲ್ಲ", "Unable to disable user synchronized application settings": "ಬಳಕೆದಾರರ ಸಿಂಕ್ ಮಾಡಿದ ಅಪ್ಲಿಕೇಶನ್ ಸೆಟ್ಟಿಂಗ್ಸ್ ನಿಷ್ಕ್ರಿಯಗೊಳಿಸಲು ಸಾಧ್ಯವಾಗಿಲ್ಲ", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "ಮತ್ತೆ ಲಾಗಿನ್ ಮಾಡಲು ನೀವು ಖಚಿತವೇ?", "Exchange Rates Data": "ವಿನಿಮಯ ದರ ಡೇಟಾ", "User Custom": "ಬಳಕೆದಾರ ಕಸ್ಟಮ್", diff --git a/src/locales/ko.json b/src/locales/ko.json index 15b0b206..4d6d8fbc 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "사용자 동기화된 애플리케이션 설정을 검색할 수 없습니다.", "Unable to update user synchronized application settings": "사용자 동기화된 애플리케이션 설정을 업데이트할 수 없습니다.", "Unable to disable user synchronized application settings": "사용자 동기화된 애플리케이션 설정을 비활성화할 수 없습니다.", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "다시 로그인하시겠습니까?", "Exchange Rates Data": "환율 데이터", "User Custom": "사용자 정의", diff --git a/src/locales/nl.json b/src/locales/nl.json index 9be5fe1b..e36ea2dc 100644 --- a/src/locales/nl.json +++ b/src/locales/nl.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Kan gesynchroniseerde applicatie-instellingen van gebruiker niet ophalen", "Unable to update user synchronized application settings": "Kan gesynchroniseerde applicatie-instellingen van gebruiker niet bijwerken", "Unable to disable user synchronized application settings": "Kan gesynchroniseerde applicatie-instellingen van gebruiker niet uitschakelen", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Weet je zeker dat je opnieuw wilt inloggen?", "Exchange Rates Data": "Wisselkoersgegevens", "User Custom": "Gebruiker aangepast", diff --git a/src/locales/pt_BR.json b/src/locales/pt_BR.json index ef3eed09..53446e0c 100644 --- a/src/locales/pt_BR.json +++ b/src/locales/pt_BR.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Unable to retrieve user synchronized application settings", "Unable to update user synchronized application settings": "Unable to update user synchronized application settings", "Unable to disable user synchronized application settings": "Unable to disable user synchronized application settings", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Tem certeza de que deseja fazer login novamente?", "Exchange Rates Data": "Dados de Taxas de Câmbio", "User Custom": "Personalização do Usuário", diff --git a/src/locales/ru.json b/src/locales/ru.json index c2dd5b66..4b881bb7 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Не удалось получить пользовательские синхронизированные настройки приложения", "Unable to update user synchronized application settings": "Не удалось обновить пользовательские настройки приложения", "Unable to disable user synchronized application settings": "Не удалось удалить пользовательские настройки приложения", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Вы уверены, что хотите войти снова?", "Exchange Rates Data": "Данные о курсах валют", "User Custom": "Пользовательские настройки", diff --git a/src/locales/sl.json b/src/locales/sl.json index b6a81b51..a3223279 100644 --- a/src/locales/sl.json +++ b/src/locales/sl.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Sinhroniziranih nastavitev aplikacije ni mogoče pridobiti", "Unable to update user synchronized application settings": "Sinhroniziranih nastavitev aplikacije ni mogoče posodobiti", "Unable to disable user synchronized application settings": "Sinhronizacije nastavitev aplikacije ni mogoče onemogočiti", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Ali ste prepričani, da se želite ponovno prijaviti?", "Exchange Rates Data": "Podatki o menjalnih tečajih", "User Custom": "Uporabniške nastavitve po meri", diff --git a/src/locales/ta.json b/src/locales/ta.json index e4a8b24d..aee7144d 100644 --- a/src/locales/ta.json +++ b/src/locales/ta.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "பயனர் ஒத்திசைவு செய் பயன்பாடு அமைப்புகள் பெற முடியவில்லை", "Unable to update user synchronized application settings": "பயனர் ஒத்திசைவு செய் பயன்பாடு அமைப்புகள் புதுப்பிக்க முடியவில்லை", "Unable to disable user synchronized application settings": "பயனர் ஒத்திசைவு செய் பயன்பாடு அமைப்புகள் செயலற்றப்படுத்த முடியவில்லை", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "மீண்டும் உள்நுழை செய்ய நீங்கள் உறுதியா?", "Exchange Rates Data": "மாற்று விகிதம் தரவு", "User Custom": "தனிப்பயன்", diff --git a/src/locales/th.json b/src/locales/th.json index ea953678..ba822bc1 100644 --- a/src/locales/th.json +++ b/src/locales/th.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "ไม่สามารถดึงการตั้งค่าแอปที่ซิงค์ของผู้ใช้ได้", "Unable to update user synchronized application settings": "ไม่สามารถอัปเดตการตั้งค่าแอปที่ซิงค์ของผู้ใช้ได้", "Unable to disable user synchronized application settings": "ไม่สามารถปิดการซิงค์การตั้งค่าแอปของผู้ใช้ได้", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "คุณแน่ใจหรือว่าต้องการเข้าสู่ระบบอีกครั้ง?", "Exchange Rates Data": "ข้อมูลอัตราแลกเปลี่ยน", "User Custom": "กำหนดเองโดยผู้ใช้", diff --git a/src/locales/tr.json b/src/locales/tr.json index 78a577a8..a0390cd5 100644 --- a/src/locales/tr.json +++ b/src/locales/tr.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Kullanıcının eşitlenen uygulama ayarları alınamadı", "Unable to update user synchronized application settings": "Kullanıcının eşitlenen uygulama ayarları güncellenemedi", "Unable to disable user synchronized application settings": "Kullanıcının eşitlenen uygulama ayarları devre dışı bırakılamadı", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Tekrar giriş yapmak istediğinize emin misiniz?", "Exchange Rates Data": "Döviz Kuru Verileri", "User Custom": "Kullanıcı Özel", diff --git a/src/locales/uk.json b/src/locales/uk.json index a351dc2d..bdaba4f2 100644 --- a/src/locales/uk.json +++ b/src/locales/uk.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Unable to retrieve user synchronized application settings", "Unable to update user synchronized application settings": "Unable to update user synchronized application settings", "Unable to disable user synchronized application settings": "Unable to disable user synchronized application settings", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Ви впевнені, що хочете увійти знову?", "Exchange Rates Data": "Дані про курси валют", "User Custom": "User Custom", diff --git a/src/locales/vi.json b/src/locales/vi.json index f03afa76..71f33922 100644 --- a/src/locales/vi.json +++ b/src/locales/vi.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "Unable to retrieve user synchronized application settings", "Unable to update user synchronized application settings": "Unable to update user synchronized application settings", "Unable to disable user synchronized application settings": "Unable to disable user synchronized application settings", + "Browser Cache Management": "Browser Cache Management", + "File Cache": "File Cache", + "Used storage": "Used storage", + "Application Code": "Application Code", + "Resource Files": "Resource Files", + "Map Data": "Map Data", + "Others": "Others", + "Failed to load browser cache statistics": "Failed to load browser cache statistics", + "Clear File Cache": "Clear File Cache", + "Are you sure you want to clear file cache?": "Are you sure you want to clear file cache?", "Are you sure you want to re-login?": "Bạn có chắc chắn muốn đăng nhập lại không?", "Exchange Rates Data": "Dữ liệu tỷ giá hối đoái", "User Custom": "User Custom", diff --git a/src/locales/zh_Hans.json b/src/locales/zh_Hans.json index 49950936..1bf1f10a 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "无法获取用户同步的应用设置", "Unable to update user synchronized application settings": "无法更新用户同步的应用设置", "Unable to disable user synchronized application settings": "无法禁用用户同步的应用设置", + "Browser Cache Management": "浏览器缓存管理", + "File Cache": "文件缓存", + "Used storage": "已用存储", + "Application Code": "应用代码", + "Resource Files": "资源文件", + "Map Data": "地图数据", + "Others": "其他", + "Failed to load browser cache statistics": "加载浏览器缓存统计数据失败", + "Clear File Cache": "清除文件缓存", + "Are you sure you want to clear file cache?": "您确定要清除文件缓存?", "Are you sure you want to re-login?": "您确定要重新登录?", "Exchange Rates Data": "汇率数据", "User Custom": "用户自定义", diff --git a/src/locales/zh_Hant.json b/src/locales/zh_Hant.json index 6efd07dc..1114d239 100644 --- a/src/locales/zh_Hant.json +++ b/src/locales/zh_Hant.json @@ -2505,6 +2505,16 @@ "Unable to retrieve user synchronized application settings": "無法取得使用者同步的應用程式設定", "Unable to update user synchronized application settings": "無法更新使用者同步的應用程式設定", "Unable to disable user synchronized application settings": "無法停用使用者同步的應用程式設定", + "Browser Cache Management": "瀏覽器快取管理", + "File Cache": "檔案快取", + "Used storage": "已使用的儲存空間", + "Application Code": "應用程式程式碼", + "Resource Files": "資源檔案", + "Map Data": "地圖資料", + "Others": "其他", + "Failed to load browser cache statistics": "載入瀏覽器快取統計資料失敗", + "Clear File Cache": "清除檔案快取", + "Are you sure you want to clear file cache?": "您確定要清除檔案快取?", "Are you sure you want to re-login?": "您確定要重新登入?", "Exchange Rates Data": "匯率資料", "User Custom": "使用者自訂", diff --git a/src/router/mobile.ts b/src/router/mobile.ts index 4a823502..17c4a1fe 100644 --- a/src/router/mobile.ts +++ b/src/router/mobile.ts @@ -23,6 +23,7 @@ import TextSizeSettingsPage from '@/views/mobile/settings/TextSizeSettingsPage.v import PageSettingsPage from '@/views/mobile/settings/PageSettingsPage.vue'; import AccountCategoryDisplayOrderSettingsPage from '@/views/mobile/settings/AccountCategoryDisplayOrderSettingsPage.vue'; import ApplicationCloudSyncSettingsPage from '@/views/mobile/settings/ApplicationCloudSyncSettingsPage.vue'; +import BrowserCacheSettingPage from '@/views/mobile/settings/BrowserCacheSettingPage.vue'; import AccountFilterSettingsPage from '@/views/mobile/settings/AccountFilterSettingsPage.vue'; import CategoryFilterSettingsPage from '@/views/mobile/settings/CategoryFilterSettingsPage.vue'; import TransactionTagFilterSettingsPage from '@/views/mobile/settings/TransactionTagFilterSettingsPage.vue'; @@ -250,6 +251,11 @@ const routes: Router.RouteParameters[] = [ async: asyncResolve(ApplicationCloudSyncSettingsPage), beforeEnter: [checkLogin] }, + { + path: '/settings/browser_caches', + async: asyncResolve(BrowserCacheSettingPage), + beforeEnter: [checkLogin] + }, { path: '/settings', async: asyncResolve(SettingsPage), diff --git a/src/stores/exchangeRates.ts b/src/stores/exchangeRates.ts index a9a5728e..9849ee33 100644 --- a/src/stores/exchangeRates.ts +++ b/src/stores/exchangeRates.ts @@ -33,6 +33,10 @@ function getExchangeRatesFromLocalStorage(): LatestExchangeRates { return JSON.parse(storageData) as LatestExchangeRates; } +function getExchangeRatesRawDataFromLocalStorage(): string | null { + return localStorage.getItem(exchangeRatesLocalStorageKey); +} + function setExchangeRatesToLocalStorage(value: LatestExchangeRates): void { const storageData = JSON.stringify(value); localStorage.setItem(exchangeRatesLocalStorageKey, storageData); @@ -121,6 +125,16 @@ export const useExchangeRatesStore = defineStore('exchangeRates', () => { } } + function getExchangeRatesCacheSize(): number { + const storageData = getExchangeRatesRawDataFromLocalStorage(); + + if (!storageData) { + return 0; + } + + return new Blob([storageData]).size; + } + function resetLatestExchangeRates(): void { latestExchangeRates.value = {}; clearExchangeRatesFromLocalStorage(); @@ -283,6 +297,7 @@ export const useExchangeRatesStore = defineStore('exchangeRates', () => { exchangeRatesLastUpdateTime, latestExchangeRateMap, // functions + getExchangeRatesCacheSize, resetLatestExchangeRates, getLatestExchangeRates, updateUserCustomExchangeRate, diff --git a/src/views/base/AboutPageBase.ts b/src/views/base/AboutPageBase.ts index f4c9bc5f..50bdf64a 100644 --- a/src/views/base/AboutPageBase.ts +++ b/src/views/base/AboutPageBase.ts @@ -15,7 +15,7 @@ import { getMapWebsite } from '@/lib/map/index.ts'; import { getContributors } from '@/lib/contributors.ts'; import { getLicense, getThirdPartyLicenses } from '@/lib/licenses.ts'; import { formatDisplayVersion, getClientDisplayVersion, getClientBuildTime } from '@/lib/version.ts'; -import { clearBrowserCaches } from '@/lib/ui/common.ts'; +import { clearAllBrowserCaches } from '@/lib/cache.ts'; export function useAboutPageBase() { const { tt, formatDateTimeToLongDateTime } = useI18n(); @@ -61,7 +61,7 @@ export function useAboutPageBase() { const thirdPartyLicenses = computed(() => getThirdPartyLicenses()); function refreshBrowserCache(): void { - clearBrowserCaches().then(() => { + clearAllBrowserCaches().then(() => { location.reload(); }); } diff --git a/src/views/desktop/app/AppSettingsPage.vue b/src/views/desktop/app/AppSettingsPage.vue index ad4f4c18..3ebd5000 100644 --- a/src/views/desktop/app/AppSettingsPage.vue +++ b/src/views/desktop/app/AppSettingsPage.vue @@ -17,6 +17,10 @@ {{ tt('Settings Sync') }} + + + {{ tt('Browser Cache Management') }} + @@ -35,6 +39,10 @@ + + + + @@ -44,6 +52,7 @@ import AppBasicSettingTab from './settings/tabs/AppBasicSettingTab.vue'; import AppLockSettingTab from './settings/tabs/AppLockSettingTab.vue'; import AppStatisticsSettingTab from './settings/tabs/AppStatisticsSettingTab.vue'; import AppCloudSyncSettingTab from './settings/tabs/AppCloudSyncSettingTab.vue'; +import AppBrowserCacheSettingTab from './settings/tabs/AppBrowserCacheSettingTab.vue'; import { ref } from 'vue'; import { useRouter, onBeforeRouteUpdate } from 'vue-router'; @@ -54,7 +63,8 @@ import { mdiCogOutline, mdiLockOpenOutline, mdiChartPieOutline, - mdiCloudOutline + mdiCloudOutline, + mdiDatabaseClockOutline } from '@mdi/js'; const props = defineProps<{ @@ -69,7 +79,8 @@ const ALL_TABS: string[] = [ 'basicSetting', 'applicationLockSetting', 'statisticsSetting', - 'cloudSyncSetting' + 'cloudSyncSetting', + 'browserCacheSetting' ]; const activeTab = ref((() => { diff --git a/src/views/desktop/app/settings/tabs/AppBrowserCacheSettingTab.vue b/src/views/desktop/app/settings/tabs/AppBrowserCacheSettingTab.vue new file mode 100644 index 00000000..4095a20a --- /dev/null +++ b/src/views/desktop/app/settings/tabs/AppBrowserCacheSettingTab.vue @@ -0,0 +1,161 @@ + + + diff --git a/src/views/mobile/SettingsPage.vue b/src/views/mobile/SettingsPage.vue index f4a542e5..9918e8e9 100644 --- a/src/views/mobile/SettingsPage.vue +++ b/src/views/mobile/SettingsPage.vue @@ -108,6 +108,7 @@ + diff --git a/src/views/mobile/settings/BrowserCacheSettingPage.vue b/src/views/mobile/settings/BrowserCacheSettingPage.vue new file mode 100644 index 00000000..51bd0b7e --- /dev/null +++ b/src/views/mobile/settings/BrowserCacheSettingPage.vue @@ -0,0 +1,103 @@ + + +