mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
fix(desktop-widgets): pass screen as initial property to avoid wrong spectrum registration
This commit is contained in:
@@ -290,43 +290,47 @@ Variants {
|
||||
property var _maskRegion: null
|
||||
readonly property bool _isPlugin: DesktopWidgetRegistry.isPluginWidget(modelData.id)
|
||||
|
||||
// Core widgets use sourceComponent; plugin widgets use setSource()
|
||||
// so pluginApi is available from the first binding evaluation.
|
||||
// Binding is set imperatively to avoid sourceComponent interfering with setSource.
|
||||
Component.onCompleted: {
|
||||
if (_isPlugin) {
|
||||
_loadPluginWidget();
|
||||
} else {
|
||||
sourceComponent = Qt.binding(function () {
|
||||
var _ = root.pluginReloadCounter;
|
||||
var widgets = root.registeredWidgets;
|
||||
return widgets[modelData.id] || null;
|
||||
});
|
||||
}
|
||||
}
|
||||
// All widgets use setSource() so that screen, widgetData, and
|
||||
// widgetIndex are set as initial properties, available during
|
||||
// Component.onCompleted. This prevents registration-key
|
||||
// mismatches in widgets that build IDs from screen.name.
|
||||
Component.onCompleted: _loadWidget()
|
||||
|
||||
onActiveChanged: {
|
||||
if (active && _isPlugin)
|
||||
_loadPluginWidget();
|
||||
if (active)
|
||||
_loadWidget();
|
||||
}
|
||||
|
||||
function _loadPluginWidget() {
|
||||
var comp = root.registeredWidgets[modelData.id];
|
||||
function _loadWidget() {
|
||||
var widgetId = modelData.id;
|
||||
var comp = root.registeredWidgets[widgetId];
|
||||
if (!comp)
|
||||
return;
|
||||
var pluginId = modelData.id.replace("plugin:", "");
|
||||
var api = PluginService.getPluginAPI(pluginId);
|
||||
setSource(comp.url, api ? {
|
||||
"pluginApi": api
|
||||
} : {});
|
||||
|
||||
var props = {
|
||||
"screen": window.screen,
|
||||
"widgetData": modelData,
|
||||
"widgetIndex": index
|
||||
};
|
||||
|
||||
if (_isPlugin) {
|
||||
var pluginId = widgetId.replace("plugin:", "");
|
||||
var api = PluginService.getPluginAPI(pluginId);
|
||||
if (api)
|
||||
props.pluginApi = api;
|
||||
setSource(comp.url, props);
|
||||
} else {
|
||||
// Core widgets: use explicit URL (inline Component.url
|
||||
// returns the registry file, not the widget file)
|
||||
var url = DesktopWidgetRegistry.widgetUrls[widgetId];
|
||||
if (url)
|
||||
setSource(url, props);
|
||||
}
|
||||
}
|
||||
|
||||
onLoaded: {
|
||||
if (item) {
|
||||
item.screen = window.screen;
|
||||
item.parent = widgetsContainer;
|
||||
item.widgetData = modelData;
|
||||
item.widgetIndex = index;
|
||||
|
||||
// Create mask region so this widget receives mouse input
|
||||
_maskRegion = maskRegionComponent.createObject(window);
|
||||
|
||||
@@ -19,14 +19,14 @@ Singleton {
|
||||
function registerComponent(componentId) {
|
||||
root._registeredComponents[componentId] = true;
|
||||
root._registeredComponents = Object.assign({}, root._registeredComponents);
|
||||
Logger.d("Spectrum", "Component registered:", componentId, "- total:", root.registeredCount);
|
||||
Logger.d("Spectrum", "Component registered:", componentId, "- total:", root._registeredCount);
|
||||
}
|
||||
|
||||
// Unregister a component when it no longer needs audio data.
|
||||
function unregisterComponent(componentId) {
|
||||
delete root._registeredComponents[componentId];
|
||||
root._registeredComponents = Object.assign({}, root._registeredComponents);
|
||||
Logger.d("Spectrum", "Component unregistered:", componentId, "- total:", root.registeredCount);
|
||||
Logger.d("Spectrum", "Component unregistered:", componentId, "- total:", root._registeredCount);
|
||||
}
|
||||
|
||||
// Check if a component is registered
|
||||
|
||||
@@ -36,6 +36,12 @@ Singleton {
|
||||
// Created in Component.onCompleted to ensure Components are ready
|
||||
property var widgets: ({})
|
||||
|
||||
// Explicit URLs for core widgets. Inline Component.url returns the parent
|
||||
// file's URL, so we need these for Loader.setSource() with initial properties.
|
||||
// Plugin widgets use their Component.url directly (loaded from actual files).
|
||||
readonly property string _widgetsDir: Quickshell.shellDir + "/Modules/DesktopWidgets/Widgets/"
|
||||
property var widgetUrls: ({})
|
||||
|
||||
Component.onCompleted: {
|
||||
// Initialize widgets object after Components are ready
|
||||
var widgetsObj = {};
|
||||
@@ -46,6 +52,14 @@ Singleton {
|
||||
widgetsObj["AudioVisualizer"] = audioVisualizerComponent;
|
||||
widgets = widgetsObj;
|
||||
|
||||
var urlsObj = {};
|
||||
urlsObj["Clock"] = _widgetsDir + "DesktopClock.qml";
|
||||
urlsObj["MediaPlayer"] = _widgetsDir + "DesktopMediaPlayer.qml";
|
||||
urlsObj["Weather"] = _widgetsDir + "DesktopWeather.qml";
|
||||
urlsObj["SystemStat"] = _widgetsDir + "DesktopSystemStat.qml";
|
||||
urlsObj["AudioVisualizer"] = _widgetsDir + "DesktopAudioVisualizer.qml";
|
||||
widgetUrls = urlsObj;
|
||||
|
||||
Logger.i("DesktopWidgetRegistry", "Service started");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user