Skip to content

Commit cb4102d

Browse files
Update plugin readme
1 parent 2056ae4 commit cb4102d

File tree

1 file changed

+40
-31
lines changed

1 file changed

+40
-31
lines changed

README.md

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,49 @@ Details may change every now and then anyway.
1717
## CMake
1818

1919
A native plugin is a [Qt Plugin](https://doc.qt.io/qt-6/plugins-howto.html#the-low-level-api-extending-qt-applications), i.e. a shared library providing a particular interface.
20-
To build such a library you have to define CMake targets and create an appropiate metadata file.
21-
The [CMake module](https://raw.githubusercontent.com/albertlauncher/albert/master/cmake/albert-macros.cmake) provides convenience macros for this purpose.
22-
You should probably skim through this module once.
23-
The `albert_plugin` macro should be sufficient for most trivial plugins:
20+
Albert uses CMake and provides convenient macros, most notably the `albert_plugin` macro, you can utilize to get started without having to write a lot of CMake boilerplate code.
21+
Read the documentation header of the [CMake module](https://raw.githubusercontent.com/albertlauncher/albert/master/cmake/albert-macros.cmake) before you proceed.
22+
23+
This basic CMakeLists.txt is sufficient to build a basic plugin without dependencies and translations:
2424

2525
```cmake
26-
albert_plugin (
27-
NAME name
28-
DESCRIPTION description
29-
LICENSE licencse
30-
URL url
31-
[LONG_DESCRIPTION long_description]
32-
[FRONTEND]
33-
[MAINTAINERS ...]
34-
[QT_DEPENDENCIES ...]
35-
[LIB_DEPENDENCIES ...]
36-
[EXEC_DEPENDENCIES ...]
26+
project(my_plugin VERSION 1.0)
27+
albert_plugin(
28+
SOURCE_FILES
29+
src/*
3730
)
3831
```
3932

33+
Unless you specify `METADATA` in the `albert_plugin` macro, a metadata file is expected to be found at `metadata.json`.
34+
35+
Supported metadata keys:
36+
4037

41-
| Parameter | Type | Notes |
42-
|------------------:|:------:|---|
43-
| NAME | value | Human readable name. |
44-
| DESCRIPTION | value | Brief, imperative description, e.g. "Open files". |
45-
| LICENSE | value | Short form, e.g. BSD-2-Clause or GPL-3.0. |
46-
| URL | value | Browsable online source, issues etc. |
47-
| LONG_DESCRIPTION | value | Longer description or absolute file path to a text file (supports Markdown). |
48-
| MAINTAINERS | list | A list of active maintainers. Preferrably using mentionable GitHub usernames. |
49-
| QT_DEPENDENCIES | list | Qt dependencies to import and link. Qt::Core is in the public interface of libalbert. |
50-
| LIB_DEPENDENCIES | list | Required libraries. Displayed to the user. |
51-
| EXEC_DEPENDENCIES | list | Required executables. Displayed to the user. |
52-
| FRONTEND | option | Indicates that this plugin implements the frontend interface. |
53-
| NOUNLOAD | option | Prohibits unloading at runtime. |
38+
| Parameter | Type | Notes |
39+
|---------------------:|:------------:|---------------------------------------------------------------------------|
40+
| id | | Reserved. Added by CMake. |
41+
| version | | Reserved. Added by CMake. |
42+
| name | local string | Human readable name. |
43+
| description | local string | Brief, imperative description, e.g. "Open files". |
44+
| license | string | SPDX license identifier. E.g. BSD-2-Clause, MIT, LGPL-3.0-only, … |
45+
| url | string | Browsable online source code, issues etc. |
46+
| authors | string list | List of copyright holders. Preferably using mentionable GitHub usernames. |
47+
| runtime_dependencies | string list | Default: `[]`. Required libraries. |
48+
| binary_dependencies | string list | Default: `[]`. Required executables. |
49+
| credits | string list | Default: `[]`. Attributions, mentions, third party library licenses, … |
50+
| loadtype | string | Default: `user`. One `frontend`, `nounload`, `user`. |
5451

52+
A basic metadata file looks like this:
5553

54+
```json
55+
{
56+
"name": "My Plugin",
57+
"description": "Do useful stuff",
58+
"authors": ["@myname"],
59+
"license": "MIT",
60+
"url": "https://github.com/myusername/my-albert-plugin",
61+
}
62+
```
5663
## C++
5764

5865
On the C++ side you have to tell the Qt MOC which interface the plugin implements and where the metadata is located.
@@ -69,10 +76,13 @@ By now you should understand a plugin class declaration like this:
6976
#include "albert/extension/queryhandler/triggerqueryhandler.h"
7077
#include "albert/plugin.h"
7178

72-
class Plugin : public albert::plugin::ExtensionPlugin<albert::TriggerQueryHandler>
79+
class Plugin : public albert::plugin::ExtensionPlugin,
80+
public albert::TriggerQueryHandler
7381
{
7482
Q_OBJECT ALBERT_PLUGIN
75-
...
83+
public:
84+
std::vector<albert::RankItem> handleGlobalQuery(const GlobalQuery*) const override;
85+
QWidget *buildConfigWidget() override;
7686
};
7787
```
7888

@@ -85,7 +95,6 @@ See
8595

8696
Self explanatory examples serve way better as educational source than hundreds of lines of text.
8797
See the [official native plugins](https://github.com/albertlauncher/plugins/tree/master/) as a reference.
88-
The `debug`, `template` and `hash` plugins are good plugins to start reading.
8998

9099
Finally you may want to skim through the entire [albert namespace](https://albertlauncher.github.io/reference/namespacealbert.html).
91100

0 commit comments

Comments
 (0)