Move more things to WidgetLoader.qml
This commit is contained in:
parent
68181a4df6
commit
566e3e2aa7
4 changed files with 46 additions and 127 deletions
|
|
@ -21,12 +21,10 @@ QtObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
const widgetPath = `../Modules/Bar/Widgets/${widgetName}.qml`
|
const widgetPath = `../Modules/Bar/Widgets/${widgetName}.qml`
|
||||||
Logger.log("WidgetLoader", `Attempting to load widget from: ${widgetPath}`)
|
|
||||||
|
|
||||||
// Try to load the widget directly from file
|
// Try to load the widget directly from file
|
||||||
const component = Qt.createComponent(widgetPath)
|
const component = Qt.createComponent(widgetPath)
|
||||||
if (component.status === Component.Ready) {
|
if (component.status === Component.Ready) {
|
||||||
Logger.log("WidgetLoader", `Successfully created component for: ${widgetName}.qml`)
|
|
||||||
return component
|
return component
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,10 +38,6 @@ QtObject {
|
||||||
totalWidgets = widgetList.length
|
totalWidgets = widgetList.length
|
||||||
loadedWidgets = 0
|
loadedWidgets = 0
|
||||||
failedWidgets = 0
|
failedWidgets = 0
|
||||||
|
|
||||||
if (totalWidgets > 0) {
|
|
||||||
Logger.log("WidgetLoader", `Attempting to load ${totalWidgets} widgets`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track widget loading success
|
// Track widget loading success
|
||||||
|
|
@ -52,7 +46,7 @@ QtObject {
|
||||||
widgetLoaded(widgetName)
|
widgetLoaded(widgetName)
|
||||||
|
|
||||||
if (loadedWidgets + failedWidgets === totalWidgets) {
|
if (loadedWidgets + failedWidgets === totalWidgets) {
|
||||||
Logger.log("WidgetLoader", `Loaded ${loadedWidgets}/${totalWidgets} widgets`)
|
Logger.log("WidgetLoader", `Loaded ${loadedWidgets} widgets`)
|
||||||
loadingComplete(totalWidgets, loadedWidgets, failedWidgets)
|
loadingComplete(totalWidgets, loadedWidgets, failedWidgets)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -63,8 +57,35 @@ QtObject {
|
||||||
widgetFailed(widgetName, error)
|
widgetFailed(widgetName, error)
|
||||||
|
|
||||||
if (loadedWidgets + failedWidgets === totalWidgets) {
|
if (loadedWidgets + failedWidgets === totalWidgets) {
|
||||||
Logger.log("WidgetLoader", `Loaded ${loadedWidgets}/${totalWidgets} widgets`)
|
|
||||||
loadingComplete(totalWidgets, loadedWidgets, failedWidgets)
|
loadingComplete(totalWidgets, loadedWidgets, failedWidgets)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is where you should add your Modules/Bar/Widgets/
|
||||||
|
// so it gets registered in the BarTab
|
||||||
|
function discoverAvailableWidgets() {
|
||||||
|
const widgetFiles = [
|
||||||
|
"ActiveWindow", "Battery", "Bluetooth", "Brightness", "Clock",
|
||||||
|
"MediaMini", "NotificationHistory", "ScreenRecorderIndicator",
|
||||||
|
"SidePanelToggle", "SystemMonitor", "Tray", "Volume", "WiFi", "Workspace"
|
||||||
|
]
|
||||||
|
|
||||||
|
const availableWidgets = []
|
||||||
|
|
||||||
|
widgetFiles.forEach(widgetName => {
|
||||||
|
// Test if the widget can be loaded
|
||||||
|
const component = getWidgetComponent(widgetName)
|
||||||
|
if (component) {
|
||||||
|
availableWidgets.push({
|
||||||
|
key: widgetName,
|
||||||
|
name: widgetName
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Sort alphabetically
|
||||||
|
availableWidgets.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
|
|
||||||
|
return availableWidgets
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,17 +137,9 @@ Variants {
|
||||||
WidgetLoader {
|
WidgetLoader {
|
||||||
id: widgetLoader
|
id: widgetLoader
|
||||||
|
|
||||||
onWidgetLoaded: function(widgetName) {
|
|
||||||
Logger.log("Bar", `Widget loaded: ${widgetName}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
onWidgetFailed: function(widgetName, error) {
|
onWidgetFailed: function(widgetName, error) {
|
||||||
Logger.error("Bar", `Widget failed: ${widgetName} - ${error}`)
|
Logger.error("Bar", `Widget failed: ${widgetName} - ${error}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoadingComplete: function(total, loaded, failed) {
|
|
||||||
Logger.log("Bar", `Widget loading complete: ${loaded}/${total} loaded, ${failed} failed`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize widget loading tracking
|
// Initialize widget loading tracking
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Qt.labs.folderlistmodel
|
|
||||||
import qs.Commons
|
import qs.Commons
|
||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
@ -196,6 +195,7 @@ ColumnLayout {
|
||||||
Item { Layout.fillWidth: true }
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
NComboBox {
|
NComboBox {
|
||||||
|
id: leftComboBox
|
||||||
width: 120 * scaling
|
width: 120 * scaling
|
||||||
model: availableWidgets
|
model: availableWidgets
|
||||||
label: ""
|
label: ""
|
||||||
|
|
@ -319,6 +319,7 @@ ColumnLayout {
|
||||||
Item { Layout.fillWidth: true }
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
NComboBox {
|
NComboBox {
|
||||||
|
id: centerComboBox
|
||||||
width: 120 * scaling
|
width: 120 * scaling
|
||||||
model: availableWidgets
|
model: availableWidgets
|
||||||
label: ""
|
label: ""
|
||||||
|
|
@ -326,6 +327,7 @@ ColumnLayout {
|
||||||
placeholder: "Add widget to center section"
|
placeholder: "Add widget to center section"
|
||||||
onSelected: key => {
|
onSelected: key => {
|
||||||
addWidgetToSection(key, "center")
|
addWidgetToSection(key, "center")
|
||||||
|
reset() // Reset selection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -442,6 +444,7 @@ ColumnLayout {
|
||||||
Item { Layout.fillWidth: true }
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
NComboBox {
|
NComboBox {
|
||||||
|
id: rightComboBox
|
||||||
width: 120 * scaling
|
width: 120 * scaling
|
||||||
model: availableWidgets
|
model: availableWidgets
|
||||||
label: ""
|
label: ""
|
||||||
|
|
@ -449,6 +452,7 @@ ColumnLayout {
|
||||||
placeholder: "Add widget to right section"
|
placeholder: "Add widget to right section"
|
||||||
onSelected: key => {
|
onSelected: key => {
|
||||||
addWidgetToSection(key, "right")
|
addWidgetToSection(key, "right")
|
||||||
|
reset() // Reset selection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -585,13 +589,9 @@ ColumnLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dynamic widget discovery using FolderListModel
|
// Widget loader for discovering available widgets
|
||||||
FolderListModel {
|
WidgetLoader {
|
||||||
id: widgetFolderModel
|
id: widgetLoader
|
||||||
folder: Qt.resolvedUrl("../../Bar/Widgets/")
|
|
||||||
nameFilters: ["*.qml"]
|
|
||||||
showDirs: false
|
|
||||||
showFiles: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
|
|
@ -602,115 +602,19 @@ ColumnLayout {
|
||||||
discoverWidgets()
|
discoverWidgets()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Automatically discover available widgets from the Widgets directory
|
// Automatically discover available widgets using WidgetLoader
|
||||||
function discoverWidgets() {
|
function discoverWidgets() {
|
||||||
console.log("Discovering widgets...")
|
|
||||||
console.log("FolderListModel count:", widgetFolderModel.count)
|
|
||||||
console.log("FolderListModel folder:", widgetFolderModel.folder)
|
|
||||||
|
|
||||||
availableWidgets.clear()
|
availableWidgets.clear()
|
||||||
|
|
||||||
// Process each .qml file found in the directory
|
// Use WidgetLoader to discover available widgets
|
||||||
for (let i = 0; i < widgetFolderModel.count; i++) {
|
const discoveredWidgets = widgetLoader.discoverAvailableWidgets()
|
||||||
const fileName = widgetFolderModel.get(i, "fileName")
|
|
||||||
console.log("Found file:", fileName)
|
|
||||||
const widgetName = fileName.replace('.qml', '')
|
|
||||||
|
|
||||||
// Skip TrayMenu as it's not a standalone widget
|
|
||||||
if (widgetName !== 'TrayMenu') {
|
|
||||||
console.log("Adding widget:", widgetName)
|
|
||||||
availableWidgets.append({
|
|
||||||
key: widgetName,
|
|
||||||
name: widgetName,
|
|
||||||
icon: getDefaultIcon(widgetName)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Total widgets added:", availableWidgets.count)
|
// Add discovered widgets to the ListModel
|
||||||
|
discoveredWidgets.forEach(widget => {
|
||||||
// If FolderListModel didn't find anything, use fallback
|
|
||||||
if (availableWidgets.count === 0) {
|
|
||||||
console.log("FolderListModel failed, using fallback list")
|
|
||||||
const fallbackWidgets = [
|
|
||||||
"ActiveWindow", "Battery", "Bluetooth", "Brightness", "Clock",
|
|
||||||
"MediaMini", "NotificationHistory", "ScreenRecorderIndicator",
|
|
||||||
"SidePanelToggle", "SystemMonitor", "Tray", "Volume", "WiFi", "Workspace"
|
|
||||||
]
|
|
||||||
|
|
||||||
fallbackWidgets.forEach(widgetName => {
|
|
||||||
availableWidgets.append({
|
|
||||||
key: widgetName,
|
|
||||||
name: widgetName,
|
|
||||||
icon: getDefaultIcon(widgetName)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort alphabetically by name
|
|
||||||
sortWidgets()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort widgets alphabetically
|
|
||||||
function sortWidgets() {
|
|
||||||
const widgets = []
|
|
||||||
for (let i = 0; i < availableWidgets.count; i++) {
|
|
||||||
widgets.push({
|
|
||||||
key: availableWidgets.get(i).key,
|
|
||||||
name: availableWidgets.get(i).name,
|
|
||||||
icon: availableWidgets.get(i).icon
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
widgets.sort((a, b) => a.name.localeCompare(b.name))
|
|
||||||
|
|
||||||
availableWidgets.clear()
|
|
||||||
widgets.forEach(widget => {
|
|
||||||
availableWidgets.append(widget)
|
availableWidgets.append(widget)
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
// Get default icon for widget (can be overridden in widget files)
|
|
||||||
function getDefaultIcon(widgetName) {
|
|
||||||
const iconMap = {
|
|
||||||
"ActiveWindow": "web_asset",
|
|
||||||
"Battery": "battery_full",
|
|
||||||
"Bluetooth": "bluetooth",
|
|
||||||
"Brightness": "brightness_6",
|
|
||||||
"Clock": "schedule",
|
|
||||||
"MediaMini": "music_note",
|
|
||||||
"NotificationHistory": "notifications",
|
|
||||||
"ScreenRecorderIndicator": "videocam",
|
|
||||||
"SidePanelToggle": "widgets",
|
|
||||||
"SystemMonitor": "memory",
|
|
||||||
"Tray": "apps",
|
|
||||||
"Volume": "volume_up",
|
|
||||||
"WiFi": "wifi",
|
|
||||||
"Workspace": "dashboard"
|
|
||||||
}
|
|
||||||
return iconMap[widgetName] || "widgets"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Helper function to get widget icons
|
|
||||||
function getWidgetIcon(widgetKey) {
|
|
||||||
switch(widgetKey) {
|
|
||||||
case "SystemMonitor": return "memory"
|
|
||||||
case "ActiveWindow": return "web_asset"
|
|
||||||
case "MediaMini": return "music_note"
|
|
||||||
case "Workspace": return "dashboard"
|
|
||||||
case "ScreenRecorderIndicator": return "videocam"
|
|
||||||
case "Tray": return "apps"
|
|
||||||
case "NotificationHistory": return "notifications"
|
|
||||||
case "WiFi": return "wifi"
|
|
||||||
case "Bluetooth": return "bluetooth"
|
|
||||||
case "Battery": return "battery_full"
|
|
||||||
case "Volume": return "volume_up"
|
|
||||||
case "Brightness": return "brightness_6"
|
|
||||||
case "Clock": return "schedule"
|
|
||||||
case "SidePanelToggle": return "widgets"
|
|
||||||
default: return "widgets"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ ColumnLayout {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ComboBox {
|
ComboBox {
|
||||||
id: combo
|
id: combo
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue