Skip to content

Commit 5080691

Browse files
feat: enhance configuration management with edit session and preview capabilities
- Introduced edit session management in Config.qml to track changes and handle pending modifications. - Added functions for saving, reverting, and applying changes in ControlCenter.qml, improving user interaction with configuration settings. - Implemented a preview system for appearance, color schemes, and wallpapers in various sections, allowing users to visualize changes before applying them. - Enhanced user experience with new UI elements for applying, saving, and reverting changes in the control center. - Created AppearancePreviewPane.qml to display live previews of selected themes and wallpapers, enriching the customization experience.
1 parent 612b5ce commit 5080691

11 files changed

Lines changed: 780 additions & 63 deletions

File tree

home/dot_config/quickshell/config/Config.qml

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,53 @@ Singleton {
2727
property alias services: adapter.services
2828
property alias paths: adapter.paths
2929

30+
property bool editSessionActive: false
31+
property bool hasPendingChanges: false
32+
33+
function beginEditSession(): void {
34+
editSessionActive = true;
35+
}
36+
37+
function endEditSession(): void {
38+
editSessionActive = false;
39+
}
40+
41+
function writeNow(): void {
42+
timer.restart();
43+
try {
44+
let config = {};
45+
try {
46+
config = JSON.parse(fileView.text());
47+
} catch (e) {
48+
config = {};
49+
}
50+
51+
config = serializeConfig();
52+
fileView.setText(JSON.stringify(config, null, 2));
53+
recentlySaved = true;
54+
recentSaveCooldown.restart();
55+
hasPendingChanges = false;
56+
} catch (e) {
57+
Toaster.toast(qsTr("Failed to serialize config"), e.message, "settings_alert", Toast.Error);
58+
}
59+
}
60+
61+
function revertChanges(): void {
62+
hasPendingChanges = false;
63+
recentlySaved = false;
64+
fileView.reload();
65+
}
66+
3067
// Public save function - call this to persist config changes
3168
function save(): void {
69+
if (editSessionActive) {
70+
hasPendingChanges = true;
71+
return;
72+
}
3273
saveTimer.restart();
3374
recentlySaved = true;
3475
recentSaveCooldown.restart();
76+
hasPendingChanges = false;
3577
}
3678

3779
property bool recentlySaved: false
@@ -45,25 +87,7 @@ Singleton {
4587

4688
interval: 500
4789
onTriggered: {
48-
timer.restart();
49-
try {
50-
// Parse current config to preserve structure and comments if possible
51-
let config = {};
52-
try {
53-
config = JSON.parse(fileView.text());
54-
} catch (e) {
55-
// If parsing fails, start with empty object
56-
config = {};
57-
}
58-
59-
// Update config with current values
60-
config = serializeConfig();
61-
62-
// Save to file with pretty printing
63-
fileView.setText(JSON.stringify(config, null, 2));
64-
} catch (e) {
65-
Toaster.toast(qsTr("Failed to serialize config"), e.message, "settings_alert", Toast.Error);
66-
}
90+
writeNow();
6791
}
6892
}
6993

home/dot_config/quickshell/modules/controlcenter/ControlCenter.qml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import qs.components
44
import qs.components.controls
55
import qs.services
66
import qs.config
7+
import qs.modules.launcher.services
78
import Quickshell
89
import QtQuick
910
import QtQuick.Layouts
@@ -24,12 +25,43 @@ Item {
2425
root: root
2526
}
2627

28+
readonly property bool hasPendingChanges: Config.hasPendingChanges || session.hasPendingActions
29+
2730
function close(): void {
2831
}
2932

33+
function applyChanges(): void {
34+
session.applyPendingActions();
35+
Schemes.reload();
36+
Appearances.reload();
37+
Wallpapers.stopPreview();
38+
Colours.showPreview = false;
39+
}
40+
41+
function saveChanges(): void {
42+
session.applyPendingActions();
43+
Config.writeNow();
44+
Schemes.reload();
45+
Appearances.reload();
46+
Wallpapers.stopPreview();
47+
Colours.showPreview = false;
48+
}
49+
50+
function revertChanges(): void {
51+
session.clearPendingActions();
52+
Config.revertChanges();
53+
Schemes.reload();
54+
Appearances.reload();
55+
Wallpapers.stopPreview();
56+
Colours.showPreview = false;
57+
}
58+
3059
implicitWidth: implicitHeight * Config.controlCenter.sizes.ratio
3160
implicitHeight: screen.height * Config.controlCenter.sizes.heightMult
3261

62+
Component.onCompleted: Config.beginEditSession()
63+
Component.onDestruction: Config.endEditSession()
64+
3365
GridLayout {
3466
anchors.fill: parent
3567

@@ -96,5 +128,50 @@ Item {
96128
}
97129
}
98130

131+
StyledRect {
132+
id: actionBar
133+
z: 20
134+
135+
anchors.right: parent.right
136+
anchors.bottom: parent.bottom
137+
anchors.rightMargin: Appearance.padding.large
138+
anchors.bottomMargin: Appearance.padding.large
139+
140+
color: Colours.tPalette.m3surfaceContainerHigh
141+
radius: Appearance.rounding.full
142+
visible: true
143+
opacity: root.hasPendingChanges ? 1 : 0.9
144+
145+
implicitHeight: actionsRow.implicitHeight + Appearance.padding.small * 2
146+
implicitWidth: actionsRow.implicitWidth + Appearance.padding.small * 2
147+
148+
RowLayout {
149+
id: actionsRow
150+
anchors.centerIn: parent
151+
spacing: Appearance.spacing.small
152+
153+
TextButton {
154+
type: TextButton.Tonal
155+
text: qsTr("Apply")
156+
enabled: root.hasPendingChanges
157+
onClicked: root.applyChanges()
158+
}
159+
160+
TextButton {
161+
type: TextButton.Filled
162+
text: qsTr("Save")
163+
enabled: root.hasPendingChanges
164+
onClicked: root.saveChanges()
165+
}
166+
167+
TextButton {
168+
type: TextButton.Text
169+
text: qsTr("Revert")
170+
enabled: root.hasPendingChanges
171+
onClicked: root.revertChanges()
172+
}
173+
}
174+
}
175+
99176
readonly property bool initialOpeningComplete: panes.initialOpeningComplete
100177
}

