mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-05 21:15:38 -05:00
feat: add autohide and settings ipc functions (#786)
* feat: bar visibility and autoHide IPC also changed reveal to show * feat: settings get/set IPC * fix: show -> reveal, show is reserved keyword * move IpcHandlers from SettingsData to DMSShellIPC
This commit is contained in:
@@ -1390,27 +1390,4 @@ rm -rf '${home}'/.cache/icon-cache '${home}'/.cache/thumbnails 2>/dev/null || tr
|
|||||||
}
|
}
|
||||||
|
|
||||||
property bool pluginSettingsFileExists: false
|
property bool pluginSettingsFileExists: false
|
||||||
|
|
||||||
IpcHandler {
|
|
||||||
function reveal(): string {
|
|
||||||
root.setShowDock(true);
|
|
||||||
return "DOCK_SHOW_SUCCESS";
|
|
||||||
}
|
|
||||||
|
|
||||||
function hide(): string {
|
|
||||||
root.setShowDock(false);
|
|
||||||
return "DOCK_HIDE_SUCCESS";
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggle(): string {
|
|
||||||
root.toggleShowDock();
|
|
||||||
return root.showDock ? "DOCK_SHOW_SUCCESS" : "DOCK_HIDE_SUCCESS";
|
|
||||||
}
|
|
||||||
|
|
||||||
function status(): string {
|
|
||||||
return root.showDock ? "visible" : "hidden";
|
|
||||||
}
|
|
||||||
|
|
||||||
target: "dock"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -480,56 +480,108 @@ Item {
|
|||||||
target: "dankdash"
|
target: "dankdash"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getBarConfig(selector: string, value: string): var {
|
||||||
|
const barSelectors = ["id", "name", "index"];
|
||||||
|
if (!barSelectors.includes(selector)) return { error: "BAR_INVALID_SELECTOR" };
|
||||||
|
const index = selector === "index" ? Number(value) : SettingsData.barConfigs.findIndex(bar => bar[selector] == value);
|
||||||
|
const barConfig = SettingsData.barConfigs?.[index];
|
||||||
|
if (!barConfig) return { error: "BAR_NOT_FOUND" };
|
||||||
|
return { barConfig };
|
||||||
|
}
|
||||||
|
|
||||||
IpcHandler {
|
IpcHandler {
|
||||||
function reveal(index: int): string {
|
function reveal(selector: string, value: string): string {
|
||||||
const idx = index - 1;
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
if (idx < 0 || idx >= SettingsData.barConfigs.length) {
|
if (error) return error;
|
||||||
return `BAR_${index}_NOT_FOUND`;
|
SettingsData.updateBarConfig(barConfig.id, {visible: true});
|
||||||
}
|
return "BAR_SHOW_SUCCESS";
|
||||||
const bar = SettingsData.barConfigs[idx];
|
|
||||||
SettingsData.updateBarConfig(bar.id, {
|
|
||||||
visible: true
|
|
||||||
});
|
|
||||||
return `BAR_${index}_SHOW_SUCCESS`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hide(index: int): string {
|
function hide(selector: string, value: string): string {
|
||||||
const idx = index - 1;
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
if (idx < 0 || idx >= SettingsData.barConfigs.length) {
|
if (error) return error;
|
||||||
return `BAR_${index}_NOT_FOUND`;
|
SettingsData.updateBarConfig(barConfig.id, {visible: false});
|
||||||
}
|
return "BAR_HIDE_SUCCESS";
|
||||||
const bar = SettingsData.barConfigs[idx];
|
|
||||||
SettingsData.updateBarConfig(bar.id, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
return `BAR_${index}_HIDE_SUCCESS`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggle(index: int): string {
|
function toggle(selector: string, value: string): string {
|
||||||
const idx = index - 1;
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
if (idx < 0 || idx >= SettingsData.barConfigs.length) {
|
if (error) return error;
|
||||||
return `BAR_${index}_NOT_FOUND`;
|
SettingsData.updateBarConfig(barConfig.id, {visible: !barConfig.visible});
|
||||||
}
|
return !barConfig.visible ? "BAR_SHOW_SUCCESS" : "BAR_HIDE_SUCCESS";
|
||||||
const bar = SettingsData.barConfigs[idx];
|
|
||||||
const newVisible = !(bar.visible ?? true);
|
|
||||||
SettingsData.updateBarConfig(bar.id, {
|
|
||||||
visible: newVisible
|
|
||||||
});
|
|
||||||
return newVisible ? `BAR_${index}_SHOW_SUCCESS` : `BAR_${index}_HIDE_SUCCESS`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function status(index: int): string {
|
function status(selector: string, value: string): string {
|
||||||
const idx = index - 1;
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
if (idx < 0 || idx >= SettingsData.barConfigs.length) {
|
if (error) return error;
|
||||||
return `BAR_${index}_NOT_FOUND`;
|
return barConfig.visible ? "visible" : "hidden";
|
||||||
}
|
}
|
||||||
const bar = SettingsData.barConfigs[idx];
|
|
||||||
return (bar.visible ?? true) ? "visible" : "hidden";
|
function autoHide(selector: string, value: string): string {
|
||||||
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
|
if (error) return error;
|
||||||
|
SettingsData.updateBarConfig(barConfig.id, {autoHide: true});
|
||||||
|
return "BAR_AUTO_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function manualHide(selector: string, value: string): string {
|
||||||
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
|
if (error) return error;
|
||||||
|
SettingsData.updateBarConfig(barConfig.id, {autoHide: false});
|
||||||
|
return "BAR_MANUAL_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleAutoHide(selector: string, value: string): string {
|
||||||
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
|
if (error) return error;
|
||||||
|
SettingsData.updateBarConfig(barConfig.id, {autoHide: !barConfig.autoHide});
|
||||||
|
return barConfig.autoHide ? "BAR_MANUAL_HIDE_SUCCESS": "BAR_AUTO_HIDE_SUCCESS";
|
||||||
}
|
}
|
||||||
|
|
||||||
target: "bar"
|
target: "bar"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IpcHandler {
|
||||||
|
function reveal(): string {
|
||||||
|
SettingsData.setShowDock(true);
|
||||||
|
return "DOCK_SHOW_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hide(): string {
|
||||||
|
SettingsData.setShowDock(false);
|
||||||
|
return "DOCK_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggle(): string {
|
||||||
|
SettingsData.toggleShowDock();
|
||||||
|
return SettingsData.showDock ? "DOCK_SHOW_SUCCESS" : "DOCK_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function status(): string {
|
||||||
|
return SettingsData.showDock ? "visible" : "hidden";
|
||||||
|
}
|
||||||
|
|
||||||
|
function autoHide(): string {
|
||||||
|
SettingsData.dockAutoHide = true
|
||||||
|
SettingsData.saveSettings()
|
||||||
|
return "BAR_AUTO_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function manualHide(): string {
|
||||||
|
SettingsData.dockAutoHide = false
|
||||||
|
SettingsData.saveSettings()
|
||||||
|
return "BAR_MANUAL_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleAutoHide(): string {
|
||||||
|
SettingsData.dockAutoHide = !SettingsData.dockAutoHide
|
||||||
|
SettingsData.saveSettings()
|
||||||
|
return SettingsData.dockAutoHide ? "BAR_AUTO_HIDE_SUCCESS" : "BAR_MANUAL_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
target: "dock"
|
||||||
|
}
|
||||||
|
|
||||||
IpcHandler {
|
IpcHandler {
|
||||||
function open(): string {
|
function open(): string {
|
||||||
PopoutService.openSettings();
|
PopoutService.openSettings();
|
||||||
@@ -546,6 +598,53 @@ Item {
|
|||||||
return "SETTINGS_TOGGLE_SUCCESS";
|
return "SETTINGS_TOGGLE_SUCCESS";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get(key: string): string {
|
||||||
|
return JSON.stringify(SettingsData?.[key])
|
||||||
|
}
|
||||||
|
|
||||||
|
function set(key: string, value: string): string {
|
||||||
|
|
||||||
|
if (!(key in SettingsData)) {
|
||||||
|
console.warn("Cannot set property, not found:", key)
|
||||||
|
return "SETTINGS_INVALID_KEY"
|
||||||
|
}
|
||||||
|
|
||||||
|
const typeName = typeof SettingsData?.[key]
|
||||||
|
|
||||||
|
try {
|
||||||
|
switch (typeName) {
|
||||||
|
case "boolean":
|
||||||
|
if (value === "true" || value === "false") value = (value === "true")
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn("Setting:", key, value)
|
||||||
|
SettingsData[key] = value
|
||||||
|
SettingsData.saveSettings()
|
||||||
|
return "SETTINGS_SET_SUCCESS"
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Failed to set property:", key, "error:", e)
|
||||||
|
return "SETTINGS_SET_FAILURE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
target: "settings"
|
target: "settings"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user