Skip to content

Commit

Permalink
Emulator - Force Local roms/index.json (#41)
Browse files Browse the repository at this point in the history
* * added `local=1` param to force loading the rom index.json locally when hosting the emulator yourself
  - allows users to customize their roms/index.json to support auto-loading custom ROMs

Example: http://127.0.0.1:1145/?r=roms/os_with_romdisk.img&local=1
  • Loading branch information
zoul0813 authored Oct 11, 2024
1 parent 250fa88 commit fc85dd4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions view/readrom.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function processIndex(index) {
attrs.selected = true;
}
const attributes = Object.keys(attrs).reduce((acc,key) => {
acc += `${key}`;
acc += ` ${key}`;
if(!['selected', 'disabled'].includes(key) && attrs[key]) {
acc += `="${attrs[key]}" `;
}
Expand Down Expand Up @@ -149,7 +149,9 @@ function processIndex(index) {
all_options.push(`<optgroup label="--- Nightly ---" data-type="nightly">` + nightly.join("") + `</optgroup>`);
}
if(index.stable) {
const stable = index.stable.map((entry) => to_option(entry, false));
const stable = index.stable.map((entry) => {
return to_option(entry, (params.r == entry.urls));
});
all_options.push(`<optgroup label="--- Stable ---" data-type="stable">` + stable.join("") + `</optgroup>`);
}

Expand Down Expand Up @@ -198,7 +200,10 @@ async function switchRom() {
return;
}
if(rom_chosen !== compare) {
window.history.pushState({}, undefined, `?r=${rom_chosen}`);
params.r = rom_chosen;
window.history.pushState({}, undefined, `?${Object.keys(params).reduce((a,k) => {
return a += `${k}=${params[k]}&`;
}, '').slice(0,-1)}`);
if(reload) {
window.location.reload();
return;
Expand All @@ -210,7 +215,7 @@ async function switchRom() {
/* Get the hash for the current binary */
let hash = $(`#romchoice option[value="${rom_chosen}"]`).attr("hash");
let data = await readBlobFromUrl(rom_chosen);
let hashcomp = await filehash(data, hash);
let hashcomp = params.local ? true : await filehash(data, hash);
if (hashcomp == true) {
loadRom(data);
}
Expand Down Expand Up @@ -238,7 +243,7 @@ jQuery(() => {
* Manage the pre-built ROMs list. Available ROMs will be fetched from a remote JSON file that contains
* names and links to all of the available ROMs, the first one will always be the default.
*/
const prebuilt_json_url_host = "https://zeal8bit.com";
const prebuilt_json_url_host = params.local ? '' : "https://zeal8bit.com";
const prebuilt_json_url_path = "/roms/index.json";
/* Fetch the remote JSON file, and pass the content to the previous function */
fetch(prebuilt_json_url_host + prebuilt_json_url_path)
Expand Down

0 comments on commit fc85dd4

Please sign in to comment.