Commit a49408fd authored by David Boddie's avatar David Boddie 💬
Browse files

Merge branch 'permissions' into 'master'

Start a guide to sandbox permissions

Closes #73

See merge request Librem5/!209
parents 46f0d5be 0c3b9dc3
Pipeline #5462 passed with stages
in 10 minutes and 31 seconds
......@@ -44,7 +44,7 @@ Adaptive Labels
A GtkLabel_ can prevent your application's UI from reaching really small sizes, but there are simple tricks to make them do so. Consider using one of the following tricks on each of your labels!
Allowing your label to ellipsize will cut a part of your string when there isn't enough space for it, you can enable it and choose which part will be cut with the `GtkLabel ellipize property`_. Use it if you really need your label to be on a single line.
Allowing your label to ellipsize will cut a part of your string when there isn't enough space for it, you can enable it and choose which part will be cut with the `GtkLabel ellipsize property`_. Use it if you really need your label to be on a single line.
.. note:: If you allow your label to be ellipsized, make sure that its `xalign property <GtkLabel xalign property_>`_ matches its justification or your label may not be properly aligned when ellipsized: 0 for left, 1 for right, or 0.5 for center.
.. _gnome_settings:
Settings, User Data and Files
Applications access three kinds of information from the user's account: settings, user data and files. These hold three different kinds of information.
Settings hold information about the way the user has configured an application, such as the font size, window size or theme. This information is typically about the application itself or metadata that describes data produced by the application.
GNOME applications access their settings using the GSettings_ class. This stores data in a suitable directory in the user's home directory. Applications distributed as flatpaks require permissions to be granted in order to access the user's settings. See the :ref:`flatpak_app_permissions_guide` guide for details.
.. _gnome_settings_user_data:
User Data
Some applications prefer to store data that the user has created or imported in a special data directory set aside for the application.
Simple data can be accessed using keyfiles that record pieces of information as key-value pairs. Access to a suitable data directory is obtained using the `GLib.get_user_data_dir() <g_get_user_data_dir_>`_ function. The GKeyFile_ class is used to read and write keyfiles stored in a subdirectory of the data directory.
.. Include a snippet of this from the treasure example
More complex and larger data is also included in the user data directories by applications where it does not necessarily make sense for the user to decide where their data should be stored. These applications function like appliances, hiding the details of data storage, or using different ways to refer to user data than applications using the traditional *Open*, *Load* and *Save* actions.
Applications distributed as flatpaks do not need to request permissions in order to access user data stored in a data directory that has been set aside for that purpose.
Traditional applications can load and save files from arbitrary directories as long as the user has permission to access them. For types of files that can be opened by many different applications, such as music and video files, it is common to find that directories have been set aside for these files in the user's home directory. The `XDG Base Directory Specification`_ describes how these directories are organized.
Some applications rely on finding data files in these standard locations, though they may also allow the user to select files from elsewhere, like traditional applications. These obtain the directory to access via the ``GLib.get_user_special_dir`` function, passing one of the ``Glib.UserDirectory`` values given in the table below.
=========================== ====================================================
**Directory** **Contents**
=========================== ====================================================
``DIRECTORY_DOCUMENTS`` Documents, such as text or word processing files
``DIRECTORY_DOWNLOAD`` Files downloaded by applications
``DIRECTORY_MUSIC`` Music files
``DIRECTORY_PICTURES`` Pictures and photographs
``DIRECTORY_VIDEOS`` Movies and videos
=========================== ====================================================
The photographs and videos taken by the camera are stored in the directories represented by ``DIRECTORY_PICTURES`` and ``DIRECTORY_VIDEOS`` respectively.
A more complete list of directories that can be accessed is provided in the `XDG Base Directory Specification`_ document.
.. Provide an example showing how to obtain the directory.
An application distributed as a flatpak needs to declare permissions in the ``finish-args`` entry of its manifest to be able to access these directories. The following table shows which permission corresponds to each directory, as described by the table above.
=================================== =======================
**Directory** **Flatpak Permission**
=================================== =======================
``DIRECTORY_DOCUMENTS`` ``--xdg-documents``
``DIRECTORY_DOWNLOAD`` ``--xdg-download``
``DIRECTORY_MUSIC`` ``--xdg-music``
``DIRECTORY_PICTURES`` ``--xdg-pictures``
``DIRECTORY_VIDEOS`` ``--xdg-videos``
=================================== =======================
See the :ref:`flatpak_app_permissions_guide` for a more complete description of permissions, and consult the `Sandbox Permissions`_ section of the Flatpak documentation for a more extensive list of permissions.
.. include:: /links.txt
......@@ -18,12 +18,14 @@ a typical GNOME development environment. The following sections cover use of
these tools in more detail.
.. toctree::
:maxdepth: 1
.. include:: /links.txt
"app-id": "com.example.some_example",
"runtime": "org.gnome.Platform",
"runtime-version": "3.32",
"sdk": "org.gnome.Sdk",
"command": "my-program",
"finish-args": [
.. _flatpak_app_permissions_guide:
Application Permissions
.. |br| raw:: html
<br />
When an application is distributed as a flatpak it needs permission to access
certain features on the phone, such as using the network, or reading and
writing the user's files. This is done by requesting permissions in the Flatpak
manifest file.
The permissions required by an application are included in the ``finish-args``
entry of its manifest. The following example shows the first part of a manifest
for an application that uses the display and maintains user-specific settings:
.. literalinclude:: _files/example.json
:language: json
Some tasks can be performed without the need to request permissions. For
example, each application can store and retrieve user data in its own private
area. This mechanism for storing persistent data is described in the section
about :ref:`gnome_settings_user_data`.
Permissions for Common Features
The table below shows the permissions that correspond to some common features
used by applications.
======================================= ================================================
Feature Flatpak Permissions
======================================= ================================================
Display a graphical user interface ``--socket=wayland``
Access the Internet using sockets ``--share=network``
Access settings (GNOME applications) ``--filesystem=~/.config/dconf:ro`` |br|
``--talk-name=ca.desrt.dconf`` |br|
Access Bluetooth devices ``--allow=bluetooth``
Read and write user's documents ``--xdg-documents``
Read and write user's downloads ``--xdg-download``
Read and write user's music ``--xdg-music``
Read and write user's pictures ``--xdg-pictures``
Read and write user's videos ``--xdg-videos``
======================================= ================================================
A more detailed description of permissions is given in the `Sandbox Permissions`_
section of the Flatpak documentation, which also contains a more extensive list.
.. include:: /links.txt
......@@ -11,6 +11,7 @@ to encounter. We aim to add more guides to this collection over time.
:maxdepth: 1
......@@ -12,29 +12,40 @@
.. _`Flatpak Building Introduction`:
.. _`Flatpak debugging documentation`:
.. _`Flatpak documentation`:
.. _`Freedesktop quick reference`:
.. _`Gio.GApplication documentation`:
.. _`git-buildpackage`:
.. _`GKeyFile`:
.. _`Glade`:
.. _`Glade Tutorials`:
.. _`glib-compile-resources`:
.. _`g_get_user_data_dir`:
.. _`GMenu`:
.. _`GNOME API Reference`:
.. _`GNOME Builder`:
.. _`GNOME Builder documentation`:
.. _`GNOME git client`:
.. _`GNOME`:
.. _`GNOME Human Interface Guidelines`:
.. _`The GNU Privacy Handbook`:
.. _`GResource`:
.. _`GSettings`:
.. _`GSimpleAction`:
.. _`GTK+ 3 documentation`:
.. _`GtkApplicationWindow`:
.. _GtkButton :
.. _GtkHeaderBar :
.. _`GTK+ Inspector`:
.. _GtkLabel ellipize property :
.. _GtkLabel ellipsize property :
.. _GtkLabel :
.. _GtkLabel wrap-mode property :
.. _GtkLabel wrap property :
.. _GtkLabel xalign property :
.. _GtkMenuButton:
.. _GtkSeparator :
.. _GtkScrolledWindow :
.. _GtkSizeGroup :
.. _GtkToolButton :
.. _`GTK+ toolkit`:
.. _`GTK+ website`:
.. _HdyHeaderGroup :
......@@ -70,7 +81,9 @@
.. _`Qt Quick`:
.. _`Qt Quick Controls 2`:
.. _`Running GTK+ Applications`:
.. _`Sandbox Permissions`:
.. _`Scalable Vector Graphics`:
.. _`XDG Base Directory Specification`:
.. _`FH34SRJ-6S-0.5SH(50) (Touch)`:
.. _`74LVC2G241DC,125`:
......@@ -7,3 +7,6 @@
# from gi.repository import GLib, Gtk
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment