Skip to content

Commit 04b1a24

Browse files
committed
feat: add settings ipc functions
1 parent ba5fe37 commit 04b1a24

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

quickshell/Common/SettingsData.qml

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,57 @@ rm -rf '${home}'/.cache/icon-cache '${home}'/.cache/thumbnails 2>/dev/null || tr
10291029
property bool pluginSettingsFileExists: false
10301030

10311031
IpcHandler {
1032-
function reveal(): string {
1032+
function get(arg: string): string {
1033+
return root[arg]
1034+
}
1035+
1036+
function set(arg: string, value: string): string {
1037+
1038+
if (!(arg in root)) {
1039+
console.warn("Cannot set property, not found:", arg)
1040+
return "SETTINGS_SET_FAILURE"
1041+
}
1042+
1043+
const typeName = typeof root[arg]
1044+
1045+
try {
1046+
switch (typeName) {
1047+
case "boolean":
1048+
if (value === "true" || value === "false") value = Boolean(value)
1049+
else throw `${value} is not a Boolean`
1050+
break
1051+
case "number":
1052+
value = Number(value)
1053+
if (isNaN(value)) throw `${value} is not a Number`
1054+
break
1055+
case "string":
1056+
value = String(value)
1057+
break
1058+
case "object":
1059+
// NOTE: Parsing lists is messed up upstream and not sure if we want
1060+
// to make sure objects are well structured or just let people set
1061+
// whatever they want
1062+
// objects/arrays are disabled for now
1063+
// https://github.com/quickshell-mirror/quickshell/pull/22
1064+
throw "Setting Objects and Arrays not supported"
1065+
default:
1066+
throw "Unsupported type"
1067+
}
1068+
1069+
root[arg] = value
1070+
root.saveSettings()
1071+
return "SETTINGS_SET_SUCCESS"
1072+
} catch (e) {
1073+
console.warn("Failed to set property:", arg, "error:", e)
1074+
return "SETTINGS_SET_FAILURE"
1075+
}
1076+
}
1077+
1078+
target: "settings"
1079+
}
1080+
1081+
IpcHandler {
1082+
function show(): string {
10331083
root.dankBarVisible = true
10341084
root.saveSettings()
10351085
return "BAR_SHOW_SUCCESS"

0 commit comments

Comments
 (0)