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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
import QtQuick
import Quickshell
import qs.Services
Item {
id: root
property var pluginService: null
property string trigger: "n"
signal itemsChanged
property var notes: []
property int maxNotes: 50
Component.onCompleted: {
if (!pluginService)
return;
trigger = pluginService.loadPluginData("quickNotesExample", "trigger", "n");
maxNotes = pluginService.loadPluginData("quickNotesExample", "maxNotes", 50);
// Load notes from plugin STATE (persistent across sessions, separate file)
notes = pluginService.loadPluginState("quickNotesExample", "notes", []);
}
function getItems(query) {
const items = [];
if (query && query.trim().length > 0) {
const text = query.trim();
items.push({
name: "Save note: " + text,
icon: "material:note_add",
comment: "Save as a new note",
action: "add:" + text,
categories: ["Quick Notes"]
});
items.push({
name: "Copy: " + text,
icon: "material:content_copy",
comment: "Copy text to clipboard",
action: "copy:" + text,
categories: ["Quick Notes"]
});
}
const filteredNotes = query ? notes.filter(n => n.text.toLowerCase().includes(query.toLowerCase())) : notes;
for (let i = 0; i < Math.min(20, filteredNotes.length); i++) {
const note = filteredNotes[i];
const age = _formatAge(note.timestamp);
items.push({
name: note.text,
icon: "material:sticky_note_2",
comment: age + " — select to copy, hold for options",
action: "copy:" + note.text,
categories: ["Quick Notes"]
});
}
if (notes.length > 0 && !query) {
items.push({
name: "Clear all notes (" + notes.length + ")",
icon: "material:delete_sweep",
comment: "Remove all saved notes",
action: "clear:",
categories: ["Quick Notes"]
});
}
return items;
}
function executeItem(item) {
if (!item?.action)
return;
const colonIdx = item.action.indexOf(":");
const actionType = item.action.substring(0, colonIdx);
const actionData = item.action.substring(colonIdx + 1);
switch (actionType) {
case "add":
addNote(actionData);
break;
case "copy":
copyToClipboard(actionData);
break;
case "remove":
removeNote(actionData);
break;
case "clear":
clearAllNotes();
break;
default:
showToast("Unknown action: " + actionType);
}
}
function addNote(text) {
if (!text)
return;
const existing = notes.findIndex(n => n.text === text);
if (existing !== -1)
notes.splice(existing, 1);
notes.unshift({
text: text,
timestamp: Date.now()
});
if (notes.length > maxNotes)
notes = notes.slice(0, maxNotes);
_saveNotes();
showToast("Note saved");
}
function removeNote(text) {
notes = notes.filter(n => n.text !== text);
_saveNotes();
showToast("Note removed");
}
function clearAllNotes() {
notes = [];
pluginService.clearPluginState("quickNotesExample");
showToast("All notes cleared");
itemsChanged();
}
function _saveNotes() {
if (!pluginService)
return;
// Save to plugin STATE — writes to quickNotesExample_state.json
// This is separate from plugin SETTINGS (plugin_settings.json)
pluginService.savePluginState("quickNotesExample", "notes", notes);
itemsChanged();
}
function copyToClipboard(text) {
Quickshell.execDetached(["dms", "cl", "copy", text]);
showToast("Copied to clipboard");
}
function showToast(message) {
if (typeof ToastService !== "undefined")
ToastService.showInfo("Quick Notes", message);
}
function _formatAge(timestamp) {
if (!timestamp)
return "";
const seconds = Math.floor((Date.now() - timestamp) / 1000);
if (seconds < 60)
return "just now";
const minutes = Math.floor(seconds / 60);
if (minutes < 60)
return minutes + "m ago";
const hours = Math.floor(minutes / 60);
if (hours < 24)
return hours + "h ago";
const days = Math.floor(hours / 24);
return days + "d ago";
}
onTriggerChanged: {
if (!pluginService)
return;
pluginService.savePluginData("quickNotesExample", "trigger", trigger);
}
}
|