@wox-launcher/wox-plugin 0.0.107 → 0.0.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -1
- package/dist/context.js +31 -0
- package/dist/image.js +21 -0
- package/dist/index.js +20 -0
- package/package.json +1 -1
- package/types/ai.d.ts +354 -5
- package/types/index.d.ts +1037 -49
- package/types/setting.d.ts +419 -3
package/types/index.d.ts
CHANGED
|
@@ -1,119 +1,532 @@
|
|
|
1
1
|
import { MetadataCommand, PluginSettingDefinitionItem } from "./setting.js"
|
|
2
2
|
import { AI } from "./ai.js"
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A dictionary type for string key-value pairs.
|
|
6
|
+
*
|
|
7
|
+
* Used throughout the plugin API for passing arbitrary string data,
|
|
8
|
+
* such as context data, settings, and metadata.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const data: MapString = {
|
|
13
|
+
* "userId": "12345",
|
|
14
|
+
* "category": "documents",
|
|
15
|
+
* "tag": "favorite"
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
4
19
|
export type MapString = { [key: string]: string }
|
|
5
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Operating system platform identifier.
|
|
23
|
+
*
|
|
24
|
+
* Used for platform-specific functionality and conditional behavior.
|
|
25
|
+
*
|
|
26
|
+
* - `windows`: Windows operating system
|
|
27
|
+
* - `darwin`: macOS operating system
|
|
28
|
+
* - `linux`: Linux operating system
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* if (platform === "darwin") {
|
|
33
|
+
* // macOS-specific code
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
6
37
|
export type Platform = "windows" | "darwin" | "linux"
|
|
7
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Main plugin interface that all Wox plugins must implement.
|
|
41
|
+
*
|
|
42
|
+
* A plugin is a class or object that provides search functionality to Wox.
|
|
43
|
+
* It must implement the `init` and `query` methods.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* class MyPlugin implements Plugin {
|
|
48
|
+
* private api: PublicAPI
|
|
49
|
+
*
|
|
50
|
+
* async init(ctx: Context, initParams: PluginInitParams): Promise<void> {
|
|
51
|
+
* this.api = initParams.API
|
|
52
|
+
* await this.api.Log(ctx, "Info", "Plugin initialized")
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* async query(ctx: Context, query: Query): Promise<Result[]> {
|
|
56
|
+
* return [{
|
|
57
|
+
* Title: "Hello World",
|
|
58
|
+
* SubTitle: "My first result",
|
|
59
|
+
* Icon: { ImageType: "emoji", ImageData: "👋" },
|
|
60
|
+
* Score: 100
|
|
61
|
+
* }]
|
|
62
|
+
* }
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
8
66
|
export interface Plugin {
|
|
67
|
+
/**
|
|
68
|
+
* Initialize the plugin with the provided context and parameters.
|
|
69
|
+
*
|
|
70
|
+
* Called once when the plugin is first loaded. Use this to:
|
|
71
|
+
* - Store the API for later use
|
|
72
|
+
* - Load initial data
|
|
73
|
+
* - Register callbacks
|
|
74
|
+
* - Set up any required resources
|
|
75
|
+
*
|
|
76
|
+
* @param ctx - Request context with trace ID for logging
|
|
77
|
+
* @param initParams - Initialization parameters including API and plugin directory
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* async init(ctx: Context, initParams: PluginInitParams): Promise<void> {
|
|
82
|
+
* this.api = initParams.API
|
|
83
|
+
* this.pluginDir = initParams.PluginDirectory
|
|
84
|
+
*
|
|
85
|
+
* // Load settings
|
|
86
|
+
* const apiKey = await this.api.GetSetting(ctx, "apiKey")
|
|
87
|
+
*
|
|
88
|
+
* // Register callbacks
|
|
89
|
+
* await this.api.OnSettingChanged(ctx, (ctx, key, value) => {
|
|
90
|
+
* console.log(`Setting changed: ${key} = ${value}`)
|
|
91
|
+
* })
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
9
95
|
init: (ctx: Context, initParams: PluginInitParams) => Promise<void>
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Query handler that returns results based on user input.
|
|
99
|
+
*
|
|
100
|
+
* Called whenever the user types a query that triggers this plugin.
|
|
101
|
+
* The plugin should return a list of matching results sorted by relevance.
|
|
102
|
+
*
|
|
103
|
+
* @param ctx - Request context with trace ID for logging
|
|
104
|
+
* @param query - The query object containing search text, type, environment
|
|
105
|
+
* @returns Array of results to display to the user
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* async query(ctx: Context, query: Query): Promise<Result[]> {
|
|
110
|
+
* if (query.Type === "selection") {
|
|
111
|
+
* return this.handleSelection(query.Selection)
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* const searchTerm = query.Search.toLowerCase()
|
|
115
|
+
* return this.items
|
|
116
|
+
* .filter(item => item.name.toLowerCase().includes(searchTerm))
|
|
117
|
+
* .map(item => ({
|
|
118
|
+
* Title: item.name,
|
|
119
|
+
* SubTitle: item.description,
|
|
120
|
+
* Icon: this.getIcon(item),
|
|
121
|
+
* Score: this.calculateScore(item, searchTerm),
|
|
122
|
+
* Actions: [
|
|
123
|
+
* {
|
|
124
|
+
* Name: "Open",
|
|
125
|
+
* Icon: { ImageType: "emoji", ImageData: "🔗" },
|
|
126
|
+
* Action: async (ctx, actionCtx) => {
|
|
127
|
+
* await this.openItem(item)
|
|
128
|
+
* }
|
|
129
|
+
* }
|
|
130
|
+
* ]
|
|
131
|
+
* }))
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
10
135
|
query: (ctx: Context, query: Query) => Promise<Result[]>
|
|
11
136
|
}
|
|
12
137
|
|
|
138
|
+
/**
|
|
139
|
+
* User-selected or drag-dropped data.
|
|
140
|
+
*
|
|
141
|
+
* When a plugin has the `MetadataFeatureQuerySelection` feature enabled,
|
|
142
|
+
* it can receive selection queries in addition to input queries.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* async query(ctx: Context, query: Query): Promise<Result[]> {
|
|
147
|
+
* if (query.Type === "selection") {
|
|
148
|
+
* const selection = query.Selection
|
|
149
|
+
* if (selection.Type === "text") {
|
|
150
|
+
* console.log("Selected text:", selection.Text)
|
|
151
|
+
* } else if (selection.Type === "file") {
|
|
152
|
+
* console.log("Selected files:", selection.FilePaths)
|
|
153
|
+
* }
|
|
154
|
+
* }
|
|
155
|
+
* return []
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
13
159
|
export interface Selection {
|
|
160
|
+
/**
|
|
161
|
+
* The type of selection data.
|
|
162
|
+
*
|
|
163
|
+
* - `text`: User has selected text content
|
|
164
|
+
* - `file`: User has selected or drag-dropped files
|
|
165
|
+
*/
|
|
14
166
|
Type: "text" | "file"
|
|
15
|
-
|
|
167
|
+
/**
|
|
168
|
+
* The selected text content.
|
|
169
|
+
*
|
|
170
|
+
* Only available when Type is "text".
|
|
171
|
+
*/
|
|
16
172
|
Text: string
|
|
17
|
-
|
|
173
|
+
/**
|
|
174
|
+
* Array of selected file paths.
|
|
175
|
+
*
|
|
176
|
+
* Only available when Type is "file".
|
|
177
|
+
* Contains full paths to all selected/dropped files.
|
|
178
|
+
*/
|
|
18
179
|
FilePaths: string[]
|
|
19
180
|
}
|
|
20
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Environment context for a query.
|
|
184
|
+
*
|
|
185
|
+
* Provides information about the user's current environment when the
|
|
186
|
+
* query was made, such as the active window, browser URL, etc.
|
|
187
|
+
*
|
|
188
|
+
* This allows plugins to provide context-aware results.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* // Show different results based on active window
|
|
193
|
+
* async query(ctx: Context, query: Query): Promise<Result[]> {
|
|
194
|
+
* if (query.Env.ActiveWindowTitle.includes("Visual Studio")) {
|
|
195
|
+
* return this.getVSCodeActions()
|
|
196
|
+
* }
|
|
197
|
+
* return []
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
21
201
|
export interface QueryEnv {
|
|
22
202
|
/**
|
|
23
|
-
*
|
|
203
|
+
* Title of the active window when the query was made.
|
|
204
|
+
*
|
|
205
|
+
* Useful for context-aware results based on what application
|
|
206
|
+
* the user is currently using.
|
|
24
207
|
*/
|
|
25
208
|
ActiveWindowTitle: string
|
|
26
209
|
|
|
27
210
|
/**
|
|
28
|
-
*
|
|
211
|
+
* Process ID of the active window.
|
|
212
|
+
*
|
|
213
|
+
* Zero if the information is not available.
|
|
29
214
|
*/
|
|
30
215
|
ActiveWindowPid: number
|
|
31
216
|
|
|
32
217
|
/**
|
|
33
|
-
*
|
|
218
|
+
* Icon of the active window.
|
|
219
|
+
*
|
|
220
|
+
* May be empty if no icon is available.
|
|
34
221
|
*/
|
|
35
222
|
ActiveWindowIcon: WoxImage
|
|
36
223
|
|
|
37
|
-
|
|
38
|
-
|
|
224
|
+
/**
|
|
225
|
+
* URL of the active browser tab.
|
|
226
|
+
*
|
|
227
|
+
* Only available when:
|
|
228
|
+
* - The active window is a supported browser
|
|
229
|
+
* - The Wox browser extension is installed
|
|
230
|
+
*
|
|
231
|
+
* @see https://github.com/Wox-launcher/Wox.Chrome.Extension
|
|
232
|
+
*/
|
|
39
233
|
ActiveBrowserUrl: string
|
|
40
234
|
}
|
|
41
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Query object containing user input and context.
|
|
238
|
+
*
|
|
239
|
+
* Passed to the plugin's `query()` method, contains all information
|
|
240
|
+
* about the user's search query including the search text, type,
|
|
241
|
+
* trigger keyword, and environment context.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* async query(ctx: Context, query: Query): Promise<Result[]> {
|
|
246
|
+
* // Handle input query
|
|
247
|
+
* if (query.Type === "input") {
|
|
248
|
+
* console.log("Search:", query.Search)
|
|
249
|
+
* console.log("Trigger:", query.TriggerKeyword)
|
|
250
|
+
* }
|
|
251
|
+
*
|
|
252
|
+
* // Handle selection query
|
|
253
|
+
* if (query.Type === "selection") {
|
|
254
|
+
* console.log("Selection:", query.Selection)
|
|
255
|
+
* }
|
|
256
|
+
*
|
|
257
|
+
* // Check environment
|
|
258
|
+
* if (query.Env.ActiveBrowserUrl) {
|
|
259
|
+
* console.log("Browser:", query.Env.ActiveBrowserUrl)
|
|
260
|
+
* }
|
|
261
|
+
* }
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
42
264
|
export interface Query {
|
|
43
265
|
/**
|
|
44
|
-
*
|
|
266
|
+
* Unique query identifier.
|
|
267
|
+
*
|
|
268
|
+
* Used to correlate async updates with the original query.
|
|
269
|
+
* Pass this ID when calling UpdateResult or PushResults.
|
|
45
270
|
*/
|
|
46
271
|
Id: string
|
|
272
|
+
|
|
47
273
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
274
|
+
* Query type.
|
|
275
|
+
*
|
|
276
|
+
* - `input`: User typed a query
|
|
277
|
+
* - `selection`: User selected text or drag-dropped files
|
|
278
|
+
*
|
|
279
|
+
* Note: Selection queries require the `MetadataFeatureQuerySelection` feature.
|
|
50
280
|
*/
|
|
51
281
|
Type: "input" | "selection"
|
|
282
|
+
|
|
52
283
|
/**
|
|
53
|
-
* Raw query
|
|
54
|
-
* We didn't recommend use this property directly. You should always use Search property.
|
|
284
|
+
* Raw query string including trigger keyword.
|
|
55
285
|
*
|
|
56
|
-
*
|
|
286
|
+
* Not recommended for direct use. Use `Search` instead for the
|
|
287
|
+
* actual search term without the trigger keyword.
|
|
288
|
+
*
|
|
289
|
+
* Only available when Type is "input".
|
|
57
290
|
*/
|
|
58
291
|
RawQuery: string
|
|
292
|
+
|
|
59
293
|
/**
|
|
60
|
-
* Trigger keyword
|
|
294
|
+
* Trigger keyword that activated this plugin.
|
|
295
|
+
*
|
|
296
|
+
* Empty if using global trigger keyword.
|
|
61
297
|
*
|
|
62
|
-
*
|
|
298
|
+
* Only available when Type is "input".
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* If user types "git status", TriggerKeyword is "git" and Search is "status"
|
|
63
302
|
*/
|
|
64
303
|
TriggerKeyword?: string
|
|
304
|
+
|
|
65
305
|
/**
|
|
66
|
-
* Command part of
|
|
306
|
+
* Command part of the query (between trigger and search).
|
|
307
|
+
*
|
|
308
|
+
* Only available when Type is "input".
|
|
67
309
|
*
|
|
68
|
-
*
|
|
310
|
+
* @example
|
|
311
|
+
* If user types "myplugin cmd search", Command is "cmd" and Search is "search"
|
|
69
312
|
*/
|
|
70
313
|
Command?: string
|
|
314
|
+
|
|
71
315
|
/**
|
|
72
|
-
*
|
|
316
|
+
* The actual search term.
|
|
317
|
+
*
|
|
318
|
+
* This is the text the user wants to search for, without
|
|
319
|
+
* trigger keyword or command. Use this for your search logic.
|
|
73
320
|
*
|
|
74
|
-
*
|
|
321
|
+
* Only available when Type is "input".
|
|
75
322
|
*/
|
|
76
323
|
Search: string
|
|
77
324
|
|
|
78
325
|
/**
|
|
79
|
-
* User selected or drag-
|
|
326
|
+
* User selected or drag-dropped data.
|
|
80
327
|
*
|
|
81
|
-
*
|
|
328
|
+
* Only available when Type is "selection".
|
|
82
329
|
*/
|
|
83
330
|
Selection: Selection
|
|
84
331
|
|
|
85
332
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
333
|
+
* Environment context when the query was made.
|
|
334
|
+
*
|
|
335
|
+
* Includes information about the active window, browser URL, etc.
|
|
336
|
+
* Use this to provide context-aware results.
|
|
88
337
|
*/
|
|
89
338
|
Env: QueryEnv
|
|
90
339
|
|
|
91
340
|
/**
|
|
92
|
-
*
|
|
341
|
+
* Check if this is a global query (no trigger keyword).
|
|
342
|
+
*
|
|
343
|
+
* @returns true if triggered globally, false if triggered by keyword
|
|
93
344
|
*/
|
|
94
345
|
IsGlobalQuery(): boolean
|
|
95
346
|
}
|
|
96
347
|
|
|
348
|
+
/**
|
|
349
|
+
* A search result displayed to the user.
|
|
350
|
+
*
|
|
351
|
+
* Results are displayed in the Wox UI and can include icons, previews,
|
|
352
|
+
* actions, and tail elements for additional information.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```typescript
|
|
356
|
+
* const result: Result = {
|
|
357
|
+
* Id: "result-1",
|
|
358
|
+
* Title: "Open Calculator",
|
|
359
|
+
* SubTitle: "Launch the system calculator app",
|
|
360
|
+
* Icon: { ImageType: "emoji", ImageData: "🔢" },
|
|
361
|
+
* Score: 100,
|
|
362
|
+
* Preview: {
|
|
363
|
+
* PreviewType: "markdown",
|
|
364
|
+
* PreviewData: "# Calculator\n\nA simple calculator app",
|
|
365
|
+
* PreviewProperties: {}
|
|
366
|
+
* },
|
|
367
|
+
* Tails: [
|
|
368
|
+
* { Type: "text", Text: "⌘⏎ Quick Action" }
|
|
369
|
+
* ],
|
|
370
|
+
* Actions: [
|
|
371
|
+
* {
|
|
372
|
+
* Name: "Open",
|
|
373
|
+
* Icon: { ImageType: "emoji", ImageData: "🚀" },
|
|
374
|
+
* Action: async (ctx, actionCtx) => {
|
|
375
|
+
* // Open calculator
|
|
376
|
+
* }
|
|
377
|
+
* }
|
|
378
|
+
* ]
|
|
379
|
+
* }
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
97
382
|
export interface Result {
|
|
383
|
+
/**
|
|
384
|
+
* Unique identifier for this result.
|
|
385
|
+
*
|
|
386
|
+
* Optional. If not provided, Wox will generate a random ID.
|
|
387
|
+
* Use this ID with UpdateResult to update the result later.
|
|
388
|
+
*/
|
|
98
389
|
Id?: string
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Main title displayed to the user.
|
|
393
|
+
*
|
|
394
|
+
* This is the primary text shown in the result list.
|
|
395
|
+
* Should be concise but descriptive.
|
|
396
|
+
*/
|
|
99
397
|
Title: string
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Secondary text shown below the title.
|
|
401
|
+
*
|
|
402
|
+
* Use for additional context like description, path, or metadata.
|
|
403
|
+
*/
|
|
100
404
|
SubTitle?: string
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Icon displayed next to the result.
|
|
408
|
+
*
|
|
409
|
+
* Can be emoji, image path, base64, etc.
|
|
410
|
+
*/
|
|
101
411
|
Icon: WoxImage
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Preview panel content.
|
|
415
|
+
*
|
|
416
|
+
* When selected, this content is shown in the preview panel.
|
|
417
|
+
* Supports markdown, text, images, URLs, and files.
|
|
418
|
+
*/
|
|
102
419
|
Preview?: WoxPreview
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Relevance score for sorting.
|
|
423
|
+
*
|
|
424
|
+
* Higher values appear first in the result list.
|
|
425
|
+
* Default is 0.
|
|
426
|
+
*/
|
|
103
427
|
Score?: number
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Group name for organizing results.
|
|
431
|
+
*
|
|
432
|
+
* Results with the same group name are displayed together
|
|
433
|
+
* with a group header.
|
|
434
|
+
*/
|
|
104
435
|
Group?: string
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Score for group sorting.
|
|
439
|
+
*
|
|
440
|
+
* Determines the order of groups in the result list.
|
|
441
|
+
*/
|
|
105
442
|
GroupScore?: number
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Additional visual elements displayed after the result.
|
|
446
|
+
*
|
|
447
|
+
* Tails are small UI elements like text labels or icons
|
|
448
|
+
* shown to the right of the result.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```typescript
|
|
452
|
+
* Tails: [
|
|
453
|
+
* { Type: "text", Text: "⭐ Favorite" },
|
|
454
|
+
* { Type: "image", Image: { ImageType: "emoji", ImageData: "🔥" } }
|
|
455
|
+
* ]
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
106
458
|
Tails?: ResultTail[]
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* User actions available for this result.
|
|
462
|
+
*
|
|
463
|
+
* Actions are shown when the result is selected and can be
|
|
464
|
+
* triggered via keyboard shortcuts or clicking.
|
|
465
|
+
*/
|
|
107
466
|
Actions?: ResultAction[]
|
|
108
467
|
}
|
|
109
468
|
|
|
469
|
+
/**
|
|
470
|
+
* A visual element displayed after a result.
|
|
471
|
+
*
|
|
472
|
+
* Tails are small UI elements that provide additional information
|
|
473
|
+
* or quick actions. They appear to the right of the result in
|
|
474
|
+
* the list view.
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* ```typescript
|
|
478
|
+
* // Text tail for status
|
|
479
|
+
* { Type: "text", Text: "✓ Verified", Id: "status-tail" }
|
|
480
|
+
*
|
|
481
|
+
* // Image tail for icon
|
|
482
|
+
* { Type: "image", Image: { ImageType: "emoji", ImageData: "🔥" } }
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
110
485
|
export interface ResultTail {
|
|
486
|
+
/**
|
|
487
|
+
* The type of tail content.
|
|
488
|
+
*
|
|
489
|
+
* - `text`: Display text content
|
|
490
|
+
* - `image`: Display an icon or image
|
|
491
|
+
*/
|
|
111
492
|
Type: "text" | "image"
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Text content for text tails.
|
|
496
|
+
*
|
|
497
|
+
* Only used when Type is "text".
|
|
498
|
+
*/
|
|
112
499
|
Text?: string
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Image content for image tails.
|
|
503
|
+
*
|
|
504
|
+
* Only used when Type is "image".
|
|
505
|
+
*/
|
|
113
506
|
Image?: WoxImage
|
|
114
|
-
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Unique identifier for this tail.
|
|
510
|
+
*
|
|
511
|
+
* Optional. If not provided, Wox generates a random ID.
|
|
512
|
+
* Use this to identify specific tails for updates.
|
|
513
|
+
*/
|
|
115
514
|
Id?: string
|
|
116
|
-
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Additional data associated with this tail.
|
|
518
|
+
*
|
|
519
|
+
* Store arbitrary key-value pairs for identification and metadata.
|
|
520
|
+
*
|
|
521
|
+
* Note: This data is NOT passed to action callbacks.
|
|
522
|
+
* Use ResultAction.ContextData for data that needs to be available
|
|
523
|
+
* in action handlers.
|
|
524
|
+
*
|
|
525
|
+
* Tail context data is primarily used for:
|
|
526
|
+
* - Identifying specific tails (e.g., custom IDs, tags)
|
|
527
|
+
* - Storing tail metadata for UI updates
|
|
528
|
+
* - System-level tail identification (e.g., "system:favorite")
|
|
529
|
+
*/
|
|
117
530
|
ContextData?: MapString
|
|
118
531
|
}
|
|
119
532
|
|
|
@@ -145,6 +558,8 @@ export interface UpdatableResult {
|
|
|
145
558
|
Title?: string
|
|
146
559
|
/** Optional - update the subtitle */
|
|
147
560
|
SubTitle?: string
|
|
561
|
+
/** Optional - update the icon */
|
|
562
|
+
Icon?: WoxImage
|
|
148
563
|
/** Optional - update the tails */
|
|
149
564
|
Tails?: ResultTail[]
|
|
150
565
|
/** Optional - update the preview */
|
|
@@ -153,112 +568,424 @@ export interface UpdatableResult {
|
|
|
153
568
|
Actions?: ResultAction[]
|
|
154
569
|
}
|
|
155
570
|
|
|
571
|
+
/**
|
|
572
|
+
* Type of result action.
|
|
573
|
+
*
|
|
574
|
+
* - `execute`: Immediately execute the action's callback function
|
|
575
|
+
* - `form`: Display a form to the user before executing
|
|
576
|
+
*/
|
|
156
577
|
export type ResultActionType = "execute" | "form"
|
|
157
578
|
|
|
579
|
+
/**
|
|
580
|
+
* A user action that can be performed on a result.
|
|
581
|
+
*
|
|
582
|
+
* Actions are displayed when a result is selected and can be triggered
|
|
583
|
+
* via keyboard shortcuts or by clicking. There are two types:
|
|
584
|
+
* execute actions (run immediately) and form actions (show form first).
|
|
585
|
+
*
|
|
586
|
+
* @example
|
|
587
|
+
* ```typescript
|
|
588
|
+
* const action: ExecuteResultAction = {
|
|
589
|
+
* Name: "Copy to Clipboard",
|
|
590
|
+
* Icon: { ImageType: "emoji", ImageData: "📋" },
|
|
591
|
+
* IsDefault: true,
|
|
592
|
+
* Hotkey: "Ctrl+C",
|
|
593
|
+
* Action: async (ctx, actionCtx) => {
|
|
594
|
+
* await api.Copy(ctx, { type: "text", text: "Hello" })
|
|
595
|
+
* }
|
|
596
|
+
* }
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
158
599
|
export type ResultAction = ExecuteResultAction | FormResultAction
|
|
159
600
|
|
|
601
|
+
/**
|
|
602
|
+
* An action that executes immediately when triggered.
|
|
603
|
+
*
|
|
604
|
+
* Execute actions run their callback function as soon as the user
|
|
605
|
+
* activates them (via keyboard shortcut or click).
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```typescript
|
|
609
|
+
* const action: ExecuteResultAction = {
|
|
610
|
+
* Id: "action-copy",
|
|
611
|
+
* Name: "Copy",
|
|
612
|
+
* Icon: { ImageType: "emoji", ImageData: "📋" },
|
|
613
|
+
* IsDefault: true,
|
|
614
|
+
* PreventHideAfterAction: false,
|
|
615
|
+
* Hotkey: "Ctrl+C",
|
|
616
|
+
* ContextData: { "copyType": "text" },
|
|
617
|
+
* Action: async (ctx, actionCtx) => {
|
|
618
|
+
* console.log("ResultId:", actionCtx.ResultId)
|
|
619
|
+
* await this.copyItem(ctx, actionCtx)
|
|
620
|
+
* }
|
|
621
|
+
* }
|
|
622
|
+
* ```
|
|
623
|
+
*/
|
|
160
624
|
export interface ExecuteResultAction {
|
|
161
625
|
/**
|
|
162
|
-
*
|
|
626
|
+
* Unique identifier for this action.
|
|
627
|
+
*
|
|
628
|
+
* Optional. If not provided, Wox generates a random ID.
|
|
629
|
+
* Use this to identify the action for updates or logging.
|
|
163
630
|
*/
|
|
164
631
|
Id?: string
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Action type discriminator.
|
|
635
|
+
*
|
|
636
|
+
* Set to "execute" for immediate execution actions.
|
|
637
|
+
*/
|
|
165
638
|
Type?: "execute"
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Display name for the action.
|
|
642
|
+
*
|
|
643
|
+
* This is shown to the user in the UI.
|
|
644
|
+
*/
|
|
166
645
|
Name: string
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Icon displayed next to the action name.
|
|
649
|
+
*/
|
|
167
650
|
Icon?: WoxImage
|
|
651
|
+
|
|
168
652
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
653
|
+
* Whether this is the default action.
|
|
654
|
+
*
|
|
655
|
+
* If true, this action is triggered when the user presses Enter.
|
|
656
|
+
* Only one action per result can be the default.
|
|
657
|
+
* If not set, the first action becomes the default.
|
|
171
658
|
*/
|
|
172
659
|
IsDefault?: boolean
|
|
660
|
+
|
|
173
661
|
/**
|
|
174
|
-
*
|
|
662
|
+
* Whether to keep Wox visible after executing this action.
|
|
663
|
+
*
|
|
664
|
+
* If true, Wox remains open after the action completes.
|
|
665
|
+
* Useful for actions that update the result rather than navigate away.
|
|
175
666
|
*/
|
|
176
667
|
PreventHideAfterAction?: boolean
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* The callback function to execute when the action is triggered.
|
|
671
|
+
*
|
|
672
|
+
* @param ctx - Request context
|
|
673
|
+
* @param actionContext - Action context with result ID and context data
|
|
674
|
+
*/
|
|
177
675
|
Action: (ctx: Context, actionContext: ActionContext) => Promise<void>
|
|
676
|
+
|
|
178
677
|
/**
|
|
179
|
-
*
|
|
180
|
-
* Case insensitive, space insensitive
|
|
678
|
+
* Keyboard shortcut to trigger this action.
|
|
181
679
|
*
|
|
182
|
-
*
|
|
680
|
+
* Examples: "Ctrl+Shift+Space", "Ctrl+1", "Command+K"
|
|
681
|
+
* Case and space insensitive.
|
|
682
|
+
*
|
|
683
|
+
* If IsDefault is true, the hotkey defaults to Enter.
|
|
183
684
|
*/
|
|
184
685
|
Hotkey?: string
|
|
686
|
+
|
|
185
687
|
/**
|
|
186
|
-
* Additional data
|
|
688
|
+
* Additional data associated with this action.
|
|
689
|
+
*
|
|
690
|
+
* This data is passed to ActionContext.ContextData when
|
|
691
|
+
* the action is executed. Use it to identify which action
|
|
692
|
+
* was triggered or pass custom parameters.
|
|
187
693
|
*/
|
|
188
694
|
ContextData?: MapString
|
|
189
695
|
}
|
|
190
696
|
|
|
697
|
+
/**
|
|
698
|
+
* An action that shows a form before executing.
|
|
699
|
+
*
|
|
700
|
+
* Form actions display a form to the user, collect input,
|
|
701
|
+
* and then execute the OnSubmit callback with the form values.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```typescript
|
|
705
|
+
* const action: FormResultAction = {
|
|
706
|
+
* Name: "Create New Item",
|
|
707
|
+
* Icon: { ImageType: "emoji", ImageData: "➕" },
|
|
708
|
+
* Form: [
|
|
709
|
+
* createTextboxSetting({
|
|
710
|
+
* key: "name",
|
|
711
|
+
* label: "Name",
|
|
712
|
+
* defaultValue: ""
|
|
713
|
+
* }),
|
|
714
|
+
* createCheckboxSetting({
|
|
715
|
+
* key: "enabled",
|
|
716
|
+
* label: "Enable",
|
|
717
|
+
* defaultValue: "true"
|
|
718
|
+
* })
|
|
719
|
+
* ],
|
|
720
|
+
* OnSubmit: async (ctx, formCtx) => {
|
|
721
|
+
* console.log("Name:", formCtx.Values["name"])
|
|
722
|
+
* console.log("Enabled:", formCtx.Values["enabled"])
|
|
723
|
+
* await this.createItem(ctx, formCtx.Values)
|
|
724
|
+
* }
|
|
725
|
+
* }
|
|
726
|
+
* ```
|
|
727
|
+
*/
|
|
191
728
|
export interface FormResultAction {
|
|
192
729
|
/**
|
|
193
|
-
*
|
|
730
|
+
* Unique identifier for this action.
|
|
731
|
+
*
|
|
732
|
+
* Optional. If not provided, Wox generates a random ID.
|
|
194
733
|
*/
|
|
195
734
|
Id?: string
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Action type discriminator.
|
|
738
|
+
*
|
|
739
|
+
* Must be "form" for form-based actions.
|
|
740
|
+
*/
|
|
196
741
|
Type: "form"
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Display name for the action.
|
|
745
|
+
*/
|
|
197
746
|
Name: string
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Icon displayed next to the action name.
|
|
750
|
+
*/
|
|
198
751
|
Icon?: WoxImage
|
|
752
|
+
|
|
199
753
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
754
|
+
* Whether this is the default action.
|
|
755
|
+
*
|
|
756
|
+
* If true, this action is triggered when the user presses Enter.
|
|
757
|
+
* Only one action per result can be the default.
|
|
202
758
|
*/
|
|
203
759
|
IsDefault?: boolean
|
|
760
|
+
|
|
204
761
|
/**
|
|
205
|
-
*
|
|
762
|
+
* Whether to keep Wox visible after executing this action.
|
|
206
763
|
*/
|
|
207
764
|
PreventHideAfterAction?: boolean
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Form definition to display.
|
|
768
|
+
*
|
|
769
|
+
* Array of setting items that define the form fields.
|
|
770
|
+
*/
|
|
208
771
|
Form: PluginSettingDefinitionItem[]
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Callback executed when the form is submitted.
|
|
775
|
+
*
|
|
776
|
+
* @param ctx - Request context
|
|
777
|
+
* @param actionContext - Form action context with submitted values
|
|
778
|
+
*/
|
|
209
779
|
OnSubmit: (ctx: Context, actionContext: FormActionContext) => Promise<void>
|
|
780
|
+
|
|
210
781
|
/**
|
|
211
|
-
*
|
|
212
|
-
* Case insensitive, space insensitive
|
|
782
|
+
* Keyboard shortcut to trigger this action.
|
|
213
783
|
*
|
|
214
|
-
*
|
|
784
|
+
* Examples: "Ctrl+Shift+Space", "Ctrl+1", "Command+K"
|
|
215
785
|
*/
|
|
216
786
|
Hotkey?: string
|
|
787
|
+
|
|
217
788
|
/**
|
|
218
|
-
* Additional data
|
|
789
|
+
* Additional data associated with this action.
|
|
219
790
|
*/
|
|
220
791
|
ContextData?: MapString
|
|
221
792
|
}
|
|
222
793
|
|
|
794
|
+
/**
|
|
795
|
+
* Context passed to action callback functions.
|
|
796
|
+
*
|
|
797
|
+
* When a user triggers an action, Wox creates an ActionContext
|
|
798
|
+
* containing information about which result and action were triggered,
|
|
799
|
+
* along with any custom context data.
|
|
800
|
+
*
|
|
801
|
+
* @example
|
|
802
|
+
* ```typescript
|
|
803
|
+
* Action: async (ctx: Context, actionContext: ActionContext) => {
|
|
804
|
+
* console.log("Result ID:", actionContext.ResultId)
|
|
805
|
+
* console.log("Action ID:", actionContext.ResultActionId)
|
|
806
|
+
* console.log("Custom data:", actionContext.ContextData)
|
|
807
|
+
*
|
|
808
|
+
* // Update the result
|
|
809
|
+
* await api.UpdateResult(ctx, {
|
|
810
|
+
* Id: actionContext.ResultId,
|
|
811
|
+
* Title: "Updated!"
|
|
812
|
+
* })
|
|
813
|
+
* }
|
|
814
|
+
* ```
|
|
815
|
+
*/
|
|
223
816
|
export interface ActionContext {
|
|
224
817
|
/**
|
|
225
|
-
* The ID of the result that triggered this action
|
|
226
|
-
*
|
|
227
|
-
*
|
|
818
|
+
* The ID of the result that triggered this action.
|
|
819
|
+
*
|
|
820
|
+
* Automatically set by Wox when the action is invoked.
|
|
821
|
+
* Use this with UpdateResult to modify the result's UI.
|
|
228
822
|
*/
|
|
229
823
|
ResultId: string
|
|
230
824
|
/**
|
|
231
|
-
* The ID of the action that was triggered
|
|
232
|
-
*
|
|
233
|
-
*
|
|
825
|
+
* The ID of the action that was triggered.
|
|
826
|
+
*
|
|
827
|
+
* Automatically set by Wox when the action is invoked.
|
|
828
|
+
* Useful for identifying which action was executed.
|
|
234
829
|
*/
|
|
235
830
|
ResultActionId: string
|
|
236
831
|
/**
|
|
237
|
-
* Additional data associated with this action
|
|
832
|
+
* Additional data associated with this action.
|
|
833
|
+
*
|
|
834
|
+
* Contains the ContextData from the ResultAction that was triggered.
|
|
835
|
+
* Use this to pass custom parameters to your action handler.
|
|
238
836
|
*/
|
|
239
837
|
ContextData: MapString
|
|
240
838
|
}
|
|
241
839
|
|
|
840
|
+
/**
|
|
841
|
+
* Extended action context for form submissions.
|
|
842
|
+
*
|
|
843
|
+
* In addition to the standard ActionContext fields, this includes
|
|
844
|
+
* the form values submitted by the user.
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* ```typescript
|
|
848
|
+
* OnSubmit: async (ctx: Context, formContext: FormActionContext) => {
|
|
849
|
+
* const name = formContext.Values["name"]
|
|
850
|
+
* const email = formContext.Values["email"]
|
|
851
|
+
* console.log("User submitted:", name, email)
|
|
852
|
+
* }
|
|
853
|
+
* ```
|
|
854
|
+
*/
|
|
242
855
|
export interface FormActionContext extends ActionContext {
|
|
856
|
+
/**
|
|
857
|
+
* Form field values submitted by the user.
|
|
858
|
+
*
|
|
859
|
+
* Keys are the setting keys, values are the user-submitted strings.
|
|
860
|
+
*/
|
|
243
861
|
Values: Record<string, string>
|
|
244
862
|
}
|
|
245
863
|
|
|
864
|
+
/**
|
|
865
|
+
* Most Recently Used (MRU) item data.
|
|
866
|
+
*
|
|
867
|
+
* Wox keeps track of recently selected items and can restore them
|
|
868
|
+
* via the OnMRURestore callback.
|
|
869
|
+
*
|
|
870
|
+
* @example
|
|
871
|
+
* ```typescript
|
|
872
|
+
* await api.OnMRURestore(ctx, async (ctx, mruData) => {
|
|
873
|
+
* // Find the item in our data
|
|
874
|
+
* const item = this.findById(mruData.ContextData["id"])
|
|
875
|
+
* if (!item) {
|
|
876
|
+
* return null // Item no longer exists
|
|
877
|
+
* }
|
|
878
|
+
*
|
|
879
|
+
* // Return a result for the MRU item
|
|
880
|
+
* return {
|
|
881
|
+
* Title: item.name,
|
|
882
|
+
* SubTitle: item.description,
|
|
883
|
+
* Icon: mruData.Icon
|
|
884
|
+
* }
|
|
885
|
+
* })
|
|
886
|
+
* ```
|
|
887
|
+
*/
|
|
246
888
|
export interface MRUData {
|
|
889
|
+
/**
|
|
890
|
+
* Plugin ID that owns this MRU item.
|
|
891
|
+
*/
|
|
247
892
|
PluginID: string
|
|
893
|
+
/**
|
|
894
|
+
* Title of the MRU item.
|
|
895
|
+
*/
|
|
248
896
|
Title: string
|
|
897
|
+
/**
|
|
898
|
+
* Subtitle of the MRU item.
|
|
899
|
+
*/
|
|
249
900
|
SubTitle: string
|
|
901
|
+
/**
|
|
902
|
+
* Icon of the MRU item.
|
|
903
|
+
*/
|
|
250
904
|
Icon: WoxImage
|
|
905
|
+
/**
|
|
906
|
+
* Custom data associated with this MRU item.
|
|
907
|
+
*
|
|
908
|
+
* Use this to store identifiers or metadata needed to
|
|
909
|
+
* reconstruct the item when restoring from MRU.
|
|
910
|
+
*/
|
|
251
911
|
ContextData: MapString
|
|
252
912
|
}
|
|
253
913
|
|
|
914
|
+
/**
|
|
915
|
+
* Parameters passed to the plugin's init method.
|
|
916
|
+
*
|
|
917
|
+
* Contains the API instance and plugin directory path.
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* ```typescript
|
|
921
|
+
* async init(ctx: Context, initParams: PluginInitParams): Promise<void> {
|
|
922
|
+
* this.api = initParams.API
|
|
923
|
+
* this.pluginDir = initParams.PluginDirectory
|
|
924
|
+
*
|
|
925
|
+
* // Load data from plugin directory
|
|
926
|
+
* const dataPath = `${this.pluginDir}/data.json`
|
|
927
|
+
* this.data = JSON.parse(await fs.readFile(dataPath, 'utf-8'))
|
|
928
|
+
* }
|
|
929
|
+
* ```
|
|
930
|
+
*/
|
|
254
931
|
export interface PluginInitParams {
|
|
932
|
+
/**
|
|
933
|
+
* The public API for interacting with Wox.
|
|
934
|
+
*
|
|
935
|
+
* Store this for later use in your plugin methods.
|
|
936
|
+
*/
|
|
255
937
|
API: PublicAPI
|
|
938
|
+
/**
|
|
939
|
+
* Absolute path to the plugin directory.
|
|
940
|
+
*
|
|
941
|
+
* Use this to load plugin-specific data files, configs, etc.
|
|
942
|
+
*/
|
|
256
943
|
PluginDirectory: string
|
|
257
944
|
}
|
|
258
945
|
|
|
946
|
+
/**
|
|
947
|
+
* Parameters for changing the current Wox query.
|
|
948
|
+
*
|
|
949
|
+
* Used with the ChangeQuery API to programmatically change
|
|
950
|
+
* what the user is searching for.
|
|
951
|
+
*
|
|
952
|
+
* @example
|
|
953
|
+
* ```typescript
|
|
954
|
+
* // Change to input query
|
|
955
|
+
* await api.ChangeQuery(ctx, {
|
|
956
|
+
* QueryType: "input",
|
|
957
|
+
* QueryText: "github wox"
|
|
958
|
+
* })
|
|
959
|
+
*
|
|
960
|
+
* // Change to selection query
|
|
961
|
+
* await api.ChangeQuery(ctx, {
|
|
962
|
+
* QueryType: "selection",
|
|
963
|
+
* QuerySelection: {
|
|
964
|
+
* Type: "text",
|
|
965
|
+
* Text: "selected text"
|
|
966
|
+
* }
|
|
967
|
+
* })
|
|
968
|
+
* ```
|
|
969
|
+
*/
|
|
259
970
|
export interface ChangeQueryParam {
|
|
971
|
+
/**
|
|
972
|
+
* The type of query to change to.
|
|
973
|
+
*
|
|
974
|
+
* - `input`: Change to a text input query
|
|
975
|
+
* - `selection`: Change to a selection-based query
|
|
976
|
+
*/
|
|
260
977
|
QueryType: "input" | "selection"
|
|
978
|
+
/**
|
|
979
|
+
* New query text (for input queries).
|
|
980
|
+
*
|
|
981
|
+
* Only used when QueryType is "input".
|
|
982
|
+
*/
|
|
261
983
|
QueryText?: string
|
|
984
|
+
/**
|
|
985
|
+
* New selection data (for selection queries).
|
|
986
|
+
*
|
|
987
|
+
* Only used when QueryType is "selection".
|
|
988
|
+
*/
|
|
262
989
|
QuerySelection?: Selection
|
|
263
990
|
}
|
|
264
991
|
|
|
@@ -271,11 +998,51 @@ export interface RefreshQueryParam {
|
|
|
271
998
|
PreserveSelectedIndex: boolean
|
|
272
999
|
}
|
|
273
1000
|
|
|
1001
|
+
/**
|
|
1002
|
+
* Type of data to copy to clipboard.
|
|
1003
|
+
*
|
|
1004
|
+
* - `text`: Copy plain text
|
|
1005
|
+
* - `image`: Copy image data
|
|
1006
|
+
*/
|
|
274
1007
|
export type CopyType = "text" | "image"
|
|
275
1008
|
|
|
1009
|
+
/**
|
|
1010
|
+
* Parameters for copying data to clipboard.
|
|
1011
|
+
*
|
|
1012
|
+
* Used with the Copy API to copy text or images.
|
|
1013
|
+
*
|
|
1014
|
+
* @example
|
|
1015
|
+
* ```typescript
|
|
1016
|
+
* // Copy text
|
|
1017
|
+
* await api.Copy(ctx, {
|
|
1018
|
+
* type: "text",
|
|
1019
|
+
* text: "Hello, World!"
|
|
1020
|
+
* })
|
|
1021
|
+
*
|
|
1022
|
+
* // Copy image
|
|
1023
|
+
* await api.Copy(ctx, {
|
|
1024
|
+
* type: "image",
|
|
1025
|
+
* text: "",
|
|
1026
|
+
* woxImage: { ImageType: "base64", ImageData: "data:image/png;base64,..." }
|
|
1027
|
+
* })
|
|
1028
|
+
* ```
|
|
1029
|
+
*/
|
|
276
1030
|
export interface CopyParams {
|
|
1031
|
+
/**
|
|
1032
|
+
* Type of content to copy.
|
|
1033
|
+
*/
|
|
277
1034
|
type: CopyType
|
|
1035
|
+
/**
|
|
1036
|
+
* Text content to copy.
|
|
1037
|
+
*
|
|
1038
|
+
* Used when type is "text".
|
|
1039
|
+
*/
|
|
278
1040
|
text: string
|
|
1041
|
+
/**
|
|
1042
|
+
* Image data to copy.
|
|
1043
|
+
*
|
|
1044
|
+
* Used when type is "image".
|
|
1045
|
+
*/
|
|
279
1046
|
woxImage?: WoxImage
|
|
280
1047
|
}
|
|
281
1048
|
|
|
@@ -485,30 +1252,251 @@ export interface PublicAPI {
|
|
|
485
1252
|
Copy: (ctx: Context, params: CopyParams) => Promise<void>
|
|
486
1253
|
}
|
|
487
1254
|
|
|
1255
|
+
/**
|
|
1256
|
+
* Type of image data.
|
|
1257
|
+
*
|
|
1258
|
+
* - `absolute`: Absolute file path to an image
|
|
1259
|
+
* - `relative`: Path relative to the plugin directory
|
|
1260
|
+
* - `base64`: Base64 encoded image with data URI prefix (e.g., "data:image/png;base64,...")
|
|
1261
|
+
* - `svg`: SVG string content
|
|
1262
|
+
* - `url`: HTTP/HTTPS URL to an image
|
|
1263
|
+
* - `emoji`: Emoji character
|
|
1264
|
+
* - `lottie`: Lottie animation JSON URL or data
|
|
1265
|
+
*
|
|
1266
|
+
* @example
|
|
1267
|
+
* ```typescript
|
|
1268
|
+
* // Absolute path
|
|
1269
|
+
* { ImageType: "absolute", ImageData: "/usr/share/icons/app.png" }
|
|
1270
|
+
*
|
|
1271
|
+
* // Relative path (from plugin directory)
|
|
1272
|
+
* { ImageType: "relative", ImageData: "./icons/icon.png" }
|
|
1273
|
+
*
|
|
1274
|
+
* // Base64 with data URI prefix
|
|
1275
|
+
* { ImageType: "base64", ImageData: "data:image/png;base64,iVBORw0KGgo..." }
|
|
1276
|
+
*
|
|
1277
|
+
* // Emoji
|
|
1278
|
+
* { ImageType: "emoji", ImageData: "🔍" }
|
|
1279
|
+
*
|
|
1280
|
+
* // URL
|
|
1281
|
+
* { ImageType: "url", ImageData: "https://example.com/icon.png" }
|
|
1282
|
+
* ```
|
|
1283
|
+
*/
|
|
488
1284
|
export type WoxImageType = "absolute" | "relative" | "base64" | "svg" | "url" | "emoji" | "lottie"
|
|
489
1285
|
|
|
1286
|
+
/**
|
|
1287
|
+
* Image representation in Wox.
|
|
1288
|
+
*
|
|
1289
|
+
* Used throughout the plugin API for icons, previews, and UI elements.
|
|
1290
|
+
* The ImageData format depends on the ImageType.
|
|
1291
|
+
*
|
|
1292
|
+
* @example
|
|
1293
|
+
* ```typescript
|
|
1294
|
+
* const emojiIcon: WoxImage = {
|
|
1295
|
+
* ImageType: "emoji",
|
|
1296
|
+
* ImageData: "🔍"
|
|
1297
|
+
* }
|
|
1298
|
+
*
|
|
1299
|
+
* const base64Icon: WoxImage = {
|
|
1300
|
+
* ImageType: "base64",
|
|
1301
|
+
* ImageData: "data:image/png;base64,iVBORw0KGgoAAAA..."
|
|
1302
|
+
* }
|
|
1303
|
+
*
|
|
1304
|
+
* const relativeIcon: WoxImage = {
|
|
1305
|
+
* ImageType: "relative",
|
|
1306
|
+
* ImageData: "./icons/my-icon.png"
|
|
1307
|
+
* }
|
|
1308
|
+
* ```
|
|
1309
|
+
*/
|
|
490
1310
|
export interface WoxImage {
|
|
1311
|
+
/**
|
|
1312
|
+
* The type of image data.
|
|
1313
|
+
*
|
|
1314
|
+
* Determines how ImageData should be interpreted.
|
|
1315
|
+
*/
|
|
491
1316
|
ImageType: WoxImageType
|
|
1317
|
+
/**
|
|
1318
|
+
* The image data.
|
|
1319
|
+
*
|
|
1320
|
+
* Format depends on ImageType:
|
|
1321
|
+
* - `absolute`: Absolute file path
|
|
1322
|
+
* - `relative`: Path relative to plugin directory
|
|
1323
|
+
* - `base64`: Data URI with base64 content (e.g., "data:image/png;base64,...")
|
|
1324
|
+
* - `svg`: SVG string content
|
|
1325
|
+
* - `url`: HTTP/HTTPS URL
|
|
1326
|
+
* - `emoji`: Single emoji character
|
|
1327
|
+
* - `lottie`: Lottie JSON URL or data
|
|
1328
|
+
*/
|
|
492
1329
|
ImageData: string
|
|
493
1330
|
}
|
|
494
1331
|
|
|
1332
|
+
/**
|
|
1333
|
+
* Type of preview content.
|
|
1334
|
+
*
|
|
1335
|
+
* - `markdown`: Rendered markdown content
|
|
1336
|
+
* - `text`: Plain text content
|
|
1337
|
+
* - `image`: Image preview
|
|
1338
|
+
* - `url`: Website URL preview
|
|
1339
|
+
* - `file`: File preview
|
|
1340
|
+
*/
|
|
495
1341
|
export type WoxPreviewType = "markdown" | "text" | "image" | "url" | "file"
|
|
496
1342
|
|
|
1343
|
+
/**
|
|
1344
|
+
* Preview panel content for a result.
|
|
1345
|
+
*
|
|
1346
|
+
* When a result is selected, the preview panel displays additional
|
|
1347
|
+
* information using the specified preview type.
|
|
1348
|
+
*
|
|
1349
|
+
* @example
|
|
1350
|
+
* ```typescript
|
|
1351
|
+
* // Markdown preview
|
|
1352
|
+
* {
|
|
1353
|
+
* PreviewType: "markdown",
|
|
1354
|
+
* PreviewData: "# Title\n\nDescription with **formatting**",
|
|
1355
|
+
* PreviewProperties: {}
|
|
1356
|
+
* }
|
|
1357
|
+
*
|
|
1358
|
+
* // Image preview
|
|
1359
|
+
* {
|
|
1360
|
+
* PreviewType: "image",
|
|
1361
|
+
* PreviewData: "https://example.com/image.png",
|
|
1362
|
+
* PreviewProperties: { "height": "300" }
|
|
1363
|
+
* }
|
|
1364
|
+
*
|
|
1365
|
+
* // URL preview
|
|
1366
|
+
* {
|
|
1367
|
+
* PreviewType: "url",
|
|
1368
|
+
* PreviewData: "https://github.com/Wox-launcher/Wox",
|
|
1369
|
+
* PreviewProperties: {}
|
|
1370
|
+
* }
|
|
1371
|
+
* ```
|
|
1372
|
+
*/
|
|
497
1373
|
export interface WoxPreview {
|
|
1374
|
+
/**
|
|
1375
|
+
* The type of preview content.
|
|
1376
|
+
*
|
|
1377
|
+
* Determines how PreviewData is rendered.
|
|
1378
|
+
*/
|
|
498
1379
|
PreviewType: WoxPreviewType
|
|
1380
|
+
/**
|
|
1381
|
+
* The preview content data.
|
|
1382
|
+
*
|
|
1383
|
+
* Format depends on PreviewType:
|
|
1384
|
+
* - `markdown`: Markdown string to render
|
|
1385
|
+
* - `text`: Plain text string
|
|
1386
|
+
* - `image`: Image URL, path, or base64 data
|
|
1387
|
+
* - `url`: Website URL to preview
|
|
1388
|
+
* - `file`: File path to preview
|
|
1389
|
+
*/
|
|
499
1390
|
PreviewData: string
|
|
1391
|
+
/**
|
|
1392
|
+
* Additional properties for the preview.
|
|
1393
|
+
*
|
|
1394
|
+
* Type-specific options like height, width, scroll position, etc.
|
|
1395
|
+
*
|
|
1396
|
+
* @example
|
|
1397
|
+
* ```typescript
|
|
1398
|
+
* { "height": "400", "width": "600" }
|
|
1399
|
+
* { "scrollPosition": "top" }
|
|
1400
|
+
* ```
|
|
1401
|
+
*/
|
|
500
1402
|
PreviewProperties: Record<string, string>
|
|
501
1403
|
}
|
|
502
1404
|
|
|
1405
|
+
/**
|
|
1406
|
+
* Request context for tracking and passing data.
|
|
1407
|
+
*
|
|
1408
|
+
* Context is passed to all plugin API calls and contains a trace ID
|
|
1409
|
+
* for logging and debugging. Plugins can also store custom values
|
|
1410
|
+
* in the context for passing between function calls.
|
|
1411
|
+
*
|
|
1412
|
+
* @example
|
|
1413
|
+
* ```typescript
|
|
1414
|
+
* // Create a new context
|
|
1415
|
+
* const ctx = NewContext()
|
|
1416
|
+
* const traceId = ctx.Get("traceId") // Auto-generated UUID
|
|
1417
|
+
*
|
|
1418
|
+
* // Store custom data
|
|
1419
|
+
* ctx.Set("userId", "12345")
|
|
1420
|
+
* ctx.Set("requestId", "req-abc")
|
|
1421
|
+
*
|
|
1422
|
+
* // Check if key exists
|
|
1423
|
+
* if (ctx.Exists("userId")) {
|
|
1424
|
+
* console.log("User ID:", ctx.Get("userId"))
|
|
1425
|
+
* }
|
|
1426
|
+
*
|
|
1427
|
+
* // Create with initial value
|
|
1428
|
+
* const ctxWithValue = NewContextWithValue("userId", "12345")
|
|
1429
|
+
* ```
|
|
1430
|
+
*/
|
|
503
1431
|
export declare interface Context {
|
|
1432
|
+
/**
|
|
1433
|
+
* Key-value storage for context data.
|
|
1434
|
+
*
|
|
1435
|
+
* Contains auto-generated trace ID and any custom values.
|
|
1436
|
+
*/
|
|
504
1437
|
Values: { [key: string]: string }
|
|
1438
|
+
/**
|
|
1439
|
+
* Get a value from the context.
|
|
1440
|
+
*
|
|
1441
|
+
* @param key - The key to retrieve
|
|
1442
|
+
* @returns The value, or undefined if not found
|
|
1443
|
+
*/
|
|
505
1444
|
Get: (key: string) => string | undefined
|
|
1445
|
+
/**
|
|
1446
|
+
* Set a value in the context.
|
|
1447
|
+
*
|
|
1448
|
+
* @param key - The key to set
|
|
1449
|
+
* @param value - The value to store
|
|
1450
|
+
*/
|
|
506
1451
|
Set: (key: string, value: string) => void
|
|
1452
|
+
/**
|
|
1453
|
+
* Check if a key exists in the context.
|
|
1454
|
+
*
|
|
1455
|
+
* @param key - The key to check
|
|
1456
|
+
* @returns true if the key exists, false otherwise
|
|
1457
|
+
*/
|
|
507
1458
|
Exists: (key: string) => boolean
|
|
508
1459
|
}
|
|
509
1460
|
|
|
1461
|
+
/**
|
|
1462
|
+
* Create a new context with auto-generated trace ID.
|
|
1463
|
+
*
|
|
1464
|
+
* @returns A new Context instance with a UUID in the "traceId" key
|
|
1465
|
+
*
|
|
1466
|
+
* @example
|
|
1467
|
+
* ```typescript
|
|
1468
|
+
* const ctx = NewContext()
|
|
1469
|
+
* console.log(ctx.Get("traceId")) // e.g., "550e8400-e29b-41d4-a716-446655440000"
|
|
1470
|
+
* ```
|
|
1471
|
+
*/
|
|
510
1472
|
export function NewContext(): Context
|
|
511
1473
|
|
|
1474
|
+
/**
|
|
1475
|
+
* Create a new context with an initial key-value pair.
|
|
1476
|
+
*
|
|
1477
|
+
* @param key - The key to set
|
|
1478
|
+
* @param value - The value to store
|
|
1479
|
+
* @returns A new Context instance with the trace ID and custom value
|
|
1480
|
+
*
|
|
1481
|
+
* @example
|
|
1482
|
+
* ```typescript
|
|
1483
|
+
* const ctx = NewContextWithValue("userId", "12345")
|
|
1484
|
+
* console.log(ctx.Get("userId")) // "12345"
|
|
1485
|
+
* console.log(ctx.Get("traceId")) // auto-generated UUID
|
|
1486
|
+
* ```
|
|
1487
|
+
*/
|
|
512
1488
|
export function NewContextWithValue(key: string, value: string): Context
|
|
513
1489
|
|
|
1490
|
+
/**
|
|
1491
|
+
* Create a base64 WoxImage from image data.
|
|
1492
|
+
*
|
|
1493
|
+
* @param imageData - Base64 image data with data URI prefix (e.g., "data:image/png;base64,...")
|
|
1494
|
+
* @returns A WoxImage with type "base64"
|
|
1495
|
+
*
|
|
1496
|
+
* @example
|
|
1497
|
+
* ```typescript
|
|
1498
|
+
* const pngData = "data:image/png;base64,iVBORw0KGgoAAAA..."
|
|
1499
|
+
* const icon = NewBase64WoxImage(pngData)
|
|
1500
|
+
* ```
|
|
1501
|
+
*/
|
|
514
1502
|
export function NewBase64WoxImage(imageData: string): WoxImage
|