You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inhibiting the screensaver is a platform-specific operation, on Linux there are two different ways that have to be supported (dbus and xdg), on Mac OS X and Windows there are native APIs.
This is complicated enough, and would add a compiled module.
On the other hand, the functionality is embedded somewhere in libchromium. Definitely the better solution.
I actually think it is the best approach, because it doesn't require integrating with Chromium in any way
Inhibiting the screensaver is a platform-specific operation
I don't know how this would be any different in a node module vs in Electron. You'll have #ifdefs either way
On the other hand, the functionality is embedded somewhere in libchromium
As far as I can see, this isn't true - the only place I see where you can inhibit the screensaver is in the Pepper Flash host, and it's a one-off Windows only thing. The cross-platform support for screensavers in Chromium seems to only be to query whether it's running or not.
You don't need a native API to do this. You can detect the OS to do the appropriate work around by passing a shell command. All of which is supported by node out of the box.
Such as XDG for linux: xdg-screensaver suspend [window id]
Look for stderr output to see if it didn't take and do dbux instead:
dbus-send --session \
--dest=org.gnome.ScreenSaver \
--type=method_call \
--print-reply \
--reply-timeout=20000 \
/org/gnome/ScreenSaver \
org.gnome.ScreenSaver.Inhibit \
[application name e.g. ""] \
[reason e.g."playing a game"] \
[non-zero-random-integer e.g. 123]
On Windows you can disable it on video start: reg add “HKEY_CURRENT_USERControl PanelDesktop” /v ScreenSaveActive /t REG_SZ /d 0 /f
And then disable it on video end: reg add “HKEY_CURRENT_USERControl PanelDesktop” /v ScreenSaveActive /t REG_SZ /d 1 /f
I am sure there are classier ways for the ones listed and even more ways for other platforms that might be out there. I found these with a quick Google search. A little bit of research/code you could rig all this into a node package with ease. Most native applications that need to inhibit screensavers do similar methods. So I don't see how doing it from a node module would not be a good approach.
As far as I can see, this isn't true - the only place I see where you can inhibit the screensaver is in the Pepper Flash host, and it's a one-off Windows only thing. The cross-platform support for screensavers in Chromium seems to only be to query whether it's running or not.
What about the <video> tag? It inhibits the screensaver perfectly on every OS.
@baconface this seems like a stable solution for Linux. As for Windows, what will happen if the app quits unexpectedly? Will the screensaver stay disabled forever?
On OS X, the two options are pmset noidle and modifying the plist. I don't know the side effects that both have.
This is doable, but as I said, platform specific and those solutions might have side effects. That's why I'd prefer a stable (as possible) solution, but if there's no easy way to expose this I guess a node.js module would be best.
@baconface Indeed, the Windows solution is not viable. It modifies settings essentially. The proper way is setting thread execution state flag ES_DISPLAY_REQUIRED, which cannot be done without native code.
Currently it looks like we have viable solutions for OS X and Linux but we don't for world's most popular desktop OS :)
Activity
anaisbetts commentedon Jun 11, 2015
I think you can probably just build this as a native node.js module, no need to add it to Electron's core API
Ivshti commentedon Jun 11, 2015
This is definitely not the best approach.
Inhibiting the screensaver is a platform-specific operation, on Linux there are two different ways that have to be supported (dbus and xdg), on Mac OS X and Windows there are native APIs.
This is complicated enough, and would add a compiled module.
On the other hand, the functionality is embedded somewhere in libchromium. Definitely the better solution.
anaisbetts commentedon Jun 11, 2015
I actually think it is the best approach, because it doesn't require integrating with Chromium in any way
I don't know how this would be any different in a node module vs in Electron. You'll have #ifdefs either way
As far as I can see, this isn't true - the only place I see where you can inhibit the screensaver is in the Pepper Flash host, and it's a one-off Windows only thing. The cross-platform support for screensavers in Chromium seems to only be to query whether it's running or not.
baconbrad commentedon Jun 11, 2015
You don't need a native API to do this. You can detect the OS to do the appropriate work around by passing a shell command. All of which is supported by node out of the box.
Such as XDG for linux:
xdg-screensaver suspend [window id]Look for stderr output to see if it didn't take and do dbux instead:
On Windows you can disable it on video start:
reg add “HKEY_CURRENT_USERControl PanelDesktop” /v ScreenSaveActive /t REG_SZ /d 0 /fAnd then disable it on video end:
reg add “HKEY_CURRENT_USERControl PanelDesktop” /v ScreenSaveActive /t REG_SZ /d 1 /fI am sure there are classier ways for the ones listed and even more ways for other platforms that might be out there. I found these with a quick Google search. A little bit of research/code you could rig all this into a node package with ease. Most native applications that need to inhibit screensavers do similar methods. So I don't see how doing it from a node module would not be a good approach.
Ivshti commentedon Jun 12, 2015
What about the
<video>tag? It inhibits the screensaver perfectly on every OS.@baconface this seems like a stable solution for Linux. As for Windows, what will happen if the app quits unexpectedly? Will the screensaver stay disabled forever?
On OS X, the two options are
pmset noidleand modifying the plist. I don't know the side effects that both have.This is doable, but as I said, platform specific and those solutions might have side effects. That's why I'd prefer a stable (as possible) solution, but if there's no easy way to expose this I guess a node.js module would be best.
Ivshti commentedon Jun 12, 2015
@baconface Indeed, the Windows solution is not viable. It modifies settings essentially. The proper way is setting thread execution state flag ES_DISPLAY_REQUIRED, which cannot be done without native code.
Currently it looks like we have viable solutions for OS X and Linux but we don't for world's most popular desktop OS :)
Ivshti commentedon Jun 12, 2015
This is the power save blocker in Chromium: https://code.google.com/p/chromium/codesearch#search/&q=PowerSaveBlockerImpl&sq=package:chromium&type=cs
This is how it's used -> https://code.google.com/p/chromium/codesearch#chromium/src/content/browser/web_contents/web_contents_impl.cc&sq=package:chromium&type=cs&rcl=1434079984&l=3149
And here is how it's invoked -> https://code.google.com/p/chromium/codesearch#chromium/src/content/browser/web_contents/web_contents_impl.cc&q=WebContentsImpl::OnMediaPlayingNotification&sq=package:chromium&type=cs&l=3175
There should be an easy way to integrate that in Electron, and this is easier, more elegant and most importantly - more robust than a node.js module.
zcbenz commentedon Jun 12, 2015
@Ivshti Thanks for finding out that class. It looks good to me to add a built-in module for
PowerSaveBlockersince it is already in Chromium.Ivshti commentedon Jun 12, 2015
Thanks @zcbenz