@wox-launcher/wox-plugin 0.0.85 → 0.0.88

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.
Files changed (2) hide show
  1. package/package.json +9 -9
  2. package/types/index.d.ts +218 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wox-launcher/wox-plugin",
3
- "version": "0.0.85",
3
+ "version": "0.0.88",
4
4
  "description": "All nodejs plugin for Wox should use types in this package",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,13 +13,6 @@
13
13
  "dist",
14
14
  "types"
15
15
  ],
16
- "scripts": {
17
- "build": "pnpm clean && tsc",
18
- "clean": "node -e \"var { rmdirSync, existsSync } = require('fs'), path = require('path'); ['./dist'].forEach(fPath => {if (existsSync(path.join(__dirname, fPath))) rmdirSync(path.join(__dirname, fPath), { recursive: true })}); process.exit(0);\"",
19
- "clean:all": "npm run clean && (rm -r ./node_modules || true)",
20
- "lint": "eslint --ext .ts --fix src/**/*.ts",
21
- "pub": "pnpm build && pnpm version patch && pnpm publish --no-git-checks --access public"
22
- },
23
16
  "devDependencies": {
24
17
  "@typescript-eslint/eslint-plugin": "^7.13.1",
25
18
  "@typescript-eslint/parser": "^7.13.1",
@@ -28,5 +21,12 @@
28
21
  "prettier": "3.3.2",
29
22
  "typescript": "^5.4.5"
30
23
  },
31
- "dependencies": {}
24
+ "dependencies": {},
25
+ "scripts": {
26
+ "build": "pnpm clean && tsc",
27
+ "clean": "node -e \"var { rmdirSync, existsSync } = require('fs'), path = require('path'); ['./dist'].forEach(fPath => {if (existsSync(path.join(__dirname, fPath))) rmdirSync(path.join(__dirname, fPath), { recursive: true })}); process.exit(0);\"",
28
+ "clean:all": "npm run clean && (rm -r ./node_modules || true)",
29
+ "lint": "eslint --ext .ts --fix src/**/*.ts",
30
+ "pub": "pnpm build && pnpm version patch && pnpm publish --no-git-checks --access public"
31
+ }
32
32
  }
