launcher: allow configuring actions (#558)
* refactor: make launcher actions configurable * use variants + internal -> setMode + format * reorder readme --------- Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
This commit is contained in:
parent
0d8771cf4d
commit
767ced0df3
4 changed files with 242 additions and 142 deletions
106
README.md
106
README.md
|
|
@ -357,6 +357,112 @@ default, you must create it manually.
|
|||
},
|
||||
"launcher": {
|
||||
"actionPrefix": ">",
|
||||
"actions": [
|
||||
{
|
||||
"name": "Calculator",
|
||||
"icon": "calculate",
|
||||
"description": "Do simple math equations (powered by Qalc)",
|
||||
"command": ["autocomplete", "calc"],
|
||||
"enabled": true,
|
||||
"dangerous": false
|
||||
},
|
||||
{
|
||||
"name": "Scheme",
|
||||
"icon": "palette",
|
||||
"description": "Change the current colour scheme",
|
||||
"command": ["autocomplete", "scheme"],
|
||||
"enabled": true,
|
||||
"dangerous": false
|
||||
},
|
||||
{
|
||||
"name": "Wallpaper",
|
||||
"icon": "image",
|
||||
"description": "Change the current wallpaper",
|
||||
"command": ["autocomplete", "wallpaper"],
|
||||
"enabled": true,
|
||||
"dangerous": false
|
||||
},
|
||||
{
|
||||
"name": "Variant",
|
||||
"icon": "colors",
|
||||
"description": "Change the current scheme variant",
|
||||
"command": ["autocomplete", "variant"],
|
||||
"enabled": true,
|
||||
"dangerous": false
|
||||
},
|
||||
{
|
||||
"name": "Transparency",
|
||||
"icon": "opacity",
|
||||
"description": "Change shell transparency",
|
||||
"command": ["autocomplete", "transparency"],
|
||||
"enabled": false,
|
||||
"dangerous": false
|
||||
},
|
||||
{
|
||||
"name": "Random",
|
||||
"icon": "casino",
|
||||
"description": "Switch to a random wallpaper",
|
||||
"command": ["caelestia", "wallpaper", "-r"],
|
||||
"enabled": true,
|
||||
"dangerous": false
|
||||
},
|
||||
{
|
||||
"name": "Light",
|
||||
"icon": "light_mode",
|
||||
"description": "Change the scheme to light mode",
|
||||
"command": ["setMode", "light"],
|
||||
"enabled": true,
|
||||
"dangerous": false
|
||||
},
|
||||
{
|
||||
"name": "Dark",
|
||||
"icon": "dark_mode",
|
||||
"description": "Change the scheme to dark mode",
|
||||
"command": ["setMode", "dark"],
|
||||
"enabled": true,
|
||||
"dangerous": false
|
||||
},
|
||||
{
|
||||
"name": "Shutdown",
|
||||
"icon": "power_settings_new",
|
||||
"description": "Shutdown the system",
|
||||
"command": ["systemctl", "poweroff"],
|
||||
"enabled": true,
|
||||
"dangerous": true
|
||||
},
|
||||
{
|
||||
"name": "Reboot",
|
||||
"icon": "cached",
|
||||
"description": "Reboot the system",
|
||||
"command": ["systemctl", "reboot"],
|
||||
"enabled": true,
|
||||
"dangerous": true
|
||||
},
|
||||
{
|
||||
"name": "Logout",
|
||||
"icon": "exit_to_app",
|
||||
"description": "Log out of the current session",
|
||||
"command": ["loginctl", "terminate-user", ""],
|
||||
"enabled": true,
|
||||
"dangerous": true
|
||||
},
|
||||
{
|
||||
"name": "Lock",
|
||||
"icon": "lock",
|
||||
"description": "Lock the current session",
|
||||
"command": ["loginctl", "lock-session"],
|
||||
"enabled": true,
|
||||
"dangerous": false
|
||||
},
|
||||
{
|
||||
"name": "Sleep",
|
||||
"icon": "bedtime",
|
||||
"description": "Suspend then hibernate",
|
||||
"command": ["systemctl", "suspend-then-hibernate"],
|
||||
"enabled": true,
|
||||
"dangerous": false
|
||||
}
|
||||
],
|
||||
"dragThreshold": 50,
|
||||
"vimKeybinds": false,
|
||||
"enableDangerousActions": false,
|
||||
|
|
|
|||
|
|
@ -27,4 +27,111 @@ JsonObject {
|
|||
property int wallpaperWidth: 280
|
||||
property int wallpaperHeight: 200
|
||||
}
|
||||
|
||||
property list<var> actions: [
|
||||
{
|
||||
name: "Calculator",
|
||||
icon: "calculate",
|
||||
description: "Do simple math equations (powered by Qalc)",
|
||||
command: ["autocomplete", "calc"],
|
||||
enabled: true,
|
||||
dangerous: false
|
||||
},
|
||||
{
|
||||
name: "Scheme",
|
||||
icon: "palette",
|
||||
description: "Change the current colour scheme",
|
||||
command: ["autocomplete", "scheme"],
|
||||
enabled: true,
|
||||
dangerous: false
|
||||
},
|
||||
{
|
||||
name: "Wallpaper",
|
||||
icon: "image",
|
||||
description: "Change the current wallpaper",
|
||||
command: ["autocomplete", "wallpaper"],
|
||||
enabled: true,
|
||||
dangerous: false
|
||||
},
|
||||
{
|
||||
name: "Variant",
|
||||
icon: "colors",
|
||||
description: "Change the current scheme variant",
|
||||
command: ["autocomplete", "variant"],
|
||||
enabled: true,
|
||||
dangerous: false
|
||||
},
|
||||
{
|
||||
name: "Transparency",
|
||||
icon: "opacity",
|
||||
description: "Change shell transparency",
|
||||
command: ["autocomplete", "transparency"],
|
||||
enabled: false,
|
||||
dangerous: false
|
||||
},
|
||||
{
|
||||
name: "Random",
|
||||
icon: "casino",
|
||||
description: "Switch to a random wallpaper",
|
||||
command: ["caelestia", "wallpaper", "-r"],
|
||||
enabled: true,
|
||||
dangerous: false
|
||||
},
|
||||
{
|
||||
name: "Light",
|
||||
icon: "light_mode",
|
||||
description: "Change the scheme to light mode",
|
||||
command: ["setMode", "light"],
|
||||
enabled: true,
|
||||
dangerous: false
|
||||
},
|
||||
{
|
||||
name: "Dark",
|
||||
icon: "dark_mode",
|
||||
description: "Change the scheme to dark mode",
|
||||
command: ["setMode", "dark"],
|
||||
enabled: true,
|
||||
dangerous: false
|
||||
},
|
||||
{
|
||||
name: "Shutdown",
|
||||
icon: "power_settings_new",
|
||||
description: "Shutdown the system",
|
||||
command: ["systemctl", "poweroff"],
|
||||
enabled: true,
|
||||
dangerous: true
|
||||
},
|
||||
{
|
||||
name: "Reboot",
|
||||
icon: "cached",
|
||||
description: "Reboot the system",
|
||||
command: ["systemctl", "reboot"],
|
||||
enabled: true,
|
||||
dangerous: true
|
||||
},
|
||||
{
|
||||
name: "Logout",
|
||||
icon: "exit_to_app",
|
||||
description: "Log out of the current session",
|
||||
command: ["loginctl", "terminate-user", ""],
|
||||
enabled: true,
|
||||
dangerous: true
|
||||
},
|
||||
{
|
||||
name: "Lock",
|
||||
icon: "lock",
|
||||
description: "Lock the current session",
|
||||
command: ["loginctl", "lock-session"],
|
||||
enabled: true,
|
||||
dangerous: false
|
||||
},
|
||||
{
|
||||
name: "Sleep",
|
||||
icon: "bedtime",
|
||||
description: "Suspend then hibernate",
|
||||
command: ["systemctl", "suspend-then-hibernate"],
|
||||
enabled: true,
|
||||
dangerous: false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import QtQuick
|
|||
Item {
|
||||
id: root
|
||||
|
||||
required property Actions.Action modelData
|
||||
required property var modelData
|
||||
required property var list
|
||||
|
||||
implicitHeight: Config.launcher.sizes.itemHeight
|
||||
|
|
|
|||
|
|
@ -10,156 +10,43 @@ import QtQuick
|
|||
Searcher {
|
||||
id: root
|
||||
|
||||
readonly property list<Action> actions: [
|
||||
Action {
|
||||
name: qsTr("Calculator")
|
||||
desc: qsTr("Do simple math equations (powered by Qalc)")
|
||||
icon: "calculate"
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
root.autocomplete(list, "calc");
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Scheme")
|
||||
desc: qsTr("Change the current colour scheme")
|
||||
icon: "palette"
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
root.autocomplete(list, "scheme");
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Wallpaper")
|
||||
desc: qsTr("Change the current wallpaper")
|
||||
icon: "image"
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
root.autocomplete(list, "wallpaper");
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Variant")
|
||||
desc: qsTr("Change the current scheme variant")
|
||||
icon: "colors"
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
root.autocomplete(list, "variant");
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Transparency")
|
||||
desc: qsTr("Change shell transparency")
|
||||
icon: "opacity"
|
||||
disabled: true
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
root.autocomplete(list, "transparency");
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Random")
|
||||
desc: qsTr("Switch to a random wallpaper")
|
||||
icon: "casino"
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
list.visibilities.launcher = false;
|
||||
Quickshell.execDetached(["caelestia", "wallpaper", "-r"]);
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Light")
|
||||
desc: qsTr("Change the scheme to light mode")
|
||||
icon: "light_mode"
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
list.visibilities.launcher = false;
|
||||
Colours.setMode("light");
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Dark")
|
||||
desc: qsTr("Change the scheme to dark mode")
|
||||
icon: "dark_mode"
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
list.visibilities.launcher = false;
|
||||
Colours.setMode("dark");
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Shutdown")
|
||||
desc: qsTr("Shutdown the system")
|
||||
icon: "power_settings_new"
|
||||
disabled: !Config.launcher.enableDangerousActions
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
list.visibilities.launcher = false;
|
||||
Quickshell.execDetached(["systemctl", "poweroff"]);
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Reboot")
|
||||
desc: qsTr("Reboot the system")
|
||||
icon: "cached"
|
||||
disabled: !Config.launcher.enableDangerousActions
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
list.visibilities.launcher = false;
|
||||
Quickshell.execDetached(["systemctl", "reboot"]);
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Logout")
|
||||
desc: qsTr("Log out of the current session")
|
||||
icon: "exit_to_app"
|
||||
disabled: !Config.launcher.enableDangerousActions
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
list.visibilities.launcher = false;
|
||||
Quickshell.execDetached(["loginctl", "terminate-user", ""]);
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Lock")
|
||||
desc: qsTr("Lock the current session")
|
||||
icon: "lock"
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
list.visibilities.launcher = false;
|
||||
Quickshell.execDetached(["loginctl", "lock-session"]);
|
||||
}
|
||||
},
|
||||
Action {
|
||||
name: qsTr("Sleep")
|
||||
desc: qsTr("Suspend then hibernate")
|
||||
icon: "bedtime"
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
list.visibilities.launcher = false;
|
||||
Quickshell.execDetached(["systemctl", "suspend-then-hibernate"]);
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
function transformSearch(search: string): string {
|
||||
return search.slice(Config.launcher.actionPrefix.length);
|
||||
}
|
||||
|
||||
function autocomplete(list: AppList, text: string): void {
|
||||
list.search.text = `${Config.launcher.actionPrefix}${text} `;
|
||||
}
|
||||
|
||||
list: actions.filter(a => !a.disabled)
|
||||
list: variants.instances
|
||||
useFuzzy: Config.launcher.useFuzzy.actions
|
||||
|
||||
Variants {
|
||||
id: variants
|
||||
|
||||
model: Config.launcher.actions.filter(a => (a.enabled ?? true) && (Config.launcher.enableDangerousActions || !(a.dangerous ?? false)))
|
||||
|
||||
Action {}
|
||||
}
|
||||
|
||||
component Action: QtObject {
|
||||
required property string name
|
||||
required property string desc
|
||||
required property string icon
|
||||
property bool disabled
|
||||
required property var modelData
|
||||
readonly property string name: modelData.name ?? qsTr("Unnamed")
|
||||
readonly property string desc: modelData.description ?? qsTr("No description")
|
||||
readonly property string icon: modelData.icon ?? "help_outline"
|
||||
readonly property list<string> command: modelData.command ?? []
|
||||
readonly property bool enabled: modelData.enabled ?? true
|
||||
readonly property bool dangerous: modelData.dangerous ?? false
|
||||
|
||||
function onClicked(list: AppList): void {
|
||||
if (command.length === 0)
|
||||
return;
|
||||
|
||||
if (command[0] === "autocomplete" && command.length > 1) {
|
||||
list.search.text = `${Config.launcher.actionPrefix}${command[1]} `;
|
||||
} else if (command[0] === "setMode" && command.length > 1) {
|
||||
list.visibilities.launcher = false;
|
||||
Colours.setMode(command[1]);
|
||||
} else {
|
||||
list.visibilities.launcher = false;
|
||||
Quickshell.execDetached(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue