Monday 9 November 2020

Quitting an electron app after setInterval() from external script file

Edited for more clarity.

I am trying to make a splash screen applet - to start learning nodejs and electron.

I want to create an applet that launches, shows some messages every 10 seconds, and then quits.

I'm basing it off the Discord app and Teams where they have pop up loading screens that have a progress bar, and once completed load the full application.

I want to know how to do it before the "load full app" portion kicks in and how to close the splash screen completely.

Currently I have an index.js, index.html, and a main.js.

index.js is the electron browser window. index.html is the main rendered page, and the main.js is the timer to switch the innerHTML based on the time from:

// main.js
var startTime       = 0,
    totalTime       = 10,
    timeBuffer      = 2,
    totalPercent    = 0,
    timeCounter     = setInterval( progress, 1000 );

function progress() {
    if( (startTime += 1) >= (totalTime + timeBuffer + 1) ) {
        // quit app (1)
    } else {
        // show messages here
    }
}

At point (1) in the code, I've tried adding in app.close(); but that fails since I haven't added in app. I tried adding it in but that doesn't work either.

I tried adding in:

// main.js
const { ipcRenderer } = require('electron');
ipcRenderer.send('close-me');

//index.js
ipcMain.on( 'close-me', (evt, arg) => {
    app.quit();
});

But this didn't work either. I'm still trying to understand the relationship between index.js and the other scripts you might write for the app - but thought quitting the app entirely would be easy.



from Quitting an electron app after setInterval() from external script file

No comments:

Post a Comment