@edgestation/sdk 0.7.0 → 0.10.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 CHANGED
@@ -38,7 +38,7 @@ my-widget/
38
38
  }
39
39
  ```
40
40
 
41
- `minAppVersion` is the oldest EdgeStation that can run the widget: set it to the version of this package you build with (they are released together), and older apps show an error card instead of a broken widget.
41
+ `minAppVersion` is the oldest EdgeStation that can run the widget. The `0.1.0` above is only an example: set it to the version of this package you build with (they are released together), and older apps show an error card instead of a broken widget.
42
42
 
43
43
  `permissions` lists the parts of the `api` the widget uses. The examples below call `api.system()`, so they need `system`.
44
44
 
@@ -193,13 +193,19 @@ Pass `widget({ entry: 'src/other.ts' })` for another entry. For TypeScript to ac
193
193
 
194
194
  ## Try it in EdgeStation
195
195
 
196
- EdgeStation loads every folder of `%APPDATA%\com.edgestation.dashboard\widgets\` (Settings → Widgets → Open folder) that has a `manifest.json`; the folder name is the widget's id. Rather than copying your project there, link it, from a Command Prompt:
196
+ EdgeStation loads every folder of its widgets folder that has a `manifest.json`: `%APPDATA%\com.edgestation.dashboard\widgets\` on Windows, `~/.local/share/com.edgestation.dashboard/widgets/` on Linux (Settings → Widgets → Installed → Open folder). The folder name is the widget's id. Rather than copying your project there, link it once. On Windows, from a Command Prompt:
197
197
 
198
198
  ```bat
199
199
  mklink /J "%APPDATA%\com.edgestation.dashboard\widgets\my-widget" C:\path\to\my-widget
200
200
  ```
201
201
 
202
- Then rebuild on each change, and use Settings → Widgets → Reload Edge to load the new build:
202
+ On Linux, from a terminal:
203
+
204
+ ```bash
205
+ ln -s /path/to/my-widget ~/.local/share/com.edgestation.dashboard/widgets/my-widget
206
+ ```
207
+
208
+ Then rebuild on each change, and click Reload Edge at the bottom of the Settings sidebar to load the new build:
203
209
 
204
210
  ```bash
205
211
  npx vite build --watch
@@ -209,4 +215,4 @@ To share the widget, ship the folder with `manifest.json`, `dist/` and any files
209
215
 
210
216
  ## Types
211
217
 
212
- Everything is exported from `@edgestation/sdk` as types: `WidgetApi`, `WidgetModule`, `WidgetManifest`, `WidgetProps`, the settings types and the results of `api.system()`, `api.media`, `api.audio`, `api.apps` and `api.storage`.
218
+ Everything is exported from `@edgestation/sdk` as types: `WidgetApi`, `WidgetModule`, `WidgetManifest`, `WidgetPermission`, `WidgetProps`, the settings types and the results of `api.system()`, `api.media`, `api.audio`, `api.apps` and `api.storage`.
@@ -1,8 +1,8 @@
1
1
  import type { Cleanup } from '../cleanup.js';
2
2
  /**
3
3
  * The sound of the machine, as the Windows volume mixer shows it. On Linux, it comes from
4
- * PulseAudio, which PipeWire also serves, as the sound settings show it. Nothing listens between
5
- * calls.
4
+ * PulseAudio, which PipeWire also serves, as the sound settings show it. Only `onChange` and
5
+ * `onLevels` listen between calls, while a widget uses them.
6
6
  */
7
7
  export interface AudioApi {
8
8
  /**
@@ -1,3 +1,4 @@
1
+ import type { Cleanup } from '../cleanup.js';
1
2
  export interface MediaApi {
2
3
  /**
3
4
  * The session that Windows thinks is current, which the media keys control. On Linux, the
@@ -5,10 +6,38 @@ export interface MediaApi {
5
6
  * none.
6
7
  */
7
8
  current(): Promise<MediaInfo | null>;
8
- /** The album art of the track from the last `current()` call, as a data URL. `null` if none. */
9
- art(): Promise<string | null>;
10
- /** Asks the app of the current session to play, pause or skip. Resolves `false` if it refused. */
11
- control(action: MediaAction): Promise<boolean>;
9
+ /**
10
+ * All sessions, in the order of the system, with `current` set on the one that `current()`
11
+ * gives. On Linux, the MPRIS players that play or are paused. Empty if none.
12
+ */
13
+ sessions(): Promise<MediaInfo[]>;
14
+ /**
15
+ * The album art of the track of session `id`, from the last `current()` or `sessions()` call,
16
+ * as a data URL. Without `id`, the art of the current session. `null` if none.
17
+ */
18
+ art(id?: string): Promise<string | null>;
19
+ /**
20
+ * Asks the app of session `id`, or of the current session, to play, pause or skip. Resolves
21
+ * `false` if it refused or the session is gone.
22
+ */
23
+ control(action: MediaAction, id?: string): Promise<boolean>;
24
+ /**
25
+ * Asks the app of session `id`, or of the current session, to go to `position` seconds in the
26
+ * track. `seek(0)` plays the track from the start. Resolves `false` if it refused or the
27
+ * session is gone. `can.seek` tells if the app accepts it now.
28
+ */
29
+ seek(position: number, id?: string): Promise<boolean>;
30
+ /**
31
+ * Calls `fn` when a session opens, closes or becomes current, or when its track, playback
32
+ * state or timeline changes. `fn` gets no arguments, and it does not tell what changed or in
33
+ * which session: read `sessions()` or `current()` in it. The system tells the app about
34
+ * changes, so nothing polls. A burst of changes calls `fn` at most every 100 ms. The position
35
+ * of a playing track moves on without a call, so advance it yourself between reads. While the
36
+ * page of the widget is off screen or the Edge is frozen, it waits and calls `fn` once when the
37
+ * widget shows again, also if nothing changed. It stops on unmount, and the returned function
38
+ * stops it earlier.
39
+ */
40
+ onChange(fn: () => unknown): Cleanup;
12
41
  }
