summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/dms/PLUGINS/LauncherExample/LauncherExampleLauncher.qml
blob: 81040b67e07c4d927da68df4e4a265ba8efa77db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import QtQuick
import Quickshell
import qs.Services

Item {
    id: root

    // Plugin properties
    property var pluginService: null
    property string trigger: "#"

    // Plugin interface signals
    signal itemsChanged()

    Component.onCompleted: {
        console.info("LauncherExample: Plugin loaded")

        // Load custom trigger from settings
        if (pluginService) {
            trigger = pluginService.loadPluginData("launcherExample", "trigger", "#")
        }
    }

    // Required function: Get items for launcher
    function getItems(query) {
        const baseItems = [
            {
                name: "Test Item 1",
                icon: "material:lightbulb",
                comment: "This is a test item that shows a toast notification",
                action: "toast:Test Item 1 executed!",
                categories: ["LauncherExample"]
            },
            {
                name: "Test Item 2",
                icon: "material:star",
                comment: "Another test item with different action",
                action: "toast:Test Item 2 clicked!",
                categories: ["LauncherExample"]
            },
            {
                name: "Test Item 3",
                icon: "material:favorite",
                comment: "Third test item for demonstration",
                action: "toast:Test Item 3 activated!",
                categories: ["LauncherExample"]
            },
            {
                name: "Unicode Icon Example",
                icon: "unicode:🚀",
                comment: "Demonstrates unicode/emoji icon support",
                action: "toast:Unicode icons work great!",
                categories: ["LauncherExample"]
            },
            {
                name: "Example Copy Action",
                icon: "material:content_copy",
                comment: "Demonstrates copying text to clipboard",
                action: "copy:This text was copied by the launcher plugin!",
                categories: ["LauncherExample"]
            },
            {
                name: "Example Script Action",
                icon: "material:terminal",
                comment: "Demonstrates running a simple command",
                action: "script:echo 'Hello from launcher plugin!'",
                categories: ["LauncherExample"]
            }
        ]

        if (!query || query.length === 0) {
            return baseItems
        }

        // Filter items based on query
        const lowerQuery = query.toLowerCase()
        return baseItems.filter(item => {
            return item.name.toLowerCase().includes(lowerQuery) ||
                   item.comment.toLowerCase().includes(lowerQuery)
        })
    }

    // Required function: Execute item action
    function executeItem(item) {
        if (!item || !item.action) {
            console.warn("LauncherExample: Invalid item or action")
            return
        }

        console.log("LauncherExample: Executing item:", item.name, "with action:", item.action)

        const actionParts = item.action.split(":")
        const actionType = actionParts[0]
        const actionData = actionParts.slice(1).join(":")

        switch (actionType) {
            case "toast":
                showToast(actionData)
                break
            case "copy":
                copyToClipboard(actionData)
                break
            case "script":
                runScript(actionData)
                break
            default:
                console.warn("LauncherExample: Unknown action type:", actionType)
                showToast("Unknown action: " + actionType)
        }
    }

    // Helper functions for different action types
    function showToast(message) {
        if (typeof ToastService !== "undefined") {
            ToastService.showInfo("LauncherExample", message)
        } else {
            console.log("LauncherExample Toast:", message)
        }
    }

    function copyToClipboard(text) {
        Quickshell.execDetached(["dms", "cl", "copy", text])
        showToast("Copied to clipboard: " + text)
    }

    function runScript(command) {
        console.log("LauncherExample: Would run script:", command)
        showToast("Script executed: " + command)

        // In a real plugin, you might create a Process component here
        // For demo purposes, we just show what would happen
    }

    // Watch for trigger changes
    onTriggerChanged: {
        if (pluginService) {
            pluginService.savePluginData("launcherExample", "trigger", trigger)
        }
    }
}