Skip to content

Commit

Permalink
Force load page in a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Nov 16, 2024
1 parent 2410e51 commit 91e9e52
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

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

TODO: document command line args
TODO: document command line args, remove non-needed languages from electron in an auto zip script
32 changes: 27 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,26 @@ program.parse();

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

function createWindow () {
async function sleep(seconds) {
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
}

// Somwhow loadURL is a bit bugged, this seems to fix it on windows
// https://github.com/electron/electron/issues/28208#issuecomment-1129612599
async function attemptLoad(win, view) {
let loaded = false;

do {
try {
await win.loadURL(`http://localhost:9090/bundles/nodecg-vdoninja/graphics/${view}-view/main.html`);
loaded = true;
} catch (err) {
await sleep(5);
}
} while (!loaded);
}

async function createWindow () {
const { view, roomType } = program.opts();
const titleInfo = [
roomType || null
Expand Down Expand Up @@ -55,16 +74,19 @@ function createWindow () {
event.preventDefault();
});

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

app.whenReady().then(() => {
createWindow();
createWindow().catch(console.log);

// Specific macos stuff, doubt we ever need this.
app.on('activate', () => {
app.once('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
createWindow().catch(console.log);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vdon-viewer",
"version": "1.0.0",
"version": "1.1.0",
"description": "Bypassing autoplay restrictions with electron",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 91e9e52

Please sign in to comment.