@edgestation/sdk 0.4.0 → 0.6.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 +4 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/react.d.ts +5 -5
- package/dist/react.js +6 -6
- package/dist/report-error.d.ts +6 -0
- package/dist/report-error.js +9 -0
- package/dist/svelte.d.ts +7 -7
- package/dist/svelte.js +7 -7
- package/dist/types/api/apps.d.ts +28 -0
- package/dist/types/api/apps.js +1 -0
- package/dist/types/api/audio.d.ts +118 -0
- package/dist/types/api/audio.js +1 -0
- package/dist/types/api/media.d.ts +32 -0
- package/dist/types/api/media.js +1 -0
- package/dist/types/api/storage.d.ts +16 -0
- package/dist/types/api/storage.js +1 -0
- package/dist/types/api/system.d.ts +44 -0
- package/dist/types/api/system.js +1 -0
- package/dist/types/api/webview.d.ts +16 -0
- package/dist/types/api/webview.js +1 -0
- package/dist/types/api.d.ts +116 -0
- package/dist/types/api.js +1 -0
- package/dist/types/cleanup.d.ts +1 -0
- package/dist/types/cleanup.js +1 -0
- package/dist/types/manifest.d.ts +47 -0
- package/dist/types/manifest.js +1 -0
- package/dist/types/settings.d.ts +49 -0
- package/dist/types/settings.js +1 -0
- package/dist/types/widget-module.d.ts +11 -0
- package/dist/types/widget-module.js +1 -0
- package/dist/types.d.ts +11 -401
- package/dist/vite.d.ts +9 -8
- package/dist/vite.js +17 -15
- package/dist/vue.d.ts +5 -5
- package/dist/vue.js +6 -6
- package/manifest.schema.json +9 -3
- package/package.json +1 -1
- package/dist/report.d.ts +0 -3
- package/dist/report.js +0 -6
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** An option with a value for each placement. The manifest declares it. */
|
|
2
|
+
export type WidgetSetting = SelectSetting | TextSetting;
|
|
3
|
+
interface SettingBase {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/**
|
|
7
|
+
* The setting shows only while each setting in this list has the given value. At other
|
|
8
|
+
* times, its value has no meaning.
|
|
9
|
+
*/
|
|
10
|
+
when?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
/** A setting with one value from a list. */
|
|
13
|
+
export interface SelectSetting extends SettingBase {
|
|
14
|
+
type: 'select';
|
|
15
|
+
options: {
|
|
16
|
+
value: string;
|
|
17
|
+
label: string;
|
|
18
|
+
}[];
|
|
19
|
+
/**
|
|
20
|
+
* Adds the choices of a list after `options`. EdgeStation reads this list when the settings
|
|
21
|
+
* show. A saved value can be missing from the list, for example an app that does not run.
|
|
22
|
+
* This value stays saved, and the widget gets it as it is.
|
|
23
|
+
*/
|
|
24
|
+
source?: SettingSource;
|
|
25
|
+
/** The value until the user selects an option. If you do not set it, it is the first option. */
|
|
26
|
+
default?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The lists that a select setting can add choices from:
|
|
30
|
+
* - `audioApps`: the apps with sound on the default output (`api.audio`). The setting saves
|
|
31
|
+
* each app as the file name of its executable (`AudioApp.program`, such as `Discord.exe`).
|
|
32
|
+
*/
|
|
33
|
+
export type SettingSource = 'audioApps';
|
|
34
|
+
/** Free text, such as a URL. */
|
|
35
|
+
export interface TextSetting extends SettingBase {
|
|
36
|
+
type: 'text';
|
|
37
|
+
/** The value until the user types something. If you do not set it, the value is empty. */
|
|
38
|
+
default?: string;
|
|
39
|
+
/** A hint that shows while the field is empty. */
|
|
40
|
+
placeholder?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Hides the value in the settings, as in a password field. Use it for a token or a key.
|
|
43
|
+
* EdgeStation saves the value as plain text in its settings file.
|
|
44
|
+
*/
|
|
45
|
+
secret?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** The saved setting values of one placement, by key. */
|
|
48
|
+
export type WidgetSettingValues = Record<string, string>;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { WidgetApi } from './api.js';
|
|
2
|
+
import type { Cleanup } from './cleanup.js';
|
|
3
|
+
/** The default export of a widget's entry module. */
|
|
4
|
+
export interface WidgetModule {
|
|
5
|
+
/** Renders the widget into `el`. It can return a cleanup function, or a promise of one. */
|
|
6
|
+
mount(el: HTMLElement, api: WidgetApi): void | Cleanup | Promise<void | Cleanup>;
|
|
7
|
+
}
|
|
8
|
+
/** The props of the root component of a widget in the Svelte, React and Vue adapters. */
|
|
9
|
+
export interface WidgetProps {
|
|
10
|
+
api: WidgetApi;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,401 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* Oldest EdgeStation version the widget runs on, such as `"0.1.0"`: the one whose `api` it
|
|
13
|
-
* uses. Older versions show the widget's error card instead of loading it.
|
|
14
|
-
*/
|
|
15
|
-
minAppVersion?: string;
|
|
16
|
-
/** Entry module, relative to the widget folder. Defaults to `main.js`. */
|
|
17
|
-
main?: string;
|
|
18
|
-
/** Stylesheet loaded into the widget's shadow root. */
|
|
19
|
-
styles?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Image shown next to the widget's name in settings, relative to the widget folder. Only its
|
|
22
|
-
* shape counts: it is drawn in the accent color.
|
|
23
|
-
*/
|
|
24
|
-
icon?: string;
|
|
25
|
-
/** Default size in grid cells when added to a page. */
|
|
26
|
-
size?: {
|
|
27
|
-
w: number;
|
|
28
|
-
h: number;
|
|
29
|
-
};
|
|
30
|
-
/** Options the user can set per placement, in display order. */
|
|
31
|
-
settings?: WidgetSetting[];
|
|
32
|
-
/** Lets the widget call `api.webview`, and gives its settings a Profile choice. */
|
|
33
|
-
webview?: boolean;
|
|
34
|
-
}
|
|
35
|
-
/** One per-placement option, declared in the manifest. */
|
|
36
|
-
export type WidgetSetting = SelectSetting | TextSetting;
|
|
37
|
-
interface SettingBase {
|
|
38
|
-
key: string;
|
|
39
|
-
label: string;
|
|
40
|
-
/** Only shown (and only meaningful) while every listed setting has the given value. */
|
|
41
|
-
when?: Record<string, string>;
|
|
42
|
-
}
|
|
43
|
-
/** One value out of a list. */
|
|
44
|
-
export interface SelectSetting extends SettingBase {
|
|
45
|
-
type: 'select';
|
|
46
|
-
options: {
|
|
47
|
-
value: string;
|
|
48
|
-
label: string;
|
|
49
|
-
}[];
|
|
50
|
-
/**
|
|
51
|
-
* Adds the choices of a list EdgeStation reads when the settings show, after `options`. A
|
|
52
|
-
* saved value that isn't in the list then (an app that isn't running) stays saved, and the
|
|
53
|
-
* widget gets it as it is.
|
|
54
|
-
*/
|
|
55
|
-
source?: SettingSource;
|
|
56
|
-
/** Used until the user picks something. Defaults to the first option. */
|
|
57
|
-
default?: string;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Lists a select setting can add choices from:
|
|
61
|
-
* - `audioApps`: the apps with sound on the default output (`api.audio`), each saved as its
|
|
62
|
-
* executable's file name (`AudioApp.program`, such as `Discord.exe`).
|
|
63
|
-
*/
|
|
64
|
-
export type SettingSource = 'audioApps';
|
|
65
|
-
/** Free text, such as a URL. */
|
|
66
|
-
export interface TextSetting extends SettingBase {
|
|
67
|
-
type: 'text';
|
|
68
|
-
/** Used until the user types something. Defaults to empty. */
|
|
69
|
-
default?: string;
|
|
70
|
-
/** Hint shown while the field is empty. */
|
|
71
|
-
placeholder?: string;
|
|
72
|
-
}
|
|
73
|
-
/** Saved setting values of one placement, by key. */
|
|
74
|
-
export type WidgetSettingValues = Record<string, string>;
|
|
75
|
-
export type Cleanup = () => void;
|
|
76
|
-
/**
|
|
77
|
-
* What a widget receives from the host. Deliberately small for now: the full API is still
|
|
78
|
-
* to be designed. Everything registered here is released when the widget unmounts.
|
|
79
|
-
*/
|
|
80
|
-
export interface WidgetApi {
|
|
81
|
-
/** Id of this placement; two copies of a widget get different ids. */
|
|
82
|
-
readonly instanceId: string;
|
|
83
|
-
readonly manifest: WidgetManifest;
|
|
84
|
-
/**
|
|
85
|
-
* This placement's settings: every key declared in the manifest, with its default when
|
|
86
|
-
* unset. The widget is remounted when the user changes one.
|
|
87
|
-
*/
|
|
88
|
-
readonly settings: Readonly<WidgetSettingValues>;
|
|
89
|
-
/** The machine's performance, read when called; nothing is monitored in between. */
|
|
90
|
-
system(): Promise<SystemInfo>;
|
|
91
|
-
/**
|
|
92
|
-
* The programs that used the most CPU since the previous call (from any widget), busiest
|
|
93
|
-
* first: at most `count`, fewer when not that many used any. Read when called.
|
|
94
|
-
*/
|
|
95
|
-
topPrograms(count: number): Promise<ProgramUsage[]>;
|
|
96
|
-
/** What is playing on the machine, read when called, and its playback controls. */
|
|
97
|
-
readonly media: MediaApi;
|
|
98
|
-
/** The apps of the Start menu: listed when called, started, and their icons. */
|
|
99
|
-
readonly apps: AppsApi;
|
|
100
|
-
/**
|
|
101
|
-
* The machine's sound as the volume mixer shows it: the default output and microphone, the
|
|
102
|
-
* apps playing, their volumes and how loud they are. Read and changed when called.
|
|
103
|
-
*/
|
|
104
|
-
readonly audio: AudioApi;
|
|
105
|
-
/**
|
|
106
|
-
* The web's `fetch`, sent by the app rather than the Edge page, so CORS doesn't apply: any
|
|
107
|
-
* `http` or `https` URL answers as it would answer a server. Headers browsers forbid
|
|
108
|
-
* (`Cookie`, `Origin`, `Referer`, ...) can't be set. Cookies that sites set are kept across
|
|
109
|
-
* restarts and shared by every widget. A request still unanswered when the widget unmounts
|
|
110
|
-
* is cancelled.
|
|
111
|
-
*/
|
|
112
|
-
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
113
|
-
/**
|
|
114
|
-
* Data kept across remounts and restarts, shared by the widget's placements or owned by
|
|
115
|
-
* this one. Nothing in it is ever deleted automatically.
|
|
116
|
-
*/
|
|
117
|
-
readonly storage: StorageApi;
|
|
118
|
-
/** URL of a file inside the widget folder (images, data, ...). */
|
|
119
|
-
asset(path: string): string;
|
|
120
|
-
/** Wraps a callback so an error thrown in it shows this widget's error card. */
|
|
121
|
-
guard<A extends unknown[]>(fn: (...args: A) => unknown): (...args: A) => void;
|
|
122
|
-
/**
|
|
123
|
-
* A guarded `setInterval`, cleared when the widget unmounts. It stops while the widget's
|
|
124
|
-
* page is off screen or the Edge is frozen (another app is full screen), and ticks right
|
|
125
|
-
* away when it resumes. Returns a function that stops it sooner.
|
|
126
|
-
*/
|
|
127
|
-
every(ms: number, fn: () => unknown): Cleanup;
|
|
128
|
-
/**
|
|
129
|
-
* A guarded `setTimeout`, cleared if the widget unmounts first. It waits while the widget's
|
|
130
|
-
* page is off screen, and fires as soon as the page is back if it came due meanwhile.
|
|
131
|
-
* Unlike `every`, it still fires while the Edge is frozen. Returns a function that
|
|
132
|
-
* cancels it.
|
|
133
|
-
*/
|
|
134
|
-
after(ms: number, fn: () => unknown): Cleanup;
|
|
135
|
-
/**
|
|
136
|
-
* Shows web page `url` in a native browser view laid over `target`, for sites that refuse
|
|
137
|
-
* to load in an iframe. It draws above the Edge, so it hides while pages slide and while
|
|
138
|
-
* `target` is not fully on screen: once it has shown, a picture of it lies over `target`
|
|
139
|
-
* in its place meanwhile (an `<img>` added to the widget's root). It takes the touches on
|
|
140
|
-
* its area. It opens in the
|
|
141
|
-
* browser profile picked in the placement's settings (Default unless the user picks
|
|
142
|
-
* another): sign-ins last across restarts. Needs `"webview": true` in the manifest, else
|
|
143
|
-
* it shows the error card. Closed when the widget unmounts; returns a function that closes
|
|
144
|
-
* it sooner.
|
|
145
|
-
*/
|
|
146
|
-
webview(target: HTMLElement, url: string, options?: WebviewOptions): Cleanup;
|
|
147
|
-
/**
|
|
148
|
-
* Swaps the native scrollbars of `viewport`, an element of the widget that scrolls, for the
|
|
149
|
-
* app's overlay ones, which show while it scrolls. They are drawn in its parent, so wrap
|
|
150
|
-
* `viewport` in an element of its own: the parent takes the place `viewport` had in the
|
|
151
|
-
* layout, and `viewport` fills it. Removed when the widget unmounts; returns a function that
|
|
152
|
-
* removes them sooner.
|
|
153
|
-
*/
|
|
154
|
-
scrollbars(viewport: HTMLElement): Cleanup;
|
|
155
|
-
/** Runs `fn` when the widget unmounts. */
|
|
156
|
-
onDispose(fn: Cleanup): void;
|
|
157
|
-
}
|
|
158
|
-
/** How `api.webview` opens its page. */
|
|
159
|
-
export interface WebviewOptions {
|
|
160
|
-
/**
|
|
161
|
-
* Presents the view as Chrome on a phone (user agent and client hints), for every page it
|
|
162
|
-
* loads, so that sites which pick their layout from the browser serve their mobile one.
|
|
163
|
-
* Sites that only follow the width already fit the cell either way.
|
|
164
|
-
*/
|
|
165
|
-
mobile?: boolean;
|
|
166
|
-
/**
|
|
167
|
-
* Shows a round Home button above the keyboard button, over the view's bottom right corner,
|
|
168
|
-
* while it is away from `url`, which takes it back there. The view leaves a hole for it (an
|
|
169
|
-
* element added to the widget's root, like the picture). Where `url` redirects to as it loads
|
|
170
|
-
* counts as `url`.
|
|
171
|
-
*/
|
|
172
|
-
homeButton?: boolean;
|
|
173
|
-
}
|
|
174
|
-
/** Where a widget saves data: pick the scope that fits each value. */
|
|
175
|
-
export interface StorageApi {
|
|
176
|
-
/** Shared by every placement of this widget. */
|
|
177
|
-
readonly widget: WidgetStorage;
|
|
178
|
-
/** This placement's own; other copies of the widget don't see it. */
|
|
179
|
-
readonly instance: WidgetStorage;
|
|
180
|
-
}
|
|
181
|
-
/** Saved data: JSON values by key, written to disk shortly after each change. */
|
|
182
|
-
export interface WidgetStorage {
|
|
183
|
-
/** The value saved under `key`; `undefined` when there is none. */
|
|
184
|
-
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
185
|
-
/** Saves `value` (anything JSON can hold) under `key`, replacing the previous one. */
|
|
186
|
-
set(key: string, value: unknown): Promise<void>;
|
|
187
|
-
/** Removes `key`. Resolves `true` if it had a value. */
|
|
188
|
-
delete(key: string): Promise<boolean>;
|
|
189
|
-
}
|
|
190
|
-
/** Network throughput in bytes per second. */
|
|
191
|
-
export interface NetRate {
|
|
192
|
-
down: number;
|
|
193
|
-
up: number;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* The machine's performance at the time of the call. CPU load and network speeds are
|
|
197
|
-
* measured since the previous call (from any widget); calls less than 500 ms apart share
|
|
198
|
-
* one reading.
|
|
199
|
-
*/
|
|
200
|
-
export interface SystemInfo {
|
|
201
|
-
hostname: string;
|
|
202
|
-
/** Name of the connected Wi-Fi network (its Windows profile name); `null` when not connected. */
|
|
203
|
-
wifi: string | null;
|
|
204
|
-
/** Load of all CPU cores, in percent. */
|
|
205
|
-
cpu: {
|
|
206
|
-
load: number;
|
|
207
|
-
};
|
|
208
|
-
/** First NVIDIA GPU (load in percent, temperature in °C); `null` when there is none. */
|
|
209
|
-
gpu: {
|
|
210
|
-
load: number;
|
|
211
|
-
temperature: number;
|
|
212
|
-
} | null;
|
|
213
|
-
/**
|
|
214
|
-
* Since the previous call, plus averages over the calls of the last 1, 5 and 15 minutes:
|
|
215
|
-
* the full window while widgets keep asking, less right after they start or resume.
|
|
216
|
-
*/
|
|
217
|
-
net: NetRate & {
|
|
218
|
-
avg1m: NetRate;
|
|
219
|
-
avg5m: NetRate;
|
|
220
|
-
avg15m: NetRate;
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
/** A program's CPU use: every process that shows the same name, added together. */
|
|
224
|
-
export interface ProgramUsage {
|
|
225
|
-
/**
|
|
226
|
-
* What Task Manager calls it: its executable's description (`THE FINALS`, `Google Chrome`),
|
|
227
|
-
* else the executable file name (`crashpad_handler.exe`).
|
|
228
|
-
*/
|
|
229
|
-
name: string;
|
|
230
|
-
/** Percent of all logical processors, like Task Manager. */
|
|
231
|
-
cpu: number;
|
|
232
|
-
}
|
|
233
|
-
export interface MediaApi {
|
|
234
|
-
/** The session Windows considers current (the one media keys control); `null` when none. */
|
|
235
|
-
current(): Promise<MediaInfo | null>;
|
|
236
|
-
/** Album art of the track from the latest `current()` call, as a data URL; `null` when none. */
|
|
237
|
-
art(): Promise<string | null>;
|
|
238
|
-
/** Asks the current session's app to play, pause or skip. Resolves `false` if it declined. */
|
|
239
|
-
control(action: MediaAction): Promise<boolean>;
|
|
240
|
-
}
|
|
241
|
-
export type MediaAction = 'play' | 'pause' | 'next' | 'previous';
|
|
242
|
-
/** A media session as an app publishes it to Windows. Fields the app doesn't set are empty. */
|
|
243
|
-
export interface MediaInfo {
|
|
244
|
-
/** App that owns the session, as Windows names it (`Spotify.exe`, `MSEdge`, ...). */
|
|
245
|
-
app: string;
|
|
246
|
-
title: string;
|
|
247
|
-
artist: string;
|
|
248
|
-
album: string;
|
|
249
|
-
playing: boolean;
|
|
250
|
-
/**
|
|
251
|
-
* Seconds into the track at the time of the call; `null` when the app reports no timeline.
|
|
252
|
-
* When the app blanks it out (Zen and Firefox do, about once a minute), it carries on from
|
|
253
|
-
* the last one reported, as long as calls come at least every 5 seconds.
|
|
254
|
-
*/
|
|
255
|
-
position: number | null;
|
|
256
|
-
duration: number | null;
|
|
257
|
-
/** Changes whenever the album art does: call `art()` then. `null` when there is no art. */
|
|
258
|
-
art: number | null;
|
|
259
|
-
/** Which `control()` actions the app accepts right now. */
|
|
260
|
-
can: Record<MediaAction, boolean>;
|
|
261
|
-
}
|
|
262
|
-
/** The apps of the Start menu's All apps list (the shell's Apps folder). */
|
|
263
|
-
export interface AppsApi {
|
|
264
|
-
/** Every app, by name, read when called. */
|
|
265
|
-
list(): Promise<AppInfo[]>;
|
|
266
|
-
/**
|
|
267
|
-
* Starts app `id` as the Start menu does, asking for its window on the main screen rather
|
|
268
|
-
* than the Edge (apps that remember their position may still open where they were).
|
|
269
|
-
* Rejects when the app is gone.
|
|
270
|
-
*/
|
|
271
|
-
launch(id: string): Promise<void>;
|
|
272
|
-
/**
|
|
273
|
-
* URL of the icon of app `id`, for an `<img>`: a PNG `size` pixels square (16 to 256,
|
|
274
|
-
* default 64). Ask for the size it shows at in device pixels: icons drawn larger are sharper.
|
|
275
|
-
*/
|
|
276
|
-
icon(id: string, size?: number): string;
|
|
277
|
-
}
|
|
278
|
-
/** An app as the Start menu lists it. */
|
|
279
|
-
export interface AppInfo {
|
|
280
|
-
/**
|
|
281
|
-
* Launches it and draws its icon: its name in the shell's Apps folder, the app's
|
|
282
|
-
* AppUserModelID or, for a program without one, a path to it. Stays the same across
|
|
283
|
-
* restarts, so widgets can save it.
|
|
284
|
-
*/
|
|
285
|
-
id: string;
|
|
286
|
-
/** What the Start menu calls it. */
|
|
287
|
-
name: string;
|
|
288
|
-
}
|
|
289
|
-
/** The machine's sound, as Windows' volume mixer shows it. Nothing listens in between calls. */
|
|
290
|
-
export interface AudioApi {
|
|
291
|
-
/** The default output and microphone, and the apps on that output, read when called. */
|
|
292
|
-
mixer(): Promise<AudioMixer>;
|
|
293
|
-
/** How loud the default output, the microphone and each app are right now. */
|
|
294
|
-
levels(): Promise<AudioLevels>;
|
|
295
|
-
/**
|
|
296
|
-
* Calls `fn` when the mixer changes: a volume or mute, an app's sound opening, closing,
|
|
297
|
-
* starting or stopping, the default device. Read `mixer()` then. Windows tells the app, so
|
|
298
|
-
* nothing polls. While the widget's page is off screen or the Edge is frozen it waits, then
|
|
299
|
-
* calls `fn` once when the widget shows again. Stops on unmount; returns a function that stops
|
|
300
|
-
* it sooner.
|
|
301
|
-
*/
|
|
302
|
-
onChange(fn: () => unknown): Cleanup;
|
|
303
|
-
/**
|
|
304
|
-
* Calls `fn` with the levels 25 times a second while there is sound, and for two seconds
|
|
305
|
-
* after, so meters can fall; then not at all until there is sound again (it shows within a
|
|
306
|
-
* quarter of a second). Only while the widget's page shows and the Edge isn't frozen. Stops
|
|
307
|
-
* on unmount; returns a function that stops it sooner.
|
|
308
|
-
*/
|
|
309
|
-
onLevels(fn: (levels: AudioLevels) => unknown): Cleanup;
|
|
310
|
-
/**
|
|
311
|
-
* Sets the volume of `target`, from 0 to 1 (values outside are clamped). Resolves `false`
|
|
312
|
-
* when it is gone: the app closed, or there is no such device anymore.
|
|
313
|
-
*/
|
|
314
|
-
setVolume(target: AudioTarget, volume: number): Promise<boolean>;
|
|
315
|
-
/**
|
|
316
|
-
* Mutes or unmutes `target`, like `setVolume`. Muting `'input'` mutes the default
|
|
317
|
-
* microphone and, when it is another device, the default one for calls.
|
|
318
|
-
*/
|
|
319
|
-
setMuted(target: AudioTarget, muted: boolean): Promise<boolean>;
|
|
320
|
-
/** The output devices plugged in and enabled, by name, read when called. */
|
|
321
|
-
outputs(): Promise<AudioOutput[]>;
|
|
322
|
-
/**
|
|
323
|
-
* Makes output `id` the default one, as Sound settings' "Set as default device" does: calls
|
|
324
|
-
* keep the device picked for them. Resolves `false` when it is no longer plugged in. Windows
|
|
325
|
-
* has no public API for this: it uses the one Sound settings uses.
|
|
326
|
-
*/
|
|
327
|
-
setOutput(id: string): Promise<boolean>;
|
|
328
|
-
/**
|
|
329
|
-
* URL of the icon of an app's executable (`AudioApp.path`), for an `<img>`: a PNG `size`
|
|
330
|
-
* pixels square (16 to 256, default 64).
|
|
331
|
-
*/
|
|
332
|
-
icon(path: string, size?: number): string;
|
|
333
|
-
}
|
|
334
|
-
/** What `setVolume` and `setMuted` change: the default output, the microphone, or an app's `id`. */
|
|
335
|
-
export type AudioTarget = 'output' | 'input' | (string & {});
|
|
336
|
-
export interface AudioMixer {
|
|
337
|
-
/** The default output, the one the volume flyout shows; `null` without one. */
|
|
338
|
-
output: AudioDevice | null;
|
|
339
|
-
/**
|
|
340
|
-
* The default microphone; `null` without one. `muted` is `true` only when the default one
|
|
341
|
-
* for calls is muted too.
|
|
342
|
-
*/
|
|
343
|
-
input: AudioDevice | null;
|
|
344
|
-
/** The apps with a sound session on the default output, by name, System sounds last. */
|
|
345
|
-
apps: AudioApp[];
|
|
346
|
-
}
|
|
347
|
-
/** A sound device. */
|
|
348
|
-
export interface AudioDevice {
|
|
349
|
-
/** Windows' id of the device, as `outputs()` lists it. */
|
|
350
|
-
id: string;
|
|
351
|
-
/** What Sound settings calls it (`Speakers (Realtek(R) Audio)`). */
|
|
352
|
-
name: string;
|
|
353
|
-
/** From 0 to 1, as the volume flyout shows it. */
|
|
354
|
-
volume: number;
|
|
355
|
-
muted: boolean;
|
|
356
|
-
}
|
|
357
|
-
/** An app's sound: every session Windows' volume mixer shows as one. */
|
|
358
|
-
export interface AudioApp {
|
|
359
|
-
/** Names the app's sound while it runs, for `setVolume` and `levels()`. Not kept across restarts. */
|
|
360
|
-
id: string;
|
|
361
|
-
/**
|
|
362
|
-
* The name the app gives its sound, else what Task Manager calls it (its executable's
|
|
363
|
-
* description), else its executable's file name.
|
|
364
|
-
*/
|
|
365
|
-
name: string;
|
|
366
|
-
/** Its executable, for `icon()`; `null` for System sounds. */
|
|
367
|
-
path: string | null;
|
|
368
|
-
/**
|
|
369
|
-
* Its executable's file name (`Discord.exe`): it names the app across restarts and updates
|
|
370
|
-
* (its folder may change with them), so save this one. `null` for System sounds.
|
|
371
|
-
*/
|
|
372
|
-
program: string | null;
|
|
373
|
-
/** From 0 to 1, a share of the output's volume. */
|
|
374
|
-
volume: number;
|
|
375
|
-
muted: boolean;
|
|
376
|
-
/** Playing right now, rather than open and silent. */
|
|
377
|
-
active: boolean;
|
|
378
|
-
}
|
|
379
|
-
/** Peak levels of the last few milliseconds, from 0 to 1. */
|
|
380
|
-
export interface AudioLevels {
|
|
381
|
-
output: number;
|
|
382
|
-
/** The default microphone, while an app records from it; 0 otherwise. */
|
|
383
|
-
input: number;
|
|
384
|
-
/** By app `id`. */
|
|
385
|
-
apps: Record<string, number>;
|
|
386
|
-
}
|
|
387
|
-
/** An output device `setOutput` can switch to. */
|
|
388
|
-
export interface AudioOutput {
|
|
389
|
-
id: string;
|
|
390
|
-
name: string;
|
|
391
|
-
}
|
|
392
|
-
/** The default export of a widget's entry module. */
|
|
393
|
-
export interface WidgetModule {
|
|
394
|
-
/** Render into `el`. May return (or resolve to) a cleanup function. */
|
|
395
|
-
mount(el: HTMLElement, api: WidgetApi): void | Cleanup | Promise<void | Cleanup>;
|
|
396
|
-
}
|
|
397
|
-
/** Props of a widget's root component in the Svelte, React and Vue adapters. */
|
|
398
|
-
export interface WidgetProps {
|
|
399
|
-
api: WidgetApi;
|
|
400
|
-
}
|
|
401
|
-
export {};
|
|
1
|
+
export type * from './types/manifest.js';
|
|
2
|
+
export type * from './types/settings.js';
|
|
3
|
+
export type * from './types/cleanup.js';
|
|
4
|
+
export type * from './types/api.js';
|
|
5
|
+
export type * from './types/api/webview.js';
|
|
6
|
+
export type * from './types/api/storage.js';
|
|
7
|
+
export type * from './types/api/system.js';
|
|
8
|
+
export type * from './types/api/media.js';
|
|
9
|
+
export type * from './types/api/apps.js';
|
|
10
|
+
export type * from './types/api/audio.js';
|
|
11
|
+
export type * from './types/widget-module.js';
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
2
|
export interface WidgetBuildOptions {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* `src/main.tsx`, `src/main.js` and `src/main.jsx
|
|
4
|
+
* The entry module, relative to the project root. The default is the first file that exists
|
|
5
|
+
* of `src/main.ts`, `src/main.tsx`, `src/main.js` and `src/main.jsx`.
|
|
6
6
|
*/
|
|
7
7
|
entry?: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* Builds the widget into what EdgeStation loads: one self-contained ES module,
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Builds the widget into what EdgeStation loads: one self-contained ES module, `dist/main.js`,
|
|
11
|
+
* with all dependencies and frameworks in it. If the code imports CSS, it also writes
|
|
12
|
+
* `dist/main.css`. Add the Vite plugin of your framework next to it:
|
|
13
13
|
*
|
|
14
14
|
* ```ts
|
|
15
15
|
* export default defineConfig({ plugins: [react(), widget()] });
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
|
-
* It also replaces `process.env.NODE_ENV`,
|
|
19
|
-
* warns
|
|
20
|
-
* code
|
|
18
|
+
* It also replaces `process.env.NODE_ENV`, because React and Vue read it and a browser does not
|
|
19
|
+
* have it. It warns if `manifest.json` does not point to the files that it writes. It also warns
|
|
20
|
+
* if the code of the widget, not of its dependencies, calls `setTimeout` or `setInterval`,
|
|
21
|
+
* because these timers do not pause with the widget.
|
|
21
22
|
*/
|
|
22
23
|
export declare function widget(options?: WidgetBuildOptions): Plugin;
|
package/dist/vite.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Node loads this file from the Vite config of the widget. Thus use no relative imports, and
|
|
2
|
+
// only erasable TypeScript.
|
|
2
3
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
4
|
import { join, relative, resolve } from 'node:path';
|
|
4
5
|
const ENTRIES = ['src/main.ts', 'src/main.tsx', 'src/main.js', 'src/main.jsx'];
|
|
5
|
-
/**
|
|
6
|
+
/** Writes a path as `manifest.json` does, with forward slashes and no leading `./`. */
|
|
6
7
|
const normalize = (path) => path.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
7
|
-
/** What each global timer does that the `api`
|
|
8
|
+
/** What each global timer does that the `api` timer does not do. */
|
|
8
9
|
const TIMERS = {
|
|
9
10
|
setInterval: "keeps running while the widget's page is off screen or the Edge is frozen, and after " +
|
|
10
11
|
'the widget unmounts: use api.every instead',
|
|
@@ -12,7 +13,7 @@ const TIMERS = {
|
|
|
12
13
|
'api.after instead'
|
|
13
14
|
};
|
|
14
15
|
const GLOBALS = new Set(['window', 'globalThis', 'self']);
|
|
15
|
-
/**
|
|
16
|
+
/** Matches the module id of a file of the widget, not a dependency, a virtual module or a query. */
|
|
16
17
|
const OWN = /^[^\0?]+\.(?:[cm]?[jt]sx?|svelte|vue)$/;
|
|
17
18
|
/** The global timer that `callee` names (`setTimeout`, `window.setInterval`, ...), if any. */
|
|
18
19
|
function timerName(callee) {
|
|
@@ -24,7 +25,7 @@ function timerName(callee) {
|
|
|
24
25
|
const name = global ? property?.name : callee.type === 'Identifier' ? callee.name : undefined;
|
|
25
26
|
return name !== undefined && Object.hasOwn(TIMERS, name) ? name : undefined;
|
|
26
27
|
}
|
|
27
|
-
/** The global timers
|
|
28
|
+
/** The global timers that the code calls anywhere in `node`, an ESTree node or a list of nodes. */
|
|
28
29
|
function timersCalled(node, found = new Set()) {
|
|
29
30
|
if (node && typeof node === 'object') {
|
|
30
31
|
const { type, callee } = node;
|
|
@@ -37,23 +38,24 @@ function timersCalled(node, found = new Set()) {
|
|
|
37
38
|
return found;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
* Builds the widget into what EdgeStation loads: one self-contained ES module,
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* Builds the widget into what EdgeStation loads: one self-contained ES module, `dist/main.js`,
|
|
42
|
+
* with all dependencies and frameworks in it. If the code imports CSS, it also writes
|
|
43
|
+
* `dist/main.css`. Add the Vite plugin of your framework next to it:
|
|
43
44
|
*
|
|
44
45
|
* ```ts
|
|
45
46
|
* export default defineConfig({ plugins: [react(), widget()] });
|
|
46
47
|
* ```
|
|
47
48
|
*
|
|
48
|
-
* It also replaces `process.env.NODE_ENV`,
|
|
49
|
-
* warns
|
|
50
|
-
* code
|
|
49
|
+
* It also replaces `process.env.NODE_ENV`, because React and Vue read it and a browser does not
|
|
50
|
+
* have it. It warns if `manifest.json` does not point to the files that it writes. It also warns
|
|
51
|
+
* if the code of the widget, not of its dependencies, calls `setTimeout` or `setInterval`,
|
|
52
|
+
* because these timers do not pause with the widget.
|
|
51
53
|
*/
|
|
52
54
|
export function widget(options = {}) {
|
|
53
55
|
let root = process.cwd();
|
|
54
56
|
let outDir = 'dist';
|
|
55
57
|
let manifest;
|
|
56
|
-
/**
|
|
58
|
+
/** The path of a built file, as `manifest.json` must name it. */
|
|
57
59
|
const built = (file) => normalize(relative(root, resolve(root, outDir, file)));
|
|
58
60
|
return {
|
|
59
61
|
name: 'edgestation-widget',
|
|
@@ -99,8 +101,8 @@ export function widget(options = {}) {
|
|
|
99
101
|
`set "main": "${built('main.js')}".`);
|
|
100
102
|
}
|
|
101
103
|
},
|
|
102
|
-
//
|
|
103
|
-
// plugin order.
|
|
104
|
+
// Run last, so TypeScript, Svelte and Vue files are plain JavaScript at this time, in any
|
|
105
|
+
// plugin order. Do not check dependencies, because their timers are their own concern.
|
|
104
106
|
transform: {
|
|
105
107
|
order: 'post',
|
|
106
108
|
handler(code, id) {
|
|
@@ -113,7 +115,7 @@ export function widget(options = {}) {
|
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
},
|
|
116
|
-
// Not `generateBundle
|
|
118
|
+
// Not `generateBundle`, because the Vite CSS plugin adds main.css to the bundle after it.
|
|
117
119
|
writeBundle(_, bundle) {
|
|
118
120
|
const css = built('main.css');
|
|
119
121
|
const styles = typeof manifest?.styles === 'string' ? normalize(manifest.styles) : undefined;
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type Component } from 'vue';
|
|
2
2
|
import type { WidgetModule } from './types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Makes a widget
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Makes a widget from a Vue 3 component: `export default vueWidget(Clock)`. The adapter mounts
|
|
5
|
+
* the component as a Vue app on the root of the widget, and unmounts it with the widget. The
|
|
6
|
+
* component gets the `api` as its prop. Declare it with `defineProps<WidgetProps>()`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* The error card of the widget shows the errors that Vue catches. These are errors in render,
|
|
9
|
+
* lifecycle hooks, watchers and template event handlers.
|
|
10
10
|
*/
|
|
11
11
|
export declare function vueWidget(component: Component): WidgetModule;
|
package/dist/vue.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createApp } from 'vue';
|
|
2
|
-
import { report } from './report.js';
|
|
2
|
+
import { report } from './report-error.js';
|
|
3
3
|
/**
|
|
4
|
-
* Makes a widget
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Makes a widget from a Vue 3 component: `export default vueWidget(Clock)`. The adapter mounts
|
|
5
|
+
* the component as a Vue app on the root of the widget, and unmounts it with the widget. The
|
|
6
|
+
* component gets the `api` as its prop. Declare it with `defineProps<WidgetProps>()`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* The error card of the widget shows the errors that Vue catches. These are errors in render,
|
|
9
|
+
* lifecycle hooks, watchers and template event handlers.
|
|
10
10
|
*/
|
|
11
11
|
export function vueWidget(component) {
|
|
12
12
|
return {
|