Coder Social home page Coder Social logo

Comments (7)

ztefn avatar ztefn commented on August 21, 2024 1

Unfortunately, the functionalty that Gtk.Application.inhibit provides is different from what Haguichi needs. Haguichi does not start any operation that should not be interrupted. It merely listens for a PrepareForSleep() signal and then says "Hold on, let me quickly disconnect the Hamachi client before going to sleep..." in order to close the connection cleanly. And later on, when waking up, the connection is restored again. See the code at: https://github.com/ztefn/haguichi/blob/master/src/inhibitor.vala

Still, I'd love to hear if you know any other Gtk api that does provide this functionality.

from haguichi.

danirabbit avatar danirabbit commented on August 21, 2024

Thanks for clarifying that! I don't know about that off the top of my head, but I'll ask around :)

from haguichi.

danirabbit avatar danirabbit commented on August 21, 2024

It looks like LibPortal might be the route to go here. It seems like it has methods here to watch the session state: https://github.com/flatpak/libportal/blob/master/libportal/inhibit.c#L655

Or you could manually use the inhibit portal over dbus as described here: https://docs.flatpak.org/en/latest/portal-api-reference.html#gdbus-org.freedesktop.portal.Inhibit

And that should let you drop the login dbus interface

from haguichi.

ztefn avatar ztefn commented on August 21, 2024

Relevant issue in xdg-desktop-portal: flatpak/xdg-desktop-portal#137

from haguichi.

ztefn avatar ztefn commented on August 21, 2024

Specific dbus interface to watch session state changes:
https://docs.flatpak.org/en/latest/portal-api-reference.html#gdbus-signal-org-freedesktop-portal-Inhibit.StateChanged

The StateChanged signal is sent to active monitoring sessions when the session state changes.

When the session state changes to 'Query End', clients with active monitoring sessions are expected to respond by calling QueryEndResponse() within a second of receiving the StateChanged signal. They may call Inhibit() first to inhibit logout, to prevent the session from proceeding to the Ending state.

Implementation in libportal appears to be Portal.session_monitor_start

When the state changes, the Portal:session-state-changed signal is emitted.

public signal void session_state_changed (bool screensaver_active, LoginSessionState session_state)

Emitted when session state monitoring is enabled and the state of the login session changes or the screensaver is activated or deactivated.

The values of this enum are returned in the Portal::session-state-changed signal to indicate the current state of the user session.

Enum values:
ENDING - the session is about to end
QUERY_END - the session is in the query end phase, during which applications can save their state or inhibit the session from ending
RUNNING - the session is running

from haguichi.

ztefn avatar ztefn commented on August 21, 2024

Implementation in GTK 3 (same in GTK 4, but documentation for prior version is more readable):
https://valadoc.org/gtk+-3.0/Gtk.Application.query_end.html

[ Version ( since = "3.24.8" ) ]
public signal void query_end ()

Emitted when the session manager is about to end the session, only if GtkApplication::register-session is true.

Applications can connect to this signal and call inhibit with gtk_application_inhibit_logout to delay the end of the session until state has been saved.

from haguichi.

ztefn avatar ztefn commented on August 21, 2024

Last few days I have tested both Gtk and LibPortal methods and it turned out inhibitors get totally ignored when the system is suspended by the user.

Also there are no QUERY_END or ENDING signals being sent when the system is suspended. Only logout and shutdown events seem to trigger those signals.

So unless the issue Inhibit portal and PrepareForSleep signal #137 in xdg-desktop-portal gets any traction I'm afraid we're stuck with using the org.freedesktop.login1 dbus interface, just like 50 other applications currently on flathub.

Please reopen or create a new issue when there is a proper replacement.

from haguichi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.