@trippnology/mixshell 0.0.0-stage → 0.7.1

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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +320 -2
  3. package/assets/mixshell-screenshot.png +0 -0
  4. package/package.json +74 -5
  5. package/src/alsa-pulse.conf +20 -0
  6. package/src/alsa-setup.js +15 -0
  7. package/src/components/browser.js +193 -0
  8. package/src/components/config.js +168 -0
  9. package/src/components/durations.js +151 -0
  10. package/src/components/library.js +679 -0
  11. package/src/components/mediakeys.js +222 -0
  12. package/src/components/mpris.js +309 -0
  13. package/src/components/player.js +436 -0
  14. package/src/components/playlist.js +335 -0
  15. package/src/components/session.js +96 -0
  16. package/src/constants.js +164 -0
  17. package/src/engines/ffmpeg.js +610 -0
  18. package/src/engines/index.js +14 -0
  19. package/src/engines/webaudio.js +317 -0
  20. package/src/index.js +188 -0
  21. package/src/mediakeys/macos-nowplaying.js +227 -0
  22. package/src/ui/app.js +56 -0
  23. package/src/ui/artPane.js +314 -0
  24. package/src/ui/confirmPrompt.js +34 -0
  25. package/src/ui/constants.js +133 -0
  26. package/src/ui/controller.js +1654 -0
  27. package/src/ui/dom.js +9 -0
  28. package/src/ui/goToPrompt.js +105 -0
  29. package/src/ui/index.html +78 -0
  30. package/src/ui/libraryPanel.js +415 -0
  31. package/src/ui/listView.js +209 -0
  32. package/src/ui/onboarding.js +353 -0
  33. package/src/ui/playlistPanel.js +207 -0
  34. package/src/ui/settingsPanel.js +473 -0
  35. package/src/ui/shortcuts.js +30 -0
  36. package/src/ui/splash.js +302 -0
  37. package/src/ui/style.css +532 -0
  38. package/src/ui/subtabs.js +31 -0
  39. package/src/ui/visualizer/bars.js +74 -0
  40. package/src/ui/visualizer/circles.js +64 -0
  41. package/src/ui/visualizer/color.js +61 -0
  42. package/src/ui/visualizer/cube.js +105 -0
  43. package/src/ui/visualizer/grid.js +68 -0
  44. package/src/ui/visualizer/index.js +65 -0
  45. package/src/ui/visualizer/onset.js +130 -0
  46. package/src/ui/visualizer/spectrum.js +34 -0
  47. package/src/ui/visualizer/vu.js +71 -0
  48. package/src/ui/visualizer/waveform.js +58 -0
  49. package/src/utils/audioAnalyzer.js +362 -0
  50. package/src/utils/audioDevices.js +222 -0
  51. package/src/utils/cellart.js +75 -0
  52. package/src/utils/debug.js +7 -0
  53. package/src/utils/durationProbe.js +48 -0
  54. package/src/utils/folderArt.js +46 -0
  55. package/src/utils/format.js +20 -0
  56. package/src/utils/id3.js +84 -0
  57. package/src/utils/pathInput.js +76 -0
  58. package/src/utils/playlistIO.js +176 -0
  59. package/src/utils/terminalGraphics.js +47 -0
