@sdeck/plugin-audio 0.0.0-stage → 0.1.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/bin/sdeck-audio.exe +0 -0
- package/dist/helper.d.ts +95 -0
- package/dist/helper.d.ts.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1466 -0
- package/dist/index.js.map +22 -0
- package/native/Cargo.lock +230 -0
- package/native/Cargo.toml +29 -0
- package/native/src/main.rs +28 -0
- package/native/src/policy.rs +41 -0
- package/native/src/protocol.rs +132 -0
- package/native/src/windows_audio.rs +609 -0
- package/package.json +65 -4
- package/src/helper.ts +270 -0
- package/src/index.tsx +541 -0
- package/README.md +0 -3
package/src/index.tsx
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import {
|
|
3
|
+
defineAction,
|
|
4
|
+
definePlugin,
|
|
5
|
+
type PluginContext,
|
|
6
|
+
type StateDef,
|
|
7
|
+
useHostState,
|
|
8
|
+
useImage,
|
|
9
|
+
useKeyRepeat,
|
|
10
|
+
useSensorPressed,
|
|
11
|
+
useSensorRepeat,
|
|
12
|
+
} from "@sdeck/plugin";
|
|
13
|
+
import { iconLayer, type Look, textLayer } from "@sdeck/schema";
|
|
14
|
+
import {
|
|
15
|
+
type AudioDevice,
|
|
16
|
+
AudioHelper,
|
|
17
|
+
AudioUnavailable,
|
|
18
|
+
BUILD_HINT,
|
|
19
|
+
type Change,
|
|
20
|
+
findHelper,
|
|
21
|
+
type Snapshot,
|
|
22
|
+
type Target,
|
|
23
|
+
} from "./helper.ts";
|
|
24
|
+
|
|
25
|
+
export * from "./helper.ts";
|
|
26
|
+
|
|
27
|
+
/** `Spotify.exe` → `spotify`, the key of `audio.apps`. */
|
|
28
|
+
export function appKey(name: string): string {
|
|
29
|
+
return name
|
|
30
|
+
.trim()
|
|
31
|
+
.toLowerCase()
|
|
32
|
+
.replace(/\.exe$/, "");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** What the plugin publishes, from one snapshot of the devices. */
|
|
36
|
+
export function audioState(snapshot: Snapshot | undefined) {
|
|
37
|
+
if (!snapshot) {
|
|
38
|
+
return {
|
|
39
|
+
master: undefined,
|
|
40
|
+
mic: undefined,
|
|
41
|
+
output: undefined,
|
|
42
|
+
input: undefined,
|
|
43
|
+
outputs: undefined,
|
|
44
|
+
inputs: undefined,
|
|
45
|
+
apps: undefined,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const level = (d: AudioDevice | undefined) =>
|
|
49
|
+
d && { volume: d.volume, muted: d.muted, name: d.name };
|
|
50
|
+
const output = snapshot.outputs.find((d) => d.default);
|
|
51
|
+
const input = snapshot.inputs.find((d) => d.default);
|
|
52
|
+
return {
|
|
53
|
+
master: level(output),
|
|
54
|
+
mic: level(input),
|
|
55
|
+
output: output?.name,
|
|
56
|
+
input: input?.name,
|
|
57
|
+
outputs: snapshot.outputs,
|
|
58
|
+
inputs: snapshot.inputs,
|
|
59
|
+
apps: Object.fromEntries(snapshot.apps.map((app) => [appKey(app.name), app])),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// -- The helper ---------------------------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
let context: PluginContext | undefined;
|
|
66
|
+
|
|
67
|
+
const helper = new AudioHelper({
|
|
68
|
+
command: () => {
|
|
69
|
+
if (process.platform !== "win32") {
|
|
70
|
+
throw new AudioUnavailable("Audio control is available on Windows only");
|
|
71
|
+
}
|
|
72
|
+
const path = String(context?.settings().helper || "") || findHelper();
|
|
73
|
+
if (!path) throw new AudioUnavailable(`${BUILD_HINT}.`);
|
|
74
|
+
return [path];
|
|
75
|
+
},
|
|
76
|
+
onProblem: (problem) => context?.status(problem?.message, "error"),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const stateOf = (
|
|
80
|
+
id: keyof ReturnType<typeof audioState>,
|
|
81
|
+
name: string,
|
|
82
|
+
type: "string" | "json",
|
|
83
|
+
description: string,
|
|
84
|
+
): StateDef => ({
|
|
85
|
+
id,
|
|
86
|
+
name,
|
|
87
|
+
type,
|
|
88
|
+
description,
|
|
89
|
+
start: (set) => helper.subscribe((snapshot) => set(audioState(snapshot)[id])),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
/** An icon (`lucide/mic`) as an image, once loaded. */
|
|
93
|
+
const useIcon = (icon: string, color: string) => useImage(`icon:${icon}`, color);
|
|
94
|
+
|
|
95
|
+
// -- Volume -------------------------------------------------------------------------------------
|
|
96
|
+
|
|
97
|
+
const TARGETS = [
|
|
98
|
+
{ value: "output", label: "Speakers (default output)" },
|
|
99
|
+
{ value: "input", label: "Microphone (default input)" },
|
|
100
|
+
{ value: "app", label: "One app" },
|
|
101
|
+
] as const;
|
|
102
|
+
|
|
103
|
+
interface TargetSettings {
|
|
104
|
+
target: "output" | "input" | "app";
|
|
105
|
+
app: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function targetOf(s: TargetSettings): Target {
|
|
109
|
+
if (s.target !== "app") return { kind: s.target };
|
|
110
|
+
if (!s.app.trim()) throw new Error("choose an app");
|
|
111
|
+
return { kind: "app", app: s.app.trim() };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The state path of a target's level, for templates and expressions. */
|
|
115
|
+
export function targetPath(s: TargetSettings): string {
|
|
116
|
+
if (s.target === "output") return "audio.master";
|
|
117
|
+
if (s.target === "input") return "audio.mic";
|
|
118
|
+
return `audio.apps[${JSON.stringify(appKey(s.app))}]`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const targetName = (s: TargetSettings) =>
|
|
122
|
+
s.target === "output" ? "Volume" : s.target === "input" ? "Mic" : appKey(s.app) || "App";
|
|
123
|
+
|
|
124
|
+
/** Brand icons of common apps, by executable name. */
|
|
125
|
+
const APP_ICONS: Record<string, string> = {
|
|
126
|
+
spotify: "si/SiSpotify",
|
|
127
|
+
discord: "si/SiDiscord",
|
|
128
|
+
chrome: "si/SiGooglechrome",
|
|
129
|
+
firefox: "si/SiFirefoxbrowser",
|
|
130
|
+
msedge: "fa6/FaEdge",
|
|
131
|
+
brave: "si/SiBrave",
|
|
132
|
+
opera: "si/SiOpera",
|
|
133
|
+
steam: "si/SiSteam",
|
|
134
|
+
vlc: "si/SiVlcmediaplayer",
|
|
135
|
+
obs64: "si/SiObsstudio",
|
|
136
|
+
slack: "fa6/FaSlack",
|
|
137
|
+
zoom: "si/SiZoom",
|
|
138
|
+
system: "lucide/bell",
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/** The icons of a target: sounding and muted. */
|
|
142
|
+
export function targetIcons(s: TargetSettings): { on: string; off: string } {
|
|
143
|
+
if (s.target === "output") return { on: "lucide/volume-2", off: "lucide/volume-x" };
|
|
144
|
+
if (s.target === "input") return { on: "lucide/mic", off: "lucide/mic-off" };
|
|
145
|
+
const brand = APP_ICONS[appKey(s.app)];
|
|
146
|
+
// A brand keeps its own mark when muted; it turns red.
|
|
147
|
+
return brand ? { on: brand, off: brand } : { on: "lucide/app-window", off: "lucide/volume-x" };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const targetFields = {
|
|
151
|
+
target: { type: "select", label: "Control", default: "output", options: TARGETS },
|
|
152
|
+
app: {
|
|
153
|
+
type: "text",
|
|
154
|
+
label: "App",
|
|
155
|
+
source: "apps",
|
|
156
|
+
placeholder: "spotify.exe",
|
|
157
|
+
description: "The executable name, as it appears while the app plays sound.",
|
|
158
|
+
visibleIf: { target: "app" },
|
|
159
|
+
},
|
|
160
|
+
} as const;
|
|
161
|
+
|
|
162
|
+
type Operation = "up" | "down" | "set" | "mute" | "unmute" | "toggle";
|
|
163
|
+
|
|
164
|
+
async function adjust(
|
|
165
|
+
target: Target,
|
|
166
|
+
operation: Operation,
|
|
167
|
+
step: number,
|
|
168
|
+
level: number,
|
|
169
|
+
): Promise<Change> {
|
|
170
|
+
switch (operation) {
|
|
171
|
+
case "up":
|
|
172
|
+
return helper.request("setVolume", { target, delta: step });
|
|
173
|
+
case "down":
|
|
174
|
+
return helper.request("setVolume", { target, delta: -step });
|
|
175
|
+
case "set":
|
|
176
|
+
return helper.request("setVolume", { target, volume: level });
|
|
177
|
+
case "toggle":
|
|
178
|
+
return helper.request("setMute", { target });
|
|
179
|
+
default:
|
|
180
|
+
return helper.request("setMute", { target, muted: operation === "mute" });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const OPERATION_NAMES: Record<Operation, string> = {
|
|
185
|
+
up: "Volume up",
|
|
186
|
+
down: "Volume down",
|
|
187
|
+
set: "Set volume",
|
|
188
|
+
mute: "Mute",
|
|
189
|
+
unmute: "Unmute",
|
|
190
|
+
toggle: "Toggle mute",
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const volume = defineAction({
|
|
194
|
+
id: "volume",
|
|
195
|
+
name: "Volume",
|
|
196
|
+
description: "Changes or mutes the speakers, the microphone or one app, and shows its level.",
|
|
197
|
+
category: "Audio",
|
|
198
|
+
icon: "volume-2",
|
|
199
|
+
slots: ["key", "sensor"],
|
|
200
|
+
settings: {
|
|
201
|
+
...targetFields,
|
|
202
|
+
operation: {
|
|
203
|
+
type: "select",
|
|
204
|
+
label: "When pressed",
|
|
205
|
+
default: "toggle",
|
|
206
|
+
options: Object.entries(OPERATION_NAMES).map(([value, label]) => ({ value, label })) as {
|
|
207
|
+
value: Operation;
|
|
208
|
+
label: string;
|
|
209
|
+
}[],
|
|
210
|
+
},
|
|
211
|
+
step: {
|
|
212
|
+
type: "number",
|
|
213
|
+
label: "Step (%)",
|
|
214
|
+
default: 5,
|
|
215
|
+
min: 1,
|
|
216
|
+
max: 50,
|
|
217
|
+
visibleIf: { operation: ["up", "down"] },
|
|
218
|
+
},
|
|
219
|
+
level: {
|
|
220
|
+
type: "number",
|
|
221
|
+
label: "Level (%)",
|
|
222
|
+
default: 50,
|
|
223
|
+
min: 0,
|
|
224
|
+
max: 100,
|
|
225
|
+
visibleIf: { operation: "set" },
|
|
226
|
+
},
|
|
227
|
+
background: { type: "color", label: "Background", default: "#172554" },
|
|
228
|
+
},
|
|
229
|
+
run: async ({ settings }) => {
|
|
230
|
+
const target = targetOf(settings);
|
|
231
|
+
const { before, after } = await adjust(
|
|
232
|
+
target,
|
|
233
|
+
settings.operation,
|
|
234
|
+
settings.step,
|
|
235
|
+
settings.level,
|
|
236
|
+
);
|
|
237
|
+
return {
|
|
238
|
+
result: after,
|
|
239
|
+
label: `${OPERATION_NAMES[settings.operation]} (${targetName(settings)})`,
|
|
240
|
+
undo: async () => {
|
|
241
|
+
await helper.request("setVolume", { target, volume: before.volume });
|
|
242
|
+
await helper.request("setMute", { target, muted: before.muted });
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
look: (s): Look => {
|
|
247
|
+
const path = targetPath(s);
|
|
248
|
+
const muted = `${path}.muted`;
|
|
249
|
+
const icons = targetIcons(s);
|
|
250
|
+
const step = s.operation === "up" ? "plus" : s.operation === "down" ? "minus" : "";
|
|
251
|
+
return {
|
|
252
|
+
background: s.background,
|
|
253
|
+
layers: [
|
|
254
|
+
iconLayer("icon", icons.on, {
|
|
255
|
+
size: 42,
|
|
256
|
+
position: "top",
|
|
257
|
+
visible: `!${muted}`,
|
|
258
|
+
row: "icon",
|
|
259
|
+
}),
|
|
260
|
+
iconLayer("muted", icons.off, {
|
|
261
|
+
color: "#f87171",
|
|
262
|
+
size: 42,
|
|
263
|
+
position: "top",
|
|
264
|
+
visible: muted,
|
|
265
|
+
row: "icon",
|
|
266
|
+
}),
|
|
267
|
+
...(step
|
|
268
|
+
? [iconLayer("step", `lucide/${step}`, { size: 22, position: "top", row: "icon" })]
|
|
269
|
+
: []),
|
|
270
|
+
textLayer("level", `{{${path}.volume == null ? "N/A" : ${path}.volume + "%"}}`, {
|
|
271
|
+
size: 18,
|
|
272
|
+
position: "bottom",
|
|
273
|
+
}),
|
|
274
|
+
{
|
|
275
|
+
id: "bar",
|
|
276
|
+
type: "bar",
|
|
277
|
+
value: `${path}.volume ?? 0`,
|
|
278
|
+
color: "#60a5fa",
|
|
279
|
+
track: "#1e293b",
|
|
280
|
+
position: "bottom",
|
|
281
|
+
thickness: 6,
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
};
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// -- Slider -------------------------------------------------------------------------------------
|
|
289
|
+
|
|
290
|
+
const slider = defineAction({
|
|
291
|
+
id: "slider",
|
|
292
|
+
name: "Volume slider",
|
|
293
|
+
description:
|
|
294
|
+
"A level bar on a sensor strip: touch it to step the volume (the left one lowers, the right one raises), hold to keep going.",
|
|
295
|
+
category: "Audio",
|
|
296
|
+
icon: "sliders-horizontal",
|
|
297
|
+
slots: ["sensor", "window", "key"],
|
|
298
|
+
settings: {
|
|
299
|
+
...targetFields,
|
|
300
|
+
direction: {
|
|
301
|
+
type: "select",
|
|
302
|
+
label: "Touching it",
|
|
303
|
+
default: "auto",
|
|
304
|
+
options: [
|
|
305
|
+
{ value: "auto", label: "Left lowers, right raises" },
|
|
306
|
+
{ value: "down", label: "Lowers" },
|
|
307
|
+
{ value: "up", label: "Raises" },
|
|
308
|
+
],
|
|
309
|
+
},
|
|
310
|
+
step: { type: "number", label: "Step (%)", default: 4, min: 1, max: 50 },
|
|
311
|
+
color: { type: "color", label: "Bar colour", default: "#60a5fa" },
|
|
312
|
+
},
|
|
313
|
+
run: async ({ settings }) => {
|
|
314
|
+
const target = targetOf(settings);
|
|
315
|
+
const delta = settings.direction === "down" ? -settings.step : settings.step;
|
|
316
|
+
const { before, after } = await helper.request("setVolume", { target, delta });
|
|
317
|
+
return {
|
|
318
|
+
result: after,
|
|
319
|
+
label: `${targetName(settings)} ${after.volume}%`,
|
|
320
|
+
undo: () => helper.request("setVolume", { target, volume: before.volume }),
|
|
321
|
+
};
|
|
322
|
+
},
|
|
323
|
+
component: ({ settings, slot, plugin }) => {
|
|
324
|
+
const name = settings.target === "output" ? "master" : settings.target === "input" ? "mic" : "";
|
|
325
|
+
const whole = useHostState(name ? `audio.${name}` : "audio.apps");
|
|
326
|
+
const level = (
|
|
327
|
+
name ? whole : (whole as Record<string, unknown> | undefined)?.[appKey(settings.app)]
|
|
328
|
+
) as { volume: number; muted: boolean } | undefined;
|
|
329
|
+
const down =
|
|
330
|
+
settings.direction === "down" ||
|
|
331
|
+
(settings.direction === "auto" && slot.kind !== "window" && slot.index % 2 === 0);
|
|
332
|
+
const step = () => {
|
|
333
|
+
helper
|
|
334
|
+
.request("setVolume", {
|
|
335
|
+
target: targetOf(settings),
|
|
336
|
+
delta: down ? -settings.step : settings.step,
|
|
337
|
+
})
|
|
338
|
+
.catch((error: Error) => plugin.log("slider:", error.message));
|
|
339
|
+
};
|
|
340
|
+
const sensorPressed = useSensorPressed(slot.kind === "sensor" ? slot.index : 0);
|
|
341
|
+
const index = slot.kind === "window" ? -1 : slot.index;
|
|
342
|
+
useSensorRepeat((i) => slot.kind === "sensor" && i === index && step(), {
|
|
343
|
+
sensor: slot.kind === "sensor" ? index : -1,
|
|
344
|
+
intervalMs: 150,
|
|
345
|
+
});
|
|
346
|
+
useKeyRepeat((i) => slot.kind === "key" && i === index && step(), {
|
|
347
|
+
key: slot.kind === "key" ? index : -1,
|
|
348
|
+
intervalMs: 150,
|
|
349
|
+
});
|
|
350
|
+
const strip = slot.kind === "sensor";
|
|
351
|
+
const text = !level ? "N/A" : `${level.volume}%`;
|
|
352
|
+
const icons = targetIcons(settings);
|
|
353
|
+
const size = strip ? 12 : 24;
|
|
354
|
+
const icon = useIcon(level?.muted ? icons.off : icons.on, "#ffffff");
|
|
355
|
+
const arrow = useIcon(down ? "lucide/minus" : "lucide/plus", "#ffffff");
|
|
356
|
+
return (
|
|
357
|
+
<div
|
|
358
|
+
style={{
|
|
359
|
+
display: "flex",
|
|
360
|
+
position: "relative",
|
|
361
|
+
width: "100%",
|
|
362
|
+
height: "100%",
|
|
363
|
+
background: strip && sensorPressed ? "#334155" : "#0f172a",
|
|
364
|
+
alignItems: "center",
|
|
365
|
+
justifyContent: "center",
|
|
366
|
+
}}
|
|
367
|
+
>
|
|
368
|
+
<div
|
|
369
|
+
style={{
|
|
370
|
+
display: "flex",
|
|
371
|
+
position: "absolute",
|
|
372
|
+
left: 0,
|
|
373
|
+
top: 0,
|
|
374
|
+
bottom: 0,
|
|
375
|
+
width: `${level?.volume ?? 0}%`,
|
|
376
|
+
background: level?.muted ? "#7f1d1d" : settings.color,
|
|
377
|
+
opacity: 0.6,
|
|
378
|
+
}}
|
|
379
|
+
/>
|
|
380
|
+
<div
|
|
381
|
+
style={{
|
|
382
|
+
display: "flex",
|
|
383
|
+
flexDirection: "row",
|
|
384
|
+
alignItems: "center",
|
|
385
|
+
gap: strip ? 3 : 6,
|
|
386
|
+
color: "#ffffff",
|
|
387
|
+
fontWeight: 700,
|
|
388
|
+
fontSize: 20,
|
|
389
|
+
}}
|
|
390
|
+
>
|
|
391
|
+
{strip && arrow ? <img src={arrow} width={10} height={10} alt="" /> : null}
|
|
392
|
+
{icon ? <img src={icon} width={size} height={size} alt="" /> : null}
|
|
393
|
+
{/* On a sensor the bar alone shows the level. */}
|
|
394
|
+
{strip ? null : <div style={{ display: "flex" }}>{text}</div>}
|
|
395
|
+
</div>
|
|
396
|
+
</div>
|
|
397
|
+
);
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
// -- Default device -----------------------------------------------------------------------------
|
|
402
|
+
|
|
403
|
+
const NEXT = "__next";
|
|
404
|
+
|
|
405
|
+
/** The device after the default one, for "Next device". */
|
|
406
|
+
export function nextDevice(devices: readonly AudioDevice[]): AudioDevice | undefined {
|
|
407
|
+
const at = devices.findIndex((d) => d.default);
|
|
408
|
+
return devices[(at + 1) % devices.length];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const defaultDevice = defineAction({
|
|
412
|
+
id: "default-device",
|
|
413
|
+
name: "Switch audio device",
|
|
414
|
+
description: "Makes another speaker or microphone the default, or steps through them.",
|
|
415
|
+
category: "Audio",
|
|
416
|
+
icon: "speaker",
|
|
417
|
+
slots: ["key", "sensor"],
|
|
418
|
+
settings: {
|
|
419
|
+
flow: {
|
|
420
|
+
type: "select",
|
|
421
|
+
label: "Switch the",
|
|
422
|
+
default: "output",
|
|
423
|
+
options: [
|
|
424
|
+
{ value: "output", label: "Output (speakers)" },
|
|
425
|
+
{ value: "input", label: "Input (microphone)" },
|
|
426
|
+
],
|
|
427
|
+
},
|
|
428
|
+
output: {
|
|
429
|
+
type: "select",
|
|
430
|
+
label: "To",
|
|
431
|
+
default: NEXT,
|
|
432
|
+
source: "outputs",
|
|
433
|
+
options: [{ value: NEXT, label: "The next device" }],
|
|
434
|
+
visibleIf: { flow: "output" },
|
|
435
|
+
},
|
|
436
|
+
input: {
|
|
437
|
+
type: "select",
|
|
438
|
+
label: "To",
|
|
439
|
+
default: NEXT,
|
|
440
|
+
source: "inputs",
|
|
441
|
+
options: [{ value: NEXT, label: "The next device" }],
|
|
442
|
+
visibleIf: { flow: "input" },
|
|
443
|
+
},
|
|
444
|
+
background: { type: "color", label: "Background", default: "#3b0764" },
|
|
445
|
+
},
|
|
446
|
+
run: async ({ settings }) => {
|
|
447
|
+
const wanted = settings.flow === "output" ? settings.output : settings.input;
|
|
448
|
+
const snapshot = await helper.request("snapshot");
|
|
449
|
+
const devices = settings.flow === "output" ? snapshot.outputs : snapshot.inputs;
|
|
450
|
+
const device = wanted === NEXT ? nextDevice(devices) : devices.find((d) => d.id === wanted);
|
|
451
|
+
if (!device) throw new Error("that audio device is not connected");
|
|
452
|
+
const { previous } = await helper.request("setDefault", { device: device.id });
|
|
453
|
+
return {
|
|
454
|
+
result: device.name,
|
|
455
|
+
label: `Audio ${settings.flow}: ${device.name}`,
|
|
456
|
+
...(previous && {
|
|
457
|
+
undo: () => helper.request("setDefault", { device: previous }),
|
|
458
|
+
}),
|
|
459
|
+
};
|
|
460
|
+
},
|
|
461
|
+
look: (s): Look => ({
|
|
462
|
+
background: s.background,
|
|
463
|
+
layers: [
|
|
464
|
+
iconLayer("icon", s.flow === "output" ? "lucide/headphones" : "lucide/mic", {
|
|
465
|
+
size: 44,
|
|
466
|
+
position: "top",
|
|
467
|
+
row: "icon",
|
|
468
|
+
}),
|
|
469
|
+
iconLayer("switch", "lucide/arrow-left-right", {
|
|
470
|
+
color: "#c4b5fd",
|
|
471
|
+
size: 22,
|
|
472
|
+
position: "top",
|
|
473
|
+
row: "icon",
|
|
474
|
+
}),
|
|
475
|
+
textLayer("device", `{{audio.${s.flow} ?? "N/A"}}`, { size: 11, position: "bottom" }),
|
|
476
|
+
],
|
|
477
|
+
}),
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
const deviceOptions = async (flow: "outputs" | "inputs") =>
|
|
481
|
+
(await helper.request("snapshot"))[flow].map((d) => ({ value: d.id, label: d.name }));
|
|
482
|
+
|
|
483
|
+
export default definePlugin({
|
|
484
|
+
id: "@sdeck/plugin-audio",
|
|
485
|
+
name: "Audio",
|
|
486
|
+
version: "0.1.0",
|
|
487
|
+
namespace: "audio",
|
|
488
|
+
description: "Volume and mute for speakers, microphone and each app, and device switching.",
|
|
489
|
+
author: "sdeck",
|
|
490
|
+
permissions: ["audio", "process"],
|
|
491
|
+
settings: {
|
|
492
|
+
helper: {
|
|
493
|
+
type: "text",
|
|
494
|
+
label: "Audio helper",
|
|
495
|
+
placeholder: "Found automatically",
|
|
496
|
+
description: "Full path of sdeck-audio, if it is somewhere unusual.",
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
onboarding: {
|
|
500
|
+
steps: [
|
|
501
|
+
{
|
|
502
|
+
id: "helper",
|
|
503
|
+
title: "The audio helper",
|
|
504
|
+
body: "sdeck reaches your speakers, microphone and apps through a small helper that comes with this plugin on Windows. Leave this empty unless it is somewhere else.",
|
|
505
|
+
settings: ["helper"],
|
|
506
|
+
done: (activated) => {
|
|
507
|
+
const custom = String(activated.settings().helper ?? "").trim();
|
|
508
|
+
return custom ? existsSync(custom) : findHelper() !== undefined;
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
],
|
|
512
|
+
},
|
|
513
|
+
actions: [volume, slider, defaultDevice],
|
|
514
|
+
optionSources: {
|
|
515
|
+
outputs: () => deviceOptions("outputs"),
|
|
516
|
+
inputs: () => deviceOptions("inputs"),
|
|
517
|
+
apps: async () =>
|
|
518
|
+
(await helper.request("snapshot")).apps.map((a) => ({ value: a.name, label: a.name })),
|
|
519
|
+
},
|
|
520
|
+
state: [
|
|
521
|
+
stateOf("master", "Speakers", "json", "audio.master.volume, .muted, .name"),
|
|
522
|
+
stateOf("mic", "Microphone", "json", "audio.mic.volume, .muted, .name"),
|
|
523
|
+
stateOf("output", "Output device", "string", "The default output's name."),
|
|
524
|
+
stateOf("input", "Input device", "string", "The default input's name."),
|
|
525
|
+
stateOf("outputs", "Output devices", "json", "Every output with its level."),
|
|
526
|
+
stateOf("inputs", "Input devices", "json", "Every input with its level."),
|
|
527
|
+
stateOf("apps", "App volumes", "json", "audio.apps.spotify.volume, .muted, .active"),
|
|
528
|
+
],
|
|
529
|
+
activate(activated) {
|
|
530
|
+
context = activated;
|
|
531
|
+
if (process.platform !== "win32") {
|
|
532
|
+
activated.status("Audio control is available on Windows only", "info");
|
|
533
|
+
} else if (!findHelper() && !activated.settings().helper) {
|
|
534
|
+
activated.status(`${BUILD_HINT}.`, "info");
|
|
535
|
+
}
|
|
536
|
+
return () => {
|
|
537
|
+
helper.close();
|
|
538
|
+
context = undefined;
|
|
539
|
+
};
|
|
540
|
+
},
|
|
541
|
+
});
|
package/README.md
DELETED