Skip to content

Commit e86129a

Browse files
committed
Refactor fakeruntime.js to clean up code and enhance Requests method for better response handling
1 parent 2acbc5a commit e86129a

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

public/fakeruntime.js

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,55 @@
11
window.runtime = {
22
WindowSetSystemDefaultTheme() {},
3-
EventsOnMultiple(id, fn) {
4-
console.log(id, fn)
5-
},
3+
EventsOnMultiple(id, fn) {},
64
WindowIsMaximised() {},
75
WindowIsMinimised() {},
8-
}
9-
10-
const events = {
11-
data: [],
12-
on() {},
13-
}
6+
};
147

158
window.go = {
169
bridge: {
1710
App: {
1811
UpdateTray() {},
1912
UpdateTrayMenus() {},
2013
GetEnv() {
21-
return { os: 'darwin' }
14+
return { os: "darwin" };
2215
},
2316
Readdir() {
24-
return { flag: true, data: '' }
17+
return { flag: true, data: "" };
2518
},
2619
IsStartup() {
27-
return true
20+
return true;
21+
},
22+
async Requests(method, url, headers, body, options) {
23+
const res = await fetch(url, {
24+
method,
25+
headers,
26+
body: ["HEAD", "GET"].includes(method) ? null : JSON.stringify(body),
27+
});
28+
let respBody;
29+
if (res.headers["Content-Type"]?.includes("application/json")) {
30+
respBody = await res.json();
31+
} else {
32+
respBody = await res.text();
33+
}
34+
return {
35+
flag: true,
36+
status: res.status,
37+
headers: res.headers,
38+
body: respBody,
39+
};
2840
},
29-
Requests() {},
3041
Writefile(path, content) {
31-
localStorage.setItem(path, content)
32-
return { flag: true }
42+
path = window.location.pathname + path;
43+
localStorage.setItem(path, content);
44+
return { flag: true };
3345
},
3446
Readfile(path) {
35-
return { flag: true, data: localStorage.getItem(path) }
47+
path = window.location.pathname + path;
48+
return { flag: true, data: localStorage.getItem(path) };
3649
},
3750
ExecBackground(path, args, out, end) {
38-
return { flag: true, data: 999 }
51+
return { flag: true, data: 999 };
3952
},
4053
},
4154
},
42-
}
55+
};

0 commit comments

Comments
 (0)