home/dot_config/quickshell/modules/controlcenter/NavRail.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pragma ComponentBehavior: Bound
22

33
import qs.components
4+
import qs.components.controls
45
import qs.services
56
import qs.config
67
import qs.modules.controlcenter

home/dot_config/quickshell/modules/controlcenter/Session.qml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import QtQuick
22
import "./state"
33
import qs.modules.controlcenter
4+
import Quickshell
45

56
QtObject {
67
readonly property list<string> panes: PaneRegistry.labels
@@ -16,6 +17,27 @@ QtObject {
1617
readonly property EthernetState ethernet: EthernetState {}
1718
readonly property LauncherState launcher: LauncherState {}
1819
readonly property VpnState vpn: VpnState {}
20+
property var pendingActions: ({})
21+
readonly property bool hasPendingActions: Object.keys(pendingActions).length > 0
22+
23+
function queueAction(key: string, command: var): void {
24+
const next = Object.assign({}, pendingActions);
25+
next[key] = command;
26+
pendingActions = next;
27+
}
28+
29+
function clearPendingActions(): void {
30+
pendingActions = ({});
31+
}
32+
33+
function applyPendingActions(): void {
34+
const entries = Object.entries(pendingActions);
35+
for (const [, cmd] of entries) {
36+
if (Array.isArray(cmd) && cmd.length > 0)
37+
Quickshell.execDetached(cmd);
38+
}
39+
clearPendingActions();
40+
}
1941

2042
onActiveChanged: activeIndex = Math.max(0, panes.indexOf(active))
2143
onActiveIndexChanged: if (panes[activeIndex])

0 commit comments

Comments
 (0)