Skip to content

Commit

Permalink
update cache info in UI
Browse files Browse the repository at this point in the history
jtsage committed Nov 21, 2024
1 parent 3935cf1 commit 4f49ad9
Showing 4 changed files with 15 additions and 36 deletions.
24 changes: 13 additions & 11 deletions lib/modUtilLib.js
Original file line number Diff line number Diff line change
@@ -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.<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,15 +737,14 @@ class modCacheManager {


/**
* IPC Communication
* MARK: IPC Com
* @typedef serveIPC
* @type {Object}
* @property {Object} dlRequest NET download request object
* @property {module:modCheckLib~modFileCollection} modCollect mod collection
* @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,
20 changes: 2 additions & 18 deletions modAssist_main.js
Original file line number Diff line number Diff line change
@@ -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)

6 changes: 0 additions & 6 deletions renderer/renderJS/main_ui_lib.js
Original file line number Diff line number Diff line change
@@ -1491,9 +1491,7 @@ class PrefLib {
'<i18n-text class="inset-block-header" data-key="user_pref_title_clean_cache"></i18n-text>',
'<i18n-text class="inset-block-blurb-option" data-key="user_pref_blurb_clean_cache"></i18n-text>',
'<i18n-text class="inset-block-blurb-option text-body-emphasis py-1" data-key="clean_cache_size" id="clean_cache_size"></i18n-text>',
'<i18n-text class="inset-block-blurb-option text-body-emphasis py-1" data-key="clean_detail_cache_size" id="clean_detail_cache_size"></i18n-text>',
'<i18n-text class="d-block btn btn-success btn-sm w-75 mt-2 mx-auto mb-3" id="pref--cache-clean-btn" data-key="user_pref_button_clean_cache"></i18n-text>',
'<i18n-text class="d-block btn btn-warning btn-sm w-75 mt-2 mx-auto mb-3" id="pref--cache-clean-detail-btn" data-key="user_pref_button_clear_detail_cache"></i18n-text>',
'<i18n-text class="inset-block-blurb-option" data-key="user_pref_blurb_clear_cache"></i18n-text>',
'<i18n-text class="d-block btn btn-danger btn-sm w-75 mt-2 mx-auto" id="pref--cache-clear-btn" data-key="user_pref_button_clear_cache"></i18n-text>',
'<i18n-text class="inset-block-blurb-option mt-2" data-key="user_pref_blurb_clear_malware"></i18n-text>',
@@ -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()
})
1 change: 0 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4f49ad9

Please sign in to comment.