Skip to content

Commit e88b5f7

Browse files
GeekyEggoCopilot
andauthored
feat: embedded resources and message identifiers (#126)
* feat: add message identifiers to settings and global settings * feat: add embedded resource APIs * docs: add Stream Deck 7.1 requirement * refactor: centralize Resources type * 2.0.0-dev.202510211650 * docs: fix typo Co-authored-by: Copilot <[email protected]> * docs: fix typo Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Richard Herman <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 07f00bb commit e88b5f7

File tree

15 files changed

+220
-9
lines changed

15 files changed

+220
-9
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elgato/streamdeck",
3-
"version": "2.0.0-beta",
3+
"version": "2.0.0-dev.202510211650",
44
"description": "The official Node.js SDK for creating Stream Deck plugins.",
55
"main": "./dist/index.js",
66
"type": "module",

src/api/command.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { JsonObject, JsonValue } from "../plugin";
22
import type { DidReceiveGlobalSettings, DidReceiveSettings, State } from "./events";
33
import type { FeedbackPayload } from "./layout";
4+
import type { Resources } from "./resources";
45
import type { Target } from "./target";
56

67
/**
@@ -51,7 +52,12 @@ export type SetSettings = ContextualizedCommandWithPayload<"setSettings", JsonOb
5152
/**
5253
* Gets the settings associated with an instance of an action. Causes {@link DidReceiveSettings} to be emitted.
5354
*/
54-
export type GetSettings = ContextualizedCommand<"getSettings">;
55+
export type GetSettings = ContextualizedCommand<"getSettings"> & {
56+
/**
57+
* Optional identifier that can be used to identify the response to this request.
58+
*/
59+
id?: string;
60+
};
5561

5662
/**
5763
* Sets the global settings associated with the plugin.
@@ -61,13 +67,39 @@ export type SetGlobalSettings = ContextualizedCommandWithPayload<"setGlobalSetti
6167
/**
6268
* Gets the global settings associated with the plugin. Causes {@link DidReceiveGlobalSettings} to be emitted.
6369
*/
64-
export type GetGlobalSettings = ContextualizedCommand<"getGlobalSettings">;
70+
export type GetGlobalSettings = ContextualizedCommand<"getGlobalSettings"> & {
71+
/**
72+
* Optional identifier that can be used to identify the response to this request.
73+
*/
74+
id?: string;
75+
};
6576

6677
/**
6778
* Gets secrets associated with the plugin.
6879
*/
6980
export type GetSecrets = ContextualizedCommand<"getSecrets">;
7081

82+
/**
83+
* Sets the resources (files) associated with the action; these resources are embedded into the action
84+
* when it is exported, either individually, or as part of a profile.
85+
*
86+
* Available from Stream Deck 7.1.
87+
*/
88+
export type SetResources = ContextualizedCommandWithPayload<"setResources", Resources>;
89+
90+
/**
91+
* Gets the resources (files) associated with the action; these resources are embedded into the action
92+
* when it is exported, either individually, or as part of a profile.
93+
*
94+
* Available from Stream Deck 7.1.
95+
*/
96+
export type GetResources = ContextualizedCommand<"getResources"> & {
97+
/**
98+
* Optional identifier that can be used to identify the response to this request.
99+
*/
100+
id?: string;
101+
};
102+
71103
/**
72104
* Opens the URL in the user's default browser.
73105
*/
@@ -249,6 +281,7 @@ export type SendToPropertyInspector<TPayload extends JsonValue = JsonValue> = Co
249281
*/
250282
export type PluginCommand =
251283
| GetGlobalSettings
284+
| GetResources
252285
| GetSecrets
253286
| GetSettings
254287
| LogMessage
@@ -258,6 +291,7 @@ export type PluginCommand =
258291
| SetFeedbackLayout
259292
| SetGlobalSettings
260293
| SetImage
294+
| SetResources
261295
| SetSettings
262296
| SetState
263297
| SetTitle

src/api/events/action.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
11
import type { Controller, DeviceType } from "@elgato/schemas/streamdeck/plugins";
22

33
import type { JsonObject } from "../../common/json";
4+
import type { Resources } from "../resources";
45
import type { DeviceIdentifier } from "./device";
56
import type { EventIdentifier } from "./index";
67

78
/**
8-
* Occurs when the settings associated with an action instance are requested, or when the the settings were updated by the property inspector.
9+
* Occurs when the settings associated with an action instance are requested, or when the the settings
10+
* were updated in the property inspector.
911
*/
1012
export type DidReceiveSettings<TSettings extends JsonObject> = ActionEventMessage<
1113
"didReceiveSettings",
1214
MultiActionPayload<TSettings> | SingleActionPayload<TSettings>
13-
>;
15+
> & {
16+
/**
17+
* Identifier provided when requesting the settings, used to identify the source of the request.
18+
*
19+
* This is always undefined if the event is received because the settings were changed in the property
20+
* inspector.
21+
*/
22+
readonly id?: string;
23+
};
24+
25+
/**
26+
* Occurs when the resources associated with an action instance are requested, or when the the resources
27+
* were updated in the property inspector.
28+
*/
29+
export type DidReceiveResources<TSettings extends JsonObject> = ActionEventMessage<
30+
"didReceiveResources",
31+
MultiActionPayload<TSettings> | SingleActionPayload<TSettings>
32+
> & {
33+
/**
34+
* Identifier provided when requesting the resources, used to identify the source of the request.
35+
*
36+
* This is always undefined if the event is received because the resources were changed in the property
37+
* inspector.
38+
*/
39+
readonly id?: string;
40+
};
1441

1542
/**
1643
* Occurs when the user updates an action's title settings in the Stream Deck application.
@@ -140,6 +167,13 @@ export type SingleActionPayload<
140167
* NB. Requires Stream Deck 6.7 when accessed from the property inspector.
141168
*/
142169
readonly isInMultiAction: false;
170+
171+
/**
172+
* Resources (files) associated with the action.
173+
*
174+
* Available from Stream Deck 7.1.
175+
*/
176+
readonly resources: Resources;
143177
};
144178

