refactor(tree): split the plugin host from the providers it loads

plugins/ held two unrelated things: the host that discovers and installs
plugins, and the plugins themselves. The host moves to plugins/ with the
built-in pacman provider beside it in providers/, where the external
providers already live — so plugins/ is now one thing, and the name says
which.

The external plugin projects only change folder, not layout: providers/
holds aur-provider, flatpak-provider, example-provider and example-addon.
This commit is contained in:
BlackAngelTV committed 2026-09-29 21:25:34 +02:00
1 parent 2395ba3f17
commit c63b231778
15 files changed
+39 -39

No files matched your search

+127
View File
@@ -0,0 +1,127 @@
#pragma once
#include <QObject>
#include <QString>
#include <vector>
#include "zip-archive.h"
// A plugin package (.fwspacm): a ZIP archive holding a plugin and the manifest
// describing it.
//
// The package is built by a plugin author with the script at the repo root
// (make-plugin-package.py) and installed by dropping the file anywhere on the
// window. There is no catalogue and no network: what the user installs is a
// file they already have, which is the whole point of the format.
//
// Layout of the archive:
//
// plugin.json the manifest (required)
// <library> the shared library (.so / .dll / .dylib)
//
// The manifest names what the plugin is, so the application can tell the user
// what it is about to run before it is written anywhere:
//
// { "format": 1, "id": "flatpak", "name": "Flatpak", "kind": "provider",
// "version": "1.0.0", "author": "FWS", "description": "…",
// "library": "libflatpak-provider.so", "sha256": "…" }
//
// Installing a package runs third-party code inside this process, so the
// reader stays deliberately strict: the archive has to be a ZIP, the manifest
// has to be a well-formed object, the library has to be one of the entries, its
// name has to be safe to write, and its checksum — when the manifest announces
// one — has to match before anything lands in the plugin directory. The library
// is written through QSaveFile, so it appears there complete, under its final
// name, and never half-installed.
class PluginPackage : public QObject {
Q_OBJECT
public:
// What the manifest declares about a plugin. Everything but the id is
// there for the user: the plugin itself still reports its own identity
// through the C ABI once loaded, and the registry stays the authority on
// what is actually installed.
struct Manifest {
int format = 0;
QString id;
QString name;
QString description;
QString version;
QString author;
QString kind; // "provider" or "addon"; empty when unstated
QString library; // file name to write in the plugin directory
QString sha256; // optional checksum of that library
};
// Outcome of reading a package, before anything is written: what the
// manifest says and which library it points at.
struct Contents {
Manifest manifest;
QByteArray library;
QString libraryName; // name the library is written under
};
explicit PluginPackage(QObject* parent = nullptr);
// ---- Format ----
// The extension a package file carries.
static QString suffix();
// Whether a path looks like a package. Used by the window to accept a drop
// without having to open the file first.
static bool isPackagePath(const QString& path);
// ---- Installation ----
// Directory packages are installed into (created on demand). Defaults to the
// per-user plugin directory PluginManager already scans; overridable so the
// tests never touch the user's real one.
QString installDirectory() const;
void setInstallDirectory(const QString& path);
// Installs a package, then emits installFinished(). The file is only
// written once the manifest, the library and the checksum have all been
// accepted, so a refused package leaves the plugin directory untouched.
void install(const QString& path);
// Removes a package this class installed, and emits removeFinished(). A
// library the user copied in by hand is never touched.
void remove(const QString& id);
// True when a package with that id was installed here and its file is
// still on disk.
bool isInstalled(const QString& id) const;
// Absolute path of the library installed for that id (empty when none).
QString installedPath(const QString& id) const;
// Every id installed from a package, for the page that lists them.
QStringList installedIds() const;
// Reads a package without writing anything: `error` is filled (and the
// result empty) when the file is not a usable package. Pure logic, so it is
// unit-tested without touching the disk.
static Contents read(const QString& path, QString* error);
// Parses a manifest. `error` is filled when the document is not a manifest
// or when it lacks what an install needs (an id, and a library the archive
// actually contains).
static Manifest parseManifest(const QByteArray& json, const ZipArchive& archive,
QString* error);
// The name a library entry is written under in the plugin directory. An
// entry the manifest does not name is found by its library suffix, so a
// package does not have to agree with the script on the name.
static QString targetFileName(const Manifest& manifest, const ZipArchive& archive,
QString* error);
// The platform's shared-library suffix.
static QString librarySuffix();
signals:
void installFinished(const QString& id, bool success, const QString& message);
void removeFinished(const QString& id, bool success, const QString& message);
private:
// Settings key remembering the library installed for a package id.
static QString installedKey(const QString& id);
// Settings key prefix listing every installed package.
static QString installedKeyPrefix();
QString m_installDirectory; // empty = the per-user plugin directory
};