3_Developer_Guides: add new app framework documentation
[AGL/documentation.git] / docs / 3_Developer_Guides / 3_Creating_a_New_Application.md
1 ---
2 title: Creating a New Application
3 ---
4
5 Applications are either software designed to perform a specific task during a limited amount of
6 time, or graphical applications presenting the user with an interface they can interact with.
7
8 Such applications are executed by `applaunchd`, the AGL
9 [application launcher service](1_Application_Framework/2_Application_Startup/).
10
11 # Basic requirements
12
13 In order to be enumerated by `applaunchd`, applications must provide the a `.desktop` file, as
14 defined by the [Desktop Entry specification](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html).
15
16 The desktop entry file should be installed to `/usr/share/applications` (or the `applications`
17 sub-directory of any entry present in the `XDG_DATA_DIRS` environment variable) and have a
18 meaningful name. It is considered good practice to use reverse-DNS notation for the desktop
19 entry file name, following the recommendations of the [D-Bus specification](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names):
20 - this avoids potential name collisions with other desktop entry files
21 - it makes it easier to enable [D-Bus activation](#d-bus-activation) during the application
22   development cycle if needed
23 - for [graphical applications](#graphical-applications), it ensures the chosen Wayland `app-id`
24   will be unique
25
26 Such a file must contain at least the following keys:
27 - `Type`: desktop entry type, must be set to `Application`
28 - `Name`: application name, as it should be displayed in menus and application launchers
29 - `Exec`: full path to the main executable
30
31 Below is an example of a minimal desktop entry file:
32
33 ```
34 [Desktop Entry]
35 Type=Application
36 Name=Example Application
37 Exec=/usr/bin/example-app
38 ```
39
40 Graphical applications must also provide an `Icon` entry pointing to the application icon.
41 The value for this entry must either be the full path to the icon's file or, for icons part
42 of an existing [icon theme](https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html),
43 the name of an element of this theme.
44
45 In addition, a number of optional fields can be used to change how `applaunchd` will consider the
46 application:
47 - `Version`: version of the Desktop Entry Specification the file conforms to, must be `1.5`
48 - `Hidden`: boolean value, if `true` the application is always ignored by `applaunchd` and
49   won't be listed nor executed
50 - `Terminal`: boolean value, if `true` the application is excluded when requesting the list of
51   graphical applications from `applaunchd`
52 - `DBusActivatable`: boolean value, must be `true` for [D-Bus activated applications](#d-bus-activation)
53 - `Implements`: list of D-Bus interfaces the application implements, only used for D-Bus activated
54   applications.
55
56 Finally, graphical applications may also define the `StartupWMClass` key in some cases. Please
57 refer to the [graphical applications](#graphical-applications) section for more information.
58
59 # D-Bus activation
60
61 Similarly to [services](2_Creating_a_New_Service.md/#d-bus-activation), applications can
62 also be activated through D-Bus.
63
64 Such applications must name their `.desktop` file after the D-Bus name they register. In addition,
65 this file must contain the following entries:
66
67 ```
68 DBusActivatable=true
69 Implements=IFACE1;IFACE2;...
70 ```
71
72 Where `IFACEn` are the names of the D-Bus interfaces the application implements.
73
74 In addition, they must provide a D-Bus service file named `NAME.service` and installed
75 to `/usr/share/dbus-1/services`.
76
77 The contents of the D-Bus service file must be the following:
78
79 ```
80 [D-BUS Service]
81 Name=NAME
82 Exec=/path/to/executable
83 ```
84
85 For example, an application registering the `org.automotivelinux.Example` D-Bus name
86 and implementing the `org.automotivelinux.Example.Search1` and `org.automotivelinux.Example.Execute1`
87 interfaces would provide the following files:
88
89 * Desktop entry (`/usr/share/applications/org.automotivelinux.Example.desktop`):
90
91 ```
92 [Desktop Entry]
93 Type=Application
94 Version=1.5
95 Name=Example Application
96 Exec=/usr/bin/example-app
97 Icon=example-icon
98 Terminal=false
99 DBusActivatable=true
100 Implements=org.automotivelinux.Example.Search1;org.automotivelinux.Example.Execute1
101 ```
102
103 * D-Bus service file (`/usr/share/dbus-1/services/org.automotivelinux.Example.service`):
104
105 ```
106 [D-BUS Service]
107 Name=org.automotivelinux.Example
108 Exec=/usr/bin/example-app
109 ```
110
111 *Note: in addition to their own D-Bus interface, D-Bus activated applications must also
112 implement the `org.freedesktop.Application` interface as defined in the
113 [Desktop Entry specification](https://specifications.freedesktop.org/desktop-entry-spec/1.1/ar01s07.html).*
114
115 # Graphical applications
116
117 In addition, graphical applications need to comply with a few more requirements:
118
119 1. Each application must set a Wayland application ID appropriately as soon as its main window
120 is created.
121
122 2. The `app-id` must be specified in the desktop entry file by adding the following line:
123
124 ```
125 StartupWMClass=APP_ID
126 ```
127
128 3. The desktop entry file must be named `APP_ID.desktop`.
129
130 Doing so will ensure other software can associate the actual `app-id` to the proper application.
131
132 *Note: application ID's are set using the [XDG toplevel](https://wayland-book.com/xdg-shell-basics/xdg-toplevel.html)
133 Wayland interface.*