Skip to content

Commit

Permalink
Refactor fakeruntime.js to clean up code and enhance Requests method …
Browse files Browse the repository at this point in the history
…for better response handling
  • Loading branch information
Ayideyia committed Jan 22, 2025
1 parent 2acbc5a commit e86129a
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions public/fakeruntime.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
window.runtime = {
WindowSetSystemDefaultTheme() {},
EventsOnMultiple(id, fn) {
console.log(id, fn)
},
EventsOnMultiple(id, fn) {},
WindowIsMaximised() {},
WindowIsMinimised() {},
}

const events = {
data: [],
on() {},
}
};

window.go = {
bridge: {
App: {
UpdateTray() {},
UpdateTrayMenus() {},
GetEnv() {
return { os: 'darwin' }
return { os: "darwin" };
},
Readdir() {
return { flag: true, data: '' }
return { flag: true, data: "" };
},
IsStartup() {
return true
return true;
},
async Requests(method, url, headers, body, options) {
const res = await fetch(url, {
method,
headers,
body: ["HEAD", "GET"].includes(method) ? null : JSON.stringify(body),
});
let respBody;
if (res.headers["Content-Type"]?.includes("application/json")) {
respBody = await res.json();
} else {
respBody = await res.text();
}
return {
flag: true,
status: res.status,
headers: res.headers,
body: respBody,
};
},
Requests() {},
Writefile(path, content) {
localStorage.setItem(path, content)
return { flag: true }
path = window.location.pathname + path;
localStorage.setItem(path, content);
return { flag: true };
},
Readfile(path) {
return { flag: true, data: localStorage.getItem(path) }
path = window.location.pathname + path;
return { flag: true, data: localStorage.getItem(path) };
},
ExecBackground(path, args, out, end) {
return { flag: true, data: 999 }
return { flag: true, data: 999 };
},
},
},
}
};

0 comments on commit e86129a

Please sign in to comment.