In my electron app there is a home page and a page where users can view videos. Now, the requirement is that if the app is idle (meaning the user is not interacting with the app and so no touch, mousemove etc. events are getting generated) for a fixed number of seconds, the app should by itself reload the homepage and a screensaver should start.
I have been able to achieve it using electron's powermonitor api.
The code snippet for this task is in the main process and is something like this:
.....setInterval(() => {
let idle_time_for_app = powerMonitor.getSystemIdleTime();
if (idle_time_for_app % 62 >= 60) {
mainWindow
.loadURL(
url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file",
slashes: true,
})
)
.then()...
In this example I have checked whether the idle-time is greater than 60 seconds.
Now, the problem is that, in the page where videos are available, the app gets redirected to the home page(index.html) even when a video is playing and the video length is greater than the fixed idle-time. The code statement
powerMonitor.getSystemIdleTime()
sees the
app as being in the idle state even when the video is playing.
I would like to avoid this thing. I want to put a check so that if a video is running in the app the the app should not get redirected to the home page(index.html). Is there a way to achieve it? Is there a way for the main process to detect whether any video is playing in the app? Please help.