13
42
  export type MediaAction = 'play' | 'pause' | 'next' | 'previous';
14
43
  /**
@@ -16,6 +45,14 @@ export type MediaAction = 'play' | 'pause' | 'next' | 'previous';
16
45
  * that the app does not set are empty.
17
46
  */
18
47
  export interface MediaInfo {
48
+ /**
49
+ * Names the session in `art()`, `control()` and `seek()`. On Windows, it is the app id, with `#2`, `#3`,
50
+ * ... for more sessions of the same app, in the order of the system. On Linux, the bus name of
51
+ * the player.
52
+ */
53
+ id: string;
54
+ /** `true` for the session that the media keys control. */
55
+ current: boolean;
19
56
  /**
20
57
  * The app that owns the session, as Windows names it (`Spotify.exe`, `MSEdge`, ...). On Linux,
21
58
  * the desktop entry of the player (`spotify`, `firefox`, ...).
@@ -25,15 +62,21 @@ export interface MediaInfo {
25
62
  artist: string;
26
63
  album: string;
27
64
  playing: boolean;
65
+ /**
66
+ * The playback speed, 1 at normal speed. While `playing`, the position moves on by `rate`
67
+ * seconds per second. Neither `onChange` nor the system tells about this, so compute it.
68
+ */
69
+ rate: number;
28
70
  /**
29
71
  * The position in the track at the time of the call, in seconds. `null` if the app gives no
30
72
  * timeline. Some apps clear it, for example Zen and Firefox about once a minute. Then it
31
- * continues from the last position, if calls come at least every 5 seconds.
73
+ * continues from the last position, while a widget listens with `onChange` or calls come at
74
+ * least every 5 seconds.
32
75
  */
33
76
  position: number | null;
34
77
  duration: number | null;
35
78
  /** Changes each time the album art changes. Then call `art()`. `null` if there is no art. */
36
79
  art: number | null;
37
- /** The `control()` actions that the app accepts now. */
38
- can: Record<MediaAction, boolean>;
80
+ /** The `control()` actions that the app accepts now, and `seek` if it accepts `seek()`. */
81
+ can: Record<MediaAction | 'seek', boolean>;
39
82
  }
