Skip to content

Commit 91e9e52

Browse files
committed
Force load page in a loop
1 parent 2410e51 commit 91e9e52

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
This will make portable folders that you can run to start the app
77

8-
TODO: document command line args
8+
TODO: document command line args, remove non-needed languages from electron in an auto zip script

main.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,26 @@ program.parse();
2626

2727
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');
2828

29-
function createWindow () {
29+
async function sleep(seconds) {
30+
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
31+
}
32+
33+
// Somwhow loadURL is a bit bugged, this seems to fix it on windows
34+
// https://github.com/electron/electron/issues/28208#issuecomment-1129612599
35+
async function attemptLoad(win, view) {
36+
let loaded = false;
37+
38+
do {
39+
try {
40+
await win.loadURL(`http://localhost:9090/bundles/nodecg-vdoninja/graphics/${view}-view/main.html`);
41+
loaded = true;
42+
} catch (err) {
43+
await sleep(5);
44+
}
45+
} while (!loaded);
46+
}
47+
48+
async function createWindow () {
3049
const { view, roomType } = program.opts();
3150
const titleInfo = [
3251
roomType || null
@@ -55,16 +74,19 @@ function createWindow () {
5574
event.preventDefault();
5675
});
5776

58-
win.loadURL(`http://localhost:9090/bundles/nodecg-vdoninja/graphics/${view}-view/main.html`).catch(console.error);
77+
await attemptLoad(win, view);
78+
// Still nothing? Try again after 10 seconds
79+
await sleep(10);
80+
await attemptLoad(win, view);
5981
}
6082

6183
app.whenReady().then(() => {
62-
createWindow();
84+
createWindow().catch(console.log);
6385

6486
// Specific macos stuff, doubt we ever need this.
65-
app.on('activate', () => {
87+
app.once('activate', () => {
6688
if (BrowserWindow.getAllWindows().length === 0) {
67-
createWindow();
89+
createWindow().catch(console.log);
6890
}
6991
});
7092
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vdon-viewer",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Bypassing autoplay restrictions with electron",
55
"main": "main.js",
66
"scripts": {

0 commit comments

Comments
 (0)