Re: Detect when the user logs out, and save state?



On Mon, Aug 26, 2013 at 4:29 AM, Guilhem Bonnefille
<guilhem bonnefille gmail com> wrote:
I'm not sure, but if your application is dedicated to gnome, why not
registering to session manager?

https://wiki.gnome.org/SessionManagement/GnomeSession

Other question: where is your code related to saving state? I do not see it
in your example.

Aha! Thank you for pointing me to that wiki page. I somehow had no
idea gnome-session was providing a special interface to clients like
that, and I actually didn't think to look.

In my GtkApplication subclass, I set the property "register-session"
to true, and now it seems to be listening to the EndSession signal and
responding appropriately. Neat! I can't say I trust it completely,
since the documentation for GtkApplication doesn't really mention that
it's going to do this, but it does work, so that's something :)

This is what that looks like:
https://github.com/DylanMcCall/gnome-break-timer/blob/master/helper/HelperApplication.vala

The state saving stuff is a bit ugly: it throws together a json object
and sticks it in the user's cache folder. When the application starts,
it reads from there again. json-glib actually has a really handy
gobject serialization thing built in, if you're interested, but it
didn't quite fit what I needed here so I ended up with my own weird
thing.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]