package/types/index.d.ts CHANGED
@@ -29,6 +29,11 @@ export interface QueryEnv {
29
29
  */
30
30
  ActiveWindowPid: number
31
31
 
32
+ /**
33
+ * Active window icon when user query, may be empty
34
+ */
35
+ ActiveWindowIcon: WoxImage
36
+
32
37
  // active browser url when user query
33
38
  // Only available when active window is browser and https://github.com/Wox-launcher/Wox.Chrome.Extension is installed
34
39
  ActiveBrowserUrl: string
@@ -97,29 +102,92 @@ export interface Result {
97
102
  Tails?: ResultTail[]
98
103
  ContextData?: string
99
104
  Actions?: ResultAction[]
100
- // refresh result after specified interval, in milliseconds. If this value is 0, Wox will not refresh this result
101
- // interval can only divisible by 100, if not, Wox will use the nearest number which is divisible by 100
102
- // E.g. if you set 123, Wox will use 200, if you set 1234, Wox will use 1300
103
- RefreshInterval?: number
104
- // refresh result by calling OnRefresh function
105
- OnRefresh?: (current: RefreshableResult) => Promise<RefreshableResult>
106
105
  }
107
106
 
108
107
  export interface ResultTail {
109
108
  Type: "text" | "image"
110
109
  Text?: string
111
110
  Image?: WoxImage
111
+ /** Tail id, should be unique. It's optional, if you don't set it, Wox will assign a random id for you */
112
+ Id?: string
113
+ /** Additional data associate with this tail, can be retrieved later */
114
+ ContextData?: string
112
115
  }
113
116
 
114
- export interface RefreshableResult {
115
- Title: string
116
- SubTitle: string
117
- Icon: WoxImage
118
- Preview: WoxPreview
119
- Tails: ResultTail[]
120
- ContextData: string
121
- RefreshInterval: number
122
- Actions: ResultAction[]
117
+ /**
118
+ * Result that can be updated directly in the UI.
119
+ *
120
+ * All fields except Id are optional. Only non-undefined fields will be updated.
121
+ *
122
+ * Example usage:
123
+ * ```typescript
124
+ * // Update only the title
125
+ * const success = await api.updateResult(ctx, {
126
+ * Id: resultId,
127
+ * Title: "Downloading... 50%"
128
+ * })
129
+ *
130
+ * // Update title and tails
131
+ * const success = await api.updateResult(ctx, {
132
+ * Id: resultId,
133
+ * Title: "Processing...",
134
+ * Tails: [{ Type: "text", Text: "Step 1/3" }]
135
+ * })
136
+ * ```
137
+ */
138
+ export interface UpdateableResult {
139
+ /** Required - identifies which result to update */
140
+ Id: string
141
+ /** Optional - update the title */
142
+ Title?: string
143
+ /** Optional - update the subtitle */
144
+ SubTitle?: string
145
+ /** Optional - update the tails */
146
+ Tails?: ResultTail[]
147
+ /** Optional - update the preview */
148
+ Preview?: WoxPreview
149
+ /** Optional - update the actions */
150
+ Actions?: ResultAction[]
151
+ }
152
+
153
+ /**
154
+ * Represents an action that can be updated directly in the UI.
155
+ *
156
+ * This allows updating a single action's UI (name, icon, action callback) without replacing the entire actions array.
157
+ * All fields except ResultId and ActionId are optional. Only non-undefined fields will be updated.
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // Update only the action name
162
+ * const success = await api.UpdateResultAction(ctx, {
163
+ * ResultId: actionContext.ResultId,
164
+ * ActionId: actionContext.ResultActionId,
165
+ * Name: "Remove from favorite"
166
+ * })
167
+ *
168
+ * // Update name, icon and action callback
169
+ * const success = await api.UpdateResultAction(ctx, {
170
+ * ResultId: actionContext.ResultId,
171
+ * ActionId: actionContext.ResultActionId,
172
+ * Name: "Add to favorite",
173
+ * Icon: { ImageType: "emoji", ImageData: "⭐" },
174
+ * Action: async (actionContext) => {
175
+ * // New action logic
176
+ * }
177
+ * })
178
+ * ```
179
+ */
180
+ export interface UpdateableResultAction {
181
+ /** Required - identifies which result contains the action */
182
+ ResultId: string
183
+ /** Required - identifies which action to update */
184
+ ActionId: string
185
+ /** Optional - update the action name */
186
+ Name?: string
187
+ /** Optional - update the action icon */
188
+ Icon?: WoxImage
189
+ /** Optional - update the action callback */
190
+ Action?: (actionContext: ActionContext) => Promise<void>
123
191
  }
124
192
 
125
193
  export interface ResultAction {
@@ -149,6 +217,21 @@ export interface ResultAction {
149
217
  }
150
218
 
151
219
  export interface ActionContext {
220
+ /**
221
+ * The ID of the result that triggered this action
222
+ * This is automatically set by Wox when the action is invoked
223
+ * Useful for calling UpdateResult API to update the result's UI
224
+ */
225
+ ResultId: string
226
+ /**
227
+ * The ID of the action that was triggered
228
+ * This is automatically set by Wox when the action is invoked
229
+ * Useful for calling UpdateResultAction API to update this action's UI
230
+ */
231
+ ResultActionId: string
232
+ /**
233
+ * Additional data associated with this result
234
+ */
152
235
  ContextData: string
153
236
  }
154
237
 
@@ -187,6 +270,11 @@ export interface PublicAPI {
187
270
  */
188
271
  ShowApp: (ctx: Context) => Promise<void>
189
272
 
273
+ /**
274
+ * Check if Wox window is currently visible
275
+ */
276
+ IsVisible: (ctx: Context) => Promise<boolean>
277
+
190
278
  /**
191
279
  * Notify message
192
280
  */
@@ -253,6 +341,121 @@ export interface PublicAPI {
253
341
  * Return null if the MRU data is no longer valid
254
342
  */
255
343
  OnMRURestore: (ctx: Context, callback: (mruData: MRUData) => Promise<Result | null>) => Promise<void>
344
+
345
+ /**
346
+ * Get the current state of a result that is displayed in the UI.
347
+ *
348
+ * Returns UpdateableResult with current values if the result is still visible.
349
+ * Returns null if the result is no longer visible.
350
+ *
351
+ * Note: System actions and tails (like favorite icon) are automatically filtered out.
352
+ * They will be re-added by the system when you call UpdateResult().
353
+ *
354
+ * Example:
355
+ * ```typescript
356
+ * // In an action handler
357
+ * Action: async (actionContext) => {
358
+ * // Get current result state
359
+ * const updatableResult = await api.GetUpdatableResult(ctx, actionContext.ResultId)
360
+ * if (updatableResult === null) {
361
+ * return // Result no longer visible
362
+ * }
363
+ *
364
+ * // Modify the result
365
+ * updatableResult.Title = "Updated title"
366
+ * updatableResult.Tails?.push({ Type: "text", Text: "New tail" })
367
+ *
368
+ * // Update the result
369
+ * await api.UpdateResult(ctx, updatableResult)
370
+ * }
371
+ * ```
372
+ *
373
+ * @param ctx Context
374
+ * @param resultId ID of the result to get
375
+ * @returns Promise<UpdateableResult | null> Current result state, or null if not visible
376
+ */
377
+ GetUpdatableResult: (ctx: Context, resultId: string) => Promise<UpdateableResult | null>
378
+
379
+ /**
380
+ * Update a query result that is currently displayed in the UI.
381
+ *
382
+ * Returns true if the result was successfully updated (still visible in UI).
383
+ * Returns false if the result is no longer visible.
384
+ *
385
+ * This method is designed for long-running operations within Action handlers.
386
+ * Best practices:
387
+ * - Set PreventHideAfterAction: true in your action
388
+ * - Only use during action execution or in background tasks spawned by actions
389
+ * - For periodic updates, start a timer in init() and track result IDs
390
+ *
391
+ * Example:
392
+ * ```typescript
393
+ * // In an action handler
394
+ * Action: async (actionContext) => {
395
+ * // Update only the title
396
+ * const success = await api.UpdateResult(ctx, {
397
+ * Id: actionContext.ResultId,
398
+ * Title: "Downloading... 50%"
399
+ * })
400
+ *
401
+ * // Update title and tails
402
+ * const success = await api.UpdateResult(ctx, {
403
+ * Id: actionContext.ResultId,
404
+ * Title: "Processing...",
405
+ * Tails: [{ Type: "text", Text: "Step 1/3" }]
406
+ * })
407
+ * }
408
+ * ```
409
+ *
410
+ * @param ctx Context
411
+ * @param result UpdateableResult with Id (required) and optional fields to update
412
+ * @returns Promise<boolean> True if updated successfully, false if result no longer visible
413
+ */
414
+ UpdateResult: (ctx: Context, result: UpdateableResult) => Promise<boolean>
415
+
416
+ /**
417
+ * Update a single action within a query result that is currently displayed in the UI.
418
+ *
419
+ * Returns true if the action was successfully updated (result still visible in UI).
420
+ * Returns false if the result is no longer visible.
421
+ *
422
+ * This method is designed for updating action UI after execution, such as toggling
423
+ * between "Add to favorite" and "Remove from favorite" states.
424
+ *
425
+ * Best practices:
426
+ * - Set PreventHideAfterAction: true in your action
427
+ * - Use actionContext.ResultActionId to identify which action to update
428
+ * - Only update fields that have changed (use undefined for fields you don't want to update)
429
+ *
430
+ * Example:
431
+ * ```typescript
432
+ * // In an action handler
433
+ * Action: async (actionContext) => {
434
+ * if (isFavorite) {
435
+ * removeFavorite()
436
+ * const success = await api.UpdateResultAction(ctx, {
437
+ * ResultId: actionContext.ResultId,
438
+ * ActionId: actionContext.ResultActionId,
439
+ * Name: "Add to favorite",
440
+ * Icon: { ImageType: "emoji", ImageData: "⭐" }
441
+ * })
442
+ * } else {
443
+ * addFavorite()
444
+ * const success = await api.UpdateResultAction(ctx, {
445
+ * ResultId: actionContext.ResultId,
446
+ * ActionId: actionContext.ResultActionId,
447
+ * Name: "Remove from favorite",
448
+ * Icon: { ImageType: "emoji", ImageData: "❌" }
449
+ * })
450
+ * }
451
+ * }
452
+ * ```
453
+ *
454
+ * @param ctx Context
455
+ * @param action UpdateableResultAction with ResultId, ActionId (required) and optional fields to update
456
+ * @returns Promise<boolean> True if updated successfully, false if result no longer visible
457
+ */
458
+ UpdateResultAction: (ctx: Context, action: UpdateableResultAction) => Promise<boolean>
256
459
  }
257
460
 
258
461
  export type WoxImageType = "absolute" | "relative" | "base64" | "svg" | "url" | "emoji" | "lottie"