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>
55 lines
2.1 KiB
C++
55 lines
2.1 KiB
C++
// 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"); |