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

Added a pending application service example.

parent 3a223f8c
# Example 29 - Application Service
This example shows how to supply a service file with an application so that
other applications, such as file managers, can use it to handle certain types
of files.
## Building the application
Because the application needs to be installed in a standard location for the
desktop file to work correctly, the example includes build files for use with
the [Meson](https://mesonbuild.com) build system. Enter the `29-app-service`
directory and configure the build with the following command:
``` bash
meson . _build
```
This should produce a directory called `_build` which will contain the build
products. Now run the [Ninja](https://ninja-build.org) tool to actually build
the application:
``` bash
ninja -C _build
```
Install it to a standard system location with the following command:
``` bash
ninja -C _build install
```
When no longer needed, the application can be uninstalled like this:
``` bash
ninja -C _build uninstall
```
## Running the application
By default, the application will be installed in the directory structure
within the `/usr/local` directory. It should be possible to run the executable
`/usr/local/bin/29-app-service` from the command line.
Alternatively, if you open the `/usr/local/share/applications` directory in a
file manager you should be able to see the `com.example.29-app-service.desktop`
file. This should have the icon that we assigned to it. The desktop file can be
run directly or it can be copied to a suitable place in your desktop
environment (such as a panel or launcher) where it can be used to launch the
application.
## Activating the application
Run the application with the following options:
```
ex29_app_service --gapplication-service &
```
Once the application has been run, it can be activated via D-Bus using the
`org.gtk.Application.Open` interface. For example, here is one way to interact
with it using the `gdbus` command line tool:
``` bash
gdbus call --session --dest com.example.ex29_app_service --object-path /com/example/ex29_app_service --method org.gtk.Application.Open "['https://www.puri.sm/']" "view" "{}"
```
[Desktop Entry]
Name=Example 29 App Service
Icon=com.example.29-app-service
Exec=29-app-service
DBusActivatable=true
Terminal=false
Type=Application
Categories=
StartupNotify=false
[D-BUS Service]
Name=com.example.ex29_app_service
Exec=29-app-service --gapplication-service
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg" height="64" version="1.1" width="64"
viewBox="0 0 100 100">
<rect x="0" y="0" width="100" height="100" stroke="none" fill="#8080c0" />
<rect x="0" y="60" width="100" height="40" stroke="none" fill="#80c080" />
<circle cx="70" cy="30" r="20" stroke="none" fill="#c0c080" />
</svg>
configure_file(
input: 'com.example.ex29_app_service.desktop',
output: 'com.example.ex29_app_service.desktop',
copy: true,
install: true,
install_dir: join_paths(get_option('datadir'), 'applications')
)
configure_file(
input: 'com.example.ex29_app_service.service',
output: 'com.example.ex29_app_service.service',
copy: true,
install: true,
install_dir: join_paths(get_option('datadir'), 'dbus-1', 'services')
)
install_data ('com.example.ex29_app_service.svg',
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', 'scalable', 'apps'))
# Install the service file.
project('29-app-service',
version: '0.1.0',
meson_version: '>= 0.48.0',
)
subdir('data')
subdir('src')
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2018 Purism SPC
# SPDX-License-Identifier: GPL-3.0+
# Author: David Boddie <david.boddie@puri.sm>
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, GLib, Gtk
class Application(Gtk.Application):
def __init__(self):
super().__init__(
application_id='com.example.ex29_app_service',
flags=Gio.ApplicationFlags.HANDLES_OPEN
)
GLib.set_application_name('App Service example')
def _common(self):
window = Gtk.ApplicationWindow(application=self)
self.box = Gtk.Box(orientation='vertical')
window.add(self.box)
window.set_icon_name('com.example.29-app-service')
window.show_all()
def do_activate(self):
self._common()
label = Gtk.Label(label='Hello World!')
self.box.add(label)
def do_open(self, files, hint, info):
self._common()
print('Files:', files)
print('Hint:', hint)
print('Info:', info)
for file_name in files:
label = Gtk.Label(label=file_name.get_uri())
self.box.add(label)
self.box.show_all()
if __name__ == "__main__":
app = Application()
result = app.run(sys.argv)
sys.exit(result)
configure_file(
input: 'main.py',
output: '29-app-service',
copy: true,
install: true,
install_dir: get_option('bindir')
)
Markdown is supported
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