From 4f49ad9ca029564f95118bbf0bfa9340ce028128 Mon Sep 17 00:00:00 2001 From: "J.T. Sage" Date: Wed, 20 Nov 2024 22:18:20 -0500 Subject: [PATCH] update cache info in UI --- lib/modUtilLib.js | 24 +++++++++++++----------- modAssist_main.js | 20 ++------------------ renderer/renderJS/main_ui_lib.js | 6 ------ test/test.js | 1 - 4 files changed, 15 insertions(+), 36 deletions(-) diff --git a/lib/modUtilLib.js b/lib/modUtilLib.js index cfbde125..2709f64c 100644 --- a/lib/modUtilLib.js +++ b/lib/modUtilLib.js @@ -5,7 +5,6 @@ (c) 2022-present FSG Modding. MIT License. */ /* eslint complexity: ["error", 25] */ // MARK: MOD UTIL [main] -// TODO: doc marks /** * Utility libraries for MA @@ -26,6 +25,7 @@ const baseGameLang = { * Logger Class * @class */ +// MARK: Logger class ma_logger extends EventEmitter { #isPacked = false #dataPath = null @@ -74,7 +74,7 @@ class ma_logger extends EventEmitter { } /** - * Set danger callback function + * MARK: Set danger callback * @param {function} newCallback Function to call */ set dangerCallBack(newCallback) { this.#dangerEvent = newCallback } @@ -91,7 +91,7 @@ class ma_logger extends EventEmitter { } /** - * Add a log line + * MARK: Add a log line * @param {string} level Level, one of 'danger', 'warning', 'notice', 'info', or 'debug' * @param {string} process Process to log * @param {...string} text Text to add to log @@ -118,6 +118,7 @@ class ma_logger extends EventEmitter { this.#textLog.push(simpleText) } + // MARK: unwrap text #mapTextInput(...text) { return [...text].map((item) => { if ( typeof item === 'undefined' ) { @@ -216,7 +217,7 @@ class ma_logger extends EventEmitter { } /** - * + * MARK: getSystemLocale * @returns 2 letter system locale, constrained to the set Giants uses */ const getSystemLocale = function () { @@ -251,7 +252,7 @@ const getSystemLocale = function () { } /** - * l10n Library + * MARK: l10n Library * @class */ class translator { @@ -262,6 +263,7 @@ class translator { #langPromise = null mcVersion = null /** + * MARK: icon overrides * @property {Object} iconOverrides Preset string->icon */ iconOverrides = { @@ -352,6 +354,7 @@ class translator { } /** + * MARK: units * @property {Object} currentUnits Get current measurement units */ get currentUnits() { @@ -368,7 +371,7 @@ class translator { } /** - * load Language files + * MARK: load Lang files * @private * @instance * @memberof translator @@ -390,7 +393,7 @@ class translator { } /** - * Get loaded language list + * MARK: loaded lang list * @returns {Array.} [[langCode, Language Title],...] */ async getLangList() { @@ -421,6 +424,7 @@ class translator { }) } + // MARK: getText /* eslint-disable complexity */ async getText(key, version = 22, skipDebug = false) { if ( key === null ) { return null } @@ -607,7 +611,7 @@ function getDeferPromise() { } /** - * Mod Cache Manager + * MARK: Mod Cache * @class */ class modCacheManager { @@ -733,7 +737,7 @@ class modCacheManager { /** - * IPC Communication + * MARK: IPC Com * @typedef serveIPC * @type {Object} * @property {Object} dlRequest NET download request object @@ -741,7 +745,6 @@ class modCacheManager { * @property {Set} modFolders mod folders as full paths * @property {module:modAssist_window_lib.windowLib} windowLib Window handling library * @property {module:modUtilLib~modCacheManager} storeCache Mod Cache - * @property {electron-store} storeCacheDetail Mod Details Cache * @property {electron-store} storeNote Collection Settings * @property {electron-store} storeSet Application Settings * @property {electron-store} storeSites Mod External Sites @@ -784,7 +787,6 @@ const serveIPC = { windowLib : null, storeCache : null, - storeCacheDetail : null, storeNote : null, storeSet : null, storeSites : null, diff --git a/modAssist_main.js b/modAssist_main.js index 7658caa8..e9ece705 100644 --- a/modAssist_main.js +++ b/modAssist_main.js @@ -75,7 +75,6 @@ serveIPC.storeSet = new Store({schema : settingDefault.defaults, migrati serveIPC.storeCache = new (require('./lib/modUtilLib.js')).modCacheManager(app.getPath('userData')) serveIPC.storeSites = new Store({name : 'mod_source_site', migrations : settingDefault.migrateSite, clearInvalidConfig : true}) serveIPC.storeNote = new Store({name : 'col_notes', clearInvalidConfig : true}) -serveIPC.storeCacheDetail = new Store({name : 'mod_detail_cache', clearInvalidConfig : true}) serveIPC.windowLib.loadSettings() @@ -312,15 +311,8 @@ ipcMain.handle('i18n:get', async (_, key, version = 22) => { try { const cacheSize = fs.statSync(path.join(app.getPath('userData'), 'mod_cache.json')).size/(1024*1024) const iconSize = fs.statSync(path.join(app.getPath('userData'), 'mod_icons.json')).size/(1024*1024) - return serveIPC.l10n.getTextOverride(key, 22, { suffix : ` ${cacheSize.toFixed(2)}MB / ${iconSize.toFixed(2)}MB` }) - } catch { - return serveIPC.l10n.getTextOverride(key, 22, { suffix : ' 0.00MB' }) - } - } - case 'clean_detail_cache_size' : { - try { - const cacheSize = fs.statSync(path.join(app.getPath('userData'), 'mod_detail_cache.json')).size/(1024*1024) - return serveIPC.l10n.getTextOverride(key, 22, { suffix : ` ${cacheSize.toFixed(2)}MB` }) + const itemSize = fs.statSync(path.join(app.getPath('userData'), 'mod_items.json')).size/(1024*1024) + return serveIPC.l10n.getTextOverride(key, 22, { suffix : ` ${cacheSize.toFixed(2)}MB / ${iconSize.toFixed(2)}MB / ${itemSize.toFixed(2)}MB` }) } catch { return serveIPC.l10n.getTextOverride(key, 22, { suffix : ' 0.00MB' }) } @@ -671,10 +663,6 @@ ipcMain.on('settings:clearMalware', () => { serveIPC.storeSet.set('suppress_malware', []) processModFolders(true) }) -ipcMain.on('settings:clearDetail', () => { - serveIPC.storeCacheDetail.clear() - return true -}) ipcMain.on('cache:clear', () => { serveIPC.storeCache.clearAll() serveIPC.windowLib.forceFocus('main') @@ -684,10 +672,6 @@ ipcMain.on('cache:malware', () => { serveIPC.storeSet.set('suppress_malware', []) processModFolders(true) }) -ipcMain.on('cache:detail', () => { - serveIPC.storeCacheDetail.clear() - serveIPC.windowLib.sendToValidWindow('main', 'settings:invalidate') -}) ipcMain.on('cache:clean', () => { const md5Set = new Set(serveIPC.storeCache.keys) diff --git a/renderer/renderJS/main_ui_lib.js b/renderer/renderJS/main_ui_lib.js index 7fa7ed57..f0d140b1 100644 --- a/renderer/renderJS/main_ui_lib.js +++ b/renderer/renderJS/main_ui_lib.js @@ -1491,9 +1491,7 @@ class PrefLib { '', '', '', - '', '', - '', '', '', '', @@ -1504,15 +1502,11 @@ class PrefLib { this.update.push(() => { MA.byId('clear_malware_size').setAttribute('refresh', 'true') MA.byId('clean_cache_size').setAttribute('refresh', 'true') - MA.byId('clean_detail_cache_size').setAttribute('refresh', 'true') }) node.querySelector('#pref--cache-clean-btn').addEventListener('click', () => { window.main_IPC.cache.clean() }) - node.querySelector('#pref--cache-clean-detail-btn').addEventListener('click', () => { - window.main_IPC.cache.detail() - }) node.querySelector('#pref--cache-clear-btn').addEventListener('click', () => { window.main_IPC.cache.clear() }) diff --git a/test/test.js b/test/test.js index bf1a8c88..aa6c19bf 100644 --- a/test/test.js +++ b/test/test.js @@ -34,7 +34,6 @@ serveIPC.log.forceNoConsole() serveIPC.isBotDisabled = true serveIPC.isModCacheDisabled = true -serveIPC.storeCacheDetail = fakeStore serveIPC.storeNote = fakeStore serveIPC.storeSet = fakeStore serveIPC.storeSites = fakeStore