@edgestation/sdk 0.6.0 → 0.9.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,11 +1,14 @@
1
- /** The apps in the All apps list of the Start menu, which is the Apps folder of the shell. */
1
+ /**
2
+ * The apps in the All apps list of the Start menu, which is the Apps folder of the shell. On
3
+ * Linux, the apps that the app menu shows: their desktop entries.
4
+ */
2
5
  export interface AppsApi {
3
6
  /** All apps in name order. The host reads them when you call this function. */
4
7
  list(): Promise<AppInfo[]>;
5
8
  /**
6
- * Starts the app `id` as the Start menu does. It asks for the app window on the main screen,
7
- * not on the Edge. An app that keeps its last position can still open there. Rejects if the
8
- * app is gone.
9
+ * Starts the app `id` as the Start menu does. On Windows, it asks for the app window on the
10
+ * main screen, not on the Edge. An app that keeps its last position can still open there. On
11
+ * Linux, the window manager places the window. Rejects if the app is gone.
9
12
  */
10
13
  launch(id: string): Promise<void>;
11
14
  /**
@@ -20,9 +23,10 @@ export interface AppInfo {
20
23
  /**
21
24
  * The value that launches the app and draws its icon. It is the name of the app in the Apps
22
25
  * folder of the shell. This is the AppUserModelID of the app or, for a program without one,
23
- * a path to the program. It stays the same across restarts, so widgets can save it.
26
+ * a path to the program. On Linux, it is the id of the desktop entry, such as
27
+ * `firefox.desktop`. It stays the same across restarts, so widgets can save it.
24
28
  */
25
29
  id: string;
26
- /** The name that the Start menu shows. */
30
+ /** The name that the Start menu or the app menu shows. */
27
31
  name: string;
28
32
  }
@@ -1,7 +1,8 @@
1
1
  import type { Cleanup } from '../cleanup.js';
2
2
  /**
3
- * The sound of the machine, as the Windows volume mixer shows it. Nothing listens between
4
- * calls.
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. Only `onChange` and
5
+ * `onLevels` listen between calls, while a widget uses them.
5
6
  */
