Rewild Your Web
web browser dweb

misc: load json files using json modules

+10 -16
+6 -4
resources/browserhtml/homescreen/index.js
··· 10 10 // Load widgets from JSON 11 11 async function loadWidgets() { 12 12 try { 13 - const response = await fetch("resources/widgets.json"); 14 - const widgets = await response.json(); 13 + const { default: widgets } = await import("./resources/widgets.json", { 14 + with: { type: "json" }, 15 + }); 15 16 renderWidgets(widgets); 16 17 } catch (e) { 17 18 console.log("[Homescreen] No widgets configured"); ··· 33 34 // Load bookmarks from JSON 34 35 async function loadBookmarks() { 35 36 try { 36 - const response = await fetch("resources/bookmarks.json"); 37 - const bookmarks = await response.json(); 37 + const { default: bookmarks } = await import("./resources/bookmarks.json", { 38 + with: { type: "json" }, 39 + }); 38 40 renderBookmarks(bookmarks); 39 41 } catch (e) { 40 42 console.error("[Homescreen] Failed to load bookmarks:", e);
+4 -12
resources/browserhtml/shared/search/engines.js
··· 2 2 3 3 const PREF_NAME = "browserhtml.search_engine"; 4 4 5 + // Load the default search engines resource. 6 + import ENGINES from "//shared.localhost:8888/search/default_engines.json" with { type: "json" }; 7 + 5 8 export default class SearchEngines extends EventTarget { 6 9 constructor() { 7 10 super(); 8 - this.engines = null; 9 11 this.currentEngine = null; 12 + this.engines = ENGINES; 10 13 } 11 14 12 15 async ensureReady() { 13 16 if (this.currentEngine) { 14 - return; 15 - } 16 - 17 - // Load the default search engines resource. 18 - try { 19 - let response = await fetch( 20 - "//shared.localhost:8888/search/default_engines.json", 21 - ); 22 - this.engines = await response.json(); 23 - } catch (e) { 24 - console.error(`Failed to load search engines: ${e}`); 25 17 return; 26 18 } 27 19