145179
/**
@@ -160,6 +194,13 @@ export type MultiActionPayload<TSettings extends JsonObject> = ActionPayload<TSe
160194
* NB. Requires Stream Deck 6.7 when accessed from the property inspector.
161195
*/
162196
readonly isInMultiAction: true;
197+
198+
/**
199+
* Resources (files) associated with the action.
200+
*
201+
* Available from Stream Deck 7.1.
202+
*/
203+
readonly resources: Resources;
163204
};
164205

165206
/**

src/api/events/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import type { JsonObject, JsonValue } from "../../common/json";
2-
import type { DidReceiveSettings, TitleParametersDidChange, WillAppear, WillDisappear } from "./action";
2+
import type {
3+
DidReceiveResources,
4+
DidReceiveSettings,
5+
TitleParametersDidChange,
6+
WillAppear,
7+
WillDisappear,
8+
} from "./action";
39
import type { DeviceDidChange, DeviceDidConnect, DeviceDidDisconnect } from "./device";
410
import type { DialDown, DialRotate, DialUp, TouchTap } from "./encoder";
511
import type { KeyDown, KeyUp } from "./keypad";
@@ -23,6 +29,7 @@ export { type DeviceIdentifier } from "./device";
2329

2430
export {
2531
type Coordinates,
32+
type DidReceiveResources,
2633
type DidReceiveSettings,
2734
type TitleParametersDidChange,
2835
type WillAppear,
@@ -69,6 +76,7 @@ export type PluginEvent =
6976
| DidReceiveDeepLink
7077
| DidReceiveGlobalSettings<JsonObject>
7178
| DidReceivePropertyInspectorMessage<JsonValue>
79+
| DidReceiveResources<JsonObject>
7280
| DidReceiveSecrets<JsonObject>
7381
| DidReceiveSettings<JsonObject>
7482
| KeyDown<JsonObject>

src/api/events/system.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ export type ApplicationDidTerminate = ApplicationEventIdentifier<"applicationDid
1818
* Occurs when the plugin receives the global settings from Stream Deck.
1919
*/
2020
export type DidReceiveGlobalSettings<TSettings extends JsonObject> = EventIdentifier<"didReceiveGlobalSettings"> & {
21+
/**
22+
* Identifier provided when requesting the settings, used to identify the source of the request.
23+
*
24+
* This is always undefined if the event is received because the settings were changed in the property inspector.
25+
*/
26+
readonly id?: string;
27+
2128
/**
2229
* Additional information about the event that occurred.
2330
*/

src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from "./events";
44
export * from "./i18n";
55
export * from "./layout";
66
export * from "./registration";
7+
export * from "./resources";
78
export * from "./target";
89

910
export { type Manifest } from "@elgato/schemas/streamdeck/plugins";

src/api/resources.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Resources (files) associated with an action, represented as a map of keys and paths, for example.
3+
* ```
4+
* {
5+
* fileOne: "c:\\hello-world.txt",
6+
* anotherFile: "c:\\icon.png"
7+
* }
8+
* ```
9+
*/
10+
export type Resources = {
11+
[key: string]: string;
12+
};

src/plugin/__tests__/settings.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe("settings", () => {
2929
expect(connection.send).toHaveBeenLastCalledWith({
3030
event: "getGlobalSettings",
3131
context: connection.registrationParameters.pluginUUID,
32+
id: expect.any(String),
3233
} as GetGlobalSettings);
3334

3435
expect(Promise.race([settings, false])).resolves.toBe(false);

src/plugin/actions/__tests__/action.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ describe("Action", () => {
7878
expect(connection.send).toHaveBeenLastCalledWith<[GetSettings]>({
7979
event: "getSettings",
8080
context: action.id,
81+
id: expect.any(String),
8182
});
8283

8384
expect(Promise.race([settings, false])).resolves.toBe(false);

0 commit comments

Comments
 (0)