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:
BlackAngelTV committed 2026-09-10 18:49:46 +02:00
1 parent 3fa306c815
commit 8658855cca
12 files changed
+535 -250

No files matched your search

+43 -12
View File
@@ -6,8 +6,8 @@
#include <iostream>
// Exercises PluginManager end-to-end: built-in registration plus runtime
// discovery of the example plugin (built into build/plugins by CMake when
// FWS_BUILD_EXAMPLE_PLUGIN=ON).
// discovery of the example plugins (built into build/plugins by CMake when
// FWS_BUILD_EXAMPLE_PLUGIN=ON and FWS_BUILD_EXAMPLE_ADDON=ON).
int main(int argc, char* argv[]) {
QCoreApplication app(argc, argv);
app.setOrganizationName("Freebuff");
@@ -16,19 +16,23 @@ int main(int argc, char* argv[]) {
PluginManager pm;
pm.registerBuiltin({"pacman", "Pacman", "1.0.0", "Natif Arch Linux", "FWS"},
new PacmanManager());
// Flatpak now ships as an external plugin (dropped next to the test binary
// by CMake, like the sample plugin) rather than a compiled-in provider.
// Flatpak and the sample plugins are dropped next to the test binary by
// CMake rather than compiled in.
pm.discoverExternal();
// pacman built-in + the flatpak and sample plugins dropped next to the
// test binary.
assert(pm.providers().size() == 3);
// test binary (flatpak is optional via FWS_BUILD_FLATPAK_PLUGIN).
#ifdef FWS_FLATPAK_PLUGIN_BUILT
assert(pm.plugins().size() == 3);
#else
assert(pm.plugins().size() == 2);
#endif
// Install hints are exposed per provider; the sample plugin omits its
// optional hint symbol (must read back empty), while the flatpak plugin
// declares the OS package backing its tool.
const auto& providers = pm.providers();
for (const auto& entry : providers) {
const auto& plugins = pm.plugins();
for (const auto& entry : plugins) {
if (entry.info.id == "flatpak") {
assert(!entry.info.builtin);
assert(entry.info.installHint == "flatpak");
@@ -37,23 +41,40 @@ int main(int argc, char* argv[]) {
}
assert(pm.findAvailable("flatpak") != nullptr);
// External plugin metadata is exposed through the C ABI.
// External provider plugin metadata is exposed through the C ABI.
const auto* sample = pm.findAvailable("sample");
assert(sample != nullptr);
assert(sample->info.name == "Sample Provider");
assert(sample->info.version == "0.1.0");
assert(sample->info.author == "FWS");
assert(!sample->info.builtin);
assert(sample->info.kind == PluginKind::Provider);
assert(sample->manager != nullptr);
assert(sample->plugin == nullptr);
assert(sample->manager->getName() == "sample");
assert(sample->manager->isAvailable());
// The example addon is a generic extension (kind Addon), not a package
// manager: it implements IPlugin and its availability proves onLoad() ran
// (see plugins/example-addon/example-addon.cpp).
const PluginManager::PluginEntry* addon = nullptr;
for (const auto& entry : pm.plugins()) {
if (entry.info.id == "example-addon") addon = &entry;
}
assert(addon != nullptr);
assert(addon->info.kind == PluginKind::Addon);
assert(addon->plugin != nullptr);
assert(addon->manager == nullptr);
assert(addon->info.available);
assert(pm.availableAddons().size() == 1);
assert(pm.availableAddons().front() == addon->plugin);
// Manager lookup works by id.
IPackageManager* pacman = pm.managerFor("pacman");
assert(pacman != nullptr);
assert(pacman->getName() == "pacman");
// Enable/disable is persisted and filters the available list.
// Enable/disable is persisted and filters the available lists.
assert(pm.isEnabled("sample"));
pm.setEnabled("sample", false);
assert(!pm.isEnabled("sample"));
@@ -61,11 +82,21 @@ int main(int argc, char* argv[]) {
pm.setEnabled("sample", true);
assert(pm.findAvailable("sample") != nullptr);
// Reload keeps built-ins (same instance) and rescans external plugins.
pm.setEnabled("example-addon", false);
assert(pm.availableAddons().empty());
pm.setEnabled("example-addon", true);
assert(pm.availableAddons().size() == 1);
// Reload keeps built-ins (same instance) and rescans external plugins:
// the addon is recreated (fresh onLoad), so its instance pointer changes.
IPackageManager* pacmanBefore = pacman;
IPlugin* addonBefore = addon->plugin;
pm.reload();
assert(pm.managerFor("pacman") == pacmanBefore);
assert(pm.findAvailable("sample") != nullptr);
const auto* reloadedAddon = pm.availableAddons().front();
assert(reloadedAddon != addonBefore);
assert(reloadedAddon->isAvailable());
// refreshAvailability re-evaluates the presence of every tool.
pm.refreshAvailability();
@@ -73,4 +104,4 @@ int main(int argc, char* argv[]) {
std::cout << "All plugin-manager tests passed." << std::endl;
return 0;
}
}