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