wings-plugin-sdk 0.6.0 → 0.7.0
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 +6 -0
- package/package.json +7 -1
- package/poll.d.ts +7 -0
- package/poll.js +28 -0
- package/wings.d.ts +9 -1
package/README.md
CHANGED
|
@@ -55,6 +55,12 @@ to fill. Every `wings.on*` call returns a function that removes the listener, so
|
|
|
55
55
|
`wings-plugin-sdk/react`, or your own `useEffect`, cleans up when a component goes. The API reference is
|
|
56
56
|
[plugins/README.md](https://github.com/josippapez/Wings/blob/main/plugins/README.md) in the Wings repo.
|
|
57
57
|
|
|
58
|
+
## Polling
|
|
59
|
+
|
|
60
|
+
Wings is often in the background, and a timer that runs `git` or a network call then costs battery for nothing.
|
|
61
|
+
`pollWhileFocused(tick, ms)` from `wings-plugin-sdk/poll` runs `tick` every `ms` only while a Wings window is in
|
|
62
|
+
front, and once at once when you come back. It uses `wings.onFocus`.
|
|
63
|
+
|
|
58
64
|
## Pack
|
|
59
65
|
|
|
60
66
|
A plugin in its own repo doesn't need to commit what it builds. `wings-plugin pack` builds it into a temporary
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wings-plugin-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The wings API types, the page frame, React hooks and the build command for Wings plugins.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"types": "./shell.d.ts",
|
|
18
18
|
"default": "./shell.js"
|
|
19
19
|
},
|
|
20
|
+
"./poll": {
|
|
21
|
+
"types": "./poll.d.ts",
|
|
22
|
+
"default": "./poll.js"
|
|
23
|
+
},
|
|
20
24
|
"./build": {
|
|
21
25
|
"types": "./build.d.ts",
|
|
22
26
|
"default": "./build.mjs"
|
|
@@ -34,6 +38,8 @@
|
|
|
34
38
|
"react.d.ts",
|
|
35
39
|
"shell.js",
|
|
36
40
|
"shell.d.ts",
|
|
41
|
+
"poll.js",
|
|
42
|
+
"poll.d.ts",
|
|
37
43
|
"build.mjs",
|
|
38
44
|
"build.d.ts",
|
|
39
45
|
"bin.mjs",
|
package/poll.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference path="./wings.d.ts" />
|
|
2
|
+
/**
|
|
3
|
+
* Calls `tick` every `ms` while Wings is focused. When Wings loses focus the timer stops; when it regains focus,
|
|
4
|
+
* `tick` runs once at once and the timer starts again. `tick` is not called for the state Wings starts in, so
|
|
5
|
+
* a plugin keeps doing its own first check. Returns a function that stops everything.
|
|
6
|
+
*/
|
|
7
|
+
export function pollWhileFocused(tick: () => void, ms: number, w?: Pick<Wings, "focused" | "onFocus">): () => void;
|
package/poll.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// A timer that runs only while the user is in Wings.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calls `tick` every `ms` while Wings is focused. When Wings loses focus the timer stops; when it regains focus,
|
|
5
|
+
* `tick` runs once at once and the timer starts again. `tick` is not called for the state Wings starts in, so
|
|
6
|
+
* a plugin keeps doing its own first check. Returns a function that stops everything.
|
|
7
|
+
*/
|
|
8
|
+
export function pollWhileFocused(tick, ms, w = globalThis.wings) {
|
|
9
|
+
let timer;
|
|
10
|
+
let wasFocused = w.focused;
|
|
11
|
+
const start = () => (timer ??= setInterval(tick, ms));
|
|
12
|
+
const stop = () => {
|
|
13
|
+
clearInterval(timer);
|
|
14
|
+
timer = undefined;
|
|
15
|
+
};
|
|
16
|
+
if (wasFocused) start();
|
|
17
|
+
const off = w.onFocus(({ focused }) => {
|
|
18
|
+
if (focused === wasFocused) return;
|
|
19
|
+
wasFocused = focused;
|
|
20
|
+
if (!focused) return stop();
|
|
21
|
+
tick();
|
|
22
|
+
start();
|
|
23
|
+
});
|
|
24
|
+
return () => {
|
|
25
|
+
off();
|
|
26
|
+
stop();
|
|
27
|
+
};
|
|
28
|
+
}
|
package/wings.d.ts
CHANGED
|
@@ -102,6 +102,14 @@ interface Wings {
|
|
|
102
102
|
// Every `on*` call returns a function that removes the listener, for cleaning up in a React effect.
|
|
103
103
|
/** Every terminal pane, on every change. */
|
|
104
104
|
onPanes(listener: (panes: WingsPane[]) => void): () => void;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the user is in Wings: true while any Wings window (the main one or a view window) is in front, false
|
|
107
|
+
* while another app is. Called once with the current state, then on each change. Needs no permission. Pause timers
|
|
108
|
+
* while it is false and check once when it turns true, or use `pollWhileFocused` from `wings-plugin-sdk/poll`.
|
|
109
|
+
*/
|
|
110
|
+
onFocus(listener: (event: { focused: boolean }) => void): () => void;
|
|
111
|
+
/** The state `onFocus` last reported. True until Wings says otherwise, which it does as soon as the frame is ready. */
|
|
112
|
+
readonly focused: boolean;
|
|
105
113
|
/**
|
|
106
114
|
* A badge action was clicked. Return a promise: the button spins until it settles (up to 5 min), and a thrown
|
|
107
115
|
* error shows in the card. What it resolves to is ignored.
|
|
@@ -154,7 +162,7 @@ interface Wings {
|
|
|
154
162
|
/** Needs `permissions.notify`. A desktop notification, up to 3 a minute. The title is cut at 64 characters, the body at 256. */
|
|
155
163
|
notify(notification: { title: string; body?: string }): Promise<void>;
|
|
156
164
|
/** Needs `"diff"` in `contributes.ui`. Leave out `patch` to open it loading, then call `updateDiff`. */
|
|
157
|
-
openDiff(diff: { title: string; subtitle?: string; patch?: string; comments?: WingsComment[] }): Promise<{ id: string }>;
|
|
165
|
+
openDiff(diff: { title: string; subtitle?: string; /** The repo or folder the diff is of, so Send to agent offers the agent working there first. */ cwd?: string; patch?: string; comments?: WingsComment[] }): Promise<{ id: string }>;
|
|
158
166
|
/** Updates a viewer opened with `openDiff`; ignored once it's closed. `{ comments }` alone keeps the patch, like after a reply. */
|
|
159
167
|
updateDiff(id: string, update: { patch: string; comments?: WingsComment[] } | { comments: WingsComment[] } | { error: string }): Promise<void>;
|
|
160
168
|
/**
|