-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-launch-handler.js
44 lines (38 loc) · 1.26 KB
/
file-launch-handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { applyCustomSkin } from "./skin.js";
import { importSongFromFile } from "./importer.js";
import { startApp, playlistSongsContainer } from "./app.js";
import { createLoadingSongPlaceholders } from "./song-ui-factory.js";
const AUDIO_EXTENSIONS = [".wav", ".mp3", ".mp4", ".adts", ".ogg", ".webm", ".flac"];
async function handleFiles(files) {
// Check if there will be song files to import, and how many.
let songFilesToImport = 0;
for (const file of files) {
if (AUDIO_EXTENSIONS.includes(file.name.substring(file.name.lastIndexOf(".")).toLowerCase())) {
songFilesToImport++;
}
}
if (songFilesToImport > 0) {
createLoadingSongPlaceholders(playlistSongsContainer, songFilesToImport);
}
for (const file of files) {
if (file.name.endsWith(".pwampskin")) {
// This is a skin file.
const blob = await file.getFile();
blob.handle = file;
const text = await blob.text();
await applyCustomSkin(text);
} else {
// Otherwise it's an audio file.
const blob = await file.getFile();
await importSongFromFile(blob);
}
}
if (songFilesToImport > 0) {
await startApp();
}
}
if ('launchQueue' in window) {
launchQueue.setConsumer(launchParams => {
handleFiles(launchParams.files);
});
}