Init: better widget upgrading process + less warnings when starting up without config or cache
This commit is contained in:
parent
b43b065cf2
commit
3271fa1d23
6 changed files with 32 additions and 27 deletions
|
|
@ -102,7 +102,8 @@ Singleton {
|
||||||
// FileView to load custom colors data from colors.json
|
// FileView to load custom colors data from colors.json
|
||||||
FileView {
|
FileView {
|
||||||
id: customColorsFile
|
id: customColorsFile
|
||||||
path: Settings.directoriesCreated ? (Settings.configDir + "colors.json") : ""
|
path: Settings.directoriesCreated ? (Settings.configDir + "colors.json") : undefined
|
||||||
|
printErrors: false
|
||||||
watchChanges: true
|
watchChanges: true
|
||||||
onFileChanged: {
|
onFileChanged: {
|
||||||
Logger.log("Color", "Reloading colors from disk")
|
Logger.log("Color", "Reloading colors from disk")
|
||||||
|
|
@ -115,7 +116,7 @@ Singleton {
|
||||||
|
|
||||||
// Trigger initial load when path changes from empty to actual path
|
// Trigger initial load when path changes from empty to actual path
|
||||||
onPathChanged: {
|
onPathChanged: {
|
||||||
if (path === Settings.configDir + "colors.json") {
|
if (path !== undefined) {
|
||||||
reload()
|
reload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,22 +105,19 @@ Singleton {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the widget was not previously migrated and skip if necessary
|
if (upgradeWidget(widget)) {
|
||||||
const keys = Object.keys(widget)
|
Logger.log("Settings", `Upgraded ${widget.id} widget:`, JSON.stringify(widget))
|
||||||
if (keys.length > 1) {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
migrateWidget(widget)
|
|
||||||
Logger.log("Settings", JSON.stringify(widget))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
function migrateWidget(widget) {
|
function upgradeWidget(widget) {
|
||||||
Logger.log("Settings", `Migrating '${widget.id}' widget`)
|
// Backup the widget definition before altering
|
||||||
|
const widgetBefore = JSON.stringify(widget)
|
||||||
|
|
||||||
|
// Migrate old bar settings to proper per widget settings
|
||||||
switch (widget.id) {
|
switch (widget.id) {
|
||||||
case "ActiveWindow":
|
case "ActiveWindow":
|
||||||
widget.showIcon = adapter.bar.showActiveWindowIcon
|
widget.showIcon = adapter.bar.showActiveWindowIcon
|
||||||
|
|
@ -128,23 +125,14 @@ Singleton {
|
||||||
case "Battery":
|
case "Battery":
|
||||||
widget.alwaysShowPercentage = adapter.bar.alwaysShowBatteryPercentage
|
widget.alwaysShowPercentage = adapter.bar.alwaysShowBatteryPercentage
|
||||||
break
|
break
|
||||||
case "Brightness":
|
|
||||||
widget.alwaysShowPercentage = BarWidgetRegistry.widgetMetadata[widget.id].alwaysShowPercentage
|
|
||||||
break
|
|
||||||
case "Clock":
|
case "Clock":
|
||||||
widget.showDate = adapter.location.showDateWithClock
|
widget.showDate = adapter.location.showDateWithClock
|
||||||
widget.use12HourClock = adapter.location.use12HourClock
|
widget.use12HourClock = adapter.location.use12HourClock
|
||||||
widget.reverseDayMonth = adapter.location.reverseDayMonth
|
widget.reverseDayMonth = adapter.location.reverseDayMonth
|
||||||
widget.showSeconds = BarWidgetRegistry.widgetMetadata[widget.id].showSeconds
|
|
||||||
break
|
break
|
||||||
case "MediaMini":
|
case "MediaMini":
|
||||||
widget.showAlbumArt = adapter.audio.showMiniplayerAlbumArt
|
widget.showAlbumArt = adapter.audio.showMiniplayerAlbumArt
|
||||||
widget.showVisualizer = adapter.audio.showMiniplayerCava
|
widget.showVisualizer = adapter.audio.showMiniplayerCava
|
||||||
widget.visualizerType = BarWidgetRegistry.widgetMetadata[widget.id].visualizerType
|
|
||||||
break
|
|
||||||
case "NotificationHistory":
|
|
||||||
widget.showUnreadBadge = BarWidgetRegistry.widgetMetadata[widget.id].showUnreadBadge
|
|
||||||
widget.hideWhenZero = BarWidgetRegistry.widgetMetadata[widget.id].hideWhenZero
|
|
||||||
break
|
break
|
||||||
case "SidePanelToggle":
|
case "SidePanelToggle":
|
||||||
widget.useDistroLogo = adapter.bar.useDistroLogo
|
widget.useDistroLogo = adapter.bar.useDistroLogo
|
||||||
|
|
@ -152,13 +140,27 @@ Singleton {
|
||||||
case "SystemMonitor":
|
case "SystemMonitor":
|
||||||
widget.showNetworkStats = adapter.bar.showNetworkStats
|
widget.showNetworkStats = adapter.bar.showNetworkStats
|
||||||
break
|
break
|
||||||
case "Volume":
|
|
||||||
widget.alwaysShowPercentage = BarWidgetRegistry.widgetMetadata[widget.id].alwaysShowPercentage
|
|
||||||
break
|
|
||||||
case "Workspace":
|
case "Workspace":
|
||||||
widget.labelMode = adapter.bar.showWorkspaceLabel
|
widget.labelMode = adapter.bar.showWorkspaceLabel
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inject missing default setting (metaData) from BarWidgetRegistry
|
||||||
|
const keys = Object.keys(BarWidgetRegistry.widgetMetadata[widget.id])
|
||||||
|
for (let i=0; i<keys.length; i++) {
|
||||||
|
const k = keys[i]
|
||||||
|
if (k === "id" || k === "allowUserSettings") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!widget.hasOwnProperty(k)) {
|
||||||
|
widget[k] = BarWidgetRegistry.widgetMetadata[widget.id][k]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Backup the widget definition before altering
|
||||||
|
const widgetAfter = JSON.stringify(widget)
|
||||||
|
return (widgetAfter !== widgetBefore)
|
||||||
}
|
}
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Kickoff essential services
|
// Kickoff essential services
|
||||||
|
|
@ -200,14 +202,15 @@ Singleton {
|
||||||
|
|
||||||
FileView {
|
FileView {
|
||||||
id: settingsFileView
|
id: settingsFileView
|
||||||
path: directoriesCreated ? settingsFile : ""
|
path: directoriesCreated ? settingsFile : undefined
|
||||||
|
printErrors: false
|
||||||
watchChanges: true
|
watchChanges: true
|
||||||
onFileChanged: reload()
|
onFileChanged: reload()
|
||||||
onAdapterUpdated: saveTimer.start()
|
onAdapterUpdated: saveTimer.start()
|
||||||
|
|
||||||
// Trigger initial load when path changes from empty to actual path
|
// Trigger initial load when path changes from empty to actual path
|
||||||
onPathChanged: {
|
onPathChanged: {
|
||||||
if (path === settingsFile) {
|
if (path !== undefined) {
|
||||||
reload()
|
reload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,6 @@ Variants {
|
||||||
left: true
|
left: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: debounceTimer
|
id: debounceTimer
|
||||||
interval: 333
|
interval: 333
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ Singleton {
|
||||||
FileView {
|
FileView {
|
||||||
id: locationFileView
|
id: locationFileView
|
||||||
path: locationFile
|
path: locationFile
|
||||||
|
printErrors: false
|
||||||
onAdapterUpdated: saveTimer.start()
|
onAdapterUpdated: saveTimer.start()
|
||||||
onLoaded: {
|
onLoaded: {
|
||||||
Logger.log("Location", "Loaded cached data")
|
Logger.log("Location", "Loaded cached data")
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ Singleton {
|
||||||
FileView {
|
FileView {
|
||||||
id: cacheFileView
|
id: cacheFileView
|
||||||
path: root.cacheFile
|
path: root.cacheFile
|
||||||
|
printErrors: false
|
||||||
|
|
||||||
JsonAdapter {
|
JsonAdapter {
|
||||||
id: cacheAdapter
|
id: cacheAdapter
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ Singleton {
|
||||||
id: historyFileView
|
id: historyFileView
|
||||||
objectName: "notificationHistoryFileView"
|
objectName: "notificationHistoryFileView"
|
||||||
path: historyFile
|
path: historyFile
|
||||||
|
printErrors: false
|
||||||
watchChanges: true
|
watchChanges: true
|
||||||
onFileChanged: reload()
|
onFileChanged: reload()
|
||||||
onAdapterUpdated: writeAdapter()
|
onAdapterUpdated: writeAdapter()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue