Skip to content

API to inhibit screensaver #1936

Closed
Closed

Description

@Ivshti

The Chromium browser already has this functionality and it is enabled when playing video on the HTML5

Recently, a new project came along that solves the video playback issues (codec support, features) in Electron - RSATom/WebChimera.js.

However, since it is a binding to VLC which draws in WebGL, screensaver can still show and the computer can sleep.

We should have an API to inhibit the screensaver / computer sleeping for when video is played but not in the

Activity

  1. anaisbetts commented on Jun 11, 2015

    @anaisbetts
    Contributor

    I think you can probably just build this as a native node.js module, no need to add it to Electron's core API

  2. Ivshti commented on Jun 11, 2015

    @Ivshti
    ContributorAuthor

    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.

  3. anaisbetts commented on Jun 11, 2015

    @anaisbetts
    Contributor

    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.

  4. baconbrad commented on Jun 11, 2015

    @baconbrad
    Contributor

    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.

  5. Ivshti commented on Jun 12, 2015

    @Ivshti
    ContributorAuthor

    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.

  6. Ivshti commented on Jun 12, 2015

    @Ivshti
    ContributorAuthor

    @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 :)

  7. zcbenz commented on Jun 12, 2015

    @zcbenz
    Contributor

    @Ivshti Thanks for finding out that class. It looks good to me to add a built-in module for PowerSaveBlocker since it is already in Chromium.

  8. Ivshti commented on Jun 12, 2015

    @Ivshti
    ContributorAuthor

    Thanks @zcbenz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions