@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.
- package/LICENSE +21 -0
- package/README.md +320 -2
- package/assets/mixshell-screenshot.png +0 -0
- package/package.json +74 -5
- package/src/alsa-pulse.conf +20 -0
- package/src/alsa-setup.js +15 -0
- package/src/components/browser.js +193 -0
- package/src/components/config.js +168 -0
- package/src/components/durations.js +151 -0
- package/src/components/library.js +679 -0
- package/src/components/mediakeys.js +222 -0
- package/src/components/mpris.js +309 -0
- package/src/components/player.js +436 -0
- package/src/components/playlist.js +335 -0
- package/src/components/session.js +96 -0
- package/src/constants.js +164 -0
- package/src/engines/ffmpeg.js +610 -0
- package/src/engines/index.js +14 -0
- package/src/engines/webaudio.js +317 -0
- package/src/index.js +188 -0
- package/src/mediakeys/macos-nowplaying.js +227 -0
- package/src/ui/app.js +56 -0
- package/src/ui/artPane.js +314 -0
- package/src/ui/confirmPrompt.js +34 -0
- package/src/ui/constants.js +133 -0
- package/src/ui/controller.js +1654 -0
- package/src/ui/dom.js +9 -0
- package/src/ui/goToPrompt.js +105 -0
- package/src/ui/index.html +78 -0
- package/src/ui/libraryPanel.js +415 -0
- package/src/ui/listView.js +209 -0
- package/src/ui/onboarding.js +353 -0
- package/src/ui/playlistPanel.js +207 -0
- package/src/ui/settingsPanel.js +473 -0
- package/src/ui/shortcuts.js +30 -0
- package/src/ui/splash.js +302 -0
- package/src/ui/style.css +532 -0
- package/src/ui/subtabs.js +31 -0
- package/src/ui/visualizer/bars.js +74 -0
- package/src/ui/visualizer/circles.js +64 -0
- package/src/ui/visualizer/color.js +61 -0
- package/src/ui/visualizer/cube.js +105 -0
- package/src/ui/visualizer/grid.js +68 -0
- package/src/ui/visualizer/index.js +65 -0
- package/src/ui/visualizer/onset.js +130 -0
- package/src/ui/visualizer/spectrum.js +34 -0
- package/src/ui/visualizer/vu.js +71 -0
- package/src/ui/visualizer/waveform.js +58 -0
- package/src/utils/audioAnalyzer.js +362 -0
- package/src/utils/audioDevices.js +222 -0
- package/src/utils/cellart.js +75 -0
- package/src/utils/debug.js +7 -0
- package/src/utils/durationProbe.js +48 -0
- package/src/utils/folderArt.js +46 -0
- package/src/utils/format.js +20 -0
- package/src/utils/id3.js +84 -0
- package/src/utils/pathInput.js +76 -0
- package/src/utils/playlistIO.js +176 -0
- package/src/utils/terminalGraphics.js +47 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { PLAYLIST_FORMAT_OPTIONS, SCREENS } from '../constants.js';
|
|
4
|
+
import { DBG } from '../utils/debug.js';
|
|
5
|
+
import { resolveSavePath } from '../utils/pathInput.js';
|
|
6
|
+
import {
|
|
7
|
+
filterLoadable,
|
|
8
|
+
readPlaylistFile,
|
|
9
|
+
serializeM3u,
|
|
10
|
+
serializePls,
|
|
11
|
+
} from '../utils/playlistIO.js';
|
|
12
|
+
|
|
13
|
+
// Keys the playlist save prompt swallows without acting — they would
|
|
14
|
+
// otherwise drive list navigation / tab switching mid-edit. Left/Right/
|
|
15
|
+
// Home/End are NOT here: the prompt's cursor consumes them.
|
|
16
|
+
const PROMPT_PARKED_KEYS = new Set([
|
|
17
|
+
'ArrowUp',
|
|
18
|
+
'ArrowDown',
|
|
19
|
+
'PageUp',
|
|
20
|
+
'PageDown',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
// Playlist file I/O UI (issues/028): the `w` save prompt (key-capture
|
|
24
|
+
// mode with an in-place cursor) and the `o` open flow. Owns the prompt
|
|
25
|
+
// state; the controller renders it via getPrompt() and routes keys here.
|
|
26
|
+
export function createPlaylistPanel({
|
|
27
|
+
playlist,
|
|
28
|
+
library,
|
|
29
|
+
browser,
|
|
30
|
+
config,
|
|
31
|
+
showMessage,
|
|
32
|
+
hideMessage,
|
|
33
|
+
confirm,
|
|
34
|
+
switchTab,
|
|
35
|
+
}) {
|
|
36
|
+
// The save prompt: null or { text, pos, base } — while set, printable
|
|
37
|
+
// keys edit the target path instead of firing shortcuts.
|
|
38
|
+
let prompt = null;
|
|
39
|
+
|
|
40
|
+
// YYYYMMDD-HHMMSS — unique, sortable, no metadata dependency.
|
|
41
|
+
function timestampSlug() {
|
|
42
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
43
|
+
const now = new Date();
|
|
44
|
+
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function saveFormat() {
|
|
48
|
+
const format = config.get('playlistSaveFormat');
|
|
49
|
+
return PLAYLIST_FORMAT_OPTIONS.includes(format) ? format : 'm3u';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// `w` opens the save prompt pre-filled with the browsed directory; Enter
|
|
53
|
+
// commits, Esc cancels. Editing mirrors the library search input mode,
|
|
54
|
+
// plus a cursor so the pre-filled path can be edited in place.
|
|
55
|
+
function startSavePrompt() {
|
|
56
|
+
if (playlist.isEmpty) {
|
|
57
|
+
showMessage('Playlist is empty — nothing to save');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const text = path.join(
|
|
61
|
+
browser.currentDirectory,
|
|
62
|
+
`playlist-${timestampSlug()}.${saveFormat()}`,
|
|
63
|
+
);
|
|
64
|
+
prompt = { text, pos: text.length, base: browser.currentDirectory };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function finishSave(filePath, format) {
|
|
68
|
+
prompt = null;
|
|
69
|
+
try {
|
|
70
|
+
const baseDir = path.dirname(filePath);
|
|
71
|
+
mkdirSync(baseDir, { recursive: true });
|
|
72
|
+
const lookup = library.trackInfoByPaths(
|
|
73
|
+
playlist.tracks.map((track) => track.path),
|
|
74
|
+
);
|
|
75
|
+
const serialize = format === 'pls' ? serializePls : serializeM3u;
|
|
76
|
+
writeFileSync(filePath, serialize(playlist.tracks, { baseDir, lookup }));
|
|
77
|
+
DBG(`playlist saved: ${filePath} (${playlist.length} tracks, ${format})`);
|
|
78
|
+
showMessage(`Saved ${playlist.length} tracks → ${filePath}`);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
DBG(`playlist save failed: ${error?.message ?? error}`);
|
|
81
|
+
showMessage(`Save failed: ${error.message}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function commitSavePrompt() {
|
|
86
|
+
const target = prompt.text.trim();
|
|
87
|
+
if (!target) {
|
|
88
|
+
prompt = null;
|
|
89
|
+
showMessage('Save cancelled');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const format = saveFormat();
|
|
93
|
+
const filePath = resolveSavePath(target, { format, base: prompt.base });
|
|
94
|
+
if (existsSync(filePath)) {
|
|
95
|
+
// Keep the prompt — declining returns to the typed text (issues/057).
|
|
96
|
+
confirm.ask(
|
|
97
|
+
`Overwrite ${filePath}? Y/N`,
|
|
98
|
+
() => finishSave(filePath, format),
|
|
99
|
+
hideMessage,
|
|
100
|
+
);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
finishSave(filePath, format);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Key capture for the save prompt. Returns true when consumed; run
|
|
107
|
+
// before every other handler so filenames can contain q/w/s/d etc.
|
|
108
|
+
// False when no prompt is open — the keydown guard doubles as the
|
|
109
|
+
// "prompt active" check. The prompt owns a cursor (prompt.pos):
|
|
110
|
+
// Left/Right move it, Backspace/Delete edit around it, Home/End jump.
|
|
111
|
+
function key(e) {
|
|
112
|
+
if (!prompt) return false;
|
|
113
|
+
const keyName = e.key;
|
|
114
|
+
if (keyName === 'Enter') {
|
|
115
|
+
commitSavePrompt();
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
if (keyName === 'Escape') {
|
|
119
|
+
prompt = null;
|
|
120
|
+
showMessage('Save cancelled');
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
if (keyName === 'Backspace') {
|
|
124
|
+
if (prompt.pos > 0) {
|
|
125
|
+
prompt.text =
|
|
126
|
+
prompt.text.slice(0, prompt.pos - 1) + prompt.text.slice(prompt.pos);
|
|
127
|
+
prompt.pos--;
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (keyName === 'Delete') {
|
|
132
|
+
if (prompt.pos < prompt.text.length) {
|
|
133
|
+
prompt.text =
|
|
134
|
+
prompt.text.slice(0, prompt.pos) + prompt.text.slice(prompt.pos + 1);
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
if (keyName === 'ArrowLeft') {
|
|
139
|
+
prompt.pos = Math.max(0, prompt.pos - 1);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
if (keyName === 'ArrowRight') {
|
|
143
|
+
prompt.pos = Math.min(prompt.text.length, prompt.pos + 1);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
if (keyName === 'Home') {
|
|
147
|
+
prompt.pos = 0;
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
if (keyName === 'End') {
|
|
151
|
+
prompt.pos = prompt.text.length;
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
// Park the rest of the navigation keys so the list stays quiet.
|
|
155
|
+
if (PROMPT_PARKED_KEYS.has(keyName)) return true;
|
|
156
|
+
if (keyName.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
157
|
+
prompt.text =
|
|
158
|
+
prompt.text.slice(0, prompt.pos) +
|
|
159
|
+
keyName +
|
|
160
|
+
prompt.text.slice(prompt.pos);
|
|
161
|
+
prompt.pos++;
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// `o` opens the picker: the browser tab, wherever the user left it —
|
|
168
|
+
// playlist files are visible (≡) and Enter loads them from any
|
|
169
|
+
// directory (issues/028). Save defaults to the same browsed directory.
|
|
170
|
+
// Re-read the listing first: a playlist written since the last
|
|
171
|
+
// loadDirectory (e.g. by `w` moments ago) is not in stale entries.
|
|
172
|
+
function openBrowser() {
|
|
173
|
+
if (!browser.loadDirectory(browser.currentDirectory, true)) {
|
|
174
|
+
showMessage(browser.lastError.error);
|
|
175
|
+
}
|
|
176
|
+
switchTab(SCREENS.BROWSER);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Open = replace the queue, park the cursor on track 1, never autoplay.
|
|
180
|
+
// Missing/foreign entries skip with a count instead of failing.
|
|
181
|
+
function openFile(filePath) {
|
|
182
|
+
try {
|
|
183
|
+
const entries = readPlaylistFile(filePath);
|
|
184
|
+
const { tracks, skipped } = filterLoadable(entries);
|
|
185
|
+
playlist.loadTracks(tracks);
|
|
186
|
+
const skippedNote = skipped > 0 ? `, skipped ${skipped}` : '';
|
|
187
|
+
DBG(
|
|
188
|
+
`playlist loaded: ${filePath} (${tracks.length} tracks${skippedNote})`,
|
|
189
|
+
);
|
|
190
|
+
showMessage(`Loaded ${tracks.length} tracks${skippedNote}`);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
DBG(`playlist load failed: ${error?.message ?? error}`);
|
|
193
|
+
showMessage(`Load failed: ${error.message}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
getPrompt: () => prompt,
|
|
199
|
+
cancelPrompt: () => {
|
|
200
|
+
prompt = null;
|
|
201
|
+
},
|
|
202
|
+
startSavePrompt,
|
|
203
|
+
key,
|
|
204
|
+
openBrowser,
|
|
205
|
+
openFile,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AUDIO_ENGINES,
|
|
3
|
+
FPS_OPTIONS,
|
|
4
|
+
PLAYLIST_FORMAT_OPTIONS,
|
|
5
|
+
SEEK_STEP_OPTIONS,
|
|
6
|
+
SMOOTHING_LABELS,
|
|
7
|
+
SMOOTHING_OPTIONS,
|
|
8
|
+
VOLUME_STEP_OPTIONS,
|
|
9
|
+
} from '../constants.js';
|
|
10
|
+
import {
|
|
11
|
+
friendlyDeviceName,
|
|
12
|
+
listOutputDevices,
|
|
13
|
+
resetDeviceProbe,
|
|
14
|
+
} from '../utils/audioDevices.js';
|
|
15
|
+
import { ART_STYLES, THEMES, VIZ_BARS } from './constants.js';
|
|
16
|
+
import { createGoToPrompt } from './goToPrompt.js';
|
|
17
|
+
import { createSubtabs } from './subtabs.js';
|
|
18
|
+
|
|
19
|
+
// Settings panel (issues/024): the Library panel's sub-screen pattern
|
|
20
|
+
// applied to settings. Views + rows come from Config's settingsViews
|
|
21
|
+
// getter; labels interpolate config values, so every render re-maps them.
|
|
22
|
+
export function createSettingsPanel({
|
|
23
|
+
config,
|
|
24
|
+
library,
|
|
25
|
+
analyzer,
|
|
26
|
+
syncVizNeeds,
|
|
27
|
+
els,
|
|
28
|
+
el,
|
|
29
|
+
getCursor,
|
|
30
|
+
setCursor,
|
|
31
|
+
showMessage,
|
|
32
|
+
hideMessage,
|
|
33
|
+
confirm,
|
|
34
|
+
refreshShortcuts,
|
|
35
|
+
onScanError,
|
|
36
|
+
renderList,
|
|
37
|
+
applyTheme,
|
|
38
|
+
onArtStyleChanged,
|
|
39
|
+
startVisualizer,
|
|
40
|
+
runOnboarding,
|
|
41
|
+
onMediaDirectoryChanged,
|
|
42
|
+
listDevices = listOutputDevices,
|
|
43
|
+
resetProbe = resetDeviceProbe,
|
|
44
|
+
}) {
|
|
45
|
+
// Drilled levels (issues/031, /058), mirroring the library panel's
|
|
46
|
+
// stack/cursor-restore pattern: `dirs` for scan roots, `devices` for the
|
|
47
|
+
// output-device picker. Y/N prompts live in the controller's shared
|
|
48
|
+
// confirm, so the Browser's scan question (issues/053) and the playlist
|
|
49
|
+
// overwrite question (issues/057) can be answered from any tab.
|
|
50
|
+
const drill = { level: null, rootCursor: 0 };
|
|
51
|
+
// Media Directory row's inline prompt (issues/051), based on the
|
|
52
|
+
// current value; Enter saves the typed directory.
|
|
53
|
+
const goTo = createGoToPrompt();
|
|
54
|
+
|
|
55
|
+
// Rows that act rather than hold a steppable value (issue 058): ←/→
|
|
56
|
+
// leave these alone so ← keeps its Back/no-op meaning.
|
|
57
|
+
const ACTION_PATHS = new Set([
|
|
58
|
+
'default_dir',
|
|
59
|
+
'library_dirs',
|
|
60
|
+
'library_rescan',
|
|
61
|
+
'run_setup',
|
|
62
|
+
]);
|
|
63
|
+
// Null while enumeration runs: deviceRows shows the listing hint.
|
|
64
|
+
const deviceList = { devices: null };
|
|
65
|
+
|
|
66
|
+
const subtabs = createSubtabs({
|
|
67
|
+
views: config.settingsViews,
|
|
68
|
+
el,
|
|
69
|
+
mount: els.settingsSubtabs,
|
|
70
|
+
onChange: () => {
|
|
71
|
+
drill.active = false;
|
|
72
|
+
if (confirm.isOpen()) confirm.cancel();
|
|
73
|
+
setCursor(0);
|
|
74
|
+
refreshShortcuts();
|
|
75
|
+
render();
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Fresh each call: view labels are static, but row labels interpolate
|
|
80
|
+
// config values, so cycled values show up on the next render.
|
|
81
|
+
function activeView() {
|
|
82
|
+
return config.settingsViews[subtabs.active()];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Root rows derive live from config so an L-add in the browser shows up
|
|
86
|
+
// without stale snapshots; counts come from the index. The hint row is
|
|
87
|
+
// permanent, so the list keeps its "how to add" state even when empty.
|
|
88
|
+
function dirRows() {
|
|
89
|
+
const rows = config.get('libraryDirs').map((dir) => ({
|
|
90
|
+
kind: 'dir',
|
|
91
|
+
dir,
|
|
92
|
+
icon: '·',
|
|
93
|
+
text: `${dir} (${library.countForRoot(dir)} tracks)`,
|
|
94
|
+
}));
|
|
95
|
+
rows.push({
|
|
96
|
+
kind: 'hint',
|
|
97
|
+
icon: '+',
|
|
98
|
+
text: 'Add directory… (press L in the browser)',
|
|
99
|
+
});
|
|
100
|
+
return rows;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function render() {
|
|
104
|
+
subtabs.render();
|
|
105
|
+
els.settingsPath.textContent = `${
|
|
106
|
+
drill.level
|
|
107
|
+
? `Settings › ${activeView().label} › ${
|
|
108
|
+
drill.level === 'dirs' ? 'Library Dirs' : 'Output Device'
|
|
109
|
+
}`
|
|
110
|
+
: `Settings › ${activeView().label}`
|
|
111
|
+
}${goTo.suffix()}`;
|
|
112
|
+
renderList(els.settingsList, rows());
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Rows are [path, label] pairs at the root level; the label is what the
|
|
116
|
+
// list shows. Drilled levels supply their own row objects.
|
|
117
|
+
function rows() {
|
|
118
|
+
if (drill.level === 'dirs') return dirRows();
|
|
119
|
+
if (drill.level === 'devices') return deviceRows();
|
|
120
|
+
return activeView().rows.map(([, name]) => ({ icon: '·', text: name }));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Keep the cursor on a real row after a removal shrinks the list (the
|
|
124
|
+
// hint row guarantees at least one row remains).
|
|
125
|
+
function clampCursor() {
|
|
126
|
+
const max = rows().length - 1;
|
|
127
|
+
if (getCursor() > max) setCursor(max);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function descendIntoDirs() {
|
|
131
|
+
drill.level = 'dirs';
|
|
132
|
+
drill.rootCursor = getCursor();
|
|
133
|
+
setCursor(0);
|
|
134
|
+
refreshShortcuts();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function ascend() {
|
|
138
|
+
if (!drill.level) return;
|
|
139
|
+
drill.level = null;
|
|
140
|
+
if (confirm.isOpen()) confirm.cancel();
|
|
141
|
+
setCursor(drill.rootCursor);
|
|
142
|
+
refreshShortcuts();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function isDrilled() {
|
|
146
|
+
return drill.level !== null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function isDeviceList() {
|
|
150
|
+
return drill.level === 'devices';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function openDirEntry() {
|
|
154
|
+
const row = dirRows()[getCursor()];
|
|
155
|
+
if (!row) return;
|
|
156
|
+
if (row.kind === 'hint') {
|
|
157
|
+
openAddDirPrompt();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
showMessage(`${row.dir} — ${library.countForRoot(row.dir)} indexed tracks`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Add a scan root from Settings (issues/053), based at the current media
|
|
164
|
+
// directory. The Browser's `L` asks through the same helper.
|
|
165
|
+
function addDirAndAskScan(dir) {
|
|
166
|
+
const dirs = config.get('libraryDirs');
|
|
167
|
+
if (!dirs.includes(dir)) {
|
|
168
|
+
config.set('libraryDirs', [...dirs, dir]);
|
|
169
|
+
config.save();
|
|
170
|
+
}
|
|
171
|
+
render();
|
|
172
|
+
confirm.ask(
|
|
173
|
+
`Scan "${dir}" into the library now? Y/N`,
|
|
174
|
+
() => rescanLibrary(),
|
|
175
|
+
() =>
|
|
176
|
+
showMessage(`Added to library: ${dir} — rescan in Settings › Library`),
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function openAddDirPrompt() {
|
|
181
|
+
goTo.start({
|
|
182
|
+
base: config.get('mediaDirectory'),
|
|
183
|
+
onConfirm: addDirAndAskScan,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function removeSelected() {
|
|
188
|
+
if (drill.level !== 'dirs') return;
|
|
189
|
+
if (confirm.isOpen()) confirm.cancel();
|
|
190
|
+
const row = dirRows()[getCursor()];
|
|
191
|
+
if (!row) return;
|
|
192
|
+
if (row.kind === 'hint') {
|
|
193
|
+
showMessage('Press L in the browser to add a directory');
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
confirm.ask(
|
|
197
|
+
'Are you sure you want to remove this item from the library? Y/N',
|
|
198
|
+
() => removeDir(row.dir),
|
|
199
|
+
hideMessage,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Removal is config-only: pruning stays the scan's job, so the follow-up
|
|
204
|
+
// prompt offers the manual rescan.
|
|
205
|
+
function removeDir(dir) {
|
|
206
|
+
const dirs = config.get('libraryDirs').filter((entry) => entry !== dir);
|
|
207
|
+
config.set('libraryDirs', dirs);
|
|
208
|
+
config.save();
|
|
209
|
+
clampCursor();
|
|
210
|
+
confirm.ask(
|
|
211
|
+
'Would you like to rescan the library to clear removed items? Y/N',
|
|
212
|
+
() => rescanLibrary(),
|
|
213
|
+
hideMessage,
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function rescanLibrary() {
|
|
218
|
+
if (library.scanning) {
|
|
219
|
+
showMessage('Scan already running');
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// Toast first: scan()'s walk/stat pass is event-loop work, and the
|
|
223
|
+
// sticky prompt must be replaced before the pass can hold the frame.
|
|
224
|
+
showMessage('Scanning library…');
|
|
225
|
+
library.scan().catch(onScanError);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Output device (issues/042, /058). Arrows step through the same
|
|
229
|
+
// `[Default, …devices]` options Enter used to cycle; Enter opens a list.
|
|
230
|
+
// Enumeration is async, so the list shows a hint row until it lands.
|
|
231
|
+
// A stored id no longer attached stays visible, marked as such.
|
|
232
|
+
function announceDevice(value, devices) {
|
|
233
|
+
// Re-picking a device clears its probe verdict (issues/047) so the
|
|
234
|
+
// next play re-probes it — a replugged device heals instead of
|
|
235
|
+
// staying on the system default until restart.
|
|
236
|
+
if (value) resetProbe(value);
|
|
237
|
+
const label = value
|
|
238
|
+
? (friendlyDeviceName(value) ??
|
|
239
|
+
devices.find((device) => device.id === value)?.name ??
|
|
240
|
+
value)
|
|
241
|
+
: 'Default';
|
|
242
|
+
showMessage(
|
|
243
|
+
devices.length || value
|
|
244
|
+
? `Output device: ${label} (next play)`
|
|
245
|
+
: 'No output devices detected — using Default',
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function deviceRows() {
|
|
250
|
+
if (!deviceList.devices) {
|
|
251
|
+
return [{ icon: ' ', text: 'Listing output devices…' }];
|
|
252
|
+
}
|
|
253
|
+
const devices = deviceList.devices;
|
|
254
|
+
const rows = [
|
|
255
|
+
{ icon: ' ', text: 'Default (system output)' },
|
|
256
|
+
...devices.map((device) => ({
|
|
257
|
+
icon: ' ',
|
|
258
|
+
text: device.name || device.id,
|
|
259
|
+
})),
|
|
260
|
+
];
|
|
261
|
+
const stored = config.get('audioDevice');
|
|
262
|
+
if (stored && !devices.some((device) => device.id === stored)) {
|
|
263
|
+
rows.push({
|
|
264
|
+
icon: ' ',
|
|
265
|
+
text: `${friendlyDeviceName(stored) ?? stored} (not connected)`,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return rows;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function openDeviceList() {
|
|
272
|
+
drill.level = 'devices';
|
|
273
|
+
drill.rootCursor = getCursor();
|
|
274
|
+
setCursor(0);
|
|
275
|
+
deviceList.devices = null;
|
|
276
|
+
refreshShortcuts();
|
|
277
|
+
listDevices().then((devices) => {
|
|
278
|
+
if (!isDeviceList()) return; // left while the probes ran
|
|
279
|
+
deviceList.devices = devices;
|
|
280
|
+
render();
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function stepAudioDevice(direction) {
|
|
285
|
+
showMessage('Listing output devices…');
|
|
286
|
+
listDevices().then((devices) => {
|
|
287
|
+
const options = [null, ...devices.map((d) => d.id)];
|
|
288
|
+
const value = config.step('audioDevice', options, direction);
|
|
289
|
+
announceDevice(value, devices);
|
|
290
|
+
render();
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function chooseDevice() {
|
|
295
|
+
if (!isDeviceList() || !deviceList.devices) return;
|
|
296
|
+
const devices = deviceList.devices;
|
|
297
|
+
const index = getCursor() - 1;
|
|
298
|
+
// Below row 0 is Default; a row past the enumerated devices is the
|
|
299
|
+
// stored (disconnected) id.
|
|
300
|
+
const value =
|
|
301
|
+
index < 0 ? null : (devices[index]?.id ?? config.get('audioDevice'));
|
|
302
|
+
config.set('audioDevice', value);
|
|
303
|
+
config.save();
|
|
304
|
+
announceDevice(value, devices);
|
|
305
|
+
ascend();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Y/N prompts: y/Y answers yes; n/N/Escape/Enter answer no. Other keys
|
|
309
|
+
// leave the prompt up and handle normally, so global playback and quit
|
|
310
|
+
// shortcuts keep working while it is visible.
|
|
311
|
+
const confirmKey = (e) => confirm.key(e);
|
|
312
|
+
|
|
313
|
+
// Path of the row under the cursor — applySelected keys on it.
|
|
314
|
+
// Undefined while drilled: root rows are not settings paths.
|
|
315
|
+
function selectedPath() {
|
|
316
|
+
return drill.level ? undefined : activeView().rows[getCursor()]?.[0];
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Keyed on the selected row's path, not the positional index —
|
|
320
|
+
// positional cases break silently when rows reorder. View-key-only
|
|
321
|
+
// side effects (theme body class, art repaint) stay in the controller
|
|
322
|
+
// via the injected callbacks. `direction` is 0 for Enter, ±1 for arrows
|
|
323
|
+
// (issue 058); action rows ignore arrows so ← stays Back/no-op.
|
|
324
|
+
function applySelected(direction = 0) {
|
|
325
|
+
const path = selectedPath();
|
|
326
|
+
if (!path) return false;
|
|
327
|
+
if (direction && ACTION_PATHS.has(path)) return false;
|
|
328
|
+
const step = direction || 1;
|
|
329
|
+
switch (path) {
|
|
330
|
+
case 'audio_device':
|
|
331
|
+
if (direction) stepAudioDevice(direction);
|
|
332
|
+
else openDeviceList();
|
|
333
|
+
break;
|
|
334
|
+
case 'default_dir':
|
|
335
|
+
goTo.start({
|
|
336
|
+
base: config.get('mediaDirectory'),
|
|
337
|
+
onConfirm: (dir) => {
|
|
338
|
+
config.set('mediaDirectory', dir);
|
|
339
|
+
config.save();
|
|
340
|
+
showMessage(`Media Directory: ${dir}`);
|
|
341
|
+
onMediaDirectoryChanged(dir);
|
|
342
|
+
render();
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
break;
|
|
346
|
+
case 'theme': {
|
|
347
|
+
const v = config.step('theme', THEMES, step);
|
|
348
|
+
applyTheme();
|
|
349
|
+
showMessage(`Theme: ${v}`);
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
case 'audio_engine': {
|
|
353
|
+
const v = config.step('audioEngine', AUDIO_ENGINES, step);
|
|
354
|
+
showMessage(`Audio Engine: ${v} (next play)`);
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
case 'volume_step': {
|
|
358
|
+
const v = config.step('volumeStep', VOLUME_STEP_OPTIONS, step);
|
|
359
|
+
showMessage(`Volume Step: ${v}%`);
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
case 'seek_step': {
|
|
363
|
+
const v = config.step('seekStep', SEEK_STEP_OPTIONS, step);
|
|
364
|
+
refreshShortcuts();
|
|
365
|
+
showMessage(`Seek Step: ${v}s`);
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
case 'playlist_save_format': {
|
|
369
|
+
const v = config.step(
|
|
370
|
+
'playlistSaveFormat',
|
|
371
|
+
PLAYLIST_FORMAT_OPTIONS,
|
|
372
|
+
step,
|
|
373
|
+
);
|
|
374
|
+
showMessage(`Playlist Save Format: ${v}`);
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
case 'auto_play_first': {
|
|
378
|
+
// Player reads the flag on every firstTrackQueued event,
|
|
379
|
+
// so no restart is needed (issues/064).
|
|
380
|
+
const enabled = !config.get('play_when_first_track_queued');
|
|
381
|
+
config.set('play_when_first_track_queued', enabled);
|
|
382
|
+
config.save();
|
|
383
|
+
showMessage(`Auto-play First Queued: ${enabled ? 'ON' : 'OFF'}`);
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
case 'media_keys': {
|
|
387
|
+
// The helper starts once at boot (issues/048), so the new value
|
|
388
|
+
// only takes effect on the next start.
|
|
389
|
+
const enabled = !config.get('mediaKeys');
|
|
390
|
+
config.set('mediaKeys', enabled);
|
|
391
|
+
config.save();
|
|
392
|
+
showMessage(`Media Keys: ${enabled ? 'ON' : 'OFF'} (next start)`);
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
case 'albumart_style': {
|
|
396
|
+
const v = config.step('albumArtStyle', ART_STYLES, step);
|
|
397
|
+
onArtStyleChanged();
|
|
398
|
+
showMessage(`Album Art Style: ${v}`);
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
case 'visualizer_quality': {
|
|
402
|
+
const v = config.step('visualizerQuality', Object.keys(VIZ_BARS), step);
|
|
403
|
+
analyzer.updateQualitySettings();
|
|
404
|
+
syncVizNeeds();
|
|
405
|
+
showMessage(`Visualizer Quality: ${v}`);
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
case 'visualizer_fps': {
|
|
409
|
+
const v = config.step('visualizerFPS', FPS_OPTIONS, step);
|
|
410
|
+
startVisualizer();
|
|
411
|
+
showMessage(`Visualizer FPS: ${v}`);
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
case 'visualizer_smoothing': {
|
|
415
|
+
const v = config.step('visualizerSmoothing', SMOOTHING_OPTIONS, step);
|
|
416
|
+
analyzer.updateQualitySettings();
|
|
417
|
+
showMessage(`Visualizer Smoothing: ${SMOOTHING_LABELS[v] ?? v}`);
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
case 'show_fps': {
|
|
421
|
+
const enabled = !config.get('showFPS');
|
|
422
|
+
config.set('showFPS', enabled);
|
|
423
|
+
config.save();
|
|
424
|
+
showMessage(`FPS Counter: ${enabled ? 'ON' : 'OFF'}`);
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
case 'library_rescan': {
|
|
428
|
+
if (!library.isConfigured()) {
|
|
429
|
+
openAddDirPrompt();
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
rescanLibrary();
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
case 'library_dirs':
|
|
436
|
+
descendIntoDirs();
|
|
437
|
+
break;
|
|
438
|
+
case 'library_scan_start': {
|
|
439
|
+
const enabled = !config.get('libraryScanOnStart');
|
|
440
|
+
config.set('libraryScanOnStart', enabled);
|
|
441
|
+
config.save();
|
|
442
|
+
showMessage(`Scan on Start: ${enabled ? 'ON' : 'OFF'}`);
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
case 'run_setup':
|
|
446
|
+
// Re-arms the onboarding flow (issues/041): it persists
|
|
447
|
+
// `onboarded: true` on completion, so run-up sets the flag
|
|
448
|
+
// to false for this invocation only.
|
|
449
|
+
config.set('onboarded', false);
|
|
450
|
+
config.save();
|
|
451
|
+
runOnboarding();
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return {
|
|
458
|
+
render,
|
|
459
|
+
rows,
|
|
460
|
+
cycleView: (delta) => subtabs.cycle(delta),
|
|
461
|
+
descendIntoDirs,
|
|
462
|
+
ascend,
|
|
463
|
+
isDrilled,
|
|
464
|
+
isDeviceList,
|
|
465
|
+
chooseDevice,
|
|
466
|
+
openDirEntry,
|
|
467
|
+
removeSelected,
|
|
468
|
+
addDirAndAskScan,
|
|
469
|
+
confirmKey,
|
|
470
|
+
promptKey: (e) => goTo.key(e),
|
|
471
|
+
applySelected,
|
|
472
|
+
};
|
|
473
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Keyboard shortcut helpers. Both pure so they can be tested without a DOM.
|
|
2
|
+
|
|
3
|
+
// Single-letter shortcuts fire only with Ctrl/Alt/Meta released (issue 062).
|
|
4
|
+
// Shift is allowed — Shift+Enter is an explicit combo.
|
|
5
|
+
export function isPlain(e) {
|
|
6
|
+
return !e.ctrlKey && !e.metaKey && !e.altKey;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Footer shortcut packing (issues/066). Greedy and in order: an entry's
|
|
10
|
+
// width is its key + one space + its label, a separator costs 3 columns and
|
|
11
|
+
// is dropped at a line break. The controller renders one <div> per returned
|
|
12
|
+
// line (CSS clips a line that is still too long with nowrap, it never wraps).
|
|
13
|
+
export function packShortcuts(entries, cols) {
|
|
14
|
+
const lines = [];
|
|
15
|
+
let line = [];
|
|
16
|
+
let width = 0;
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
const w = entry[0].length + 1 + entry[1].length;
|
|
19
|
+
if (line.length && width + 3 + w > cols) {
|
|
20
|
+
lines.push(line);
|
|
21
|
+
line = [];
|
|
22
|
+
width = 0;
|
|
23
|
+
}
|
|
24
|
+
if (line.length) width += 3;
|
|
25
|
+
line.push(entry);
|
|
26
|
+
width += w;
|
|
27
|
+
}
|
|
28
|
+
if (line.length) lines.push(line);
|
|
29
|
+
return lines;
|
|
30
|
+
}
|