6
7
  export interface AudioApi {
7
8
  /**
@@ -13,7 +14,7 @@ export interface AudioApi {
13
14
  levels(): Promise<AudioLevels>;
14
15
  /**
15
16
  * Calls `fn` when the mixer changes: a volume, a mute, the default device, or the sound of an
16
- * app when it opens, closes, starts or stops. Then read `mixer()`. Windows tells the app
17
+ * app when it opens, closes, starts or stops. Then read `mixer()`. The system tells the app
17
18
  * about changes, so nothing polls. While the page of the widget is off screen or the Edge is
18
19
  * frozen, it waits and calls `fn` once when the widget shows again. It stops on unmount, and
19
20
  * the returned function stops it earlier.
@@ -45,7 +46,7 @@ export interface AudioApi {
45
46
  * Makes the output `id` the default output, as "Set as default device" in Sound settings
46
47
  * does. Calls keep the device that the user selected for them. Resolves to `false` if the
47
48
  * device is not plugged in anymore. Windows has no public API for this, so it uses the API
48
- * of Sound settings.
49
+ * of Sound settings. On Linux, the apps that follow the default output move to it.
49
50
  */
50
51
  setOutput(id: string): Promise<boolean>;
51
52
  /**
@@ -69,7 +70,7 @@ export interface AudioMixer {
69
70
  }
70
71
  /** A sound device. */
71
72
  export interface AudioDevice {
72
- /** The Windows id of the device, as `outputs()` lists it. */
73
+ /** The Windows id of the device, or the PulseAudio name on Linux, as `outputs()` lists it. */
73
74
  id: string;
74
75
  /** The name that Sound settings shows, such as `Speakers (Realtek(R) Audio)`. */
75
76
  name: string;
@@ -77,7 +78,10 @@ export interface AudioDevice {
77
78
  volume: number;
78
79
  muted: boolean;
79
80
  }
80
- /** The sound of an app: all the sessions that the Windows volume mixer shows as one. */
81
+ /**
82
+ * The sound of an app: all the sessions that the Windows volume mixer shows as one. On Linux, all
83
+ * the streams of one executable on the default output.
84
+ */
81
85
  export interface AudioApp {
82
86
  /**
83
87
  * Identifies the sound of the app while it runs, for `setVolume` and `levels()`. It does not
@@ -86,10 +90,14 @@ export interface AudioApp {
86
90
  id: string;
87
91
  /**
88
92
  * The name that the app gives its sound. Else, the name that Task Manager shows, which is the
89
- * description of its executable. Else, the file name of its executable.
93
+ * description of its executable (on Linux, its name in the app menu). Else, the file name of
94
+ * its executable.
90
95
  */
91
96
  name: string;
92
- /** The path of its executable, for `icon()`. `null` for System sounds. */
97
+ /**
98
+ * The path of its executable, for `icon()`. `null` for System sounds, and on Linux for an app
99
+ * of another user.
100
+ */
93
101
  path: string | null;
94
102
  /**
95
103
  * The file name of its executable, such as `Discord.exe`. It identifies the app across
@@ -1,32 +1,82 @@
1
+ import type { Cleanup } from '../cleanup.js';
1
2
  export interface MediaApi {
2
- /** The session that Windows thinks is current, which the media keys control. `null` if none. */
3
+ /**
4
+ * The session that Windows thinks is current, which the media keys control. On Linux, the
5
+ * MPRIS player that plays, else the one that playerctld follows, else a paused one. `null` if
6
+ * none.
7
+ */
3
8
  current(): Promise<MediaInfo | null>;
4
- /** The album art of the track from the last `current()` call, as a data URL. `null` if none. */
5
- art(): Promise<string | null>;
6
- /** Asks the app of the current session to play, pause or skip. Resolves `false` if it refused. */
7
- 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;
8
41
  }
9
42
  export type MediaAction = 'play' | 'pause' | 'next' | 'previous';
10
43
  /**
11
- * A media session, as an app publishes it to Windows. The fields that the app does not set are
12
- * empty.
44
+ * A media session, as an app publishes it to Windows, or as an MPRIS player on Linux. The fields
45
+ * that the app does not set are empty.
13
46
  */
14
47
  export interface MediaInfo {
15
- /** The app that owns the session, as Windows names it (`Spotify.exe`, `MSEdge`, ...). */
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;
56
+ /**
57
+ * The app that owns the session, as Windows names it (`Spotify.exe`, `MSEdge`, ...). On Linux,
58
+ * the desktop entry of the player (`spotify`, `firefox`, ...).
59
+ */
16
60
  app: string;
17
61
  title: string;
18
62
  artist: string;
19
63
  album: string;
20
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;
21
70
  /**
22
71
  * The position in the track at the time of the call, in seconds. `null` if the app gives no
23
72
  * timeline. Some apps clear it, for example Zen and Firefox about once a minute. Then it
24
- * 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.
25
75
  */
26
76
  position: number | null;
27
77
  duration: number | null;
28
78
  /** Changes each time the album art changes. Then call `art()`. `null` if there is no art. */
29
79
  art: number | null;
30
- /** The `control()` actions that the app accepts now. */
31
- 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>;
32
82
  }
@@ -10,12 +10,23 @@ export interface NetRate {
10
10
  */
11
11
  export interface SystemInfo {
12
12
  hostname: string;
13
- /** The name of the connected Wi-Fi network (its Windows profile name). `null` if none. */
13
+ /**
14
+ * The name of the connected Wi-Fi network: its Windows profile name, or the name of its
15
+ * NetworkManager connection on Linux. `null` if none.
16
+ */
14
17
  wifi: string | null;
15
18
  /** The load of all CPU cores, in percent. */
16
19
  cpu: {
17
20
  load: number;
18
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
+ };
19
30
  /** The first NVIDIA GPU (load in percent, temperature in °C). `null` if there is none. */
20
31
  gpu: {
21
32
  load: number;
@@ -36,7 +47,8 @@ export interface SystemInfo {
36
47
  export interface ProgramUsage {
37
48
  /**
38
49
  * The name that Task Manager shows. This is the description of its executable (`THE FINALS`,
39
- * `Google Chrome`), else the executable file name (`crashpad_handler.exe`).
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.
40
52
  */
41
53
  name: string;
42
54
  /** The percent of all logical processors, as in Task Manager. */
@@ -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';
@@ -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.6.0",
3
+ "version": "0.9.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",