@@ -0,0 +1,222 @@
1
+ import { spawn as nodeSpawn } from 'node:child_process';
2
+ import readline from 'node:readline';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ import { DBG } from '../utils/debug.js';
6
+ import { buildMetadata } from './mpris.js';
7
+
8
+ // Media keys on macOS (issues/048) — the non-Linux counterpart of MPRIS.
9
+ // Node has no binding for Now Playing, so a helper process owns the OS API
10
+ // (src/mediakeys/macos-nowplaying.js, plain JXA run by the in-box
11
+ // `osascript`) and talks newline-delimited JSON over stdio:
12
+ //
13
+ // MixShell → helper {"type":"state", ...buildState()}
14
+ // helper → MixShell {"type":"ready"}
15
+ // {"type":"error","message":"..."} (then exits)
16
+ // {"type":"command","name":"play|pause|toggle|stop|next|previous"}
17
+ // {"type":"seek","position":<seconds>}
18
+ //
19
+ // All player logic stays here; the helper only mirrors the last state.
20
+ // Like startMpris(): opt-in via config `mediaKeys`, never blocks startup and
21
+ // every failure path logs one debug line and returns null. Windows (SMTC) has
22
+ // no helper yet — issues/048 keeps the research notes.
23
+ const HELPER_COMMAND = '/usr/bin/osascript';
24
+ const HELPER_ARGS = [
25
+ '-l',
26
+ 'JavaScript',
27
+ fileURLToPath(new URL('../mediakeys/macos-nowplaying.js', import.meta.url)),
28
+ ];
29
+ // Generous: `osascript` loading two frameworks from a cold cache is slow.
30
+ const READY_TIMEOUT_MS = 20_000;
31
+
32
+ const COMMANDS = {
33
+ play: 'play',
34
+ pause: 'pause',
35
+ toggle: 'togglePlayPause',
36
+ stop: 'stop',
37
+ next: 'next',
38
+ previous: 'previous',
39
+ };
40
+
41
+ // Pure snapshot of what the OS surfaces show — same metadata source as the
42
+ // MPRIS `Metadata` property (`buildMetadata()`). Exported for tests.
43
+ export function buildState(player, playlist) {
44
+ const meta = buildMetadata(
45
+ player.metadata,
46
+ playlist.current,
47
+ playlist.currentIndex,
48
+ );
49
+ const tagged = Number(meta.lengthUs) / 1e6;
50
+ return {
51
+ type: 'state',
52
+ status: player.isPlaying
53
+ ? player.isPaused
54
+ ? 'paused'
55
+ : 'playing'
56
+ : 'stopped',
57
+ position: Number(player.position) || 0,
58
+ // Tags win; the engine's figure fills in when tags carry no duration.
59
+ duration: tagged > 0 ? tagged : Number(player.duration) || 0,
60
+ title: meta.title,
61
+ artist: meta.artists.join(', '),
62
+ album: meta.album,
63
+ };
64
+ }
65
+
66
+ const parseLine = (line) => {
67
+ try {
68
+ const message = JSON.parse(line);
69
+ return message && typeof message === 'object' ? message : null;
70
+ } catch {
71
+ return null;
72
+ }
73
+ };
74
+
75
+ // Resolves once the helper reports in, fails or exits. Every other line goes
76
+ // to `onMessage` as it arrives — including any that shared a read with
77
+ // `ready`, before the caller could listen for itself.
78
+ function waitForReady(child, timeoutMs, onMessage) {
79
+ return new Promise((resolve) => {
80
+ const lines = readline.createInterface({ input: child.stdout });
81
+ let stderr = '';
82
+ let settled = false;
83
+ const finish = (result) => {
84
+ if (settled) return;
85
+ settled = true;
86
+ clearTimeout(timer);
87
+ child.off('exit', onExit);
88
+ child.off('error', onError);
89
+ if (!result.ok) lines.off('line', onLine);
90
+ resolve({ lines, stderr, ...result });
91
+ };
92
+ const onLine = (line) => {
93
+ const message = parseLine(line);
94
+ if (message?.type === 'ready') finish({ ok: true });
95
+ else if (message?.type === 'error')
96
+ finish({ ok: false, reason: message.message });
97
+ else if (message) onMessage(message);
98
+ };
99
+ const onExit = (code) =>
100
+ finish({ ok: false, reason: `exited with code ${code}` });
101
+ const onError = (error) => finish({ ok: false, reason: error.message });
102
+ const timer = setTimeout(
103
+ () => finish({ ok: false, reason: 'no ready signal', timeout: true }),
104
+ timeoutMs,
105
+ );
106
+
107
+ child.stderr.setEncoding('utf8');
108
+ child.stderr.on('data', (chunk) => {
109
+ stderr = `${stderr}${chunk}`.slice(-600);
110
+ });
111
+ lines.on('line', onLine);
112
+ child.on('exit', onExit);
113
+ child.on('error', onError);
114
+ });
115
+ }
116
+
117
+ export async function startMediaKeys({
118
+ player,
119
+ playlist,
120
+ enabled = true,
121
+ platform = process.platform,
122
+ spawn = nodeSpawn,
123
+ readyTimeoutMs,
124
+ }) {
125
+ if (!enabled) {
126
+ DBG('mediakeys: off (config `mediaKeys` is false)');
127
+ return null;
128
+ }
129
+ // Linux media keys ride MPRIS (startMpris); don't claim them twice.
130
+ if (platform === 'linux') {
131
+ DBG('mediakeys: skipped (linux uses MPRIS)');
132
+ return null;
133
+ }
134
+ if (platform !== 'darwin') {
135
+ DBG(`mediakeys: skipped (unsupported platform ${platform})`);
136
+ return null;
137
+ }
138
+
139
+ // One guarded player call: nothing the helper sends may reach the player
140
+ // uncaught, sync or async.
141
+ const call = (method, argument) => {
142
+ try {
143
+ Promise.resolve(player[method](argument)).catch(() => {});
144
+ } catch {}
145
+ };
146
+ const onMessage = (message) => {
147
+ if (message.type === 'command' && COMMANDS[message.name])
148
+ call(COMMANDS[message.name]);
149
+ else if (
150
+ message.type === 'seek' &&
151
+ Number.isFinite(Number(message.position))
152
+ )
153
+ call('seek', Number(message.position));
154
+ };
155
+ const child = spawn(HELPER_COMMAND, HELPER_ARGS, {
156
+ stdio: ['pipe', 'pipe', 'pipe'],
157
+ });
158
+ // A dead pipe must never surface as an unhandled stream error.
159
+ child.stdin.on('error', () => {});
160
+ child.stdout.on('error', () => {});
161
+ child.stderr.on('error', () => {});
162
+
163
+ const { ok, reason, timeout, stderr, lines } = await waitForReady(
164
+ child,
165
+ readyTimeoutMs ?? READY_TIMEOUT_MS,
166
+ onMessage,
167
+ );
168
+ if (!ok) {
169
+ lines.close();
170
+ child.kill();
171
+ // One loggable line: the helper's stderr tail, whitespace collapsed.
172
+ const detail = stderr.trim().slice(-300).replace(/\s+/g, ' ');
173
+ DBG(
174
+ `mediakeys: helper ${reason}${detail ? ` — ${detail}` : ''}${timeout ? ' (timed out)' : ''} — disabled`,
175
+ );
176
+ return null;
177
+ }
178
+
179
+ const send = (message) => {
180
+ if (child.stdin.writable) child.stdin.write(`${JSON.stringify(message)}\n`);
181
+ };
182
+ // State out: a full snapshot on every player event. Now Playing advances
183
+ // its scrubber from the playback rate; the 1 Hz `timeUpdate` only
184
+ // corrects drift.
185
+ const pushAll = () => send(buildState(player, playlist));
186
+ const events = [
187
+ 'play',
188
+ 'pause',
189
+ 'resume',
190
+ 'stop',
191
+ 'metadataUpdate',
192
+ 'seek',
193
+ 'timeUpdate',
194
+ ];
195
+ // Listeners live until the process exits — that closes the pipe, and the
196
+ // helper exits on EOF. close() is for tests.
197
+ for (const event of events) player.on(event, pushAll);
198
+ child.on('exit', (code) =>
199
+ DBG(
200
+ `mediakeys: helper exited with code ${code} — media keys off until restart`,
201
+ ),
202
+ );
203
+ child.on('error', (error) =>
204
+ DBG(`mediakeys: helper error: ${error?.message}`),
205
+ );
206
+
207
+ DBG(`mediakeys: helper ready (${HELPER_COMMAND})`);
208
+ pushAll();
209
+
210
+ let closed = false;
211
+ return {
212
+ close() {
213
+ if (closed) return;
214
+ closed = true;
215
+ for (const event of events) player.off(event, pushAll);
216
+ lines.close();
217
+ child.stdin.end();
218
+ // Give the helper a moment to drop its OS session on EOF.
219
+ setTimeout(() => child.kill(), 2000).unref();
220
+ },
221
+ };
222
+ }
@@ -0,0 +1,309 @@
1
+ import { pathToFileURL } from 'node:url';
2
+
3
+ import { DBG } from '../utils/debug.js';
4
+
5
+ const MPRIS_BUS_NAME = 'org.mpris.MediaPlayer2.mixshell';
6
+ const MPRIS_OBJECT_PATH = '/org/mpris/MediaPlayer2';
7
+ const ROOT_IFACE = 'org.mpris.MediaPlayer2';
8
+ const PLAYER_IFACE = 'org.mpris.MediaPlayer2.Player';
9
+ const TRACK_ID_BASE = '/com/trippnology/mixshell/Track';
10
+
11
+ // Repeat mode (issues/037) ↔ MPRIS LoopStatus.
12
+ const LOOP_STATUS = { off: 'None', all: 'Playlist', one: 'Track' };
13
+ const LOOP_TO_MODE = { None: 'off', Playlist: 'all', Track: 'one' };
14
+
15
+ const trackIdFor = (index) => `${TRACK_ID_BASE}/${Math.max(0, index)}`;
16
+
17
+ // Pure mapping of the current playlist track + parsed metadata to the
18
+ // MPRIS Metadata property's members (plain values — the interface getter
19
+ // wraps them in D-Bus Variants). Exported for tests.
20
+ export function buildMetadata(metadata, track, currentIndex) {
21
+ return {
22
+ trackId: trackIdFor(currentIndex),
23
+ lengthUs: secondsToUs(metadata?.duration || 0),
24
+ title: metadata?.title || track?.name || '',
25
+ artists: metadata?.artist ? [metadata.artist] : [],
26
+ album: metadata?.album || '',
27
+ url: track?.path ? pathToFileURL(track.path).href : '',
28
+ };
29
+ }
30
+
31
+ function secondsToUs(seconds) {
32
+ return BigInt(Math.round(seconds * 1e6));
33
+ }
34
+
35
+ // Linux desktop integration (issues/029): owns the MPRIS2 well-known bus
36
+ // name, exposes Root + Player interfaces and pushes PropertiesChanged as
37
+ // Player/Playlist state moves. Every failure path is graceful — one debug
38
+ // line and a null return; MixShell runs exactly as without it.
39
+ //
40
+ // dbus-next declares its service members with a decorator API that needs a
41
+ // Babel plugin; instead we use its official non-decorator surface,
42
+ // `Interface.configureMembers()` (the class defines plain methods/getters
43
+ // and members are registered in one static call).
44
+ export async function startMpris({ player, playlist, quit }) {
45
+ if (process.platform !== 'linux') {
46
+ DBG('mpris: skipped (not linux)');
47
+ return null;
48
+ }
49
+
50
+ let dbus;
51
+ try {
52
+ const mod = await import('dbus-next');
53
+ dbus = mod.default ?? mod;
54
+ } catch {
55
+ DBG('mpris: dbus-next not installed — desktop integration disabled');
56
+ return null;
57
+ }
58
+
59
+ const { Interface, ACCESS_READ, ACCESS_READWRITE } = dbus.interface;
60
+ const { Variant } = dbus;
61
+
62
+ let bus;
63
+ try {
64
+ bus = dbus.sessionBus();
65
+ } catch (error) {
66
+ DBG(`mpris: no session bus (${error?.message}) — disabled`);
67
+ return null;
68
+ }
69
+ // A dead session bus (desktop logout) must never take the player down —
70
+ // swallow into the debug log instead of the unhandled-'error' crash.
71
+ bus.on('error', (error) => DBG(`mpris: bus error: ${error?.message}`));
72
+
73
+ class MprisRoot extends Interface {
74
+ get CanQuit() {
75
+ return true;
76
+ }
77
+ get CanRaise() {
78
+ return false;
79
+ }
80
+ get HasTrackList() {
81
+ return false;
82
+ }
83
+ get Identity() {
84
+ return 'MixShell';
85
+ }
86
+ get DesktopEntry() {
87
+ return 'mixshell';
88
+ }
89
+ get SupportedUriSchemes() {
90
+ return ['file'];
91
+ }
92
+ get SupportedMimeTypes() {
93
+ return [];
94
+ }
95
+ Raise() {
96
+ // Terminal app: nothing to raise.
97
+ }
98
+ Quit() {
99
+ quit?.();
100
+ }
101
+ }
102
+ MprisRoot.configureMembers({
103
+ methods: {
104
+ Raise: { inSignature: '', outSignature: '' },
105
+ Quit: { inSignature: '', outSignature: '' },
106
+ },
107
+ properties: {
108
+ CanQuit: { signature: 'b', access: ACCESS_READ },
109
+ CanRaise: { signature: 'b', access: ACCESS_READ },
110
+ HasTrackList: { signature: 'b', access: ACCESS_READ },
111
+ Identity: { signature: 's', access: ACCESS_READ },
112
+ DesktopEntry: { signature: 's', access: ACCESS_READ },
113
+ SupportedUriSchemes: { signature: 'as', access: ACCESS_READ },
114
+ SupportedMimeTypes: { signature: 'as', access: ACCESS_READ },
115
+ },
116
+ });
117
+
118
+ class MprisPlayer extends Interface {
119
+ get PlaybackStatus() {
120
+ return player.isPlaying
121
+ ? player.isPaused
122
+ ? 'Paused'
123
+ : 'Playing'
124
+ : 'Stopped';
125
+ }
126
+ get LoopStatus() {
127
+ return LOOP_STATUS[playlist.repeat] ?? 'None';
128
+ }
129
+ set LoopStatus(value) {
130
+ const mode = LOOP_TO_MODE[value];
131
+ if (mode) {
132
+ playlist.setRepeat(mode);
133
+ }
134
+ }
135
+ get Shuffle() {
136
+ return Boolean(playlist.shuffle);
137
+ }
138
+ set Shuffle(value) {
139
+ if (Boolean(value) !== Boolean(playlist.shuffle)) {
140
+ playlist.toggleShuffle();
141
+ }
142
+ }
143
+ get Metadata() {
144
+ const meta = buildMetadata(
145
+ player.metadata,
146
+ playlist.current,
147
+ playlist.currentIndex,
148
+ );
149
+ const entry = {
150
+ 'mpris:trackid': new Variant('o', meta.trackId),
151
+ 'mpris:length': new Variant('x', meta.lengthUs),
152
+ };
153
+ if (meta.title) entry['xesam:title'] = new Variant('s', meta.title);
154
+ if (meta.artists.length > 0) {
155
+ entry['xesam:artist'] = new Variant('as', meta.artists);
156
+ }
157
+ if (meta.album) entry['xesam:album'] = new Variant('s', meta.album);
158
+ if (meta.url) entry['xesam:url'] = new Variant('s', meta.url);
159
+ return entry;
160
+ }
161
+ get Volume() {
162
+ return player.muted ? 0 : player.volume;
163
+ }
164
+ set Volume(value) {
165
+ const level = Number(value);
166
+ if (Number.isFinite(level)) {
167
+ player.setVolume(Math.max(0, Math.min(1, level)));
168
+ }
169
+ }
170
+ get Position() {
171
+ return secondsToUs(player.position || 0);
172
+ }
173
+ Play() {
174
+ player.play();
175
+ }
176
+ Pause() {
177
+ player.pause();
178
+ }
179
+ PlayPause() {
180
+ player.togglePlayPause();
181
+ }
182
+ Stop() {
183
+ player.stop();
184
+ }
185
+ Next() {
186
+ player.next();
187
+ }
188
+ Previous() {
189
+ player.previous();
190
+ }
191
+ Seek(offsetUs) {
192
+ player.seek(player.position + Number(offsetUs) / 1e6);
193
+ }
194
+ SetPosition(trackId, positionUs) {
195
+ if (trackId !== trackIdFor(playlist.currentIndex)) return;
196
+ player.seek(Number(positionUs) / 1e6);
197
+ }
198
+ Seeked(positionUs) {
199
+ return positionUs;
200
+ }
201
+ }
202
+ MprisPlayer.configureMembers({
203
+ methods: {
204
+ Play: { inSignature: '', outSignature: '' },
205
+ Pause: { inSignature: '', outSignature: '' },
206
+ PlayPause: { inSignature: '', outSignature: '' },
207
+ Stop: { inSignature: '', outSignature: '' },
208
+ Next: { inSignature: '', outSignature: '' },
209
+ Previous: { inSignature: '', outSignature: '' },
210
+ Seek: { inSignature: 'x', outSignature: '' },
211
+ SetPosition: { inSignature: 'ox', outSignature: '' },
212
+ },
213
+ properties: {
214
+ PlaybackStatus: { signature: 's', access: ACCESS_READ },
215
+ LoopStatus: { signature: 's', access: ACCESS_READWRITE },
216
+ Shuffle: { signature: 'b', access: ACCESS_READWRITE },
217
+ Metadata: { signature: 'a{sv}', access: ACCESS_READ },
218
+ Volume: { signature: 'd', access: ACCESS_READWRITE },
219
+ Position: { signature: 'x', access: ACCESS_READ },
220
+ // Position has no change signal by spec — clients poll it and the
221
+ // Seeked signal covers discontinuities.
222
+ Rate: { signature: 'd', access: ACCESS_READ },
223
+ CanGoNext: { signature: 'b', access: ACCESS_READ },
224
+ CanGoPrevious: { signature: 'b', access: ACCESS_READ },
225
+ CanPlay: { signature: 'b', access: ACCESS_READ },
226
+ CanPause: { signature: 'b', access: ACCESS_READ },
227
+ CanSeek: { signature: 'b', access: ACCESS_READ },
228
+ CanControl: { signature: 'b', access: ACCESS_READ },
229
+ },
230
+ signals: {
231
+ Seeked: { signature: 'x' },
232
+ },
233
+ });
234
+
235
+ // Fixed-rate player; these capabilities never change while running.
236
+ const FIXED = {
237
+ Rate: 1.0,
238
+ CanGoNext: true,
239
+ CanGoPrevious: true,
240
+ CanPlay: true,
241
+ CanPause: true,
242
+ CanSeek: true,
243
+ CanControl: true,
244
+ };
245
+ for (const [name, value] of Object.entries(FIXED)) {
246
+ Object.defineProperty(MprisPlayer.prototype, name, { get: () => value });
247
+ }
248
+
249
+ const push = (...names) =>
250
+ Interface.emitPropertiesChanged(
251
+ playerIface,
252
+ Object.fromEntries(names.map((name) => [name, playerIface[name]])),
253
+ );
254
+
255
+ // Export interfaces BEFORE claiming the name: desktop media-key daemons
256
+ // react to the name appearing and introspect immediately — a name with
257
+ // no interfaces yet can get cached as a broken player and never retried.
258
+ const rootIface = new MprisRoot(ROOT_IFACE);
259
+ const playerIface = new MprisPlayer(PLAYER_IFACE);
260
+ bus.export(MPRIS_OBJECT_PATH, rootIface);
261
+ bus.export(MPRIS_OBJECT_PATH, playerIface);
262
+
263
+ let nameReply;
264
+ try {
265
+ nameReply = await bus.requestName(
266
+ MPRIS_BUS_NAME,
267
+ dbus.NameFlag.DO_NOT_QUEUE,
268
+ );
269
+ } catch (error) {
270
+ DBG(`mpris: bus name request failed (${error?.message}) — disabled`);
271
+ bus.disconnect();
272
+ return null;
273
+ }
274
+ if (nameReply !== dbus.RequestNameReply.PRIMARY_OWNER) {
275
+ DBG('mpris: bus name already owned (another MixShell?) — disabled');
276
+ bus.disconnect();
277
+ return null;
278
+ }
279
+
280
+ // State out: push PropertiesChanged so media-key apps and playerctl see
281
+ // changes without polling. Listeners live until the process exits (the
282
+ // only close() callers — shutdown and tests — exit right after).
283
+ player.on('play', () => {
284
+ push('PlaybackStatus', 'Metadata');
285
+ playerIface.Seeked(secondsToUs(player.position || 0));
286
+ });
287
+ player.on('pause', () => push('PlaybackStatus'));
288
+ player.on('resume', () => push('PlaybackStatus'));
289
+ player.on('stop', () => push('PlaybackStatus'));
290
+ player.on('metadataUpdate', () => push('Metadata'));
291
+ player.on('volumeChange', () => push('Volume'));
292
+ player.on('muteChange', () => push('Volume'));
293
+ player.on('seek', (seconds) => playerIface.Seeked(secondsToUs(seconds)));
294
+ playlist.on('repeatToggled', () => push('LoopStatus'));
295
+ playlist.on('shuffleToggled', () => push('Shuffle'));
296
+
297
+ DBG(`mpris: serving ${MPRIS_BUS_NAME} on ${MPRIS_OBJECT_PATH}`);
298
+ return {
299
+ close() {
300
+ // Stop inbound processing before closing the socket: the daemon
301
+ // still announces the released name on the dying connection, and
302
+ // dbus-next's handler tries to answer over the closed stream —
303
+ // an uncaught async throw. _connection is private API of the
304
+ // library; re-check when upgrading dbus-next.
305
+ bus._connection?.removeAllListeners('message');
306
+ bus.disconnect();
307
+ },
308
+ };
309
+ }