mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
fix(plugins): pass pluginApi as initial property to prevent binding warnings. Eliminate the need for fallback chains in plugins code.
hot reload
This commit is contained in:
@@ -22,11 +22,35 @@ Item {
|
||||
return (item && item.visible) ? item[prop] : 0;
|
||||
}
|
||||
|
||||
readonly property bool _isPlugin: ControlCenterWidgetRegistry.isPluginWidget(widgetId)
|
||||
|
||||
function _loadPluginWidget() {
|
||||
var comp = ControlCenterWidgetRegistry.getWidget(widgetId);
|
||||
if (!comp)
|
||||
return;
|
||||
var pluginId = widgetId.substring(7); // Remove "plugin:" prefix
|
||||
var api = PluginService.getPluginAPI(pluginId);
|
||||
loader.setSource(comp.url, api ? {
|
||||
"pluginApi": api
|
||||
} : {});
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: loader
|
||||
anchors.fill: parent
|
||||
asynchronous: false
|
||||
sourceComponent: ControlCenterWidgetRegistry.getWidget(widgetId)
|
||||
|
||||
// Core widgets use sourceComponent; plugin widgets use setSource()
|
||||
// so pluginApi is available from the first binding evaluation.
|
||||
Component.onCompleted: {
|
||||
if (root._isPlugin) {
|
||||
root._loadPluginWidget();
|
||||
} else {
|
||||
sourceComponent = Qt.binding(function () {
|
||||
return ControlCenterWidgetRegistry.getWidget(widgetId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onLoaded: {
|
||||
if (!item)
|
||||
@@ -44,12 +68,6 @@ Item {
|
||||
item.screen = widgetScreen;
|
||||
}
|
||||
|
||||
// Pass pluginApi for plugin widgets
|
||||
if (ControlCenterWidgetRegistry.isPluginWidget(widgetId) && item.hasOwnProperty("pluginApi")) {
|
||||
var pluginId = widgetId.substring(7); // Remove "plugin:" prefix
|
||||
item.pluginApi = PluginService.getPluginAPI(pluginId);
|
||||
}
|
||||
|
||||
// Call custom onLoaded if it exists
|
||||
if (item.hasOwnProperty("onLoaded")) {
|
||||
item.onLoaded();
|
||||
|
||||
@@ -164,16 +164,14 @@ SmartPanel {
|
||||
// Get plugin API
|
||||
var api = PluginService.getPluginAPI(pluginId);
|
||||
|
||||
// Activate loader and set component simultaneously
|
||||
// Use setSource with initial properties so pluginApi is available
|
||||
// from the first binding evaluation (before onLoaded)
|
||||
root.contentLoader.active = true;
|
||||
root.contentLoader.sourceComponent = component;
|
||||
root.contentLoader.setSource(component.url, api ? {
|
||||
"pluginApi": api
|
||||
} : {});
|
||||
|
||||
// Immediately inject API (before any bindings evaluate)
|
||||
if (root.contentLoader.item) {
|
||||
if (root.contentLoader.item.hasOwnProperty("pluginApi")) {
|
||||
root.contentLoader.item.pluginApi = api;
|
||||
}
|
||||
|
||||
root.pluginInstance = root.contentLoader.item;
|
||||
root.currentPluginId = pluginId;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user