feat(plugin): support generic addon plugins and build Flatpak by default
The Plugins page replaces the Providers tab and lists every plugin alike: package-manager providers and generic C++ addons, which can be any extension (UI tweak, helper, ...) via IPlugin (onLoad/onUnload/onUiReady) exported with the new FWS_ADDON_PLUGIN macro. Flatpak now ships as a plugin built by default (FWS_BUILD_FLATPAK_PLUGIN=ON), so a plain build is Flatpak-enabled. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
12 files changed
+535
-250
No files matched your search
@@ -0,0 +1,55 @@
|
||||
// Example addon plugin — a template for non-provider extensions (UI tweaks,
|
||||
// helpers, ...) written in C++.
|
||||
//
|
||||
// Unlike provider plugins (see plugins/example-provider), an addon does not
|
||||
// manage packages: it implements IPlugin (see include/plugin.h) and exports
|
||||
// the C ABI contract via the FWS_ADDON_PLUGIN macro. The host loads it, runs
|
||||
// onLoad()/onUnload() around its lifetime and hands it the main window via
|
||||
// onUiReady() so it can attach its own widgets — here a status-bar badge.
|
||||
//
|
||||
// Build with CMake from the project root:
|
||||
// cmake -B build -DFWS_BUILD_EXAMPLE_ADDON=ON && cmake --build build
|
||||
|
||||
#include "plugin.h"
|
||||
#include "provider-plugin.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QMainWindow>
|
||||
#include <QStatusBar>
|
||||
|
||||
// A tiny UI addon: it shows a badge in the status bar while it is loaded and
|
||||
// removes it on unload. Copy this file as a starting point for real addons
|
||||
// (toolbar buttons, dashboard cards, helpers, ...).
|
||||
class ExampleAddon : public IPlugin {
|
||||
public:
|
||||
void onLoad() override { m_loaded = true; }
|
||||
void onUnload() override {
|
||||
m_loaded = false;
|
||||
if (m_badge) {
|
||||
if (m_window) m_window->statusBar()->removeWidget(m_badge);
|
||||
delete m_badge;
|
||||
m_badge = nullptr;
|
||||
m_window = nullptr;
|
||||
}
|
||||
}
|
||||
// Available only while onLoad() has run, so the host's availability check
|
||||
// also proves the lifecycle was applied.
|
||||
bool isAvailable() const override { return m_loaded; }
|
||||
|
||||
void onUiReady(QMainWindow* window) override {
|
||||
m_window = window;
|
||||
if (!m_loaded || !m_window) return;
|
||||
m_badge = new QLabel("⚡ Exemple d'addon actif");
|
||||
m_badge->setStyleSheet(
|
||||
"color: #7aa2f7; font-size: 11px; font-weight: 600; padding-right: 8px;");
|
||||
m_window->statusBar()->addPermanentWidget(m_badge);
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_loaded = false;
|
||||
QMainWindow* m_window = nullptr;
|
||||
QLabel* m_badge = nullptr;
|
||||
};
|
||||
|
||||
FWS_ADDON_PLUGIN(ExampleAddon, "example-addon", "Example Addon", "0.1.0",
|
||||
"Exemple d'addon : badge dans la barre de statut", "FWS");
|
||||
@@ -4,7 +4,10 @@
|
||||
// Build it as a shared library and drop it in a plugin directory
|
||||
// (next to the PacManager binary in ./plugins/ or in
|
||||
// ~/.local/share/PacManager/plugins/); the app discovers it at launch and on
|
||||
// the Providers page via "Recharger".
|
||||
// the Plugins page via "Recharger".
|
||||
//
|
||||
// This is a *provider* plugin: it adds a package manager. For non-provider
|
||||
// extensions (UI tweaks, helpers, ...), see plugins/example-addon instead.
|
||||
//
|
||||
// A plugin only needs to:
|
||||
// 1. implement IPackageManager (see include/package-manager.h)
|
||||
|
||||
@@ -4,13 +4,15 @@
|
||||
// in provider-plugin.h so the host can query metadata, check the backing tool,
|
||||
// and instantiate the manager without any compiled-in Flatpak support.
|
||||
//
|
||||
// Build with CMake: the flatpak-provider-plugin target compiles this file
|
||||
// together with flatpak-manager.cpp into libflatpak-provider.so and copies it
|
||||
// next to the PacManager binary.
|
||||
// Built by default (see the FWS_BUILD_FLATPAK_PLUGIN CMake option): the
|
||||
// flatpak-provider-plugin target compiles this file together with
|
||||
// flatpak-manager.cpp into libflatpak-provider.so and copies it next to the
|
||||
// PacManager binary, so a default build ships with Flatpak support enabled.
|
||||
|
||||
#include "flatpak-manager.h"
|
||||
#include "provider-plugin.h"
|
||||
|
||||
extern "C" const char* fws_plugin_kind() { return "provider"; }
|
||||
extern "C" const char* fws_plugin_id() { return "flatpak"; }
|
||||
extern "C" const char* fws_plugin_name() { return "Flatpak"; }
|
||||
extern "C" const char* fws_plugin_version() { return "1.0.0"; }
|
||||
@@ -20,5 +22,5 @@ extern "C" const char* fws_plugin_description() {
|
||||
extern "C" const char* fws_plugin_author() { return "BlackAngelTV"; }
|
||||
extern "C" IPackageManager* fws_create_provider() { return new FlatpakManager(); }
|
||||
// The backing tool is installed by the pacman package "flatpak"; exposing it
|
||||
// lets the Providers page offer to install the missing tool.
|
||||
// lets the Plugins page offer to install the missing tool.
|
||||
extern "C" const char* fws_plugin_install_hint() { return "flatpak"; }
|
||||
Reference in new issue
Block a user