Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 119 additions & 1 deletion quickshell/Common/SettingsData.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,57 @@ rm -rf '${home}'/.cache/icon-cache '${home}'/.cache/thumbnails 2>/dev/null || tr
property bool pluginSettingsFileExists: false

IpcHandler {
function reveal(): string {
function get(arg: string): string {
return JSON.stringify(root[arg])
}

function set(arg: string, value: string): string {

if (!(arg in root)) {
console.warn("Cannot set property, not found:", arg)
return "SETTINGS_SET_FAILURE"
}

const typeName = typeof root[arg]

try {
switch (typeName) {
case "boolean":
if (value === "true" || value === "false") value = Boolean(value)
else throw `${value} is not a Boolean`
break
case "number":
value = Number(value)
if (isNaN(value)) throw `${value} is not a Number`
break
case "string":
value = String(value)
break
case "object":
// NOTE: Parsing lists is messed up upstream and not sure if we want
// to make sure objects are well structured or just let people set
// whatever they want but risking messed up settings.
// Objects & Arrays are disabled for now
// https://github.com/quickshell-mirror/quickshell/pull/22
throw "Setting Objects and Arrays not supported"
default:
throw "Unsupported type"
}

root[arg] = value
root.saveSettings()
return "SETTINGS_SET_SUCCESS"
} catch (e) {
console.warn("Failed to set property:", arg, "error:", e)
return "SETTINGS_SET_FAILURE"
}
}

target: "settings"
}

IpcHandler {
function show(): string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show doesnt work in quickshell IPC context, its a reserved word I guess and it just makes it show the available functions. That's why they were reveal instead

root.setShowDock(true);
return "DOCK_SHOW_SUCCESS";
}
Expand All @@ -1413,4 +1463,72 @@ rm -rf '${home}'/.cache/icon-cache '${home}'/.cache/thumbnails 2>/dev/null || tr

target: "dock"
}

IpcHandler {
readonly property var barSelectors: ["id", "name", "index"]

function show(selector: string, value: string): string {
if (!barSelectors.includes(selector)) { return "BAR_INVALID_SELECTOR" }
const index = selector == "index" ? value : barConfigs.findIndex((bar)=> bar[selector] == value)
const barConfig = barConfigs[index]
if (!barConfig) { return "BAR_NOT_FOUND" }
updateBarConfig(barConfig.id, {visible: true})
return "BAR_SHOW_SUCCESS";
}

function hide(selector: string, value: string): string {
if (!barSelectors.includes(selector)) { return "BAR_INVALID_SELECTOR" }
const index = selector == "index" ? value : barConfigs.findIndex((bar)=> bar[selector] == value)
const barConfig = barConfigs[index]
if (!barConfig) { return "BAR_NOT_FOUND" }
updateBarConfig(barConfig.id, {visible: false})
return "BAR_HIDE_SUCCESS";
}

function toggle(selector: string, value: string): string {
if (!barSelectors.includes(selector)) { return "BAR_INVALID_SELECTOR" }
const index = selector == "index" ? value : barConfigs.findIndex((bar)=> bar[selector] == value)
const barConfig = barConfigs[index]
if (!barConfig) { return "BAR_NOT_FOUND" }
updateBarConfig(barConfig.id, {visible: !barConfig.visible})
return root.showBar ? "BAR_SHOW_SUCCESS" : "BAR_HIDE_SUCCESS";
}

function status(selector: string, value: string): string {
if (!barSelectors.includes(selector)) { return "BAR_INVALID_SELECTOR" }
const index = selector == "index" ? value : barConfigs.findIndex((bar)=> bar[selector] == value)
const barConfig = barConfigs[index]
if (!barConfig) { return "BAR_NOT_FOUND" }
return barConfig.visible ? "visible" : "hidden";
}

function autoHide(selector: string, value: string): string {
if (!barSelectors.includes(selector)) { return "BAR_INVALID_SELECTOR" }
const index = selector == "index" ? value : barConfigs.findIndex((bar)=> bar[selector] == value)
const barConfig = barConfigs[index]
if (!barConfig) { return "BAR_NOT_FOUND" }
updateBarConfig(barConfig.id, {autoHide: true})
return "BAR_AUTO_HIDE_SUCCESS"
}

function manualHide(selector: string, value: string): string {
if (!barSelectors.includes(selector)) { return "BAR_INVALID_SELECTOR" }
const index = selector == "index" ? value : barConfigs.findIndex((bar)=> bar[selector] == value)
const barConfig = barConfigs[index]
if (!barConfig) { return "BAR_NOT_FOUND" }
updateBarConfig(barConfig.id, {autoHide: false})
return "BAR_MANUAL_HIDE_SUCCESS"
}

function toggleAutoHide(selector: string, value: string): string {
if (!barSelectors.includes(selector)) { return "BAR_INVALID_SELECTOR" }
const index = selector == "index" ? value : barConfigs.findIndex((bar)=> bar[selector] == value)
const barConfig = barConfigs[index]
if (!barConfig) { return "BAR_NOT_FOUND" }
updateBarConfig(barConfig.id, {autoHide: !barConfig.autoHide})
return root.dankBarAutoHide ? "BAR_MANUAL_HIDE_SUCCESS": "BAR_AUTO_HIDE_SUCCESS"
}

target: "bar"
}
}