controlcenter: apperance panel, mostly finished
This commit is contained in:
parent
058a289a04
commit
c9d13d518e
1 changed files with 35 additions and 41 deletions
|
|
@ -9,6 +9,7 @@ import qs.components.containers
|
||||||
import qs.components.images
|
import qs.components.images
|
||||||
import qs.services
|
import qs.services
|
||||||
import qs.config
|
import qs.config
|
||||||
|
import qs.utils
|
||||||
import Caelestia.Models
|
import Caelestia.Models
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
|
|
@ -38,50 +39,45 @@ RowLayout {
|
||||||
path: `${Paths.config}/shell.json`
|
path: `${Paths.config}/shell.json`
|
||||||
watchChanges: true
|
watchChanges: true
|
||||||
|
|
||||||
property bool isSaving: false
|
|
||||||
|
|
||||||
onLoaded: {
|
onLoaded: {
|
||||||
if (!isSaving) {
|
try {
|
||||||
try {
|
const config = JSON.parse(text());
|
||||||
const config = JSON.parse(text());
|
updateFromConfig(config);
|
||||||
updateFromConfig(config);
|
} catch (e) {
|
||||||
} catch (e) {
|
console.error("Failed to parse config:", e);
|
||||||
console.error("Failed to parse config:", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onFileChanged: {
|
onSaveFailed: err => {
|
||||||
if (!isSaving) {
|
console.error("Failed to save config file:", err);
|
||||||
try {
|
|
||||||
const config = JSON.parse(text());
|
|
||||||
updateFromConfig(config);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to parse config:", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateFromConfig(config) {
|
function updateFromConfig(config) {
|
||||||
// Update background settings
|
// Update background settings
|
||||||
if (config.background) {
|
if (config.background) {
|
||||||
root.desktopClockEnabled = config.background.desktopClock?.enabled !== false;
|
root.desktopClockEnabled = config.background.desktopClock?.enabled !== undefined ? config.background.desktopClock.enabled : false;
|
||||||
root.backgroundEnabled = config.background.enabled !== false;
|
root.backgroundEnabled = config.background.enabled !== undefined ? config.background.enabled : true;
|
||||||
if (config.background.visualiser) {
|
if (config.background.visualiser) {
|
||||||
root.visualiserEnabled = config.background.visualiser.enabled !== false;
|
root.visualiserEnabled = config.background.visualiser.enabled !== undefined ? config.background.visualiser.enabled : false;
|
||||||
root.visualiserAutoHide = config.background.visualiser.autoHide !== false;
|
root.visualiserAutoHide = config.background.visualiser.autoHide !== undefined ? config.background.visualiser.autoHide : true;
|
||||||
root.visualiserRounding = config.background.visualiser.rounding || 1;
|
root.visualiserRounding = config.background.visualiser.rounding !== undefined ? config.background.visualiser.rounding : 1;
|
||||||
root.visualiserSpacing = config.background.visualiser.spacing || 1;
|
root.visualiserSpacing = config.background.visualiser.spacing !== undefined ? config.background.visualiser.spacing : 1;
|
||||||
|
} else {
|
||||||
|
// Set defaults if visualiser object doesn't exist (matching BackgroundConfig defaults)
|
||||||
|
root.visualiserEnabled = false;
|
||||||
|
root.visualiserAutoHide = true;
|
||||||
|
root.visualiserRounding = 1;
|
||||||
|
root.visualiserSpacing = 1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
}
|
// Set defaults if background object doesn't exist (matching BackgroundConfig defaults)
|
||||||
|
root.desktopClockEnabled = false;
|
||||||
Timer {
|
root.backgroundEnabled = true;
|
||||||
id: saveTimer
|
root.visualiserEnabled = false;
|
||||||
interval: 500
|
root.visualiserAutoHide = true;
|
||||||
onTriggered: {
|
root.visualiserRounding = 1;
|
||||||
configFile.isSaving = false;
|
root.visualiserSpacing = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,9 +95,6 @@ RowLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Set flag to prevent reloading during save
|
|
||||||
configFile.isSaving = true;
|
|
||||||
|
|
||||||
const config = JSON.parse(configFile.text());
|
const config = JSON.parse(configFile.text());
|
||||||
|
|
||||||
// Ensure background object exists
|
// Ensure background object exists
|
||||||
|
|
@ -121,16 +114,11 @@ RowLayout {
|
||||||
config.background.visualiser.rounding = root.visualiserRounding;
|
config.background.visualiser.rounding = root.visualiserRounding;
|
||||||
config.background.visualiser.spacing = root.visualiserSpacing;
|
config.background.visualiser.spacing = root.visualiserSpacing;
|
||||||
|
|
||||||
// Write back to file
|
// Write back to file using setText (same simple approach that worked for taskbar)
|
||||||
const jsonString = JSON.stringify(config, null, 4);
|
const jsonString = JSON.stringify(config, null, 4);
|
||||||
configFile.setText(jsonString);
|
configFile.setText(jsonString);
|
||||||
|
|
||||||
// Reset flag after a delay to allow file write to complete
|
|
||||||
// Use a timer to ensure the file system has time to write
|
|
||||||
saveTimer.restart();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to save config:", e);
|
console.error("Failed to save config:", e);
|
||||||
configFile.isSaving = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -690,6 +678,7 @@ RowLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledSwitch {
|
StyledSwitch {
|
||||||
|
id: desktopClockSwitch
|
||||||
checked: root.desktopClockEnabled
|
checked: root.desktopClockEnabled
|
||||||
onToggled: {
|
onToggled: {
|
||||||
root.desktopClockEnabled = checked;
|
root.desktopClockEnabled = checked;
|
||||||
|
|
@ -725,6 +714,7 @@ RowLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledSwitch {
|
StyledSwitch {
|
||||||
|
id: backgroundEnabledSwitch
|
||||||
checked: root.backgroundEnabled
|
checked: root.backgroundEnabled
|
||||||
onToggled: {
|
onToggled: {
|
||||||
root.backgroundEnabled = checked;
|
root.backgroundEnabled = checked;
|
||||||
|
|
@ -768,6 +758,7 @@ RowLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledSwitch {
|
StyledSwitch {
|
||||||
|
id: visualiserEnabledSwitch
|
||||||
checked: root.visualiserEnabled
|
checked: root.visualiserEnabled
|
||||||
onToggled: {
|
onToggled: {
|
||||||
root.visualiserEnabled = checked;
|
root.visualiserEnabled = checked;
|
||||||
|
|
@ -803,6 +794,7 @@ RowLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledSwitch {
|
StyledSwitch {
|
||||||
|
id: visualiserAutoHideSwitch
|
||||||
checked: root.visualiserAutoHide
|
checked: root.visualiserAutoHide
|
||||||
onToggled: {
|
onToggled: {
|
||||||
root.visualiserAutoHide = checked;
|
root.visualiserAutoHide = checked;
|
||||||
|
|
@ -838,6 +830,7 @@ RowLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomSpinBox {
|
CustomSpinBox {
|
||||||
|
id: visualiserRoundingSpinBox
|
||||||
min: 0
|
min: 0
|
||||||
max: 10
|
max: 10
|
||||||
value: Math.round(root.visualiserRounding)
|
value: Math.round(root.visualiserRounding)
|
||||||
|
|
@ -875,6 +868,7 @@ RowLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomSpinBox {
|
CustomSpinBox {
|
||||||
|
id: visualiserSpacingSpinBox
|
||||||
min: 0
|
min: 0
|
||||||
max: 10
|
max: 10
|
||||||
value: Math.round(root.visualiserSpacing)
|
value: Math.round(root.visualiserSpacing)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue