Plugin System: Toggle to enable or disable a source + Improved UI

This commit is contained in:
ItsLemmy
2025-12-04 21:50:38 -05:00
parent a2cd2a3900
commit aa48d38d57
3 changed files with 78 additions and 22 deletions
+19 -16
View File
@@ -12,7 +12,7 @@ ColumnLayout {
width: parent.width
// ------------------------------
// Section 1: Installed Plugins
// Installed Plugins
// ------------------------------
NHeader {
label: I18n.tr("settings.plugins.installed.label")
@@ -141,8 +141,14 @@ ColumnLayout {
}
// ------------------------------
// Section 2: Plugin Sources
// Available Plugins (Sources + Filter + List)
// ------------------------------
NHeader {
label: I18n.tr("settings.plugins.available.label")
description: I18n.tr("settings.plugins.available.description")
}
// Sources
NCollapsible {
Layout.fillWidth: true
label: I18n.tr("settings.plugins.sources.label")
@@ -187,6 +193,17 @@ ColumnLayout {
Layout.fillWidth: true
}
// Enable/Disable a source
NToggle {
checked: modelData.enabled !== false // Default to true if not set
baseSize: Style.baseWidgetSize * 0.7
onToggled: function (checked) {
PluginRegistry.setSourceEnabled(modelData.url, checked);
PluginService.refreshAvailablePlugins();
ToastService.showNotice(I18n.tr("settings.plugins.refresh.refreshing"));
}
}
NIconButton {
icon: "trash"
tooltipText: I18n.tr("settings.plugins.sources.remove.tooltip")
@@ -215,20 +232,6 @@ ColumnLayout {
}
}
NDivider {
Layout.fillWidth: true
Layout.topMargin: Style.marginL
Layout.bottomMargin: Style.marginL
}
// ------------------------------
// Section 3: Available Plugins
// ------------------------------
NHeader {
label: I18n.tr("settings.plugins.available.label")
description: I18n.tr("settings.plugins.available.description")
}
// Filter controls
RowLayout {
spacing: Style.marginM
+55 -3
View File
@@ -44,7 +44,8 @@ Singleton {
root.pluginSources = [
{
"name": "Official Noctalia Plugins",
"url": "https://github.com/noctalia-dev/noctalia-plugins"
"url": "https://github.com/noctalia-dev/noctalia-plugins",
"enabled": true
}
];
root.save();
@@ -61,7 +62,8 @@ Singleton {
root.pluginSources = [
{
"name": "Official Noctalia Plugins",
"url": "https://github.com/noctalia-dev/noctalia-plugins"
"url": "https://github.com/noctalia-dev/noctalia-plugins",
"enabled": true
}
];
// Scan for installed plugins
@@ -325,7 +327,8 @@ Singleton {
var newSources = root.pluginSources.slice();
newSources.push({
name: name,
url: url
url: url,
enabled: true
});
root.pluginSources = newSources;
save();
@@ -353,6 +356,55 @@ Singleton {
return true;
}
// Set source enabled/disabled state
function setSourceEnabled(url, enabled) {
var newSources = [];
var found = false;
for (var i = 0; i < root.pluginSources.length; i++) {
if (root.pluginSources[i].url === url) {
newSources.push({
name: root.pluginSources[i].name,
url: root.pluginSources[i].url,
enabled: enabled
});
found = true;
} else {
newSources.push(root.pluginSources[i]);
}
}
if (!found) {
Logger.w("PluginRegistry", "Source not found:", url);
return false;
}
root.pluginSources = newSources;
save();
Logger.i("PluginRegistry", "Source", url, enabled ? "enabled" : "disabled");
return true;
}
// Check if source is enabled
function isSourceEnabled(url) {
for (var i = 0; i < root.pluginSources.length; i++) {
if (root.pluginSources[i].url === url) {
return root.pluginSources[i].enabled !== false; // Default to true if not set
}
}
return false;
}
// Get enabled sources only
function getEnabledSources() {
var enabledSources = [];
for (var i = 0; i < root.pluginSources.length; i++) {
if (root.pluginSources[i].enabled !== false) {
enabledSources.push(root.pluginSources[i]);
}
}
return enabledSources;
}
// Get plugin directory path
function getPluginDir(pluginId) {
return root.pluginsDir + "/" + pluginId;
+4 -3
View File
@@ -129,9 +129,10 @@ Singleton {
Logger.i("PluginService", "Refreshing available plugins");
root.availablePlugins = [];
var sources = PluginRegistry.pluginSources;
for (var i = 0; i < sources.length; i++) {
fetchPluginRegistry(sources[i]);
var enabledSources = PluginRegistry.getEnabledSources();
Logger.d("PluginService", "Fetching from", enabledSources.length, "enabled sources");
for (var i = 0; i < enabledSources.length; i++) {
fetchPluginRegistry(enabledSources[i]);
}
}