Settings: centralized migration to user settings. wip
This commit is contained in:
parent
d6e253fe7f
commit
498ee478e7
5 changed files with 115 additions and 117 deletions
|
|
@ -71,34 +71,64 @@ Singleton {
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// If the settings structure has changed, ensure
|
// If the settings structure has changed, ensure
|
||||||
// backward compatibility
|
// backward compatibility by upgrading the settings
|
||||||
function upgradeSettingsData() {
|
function upgradeSettingsData() {
|
||||||
for (var i = 0; i < adapter.bar.widgets.left.length; i++) {
|
|
||||||
var obj = adapter.bar.widgets.left[i]
|
const sections = ["left", "center", "right"]
|
||||||
if (typeof obj === "string") {
|
|
||||||
adapter.bar.widgets.left[i] = {
|
// -----------------
|
||||||
"id": obj
|
// 1st. check our settings are not super old, when we only had the widget type as a string
|
||||||
|
for (var s = 0; s < sections.length; s++) {
|
||||||
|
const sectionName = sections[s]
|
||||||
|
for (var i = 0; i < adapter.bar.widgets[sectionName].length; i++) {
|
||||||
|
var widget = adapter.bar.widgets[sectionName][i]
|
||||||
|
if (typeof widget === "string") {
|
||||||
|
console.log("founf old stuff")
|
||||||
|
adapter.bar.widgets[sectionName][i] = {
|
||||||
|
"id": widget
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (var i = 0; i < adapter.bar.widgets.center.length; i++) {
|
|
||||||
var obj = adapter.bar.widgets.center[i]
|
// -----------------
|
||||||
if (typeof obj === "string") {
|
// 2nd. migrate global settings to user settings
|
||||||
adapter.bar.widgets.center[i] = {
|
for (var s = 0; s < sections.length; s++) {
|
||||||
"id": obj
|
const sectionName = sections[s]
|
||||||
|
for (var i = 0; i < adapter.bar.widgets[sectionName].length; i++) {
|
||||||
|
var widget = adapter.bar.widgets[sectionName][i]
|
||||||
|
|
||||||
|
// Check if widget registry supports user settings, if it does not, then there is nothing to do
|
||||||
|
const reg = BarWidgetRegistry.widgetMetadata[widget.id]
|
||||||
|
if ((reg === undefined) || (reg.allowUserSettings === undefined) || !reg.allowUserSettings) {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
// Check that the widget was not previously migrated and skip if necessary
|
||||||
for (var i = 0; i < adapter.bar.widgets.right.length; i++) {
|
const keys = Object.keys(widget)
|
||||||
var obj = adapter.bar.widgets.right[i]
|
if (keys.length > 1) {
|
||||||
if (typeof obj === "string") {
|
continue
|
||||||
adapter.bar.widgets.right[i] = {
|
|
||||||
"id": obj
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_migrateWidget(widget)
|
||||||
|
Logger.log("Settings", JSON.stringify(widget))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------
|
||||||
|
function _migrateWidget(widget) {
|
||||||
|
Logger.log("Settings", `Migrating '${widget.id}' widget`)
|
||||||
|
|
||||||
|
switch (widget.id) {
|
||||||
|
case "Clock":
|
||||||
|
widget.showDate = adapter.location.showDateWithClock
|
||||||
|
widget.use12HourClock = adapter.location.use12HourClock
|
||||||
|
widget.reverseDayMonth = adapter.location.reverseDayMonth
|
||||||
|
widget.showSeconds = BarWidgetRegistry.widgetMetadata[widget.id].reverseDayMonth
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Kickoff essential services
|
// Kickoff essential services
|
||||||
function kickOffServices() {
|
function kickOffServices() {
|
||||||
|
|
@ -174,13 +204,13 @@ Singleton {
|
||||||
|
|
||||||
// bar
|
// bar
|
||||||
property JsonObject bar: JsonObject {
|
property JsonObject bar: JsonObject {
|
||||||
property string position: "top" // Possible values: "top", "bottom"
|
property string position: "top" // "top" or "bottom"
|
||||||
property bool showActiveWindowIcon: true
|
property bool showActiveWindowIcon: true // TODO: delete
|
||||||
property bool alwaysShowBatteryPercentage: false
|
property bool alwaysShowBatteryPercentage: false // TODO: delete
|
||||||
property bool showNetworkStats: false
|
property bool showNetworkStats: false // TODO: delete
|
||||||
property real backgroundOpacity: 1.0
|
property real backgroundOpacity: 1.0
|
||||||
property bool useDistroLogo: false
|
property bool useDistroLogo: false // TODO: delete
|
||||||
property string showWorkspaceLabel: "none"
|
property string showWorkspaceLabel: "none" // TODO: delete
|
||||||
property list<string> monitors: []
|
property list<string> monitors: []
|
||||||
|
|
||||||
// Widget configuration for modular bar system
|
// Widget configuration for modular bar system
|
||||||
|
|
@ -236,9 +266,9 @@ Singleton {
|
||||||
property JsonObject location: JsonObject {
|
property JsonObject location: JsonObject {
|
||||||
property string name: defaultLocation
|
property string name: defaultLocation
|
||||||
property bool useFahrenheit: false
|
property bool useFahrenheit: false
|
||||||
property bool reverseDayMonth: false
|
property bool reverseDayMonth: false // TODO: delete
|
||||||
property bool use12HourClock: false
|
property bool use12HourClock: false // TODO: delete
|
||||||
property bool showDateWithClock: false
|
property bool showDateWithClock: false // TODO: delete
|
||||||
}
|
}
|
||||||
|
|
||||||
// screen recorder
|
// screen recorder
|
||||||
|
|
@ -305,8 +335,8 @@ Singleton {
|
||||||
|
|
||||||
// audio
|
// audio
|
||||||
property JsonObject audio: JsonObject {
|
property JsonObject audio: JsonObject {
|
||||||
property bool showMiniplayerAlbumArt: false
|
property bool showMiniplayerAlbumArt: false // TODO: delete
|
||||||
property bool showMiniplayerCava: false
|
property bool showMiniplayerCava: false // TODO: delete
|
||||||
property string visualizerType: "linear"
|
property string visualizerType: "linear"
|
||||||
property int volumeStep: 5
|
property int volumeStep: 5
|
||||||
property int cavaFrameRate: 60
|
property int cavaFrameRate: 60
|
||||||
|
|
|
||||||
|
|
@ -10,37 +10,37 @@ Singleton {
|
||||||
|
|
||||||
property var date: new Date()
|
property var date: new Date()
|
||||||
|
|
||||||
readonly property string dateString: {
|
// Returns a Unix Timestamp (in seconds)
|
||||||
|
readonly property int timestamp: {
|
||||||
|
return Math.floor(date / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(reverseDayMonth = true) {
|
||||||
let now = date
|
let now = date
|
||||||
let dayName = now.toLocaleDateString(Qt.locale(), "ddd")
|
let dayName = now.toLocaleDateString(Qt.locale(), "ddd")
|
||||||
dayName = dayName.charAt(0).toUpperCase() + dayName.slice(1)
|
dayName = dayName.charAt(0).toUpperCase() + dayName.slice(1)
|
||||||
let day = now.getDate()
|
let day = now.getDate()
|
||||||
let suffix
|
let suffix
|
||||||
if (day > 3 && day < 21)
|
if (day > 3 && day < 21)
|
||||||
suffix = 'th'
|
suffix = 'th'
|
||||||
else
|
else
|
||||||
switch (day % 10) {
|
switch (day % 10) {
|
||||||
case 1:
|
case 1:
|
||||||
suffix = "st"
|
suffix = "st"
|
||||||
break
|
break
|
||||||
case 2:
|
case 2:
|
||||||
suffix = "nd"
|
suffix = "nd"
|
||||||
break
|
break
|
||||||
case 3:
|
case 3:
|
||||||
suffix = "rd"
|
suffix = "rd"
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
suffix = "th"
|
suffix = "th"
|
||||||
}
|
}
|
||||||
let month = now.toLocaleDateString(Qt.locale(), "MMMM")
|
let month = now.toLocaleDateString(Qt.locale(), "MMMM")
|
||||||
let year = now.toLocaleDateString(Qt.locale(), "yyyy")
|
let year = now.toLocaleDateString(Qt.locale(), "yyyy")
|
||||||
return `${dayName}, `
|
|
||||||
+ (Settings.data.location.reverseDayMonth ? `${month} ${day}${suffix} ${year}` : `${day}${suffix} ${month} ${year}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a Unix Timestamp (in seconds)
|
return `${dayName}, ` + (reverseDayMonth ? `${month} ${day}${suffix} ${year}` : `${day}${suffix} ${month} ${year}`)
|
||||||
readonly property int timestamp: {
|
|
||||||
return Math.floor(date / 1000)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,14 @@ Rectangle {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use settings or defaults from BarWidgetRegistry metadata
|
// Resolve settings: try user settings or defaults from BarWidgetRegistry
|
||||||
readonly property bool userShowDate: (widgetSettings.showDate
|
readonly property bool showDate: widgetSettings.showDate || BarWidgetRegistry.widgetMetadata["Clock"].showDate
|
||||||
!== undefined) ? widgetSettings.showDate : BarWidgetRegistry.widgetMetadata["Clock"].showDate
|
readonly property bool use12h: widgetSettings.use12HourClock
|
||||||
readonly property bool userUse12h: (widgetSettings.use12HourClock !== undefined) ? widgetSettings.use12HourClock : BarWidgetRegistry.widgetMetadata["Clock"].use12HourClock
|
|| BarWidgetRegistry.widgetMetadata["Clock"].use12HourClock
|
||||||
readonly property bool userShowSeconds: (widgetSettings.showSeconds !== undefined) ? widgetSettings.showSeconds : BarWidgetRegistry.widgetMetadata["Clock"].showSeconds
|
readonly property bool showSeconds: widgetSettings.showSeconds
|
||||||
|
|| BarWidgetRegistry.widgetMetadata["Clock"].showSeconds
|
||||||
|
readonly property bool reverseDayMonth: widgetSettings.reverseDayMonth
|
||||||
|
|| BarWidgetRegistry.widgetMetadata["Clock"].reverseDayMonth
|
||||||
|
|
||||||
implicitWidth: clock.width + Style.marginM * 2 * scaling
|
implicitWidth: clock.width + Style.marginM * 2 * scaling
|
||||||
implicitHeight: Math.round(Style.capsuleHeight * scaling)
|
implicitHeight: Math.round(Style.capsuleHeight * scaling)
|
||||||
|
|
@ -39,22 +42,39 @@ Rectangle {
|
||||||
color: Color.mSurfaceVariant
|
color: Color.mSurfaceVariant
|
||||||
|
|
||||||
// Clock Icon with attached calendar
|
// Clock Icon with attached calendar
|
||||||
NClock {
|
NText {
|
||||||
id: clock
|
id: clock
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
text: {
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
const now = Time.date
|
||||||
// Per-instance overrides to Time formatting
|
const timeFormat = use12h ? (showSeconds ? "h:mm:ss AP" : "h:mm AP") : (showSeconds ? "HH:mm:ss" : "HH:mm")
|
||||||
showDate: userShowDate
|
const timeString = Qt.formatDateTime(now, timeFormat)
|
||||||
use12h: userUse12h
|
|
||||||
showSeconds: userShowSeconds
|
|
||||||
|
|
||||||
NTooltip {
|
if (showDate) {
|
||||||
id: tooltip
|
let dayName = now.toLocaleDateString(Qt.locale(), "ddd")
|
||||||
text: `${Time.dateString}.`
|
dayName = dayName.charAt(0).toUpperCase() + dayName.slice(1)
|
||||||
target: clock
|
let day = now.getDate()
|
||||||
positionAbove: Settings.data.bar.position === "bottom"
|
let month = now.toLocaleDateString(Qt.locale(), "MMM")
|
||||||
|
return timeString + " - " + (reverseDayMonth ? `${dayName}, ${month} ${day}` : `${dayName}, ${day} ${month}`)
|
||||||
|
}
|
||||||
|
return timeString
|
||||||
}
|
}
|
||||||
|
anchors.centerIn: parent
|
||||||
|
font.pointSize: Style.fontSizeS * scaling
|
||||||
|
font.weight: Style.fontWeightBold
|
||||||
|
}
|
||||||
|
|
||||||
|
NTooltip {
|
||||||
|
id: tooltip
|
||||||
|
text: `${Time.formatDate(reverseDayMonth)}.`
|
||||||
|
target: clock
|
||||||
|
positionAbove: Settings.data.bar.position === "bottom"
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: clockMouseArea
|
||||||
|
anchors.fill: parent
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
hoverEnabled: true
|
||||||
onEntered: {
|
onEntered: {
|
||||||
if (!PanelService.getPanel("calendarPanel")?.active) {
|
if (!PanelService.getPanel("calendarPanel")?.active) {
|
||||||
tooltip.show()
|
tooltip.show()
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,8 @@ Singleton {
|
||||||
"allowUserSettings": true,
|
"allowUserSettings": true,
|
||||||
"showDate": false,
|
"showDate": false,
|
||||||
"use12HourClock": false,
|
"use12HourClock": false,
|
||||||
"showSeconds": false
|
"showSeconds": false,
|
||||||
|
"reverseDayMonth": true
|
||||||
},
|
},
|
||||||
"Volume": {
|
"Volume": {
|
||||||
"allowUserSettings": true,
|
"allowUserSettings": true,
|
||||||
|
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
import QtQuick
|
|
||||||
import qs.Commons
|
|
||||||
import qs.Services
|
|
||||||
import qs.Widgets
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
id: root
|
|
||||||
|
|
||||||
signal entered
|
|
||||||
signal exited
|
|
||||||
signal clicked
|
|
||||||
|
|
||||||
// Per-instance overrides (default to global settings if not provided by parent)
|
|
||||||
// Parent widgets like Bar `Clock.qml` can bind these
|
|
||||||
property bool showDate: Settings.data.location.showDateWithClock
|
|
||||||
property bool use12h: Settings.data.location.use12HourClock
|
|
||||||
property bool showSeconds: false
|
|
||||||
|
|
||||||
width: textItem.paintedWidth
|
|
||||||
height: textItem.paintedHeight
|
|
||||||
color: Color.transparent
|
|
||||||
|
|
||||||
NText {
|
|
||||||
id: textItem
|
|
||||||
text: {
|
|
||||||
const now = Time.date
|
|
||||||
const timeFormat = use12h ? (showSeconds ? "h:mm:ss AP" : "h:mm AP") : (showSeconds ? "HH:mm:ss" : "HH:mm")
|
|
||||||
const timeString = Qt.formatDateTime(now, timeFormat)
|
|
||||||
|
|
||||||
if (showDate) {
|
|
||||||
let dayName = now.toLocaleDateString(Qt.locale(), "ddd")
|
|
||||||
dayName = dayName.charAt(0).toUpperCase() + dayName.slice(1)
|
|
||||||
let day = now.getDate()
|
|
||||||
let month = now.toLocaleDateString(Qt.locale(), "MMM")
|
|
||||||
return timeString + " - " + (Settings.data.location.reverseDayMonth ? `${dayName}, ${month} ${day}` : `${dayName}, ${day} ${month}`)
|
|
||||||
}
|
|
||||||
return timeString
|
|
||||||
}
|
|
||||||
anchors.centerIn: parent
|
|
||||||
font.pointSize: Style.fontSizeS * scaling
|
|
||||||
font.weight: Style.fontWeightBold
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
|
||||||
id: clockMouseArea
|
|
||||||
anchors.fill: parent
|
|
||||||
cursorShape: Qt.PointingHandCursor
|
|
||||||
hoverEnabled: true
|
|
||||||
onEntered: root.entered()
|
|
||||||
onExited: root.exited()
|
|
||||||
onClicked: root.clicked()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue