diff --git a/.gitignore b/.gitignore index 140631b..fae91c1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ data/cores/* !data/cores/package.json !data/cores/.npmignore .DS_Store +.hintrc .vscode/* !.vscode/settings.json !.vscode/extensions.json diff --git a/data/src/cache.js b/data/src/cache.js index 6108d01..2f2e7e6 100644 --- a/data/src/cache.js +++ b/data/src/cache.js @@ -222,6 +222,11 @@ class EJS_Cache { this.utils = new EJS_UTILS(); + /** + * Indicates whether the startup cleanup has been completed. + */ + this.startupCleanupCompleted = false; + if (this.debug) { console.log("Initialized EJS_Cache with settings:", { enabled: this.enabled, @@ -237,7 +242,7 @@ class EJS_Cache { * Initializes the IndexedDB database and object stores. * @returns {Promise} */ - async #createCacheDatabase() { + async createCacheDatabase() { if (!this.enabled) return; if (this.storage && this.blobStorage) return; @@ -275,11 +280,6 @@ class EJS_Cache { }); } - /** - * Indicates whether the startup cleanup has been completed. - */ - #startupCleanupCompleted = false; - /** * Generates a cache key for the given data array. * @param {Uint8Array} dataArray @@ -302,12 +302,12 @@ class EJS_Cache { if (!this.enabled) return null; // ensure database is created - await this.#createCacheDatabase(); + await this.createCacheDatabase(); // clean up cache on first get if not already done - if (!this.#startupCleanupCompleted) { + if (!this.startupCleanupCompleted) { await this.cleanup(); - this.#startupCleanupCompleted = true; + this.startupCleanupCompleted = true; } const item = await this.storage.get(key, indexName); @@ -338,7 +338,7 @@ class EJS_Cache { if (!this.enabled) return; // ensure database is created - await this.#createCacheDatabase(); + await this.createCacheDatabase(); // before putting, ensure item is of type EJS_CacheItem if (!(item instanceof EJS_CacheItem)) { @@ -402,7 +402,7 @@ class EJS_Cache { */ async delete(key) { // ensure database is created - await this.#createCacheDatabase(); + await this.createCacheDatabase(); // fail silently if the key does not exist try { @@ -418,7 +418,7 @@ class EJS_Cache { */ async clear() { // ensure database is created - await this.#createCacheDatabase(); + await this.createCacheDatabase(); const allItems = await this.storage.getAll(); for (let i = 0; i < allItems.length; i++) { @@ -433,7 +433,7 @@ class EJS_Cache { if (!this.enabled) return; // ensure database is created - await this.#createCacheDatabase(); + await this.createCacheDatabase(); if (this.debug) console.log("[EJS Cache] Starting cache cleanup..."); const cleanupStartTime = performance.now(); diff --git a/data/src/emulator.js b/data/src/emulator.js index fb323f6..3dbbf32 100644 --- a/data/src/emulator.js +++ b/data/src/emulator.js @@ -43,17 +43,6 @@ class EmulatorJS { } return rv; } - downloadType = { - "rom": { "name": "ROM", "dontCache": false }, - "core": { "name": "Core", "dontCache": false }, - "bios": { "name": "BIOS", "dontCache": false }, - "parent": { "name": "Parent", "dontCache": false }, - "patch": { "name": "Patch", "dontCache": false }, - "reports": { "name": "Reports", "dontCache": true }, - "states": { "name": "States", "dontCache": true }, - "support": { "name": "Support", "dontCache": true }, - "unknown": { "name": "Unknown", "dontCache": true } - } requiresThreads(core) { const requiresThreads = ["ppsspp", "dosbox_pure"]; return requiresThreads.includes(core); @@ -424,6 +413,19 @@ class EmulatorJS { this.config.cacheConfig.cacheMaxAgeMins = cacheConfigDefaults.cacheMaxAgeMins; } + // Populate downloadTypes + this.downloadType = { + "rom": { "name": "ROM", "dontCache": false }, + "core": { "name": "Core", "dontCache": false }, + "bios": { "name": "BIOS", "dontCache": false }, + "parent": { "name": "Parent", "dontCache": false }, + "patch": { "name": "Patch", "dontCache": false }, + "reports": { "name": "Reports", "dontCache": true }, + "states": { "name": "States", "dontCache": true }, + "support": { "name": "Support", "dontCache": true }, + "unknown": { "name": "Unknown", "dontCache": true } + } + // Initialize storage cache this.storageCache = new window.EJS_Cache( this.config.cacheConfig.enabled, @@ -1433,132 +1435,133 @@ class EmulatorJS { elem.appendChild(elm); } } - defaultButtonOptions = { - playPause: { - visible: true, - icon: "play", - displayName: "Play/Pause" - }, - play: { - visible: true, - icon: '', - displayName: "Play" - }, - pause: { - visible: true, - icon: '', - displayName: "Pause" - }, - restart: { - visible: true, - icon: '', - displayName: "Restart" - }, - mute: { - visible: true, - icon: '', - displayName: "Mute" - }, - unmute: { - visible: true, - icon: '', - displayName: "Unmute" - }, - settings: { - visible: true, - icon: '', - displayName: "Settings" - }, - fullscreen: { - visible: true, - icon: "fullscreen", - displayName: "Fullscreen" - }, - enterFullscreen: { - visible: true, - icon: '', - displayName: "Enter Fullscreen" - }, - exitFullscreen: { - visible: true, - icon: '', - displayName: "Exit Fullscreen" - }, - saveState: { - visible: true, - icon: '', - displayName: "Save State" - }, - loadState: { - visible: true, - icon: '', - displayName: "Load State" - }, - screenRecord: { - visible: true - }, - gamepad: { - visible: true, - icon: '', - displayName: "Control Settings" - }, - cheat: { - visible: true, - icon: '', - displayName: "Cheats" - }, - volumeSlider: { - visible: true - }, - saveSavFiles: { - visible: true, - icon: '', - displayName: "Export Save File" - }, - loadSavFiles: { - visible: true, - icon: '', - displayName: "Import Save File" - }, - quickSave: { - visible: true - }, - quickLoad: { - visible: true - }, - screenshot: { - visible: true - }, - cacheManager: { - visible: true, - icon: '', - displayName: "Cache Manager" - }, - exitEmulation: { - visible: true, - icon: '', - displayName: "Exit Emulation" - }, - netplay: { - visible: true, - icon: '', - displayName: "Netplay" - }, - diskButton: { - visible: true, - icon: '', - displayName: "Disks" - }, - contextMenu: { - visible: true, - icon: '', - displayName: "Context Menu" - } - }; - defaultButtonAliases = { - volume: "volumeSlider" - }; buildButtonOptions(buttonUserOpts) { + this.defaultButtonOptions = { + playPause: { + visible: true, + icon: "play", + displayName: "Play/Pause" + }, + play: { + visible: true, + icon: '', + displayName: "Play" + }, + pause: { + visible: true, + icon: '', + displayName: "Pause" + }, + restart: { + visible: true, + icon: '', + displayName: "Restart" + }, + mute: { + visible: true, + icon: '', + displayName: "Mute" + }, + unmute: { + visible: true, + icon: '', + displayName: "Unmute" + }, + settings: { + visible: true, + icon: '', + displayName: "Settings" + }, + fullscreen: { + visible: true, + icon: "fullscreen", + displayName: "Fullscreen" + }, + enterFullscreen: { + visible: true, + icon: '', + displayName: "Enter Fullscreen" + }, + exitFullscreen: { + visible: true, + icon: '', + displayName: "Exit Fullscreen" + }, + saveState: { + visible: true, + icon: '', + displayName: "Save State" + }, + loadState: { + visible: true, + icon: '', + displayName: "Load State" + }, + screenRecord: { + visible: true + }, + gamepad: { + visible: true, + icon: '', + displayName: "Control Settings" + }, + cheat: { + visible: true, + icon: '', + displayName: "Cheats" + }, + volumeSlider: { + visible: true + }, + saveSavFiles: { + visible: true, + icon: '', + displayName: "Export Save File" + }, + loadSavFiles: { + visible: true, + icon: '', + displayName: "Import Save File" + }, + quickSave: { + visible: true + }, + quickLoad: { + visible: true + }, + screenshot: { + visible: true + }, + cacheManager: { + visible: true, + icon: '', + displayName: "Cache Manager" + }, + exitEmulation: { + visible: true, + icon: '', + displayName: "Exit Emulation" + }, + netplay: { + visible: true, + icon: '', + displayName: "Netplay" + }, + diskButton: { + visible: true, + icon: '', + displayName: "Disks" + }, + contextMenu: { + visible: true, + icon: '', + displayName: "Context Menu" + } + }; + this.defaultButtonAliases = { + volume: "volumeSlider" + }; + let mergedButtonOptions = this.defaultButtonOptions; // merge buttonUserOpts with mergedButtonOptions diff --git a/data/src/storage.js b/data/src/storage.js index cf17863..aeb36b8 100644 --- a/data/src/storage.js +++ b/data/src/storage.js @@ -9,7 +9,7 @@ class EJS_STORAGE { this.storeName = storeName; this.indexes = indexes; } - #addFileToDB(key, add) { + addFileToDB(key, add) { (async () => { if (key === "?EJS_KEYS!") return; let keys = await this.get("?EJS_KEYS!"); @@ -23,7 +23,7 @@ class EJS_STORAGE { this.put("?EJS_KEYS!", keys); })(); } - #getObjectStore(mode = "readwrite") { + getObjectStore(mode = "readwrite") { return new Promise((resolve, reject) => { if (!window.indexedDB) return resolve(); let openRequest = indexedDB.open(this.dbName, 1); @@ -61,7 +61,7 @@ class EJS_STORAGE { */ get(key, indexName = null) { return new Promise(async (resolve, reject) => { - const objectStore = await this.#getObjectStore(); + const objectStore = await this.getObjectStore(); if (!objectStore) return resolve(); if (!indexName) { // Default: get by primary key @@ -84,22 +84,22 @@ class EJS_STORAGE { } put(key, data) { return new Promise(async (resolve, reject) => { - const objectStore = await this.#getObjectStore(); + const objectStore = await this.getObjectStore(); if (!objectStore) return resolve(); let request = objectStore.put(data, key); request.onerror = () => resolve(); request.onsuccess = () => { - this.#addFileToDB(key, true); + this.addFileToDB(key, true); resolve(); }; }); } remove(key) { return new Promise(async (resolve, reject) => { - const objectStore = await this.#getObjectStore(); + const objectStore = await this.getObjectStore(); if (!objectStore) return resolve(); let request = objectStore.delete(key); - this.#addFileToDB(key, false); + this.addFileToDB(key, false); request.onsuccess = () => resolve(); request.onerror = () => {}; }); @@ -144,7 +144,7 @@ class EJS_STORAGE { class EJS_DUMMYSTORAGE { constructor() {} - #addFileToDB() { + addFileToDB() { return new Promise(resolve => resolve()); } get() { diff --git a/index.html b/index.html index 88f3805..6210abc 100644 --- a/index.html +++ b/index.html @@ -1,9 +1,10 @@ - + + EmulatorJS - - + +