@@ -19,6 +19,14 @@ export interface SystemInfo {
19
19
  cpu: {
20
20
  load: number;
21
21
  };
22
+ /**
23
+ * The physical memory (RAM), in bytes. `used` is `total` minus the available memory, as in
24
+ * Task Manager.
25
+ */
26
+ memory: {
27
+ used: number;
28
+ total: number;
29
+ };
22
30
  /** The first NVIDIA GPU (load in percent, temperature in °C). `null` if there is none. */
23
31
  gpu: {
24
32
  load: number;
@@ -39,8 +47,8 @@ export interface SystemInfo {
39
47
  export interface ProgramUsage {
40
48
  /**
41
49
  * The name that Task Manager shows. This is the description of its executable (`THE FINALS`,
42
- * `Google Chrome`), else the executable file name (`crashpad_handler.exe`). On Linux, it is
43
- * the name of its app in the app menu, else the executable file name.
50
+ * `Google Chrome`), else the executable file name without `.exe` (`crashpad_handler`). On
51
+ * Linux, it is the name of its app in the app menu, else the executable file name.
44
52
  */
45
53
  name: string;
46
54
  /** The percent of all logical processors, as in Task Manager. */
@@ -102,6 +102,12 @@ export interface WidgetApi {
102
102
  * returned function closes it earlier.
103
103
  */
104
104
  webview(target: HTMLElement, url: string, options?: WebviewOptions): Cleanup;
105
+ /**
106
+ * Opens the web page `url` in the default browser of the machine, outside EdgeStation. Call
107
+ * it when the user taps a link, because the browser comes in front of the other apps. Only
108
+ * `http` and `https` addresses open. For others, the promise rejects. Needs `links`.
109
+ */
110
+ openUrl(url: string): Promise<void>;
105
111
  /**
106
112
  * Replaces the native scrollbars of `viewport` with the overlay scrollbars of the app.
107
113
  * `viewport` is an element of the widget that scrolls, and the overlay scrollbars show while
@@ -3,7 +3,7 @@ import type { WidgetSetting } from './settings.js';
3
3
  * A part of `api` that a widget must ask for in `permissions`. `system` also gives
4
4
  * `topPrograms`. The other members of `api` need no permission.
5
5
  */
6
- export type WidgetPermission = 'system' | 'media' | 'apps' | 'audio' | 'fetch' | 'webview';
6
+ export type WidgetPermission = 'system' | 'media' | 'apps' | 'audio' | 'fetch' | 'webview' | 'links';
7
7
  /**
8
8
  * The contents of the `manifest.json` of a widget, as the host gives it to the widget in
9
9
  * `api.manifest`. The file does not contain `id`. The host sets `id` to the folder name of the
@@ -4,11 +4,22 @@ interface SettingBase {
4
4
  key: string;
5
5
  label: string;
6
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.
7
+ * The setting shows only while this condition is true. At other times, its value has no
8
+ * meaning.
9
9
  */
10
- when?: Record<string, string>;
10
+ when?: SettingCondition;
11
+ /**
12
+ * The setting does not show while this condition is true. At these times, its value has no
13
+ * meaning. Use it when the values that hide the setting are fewer than the values that show
14
+ * it, or when the other setting has a `source`.
15
+ */
16
+ unless?: SettingCondition;
11
17
  }
18
+ /**
19
+ * True while each named setting has the given value, or one of the values in a list. For
20
+ * example, `{ display: ['faders', 'buttons'] }`.
21
+ */
22
+ export type SettingCondition = Record<string, string | string[]>;
12
23
  /** A setting with one value from a list. */
13
24
  export interface SelectSetting extends SettingBase {
14
25
  type: 'select';
@@ -47,7 +47,7 @@
47
47
  "type": "array",
48
48
  "description": "The parts of api the widget uses. The marketplace shows what each one allows before an install. A call to a part not listed here shows the error card. system also gives api.topPrograms. webview also gives the widget's settings a Profile choice.",
49
49
  "uniqueItems": true,
50
- "items": { "enum": ["system", "media", "apps", "audio", "fetch", "webview"] }
50
+ "items": { "enum": ["system", "media", "apps", "audio", "fetch", "webview", "links"] }
51
51
  },
52
52
  "settings": {
53
53
  "type": "array",
@@ -62,10 +62,23 @@
62
62
  "description": "Name of the value in api.settings."
63
63
  },
64
64
  "label": { "type": "string", "description": "Shown next to the field." },
65
+ "value": {
66
+ "description": "A value of the named setting, or a list that matches any of its values.",
67
+ "oneOf": [
68
+ { "type": "string" },
69
+ { "type": "array", "minItems": 1, "items": { "type": "string" } }
70
+ ]
71
+ },
65
72
  "when": {
66
73
  "type": "object",
67
- "description": "Only show this setting while the named settings have these values.",
68
- "additionalProperties": { "type": "string" }
74
+ "description": "Only show this setting while the named settings have these values. A list matches any of its values.",
75
+ "additionalProperties": { "$ref": "#/definitions/value" }
76
+ },
77
+ "unless": {
78
+ "type": "object",
79
+ "description": "Hide this setting while the named settings have these values. A list matches any of its values.",
80
+ "minProperties": 1,
81
+ "additionalProperties": { "$ref": "#/definitions/value" }
69
82
  },
70
83
  "select": {
71
84
  "type": "object",
@@ -97,7 +110,8 @@
97
110
  "type": "string",
98
111
  "description": "Value until the user picks one. Defaults to the first option."
99
112
  },
100
- "when": { "$ref": "#/definitions/when" }
113
+ "when": { "$ref": "#/definitions/when" },
114
+ "unless": { "$ref": "#/definitions/unless" }
101
115
  }
102
116
  },
103
117
  "text": {
@@ -115,7 +129,8 @@
115
129
  "type": "boolean",
116
130
  "description": "Hides the value in the settings, as in a password field. It is still saved as plain text."
117
131
  },
118
- "when": { "$ref": "#/definitions/when" }
132
+ "when": { "$ref": "#/definitions/when" },
133
+ "unless": { "$ref": "#/definitions/unless" }
119
134
  }
120
135
  }
121
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgestation/sdk",
3
- "version": "0.7.0",
3
+ "version": "0.10.0",
4
4
  "description": "Types and build helpers to write widgets for EdgeStation, the secondary display dashboard made for the Corsair Xeneon Edge, in plain JavaScript, Svelte, React or Vue.",
5
5
  "keywords": [
6
6
  "edgestation",