Skip to content

Commit 0677ad5

Browse files
committed
Introduce save/restore portal
1 parent 3374bc2 commit 0677ad5

10 files changed

+738
-0
lines changed

data/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ portal_sources = files(
2929
'org.freedesktop.portal.Realtime.xml',
3030
'org.freedesktop.portal.RemoteDesktop.xml',
3131
'org.freedesktop.portal.Request.xml',
32+
'org.freedesktop.portal.SaveRestore.xml',
3233
'org.freedesktop.portal.ScreenCast.xml',
3334
'org.freedesktop.portal.Screenshot.xml',
3435
'org.freedesktop.portal.Secret.xml',
@@ -61,6 +62,7 @@ portal_impl_sources = files(
6162
'org.freedesktop.impl.portal.Print.xml',
6263
'org.freedesktop.impl.portal.RemoteDesktop.xml',
6364
'org.freedesktop.impl.portal.Request.xml',
65+
'org.freedesktop.impl.portal.SaveRestore.xml',
6466
'org.freedesktop.impl.portal.ScreenCast.xml',
6567
'org.freedesktop.impl.portal.Screenshot.xml',
6668
'org.freedesktop.impl.portal.Secret.xml',
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Copyright Red Hat
4+
5+
SPDX-License-Identifier: LGPL-2.1-or-later
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library. If not, see <http://www.gnu.org/licenses/>.
19+
-->
20+
21+
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
22+
<!--
23+
org.freedesktop.impl.portal.SaveRestore:
24+
@short_description: Save/restore portal backend interface
25+
26+
The save/restore portal allows the session to coordinate with apps to
27+
implement a session-wide state save/restore feature.
28+
29+
Portal backends that implement this interface must implement at least
30+
version 2 of the :ref:`org.freedesktop.impl.portal.Session` interface.
31+
32+
This documentation describes version 1 of this interface.
33+
-->
34+
<interface name="org.freedesktop.impl.portal.SaveRestore">
35+
<!--
36+
Register:
37+
@session_handle: Object path for the ref:`org.freedesktop.impl.portal.Session` object representing the session being created
38+
@app_id: App id of the application
39+
@options: Vardict with optional further information
40+
@registration: Vardict directing the app how to restore its state. See :ref:`org.freedesktop.portal.SaveRestore.Register`
41+
42+
Registers an app with the save/restore API.
43+
44+
There are currently no supported keys in the @options vardict.
45+
46+
A note about instance IDs: the backend should make sure to incorporate
47+
information about the session (i.e. the name of the session manager and/or
48+
desktop environment) into the process that generates instance IDs. This
49+
allows apps that use instance IDs correctly to automatically support
50+
use-cases where people switch between different session types.
51+
-->
52+
<method name="Register">
53+
<arg type="o" name="session_handle" direction="in"/>
54+
<arg type="s" name="app_id" direction="in"/>
55+
<annotation name="org.qtproject.QtDBus.QtTypeName.In2" value="QVariantMap"/>
56+
<arg type="a{sv}" name="options" direction="in"/>
57+
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
58+
<arg type="a{sv}" name="registration" direction="out"/>
59+
</method>
60+
61+
<!--
62+
DiscardedInstanceIds:
63+
@session_handle: Object path for the :ref:`org.freedesktop.portal.Session` object
64+
@instance_ids: List of instance IDs the application discarded
65+
66+
Confirms that the caller has discarded the instance IDs, as requested by
67+
the ``discard-instance-ids`` value returned by
68+
:ref:`org.freedesktop.portal.impl.SaveRestore.Register`. The backend should
69+
finish discarding its internal tracking of the instance IDs once this is
70+
called.
71+
-->
72+
<method name="DiscardedInstanceIds">
73+
<arg type="o" name="session_handle" direction="in"/>
74+
<arg type="as" name="instance_ids" direction="in"/>
75+
</method>
76+
77+
<!--
78+
SaveHint:
79+
@session_handle: Object path for the :ref:`org.freedesktop.portal.Session` object
80+
81+
The SaveHint signal is sent to an app whenever the system thinks it
82+
would be a good moment for the app to save its state. The system should
83+
not be sending this regularly, but only in situations that might otherwise
84+
lead to data loss. For instance: this signal might be emitted before the
85+
whole system suspends, or before an individual app will be frozen and
86+
removed from the run queue to preserve resources, or before imminent
87+
system power loss.
88+
89+
Apps are expected to respond to this signal by calling
90+
:ref:`org.freedesktop.portal.impl.SaveRestore.SaveHintResponse` within
91+
3 seconds.
92+
-->
93+
<signal name="SaveHint">
94+
<arg type="o" name="session_handle" direction="out"/>
95+
</signal>
96+
97+
<!--
98+
SaveHintResponse:
99+
@session_handle: Object path for the :ref:`org.freedesktop.portal.Session` object
100+
101+
Acknowledges that the caller received the :ref:`org.freedesktop.impl.portal.SaveRestore::SaveHint`
102+
signal. This method should be called within 3 seconds of receiving the signal.
103+
-->
104+
<method name="SaveHintResponse">
105+
<arg type="o" name="session_handle" direction="in"/>
106+
</method>
107+
108+
<!--
109+
Quit:
110+
@session_handle: Object path for the :ref:`org.freedesktop.portal.Session` object
111+
112+
The Quit signal is sent to an app whenever the system decides to
113+
terminate the app to free up system resources (i.e. memory). The app
114+
should immediately save its state to disk and then exit cleanly, within
115+
3 seconds of receiving this signal. The app may be transparently restarted
116+
by the system at a later date.
117+
-->
118+
<signal name="Quit">
119+
<arg type="o" name="session_handle" direction="out"/>
120+
</signal>
121+
122+
<property name="version" type="u" access="read"/>
123+
</interface>
124+
</node>
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Copyright Red Hat
4+
5+
SPDX-License-Identifier: LGPL-2.1-or-later
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library. If not, see <http://www.gnu.org/licenses/>.
19+
-->
20+
21+
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
22+
<!--
23+
org.freedesktop.portal.SaveRestore:
24+
@short_description: Portal for coordinating app state save and restore
25+
26+
The SaveRestore interface allows the session to coordinate with applications
27+
to implement a session-wide state save/restore feature. Apps that can save
28+
their state to disk should register with this portal. In exchange, the system
29+
may restore session state after the session ends (i.e. after a reboot).
30+
It is not a portal in the strict sense, since it does not involve user
31+
interaction. Applications are expected to use this interface indirectly,
32+
via integration with their UI toolkit.
33+
34+
This documentation describes version 1 of this interface.
35+
-->
36+
<interface name="org.freedesktop.portal.SaveRestore">
37+
<!--
38+
Register:
39+
@options: Vardict with optional further information
40+
@session_handle: Object path for the created :ref:`org.freedesktop.portal.Session` object
41+
@registration: Vardict directing the app how to restore its state
42+
43+
Registers this app with the save/restore API. If the user logs out while
44+
the app is registered, the system will remember that this app was running
45+
and can relaunch it on next log-in. The app can then register itself again
46+
on next startup to be notified of what state (if any) it should restore.
47+
48+
During a clean shutdown, the app should close the created session using
49+
:ref:`org.freedesktop.portal.Session.Close`. If the app disconnects from
50+
the bus without closing the session first, the system will consider the
51+
shutdown unclean and will report this to the app on its next startup.
52+
53+
Supported keys in the @options vardict include:
54+
55+
* ``session_handle_token`` (``s``)
56+
57+
A string that will be used as the last element of the session handle. Must be a valid
58+
object path element. See the :ref:`org.freedesktop.portal.Session` documentation for
59+
more information about the session handle.
60+
61+
Supported keys in the @registration vardict include:
62+
63+
* ``instance-id`` (``s``)
64+
65+
A short alphanumeric string that identifies different instances of a
66+
multi-instance app. This allows multi-instance apps to keep the state
67+
of each instance separated. Single-instance apps should use this as
68+
well, because the system will return different identifiers when running
69+
different graphical sessions. For instance: if a user switches between
70+
GNOME and KDE regularly, even single-instance apps will need to save
71+
and load their state under different instance IDs.
72+
73+
* ``restore-reason`` (``u``)
74+
75+
Tells the app which state it needs to restore. Supported values:
76+
77+
- ``PRISTINE``: 0. The app should not attempt to restore any state.
78+
79+
- ``LAUNCH``: 1. This is a normal launch, so the app should restore
80+
some state (i.e. previous window size and position, default view on
81+
the home page) but it shouldn't attempt a full state restore. The
82+
exception is apps that have a preference that allows the user to
83+
decide if the app should always save and restore its state: if the
84+
user opts into this behavior, then it's permissible for the app to
85+
treat ``LAUNCH`` as equivalent to ``RESTORE``.
86+
87+
- ``RECOVER``: 2. This is the first launch after the app unexpectedly
88+
disconnected from the bus. The app should try to restore as much
89+
state as it can, but it should be careful to avoid crash loops. Apps
90+
can handle this by prompting users before attempting to restore state,
91+
or by strategically throwing away some state. For instance: a web
92+
browser may choose to restore open tabs but not restore the web
93+
content inside of each tab, instead showing a placeholder page and
94+
prompting the user to reload the tab. To support this feature
95+
properly, apps should periodically save their state while taking care
96+
to avoid unnecessary I/O. For instance: apps can flush their state
97+
to disk every 15 seconds, but only while the app is focused.
98+
99+
- ``RESTORE``: 3. The app should attempt to restore as much state as
100+
possible.
101+
102+
* ``discard-instance-ids`` (``as``)
103+
104+
A list of instance IDs (as above) that the system is done with and will
105+
no longer return to the app. The app should clean up any state it has
106+
associated with these IDs, and then report completion via
107+
:ref:`org.freedesktop.portal.SaveRestore.DiscardInstanceIdsResponse`.
108+
-->
109+
<method name="Register">
110+
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
111+
<arg type="a{sv}" name="options" direction="in"/>
112+
<arg type="o" name="session_handle" direction="out"/>
113+
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
114+
<arg type="a{sv}" name="registration" direction="out"/>
115+
</method>
116+
117+
<!--
118+
DiscardedInstanceIds:
119+
@session_handle: Object path for the :ref:`org.freedesktop.portal.Session` object
120+
@instance_ids: List of instance IDs the application discarded
121+
122+
Confirms that the caller has discarded the instance IDs, as requested by
123+
the ``discard-instance-ids`` value returned by
124+
:ref:`org.freedesktop.portal.SaveRestore.Register`. The system will finish
125+
discarding its internal tracking of the instance IDs once this is called.
126+
-->
127+
<method name="DiscardedInstanceIds">
128+
<arg type="o" name="session_handle" direction="in"/>
129+
<arg type="as" name="instance_ids" direction="in"/>
130+
</method>
131+
132+
<!--
133+
SaveHint:
134+
@session_handle: Object path for the :ref:`org.freedesktop.portal.Session` object
135+
136+
The SaveHint signal is sent to an app whenever the system thinks it
137+
would be a good moment for the app to save its state. In response, apps
138+
should immediately save their state and then respond with
139+
:ref:`org.freedesktop.portal.SaveRestore.SaveHintResponse`.
140+
141+
Note that apps should not be using this signal as the only reason to
142+
save their state. This signal will be emitted relatively rarely. Each
143+
app should periodically save its own state at moments where it makes
144+
sense for the app.
145+
-->
146+
<signal name="SaveHint">
147+
<arg type="o" name="session_handle" direction="out"/>
148+
</signal>
149+
150+
<!--
151+
SaveHintResponse:
152+
@session_handle: Object path for the :ref:`org.freedesktop.portal.Session` object
153+
154+
Acknowledges that the caller received the :ref:`org.freedesktop.portal.SaveRestore::SaveHint`
155+
signal. This method should be called within 3 seconds of receiving the signal.
156+
-->
157+
<method name="SaveHintResponse">
158+
<arg type="o" name="session_handle" direction="in"/>
159+
</method>
160+
161+
<!--
162+
Quit:
163+
@session_handle: Object path for the :ref:`org.freedesktop.portal.Session` object
164+
165+
The Quit signal is sent to an app whenever the system decides to
166+
terminate the app to free up system resources (i.e. memory). The app
167+
should immediately save its state to disk and then exit cleanly, within
168+
3 seconds of receiving this signal. The app may be transparently restarted
169+
by the system at a later date.
170+
-->
171+
<signal name="Quit">
172+
<arg type="o" name="session_handle" direction="out"/>
173+
</signal>
174+
175+
<property name="version" type="u" access="read"/>
176+
</interface>
177+
</node>

doc/api-reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ All apps have access to the portals below:
5959
doc-org.freedesktop.portal.Realtime.rst
6060
doc-org.freedesktop.portal.RemoteDesktop.rst
6161
doc-org.freedesktop.portal.Request.rst
62+
doc-org.freedesktop.portal.SaveRestore.rst
6263
doc-org.freedesktop.portal.ScreenCast.rst
6364
doc-org.freedesktop.portal.Screenshot.rst
6465
doc-org.freedesktop.portal.Secret.rst

doc/impl-dbus-interfaces.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ accessible to sandboxed applications.
2525
doc-org.freedesktop.impl.portal.Print.rst
2626
doc-org.freedesktop.impl.portal.RemoteDesktop.rst
2727
doc-org.freedesktop.impl.portal.Request.rst
28+
doc-org.freedesktop.impl.portal.SaveRestore.rst
2829
doc-org.freedesktop.impl.portal.ScreenCast.rst
2930
doc-org.freedesktop.impl.portal.Screenshot.rst
3031
doc-org.freedesktop.impl.portal.Secret.rst

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ xdg_desktop_portal_sources = files(
105105
'realtime.c',
106106
'registry.c',
107107
'remote-desktop.c',
108+
'save-restore.c',
108109
'screen-cast.c',
109110
'screenshot.c',
110111
'secret.c',

0 commit comments

Comments
 (0)