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
+12
-12
@@ -107,10 +107,10 @@ private slots:
|
||||
void onHistoryFilterChanged();
|
||||
void onInstalledFilterChanged(const QString& text);
|
||||
void onRecentActivityClicked(QListWidgetItem* item);
|
||||
void onProviderTableSelected(int row);
|
||||
void onToggleProvider();
|
||||
void onRescanProviders();
|
||||
void onInstallProviderTool();
|
||||
void onPluginTableSelected(int row);
|
||||
void onTogglePlugin();
|
||||
void onRescanPlugins();
|
||||
void onInstallPluginTool();
|
||||
void onCheckForUpdates();
|
||||
void onUpdateCheckFinished(bool hasUpdate, const QString& latestVersion,
|
||||
const QString& errorMessage);
|
||||
@@ -142,13 +142,13 @@ private:
|
||||
void setupBrowsePage();
|
||||
void setupHistoryPage();
|
||||
void setupLogsPage();
|
||||
void setupProvidersPage();
|
||||
void setupPluginsPage();
|
||||
void setupMenuBar();
|
||||
void updatePageTitle();
|
||||
void updateStatusBar();
|
||||
void refreshDashboard();
|
||||
void refreshRecentActivity();
|
||||
void refreshProvidersTable();
|
||||
void refreshPluginsTable();
|
||||
void updatePackageInfo(const PackageInfo& pkg);
|
||||
void resetDetailsPanel();
|
||||
void setBrowseMode(BrowseMode mode);
|
||||
@@ -218,12 +218,12 @@ private:
|
||||
// Logs page
|
||||
QTextEdit* m_logsText = nullptr;
|
||||
|
||||
// Providers page
|
||||
QTableWidget* m_providerTable = nullptr;
|
||||
QPushButton* m_providerToggleButton = nullptr;
|
||||
QPushButton* m_providerInstallButton = nullptr;
|
||||
QLabel* m_providerDescription = nullptr;
|
||||
std::string m_selectedProviderId;
|
||||
// Plugins page
|
||||
QTableWidget* m_pluginTable = nullptr;
|
||||
QPushButton* m_pluginToggleButton = nullptr;
|
||||
QPushButton* m_pluginInstallButton = nullptr;
|
||||
QLabel* m_pluginDescription = nullptr;
|
||||
std::string m_selectedPluginId;
|
||||
|
||||
// Backend
|
||||
PacmanManager* m_pacman = nullptr; // non-owning, used for sudo credentials/logs
|
||||
|
||||
+28
-19
@@ -6,47 +6,56 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Registry of package providers. It owns every IPackageManager (built-in and
|
||||
// external) and can load additional providers at runtime from shared-library
|
||||
// plugins dropped in the plugin directories (see PluginManager::scanDirectory).
|
||||
// Registry of every plugin known to the application. It owns each plugin
|
||||
// (built-in and external), loads shared-library plugins dropped in the plugin
|
||||
// directories at runtime (see PluginManager::scanDirectory) and tracks which
|
||||
// are enabled in the settings. A plugin is either a package-manager provider
|
||||
// (implements IPackageManager) or a generic addon (implements IPlugin) — both
|
||||
// kinds share the same loading, lifecycle and enable/disable flow.
|
||||
class PluginManager {
|
||||
public:
|
||||
struct ProviderEntry {
|
||||
ProviderInfo info;
|
||||
IPackageManager* manager = nullptr; // owned by the PluginManager
|
||||
struct PluginEntry {
|
||||
PluginInfo info;
|
||||
IPlugin* plugin = nullptr; // non-null for addon plugins
|
||||
IPackageManager* manager = nullptr; // non-null for provider plugins
|
||||
QLibrary* library = nullptr; // owned by the PluginManager; null for built-ins
|
||||
};
|
||||
|
||||
PluginManager();
|
||||
~PluginManager();
|
||||
|
||||
// Register a provider compiled into the application (e.g. pacman, flatpak).
|
||||
// Register a provider compiled into the application (e.g. pacman).
|
||||
// Takes ownership of the manager.
|
||||
void registerBuiltin(ProviderInfo info, IPackageManager* manager);
|
||||
void registerBuiltin(PluginInfo info, IPackageManager* manager);
|
||||
|
||||
// Scan the plugin directories for external provider plugins and load them.
|
||||
// Scan the plugin directories for external plugins and load them.
|
||||
void discoverExternal();
|
||||
|
||||
// Drop external plugins and rescan their directories; built-in providers
|
||||
// Drop external plugins and rescan their directories; built-in plugins
|
||||
// are kept (their instances stay valid).
|
||||
void reload();
|
||||
|
||||
// Re-run isAvailable() on every known provider (e.g. after the app
|
||||
// installed a missing tool) so the Providers page reflects reality.
|
||||
// Re-run isAvailable() on every plugin (e.g. after the app installed a
|
||||
// missing tool) so the Plugins page reflects reality.
|
||||
void refreshAvailability();
|
||||
|
||||
// All known providers, in registration order.
|
||||
const std::vector<ProviderEntry>& providers() const;
|
||||
// All known plugins, in registration order.
|
||||
const std::vector<PluginEntry>& plugins() const;
|
||||
|
||||
// Providers that are enabled (in settings) and whose tool is on the system.
|
||||
std::vector<const ProviderEntry*> availableProviders() const;
|
||||
// Provider plugins that are enabled (in settings) and whose tool is on the
|
||||
// system.
|
||||
std::vector<const PluginEntry*> availableProviders() const;
|
||||
|
||||
// Same as availableProviders() but as plain manager pointers, convenient
|
||||
// for running aggregated operations across every provider.
|
||||
std::vector<IPackageManager*> availableManagers() const;
|
||||
|
||||
// A single available+enabled provider matching id, or nullptr.
|
||||
const ProviderEntry* findAvailable(const std::string& id) const;
|
||||
const PluginEntry* findAvailable(const std::string& id) const;
|
||||
|
||||
// Addon plugins that are enabled and available (e.g. to hand the main
|
||||
// window to via IPlugin::onUiReady).
|
||||
std::vector<IPlugin*> availableAddons() const;
|
||||
|
||||
bool isEnabled(const std::string& id) const;
|
||||
void setEnabled(const std::string& id, bool enabled);
|
||||
@@ -59,6 +68,6 @@ private:
|
||||
void scanDirectory(const QString& dir);
|
||||
void unloadExternal();
|
||||
|
||||
std::vector<ProviderEntry> m_providers;
|
||||
std::vector<PluginEntry> m_plugins;
|
||||
QSettings m_settings;
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// Every plugin is either a package-manager provider (implements
|
||||
// IPackageManager) or a generic addon (implements IPlugin). The kind tells the
|
||||
// host which C ABI create function to resolve and how to treat the plugin in
|
||||
// the UI.
|
||||
enum class PluginKind {
|
||||
Provider, // adds a package manager (pacman, flatpak, apt, ...)
|
||||
Addon, // any other extension: UI tweak, helper, ... as long as C++
|
||||
};
|
||||
|
||||
// Metadata describing a plugin, whether it is compiled into the application
|
||||
// (pacman) or loaded at runtime from an external shared library.
|
||||
struct PluginInfo {
|
||||
std::string id; // unique identifier, e.g. "pacman", "flatpak"
|
||||
std::string name; // display name, e.g. "Flatpak"
|
||||
std::string version; // plugin version
|
||||
std::string description; // what this plugin does
|
||||
std::string author; // who wrote the plugin
|
||||
PluginKind kind = PluginKind::Provider;
|
||||
bool builtin = false; // true when compiled into the application
|
||||
std::string path; // filesystem path (external plugins only)
|
||||
bool available = false; // provider: backing tool present; addon: can run here
|
||||
// OS package name providing a provider's backing tool (e.g. "flatpak").
|
||||
// Empty when the plugin cannot be installed from the application.
|
||||
std::string installHint;
|
||||
};
|
||||
|
||||
class QMainWindow; // host window, handed to UI addons via onUiReady()
|
||||
|
||||
// Base interface every non-provider plugin implements. Providers implement
|
||||
// IPackageManager instead. Both kinds are owned and lifecycle-managed by the
|
||||
// PluginManager.
|
||||
class IPlugin {
|
||||
public:
|
||||
virtual ~IPlugin() = default;
|
||||
// Called when the plugin is loaded (at discovery or reload). Keep it
|
||||
// lightweight: the main window does not exist yet, so no UI work here.
|
||||
virtual void onLoad() {}
|
||||
// Called when the plugin is unloaded (reload, shutdown) so it can release
|
||||
// what onLoad() acquired.
|
||||
virtual void onUnload() {}
|
||||
// Whether the plugin can run on this system. Providers report whether
|
||||
// their backing tool is installed; addons usually return true.
|
||||
virtual bool isAvailable() const { return true; }
|
||||
// Called once the main window exists, so UI addons can attach their own
|
||||
// widgets (toolbar buttons, status-bar items, ...). Default: no-op.
|
||||
virtual void onUiReady(QMainWindow* /*mainWindow*/) {}
|
||||
};
|
||||
+31
-23
@@ -1,55 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "plugin.h"
|
||||
#include "package-manager.h"
|
||||
#include <string>
|
||||
|
||||
// Metadata describing a provider, whether it is compiled into the application
|
||||
// (pacman, flatpak) or loaded at runtime from an external plugin.
|
||||
struct ProviderInfo {
|
||||
std::string id; // unique identifier, e.g. "pacman", "flatpak"
|
||||
std::string name; // display name, e.g. "Flatpak"
|
||||
std::string version; // plugin version
|
||||
std::string description; // what this provider manages
|
||||
std::string author; // who wrote the provider
|
||||
bool builtin = false; // true when compiled into the application
|
||||
std::string path; // filesystem path (external plugins only)
|
||||
bool available = false; // whether the backing tool is present on the system
|
||||
// OS package name providing the backing tool (e.g. "flatpak"). Empty when
|
||||
// the provider cannot be installed from the application.
|
||||
std::string installHint;
|
||||
};
|
||||
|
||||
// ---- External plugin contract (C ABI) ----
|
||||
//
|
||||
// An external provider plugin is a shared library (lib*.so / *.dll) dropped in
|
||||
// a plugin directory (see PluginManager). It must export the symbols below so
|
||||
// the host can query metadata and instantiate the provider. The convenience
|
||||
// macro FWS_PROVIDER_PLUGIN generates them from a class implementing
|
||||
// IPackageManager:
|
||||
// A plugin is a shared library (lib*.so / *.dll) dropped in a plugin directory
|
||||
// (see PluginManager). It must export the metadata symbols below plus one
|
||||
// create function, depending on its kind:
|
||||
// - provider plugins (kind "provider") export fws_create_provider() returning
|
||||
// an IPackageManager* (use FWS_PROVIDER_PLUGIN);
|
||||
// - addon plugins (kind "addon") export fws_create_plugin() returning an
|
||||
// IPlugin* (use FWS_ADDON_PLUGIN).
|
||||
// A plugin that does not export fws_plugin_kind() is treated as a provider
|
||||
// (legacy plugins keep working).
|
||||
//
|
||||
// #include "provider-plugin.h"
|
||||
// #include "my-manager.h"
|
||||
// FWS_PROVIDER_PLUGIN(MyManager, "myprov", "My Provider", "1.0.0",
|
||||
// "Manages my stuff", "Jane Doe");
|
||||
//
|
||||
// #include "provider-plugin.h"
|
||||
// #include "my-addon.h"
|
||||
// FWS_ADDON_PLUGIN(MyAddon, "myaddon", "My Addon", "1.0.0",
|
||||
// "Tweaks the UI", "Jane Doe");
|
||||
//
|
||||
// Plugins are compiled with the same toolchain/headers as the host, exactly
|
||||
// like Qt plugins, so the IPackageManager vtable and PackageInfo layout match.
|
||||
// like Qt plugins, so the IPackageManager/IPlugin vtables and struct layouts
|
||||
// match.
|
||||
extern "C" {
|
||||
const char* fws_plugin_id();
|
||||
const char* fws_plugin_name();
|
||||
const char* fws_plugin_version();
|
||||
const char* fws_plugin_description();
|
||||
const char* fws_plugin_author();
|
||||
// "provider" (default when missing) or "addon": picks which create
|
||||
// function the host resolves.
|
||||
const char* fws_plugin_kind();
|
||||
IPackageManager* fws_create_provider();
|
||||
IPlugin* fws_create_plugin();
|
||||
// Optional: OS package name that provides the backing tool, so the app can
|
||||
// offer to install it when unavailable. May be omitted by a plugin.
|
||||
const char* fws_plugin_install_hint();
|
||||
}
|
||||
|
||||
#define FWS_PROVIDER_PLUGIN(PluginClass, id_, name_, version_, desc_, author_) \
|
||||
extern "C" const char* fws_plugin_kind() { return "provider"; } \
|
||||
extern "C" const char* fws_plugin_id() { return id_; } \
|
||||
extern "C" const char* fws_plugin_name() { return name_; } \
|
||||
extern "C" const char* fws_plugin_version() { return version_; } \
|
||||
extern "C" const char* fws_plugin_description() { return desc_; } \
|
||||
extern "C" const char* fws_plugin_author() { return author_; } \
|
||||
extern "C" IPackageManager* fws_create_provider() { return new PluginClass(); }
|
||||
|
||||
#define FWS_ADDON_PLUGIN(AddonClass, id_, name_, version_, desc_, author_) \
|
||||
extern "C" const char* fws_plugin_kind() { return "addon"; } \
|
||||
extern "C" const char* fws_plugin_id() { return id_; } \
|
||||
extern "C" const char* fws_plugin_name() { return name_; } \
|
||||
extern "C" const char* fws_plugin_version() { return version_; } \
|
||||
extern "C" const char* fws_plugin_description() { return desc_; } \
|
||||
extern "C" const char* fws_plugin_author() { return author_; } \
|
||||
extern "C" IPlugin* fws_create_plugin() { return new AddonClass(); }
|
||||
Reference in new issue
Block a user