2020-03-09 05:11:46 +08:00
|
|
|
import "./lib/range.js";
|
|
|
|
import "./menu.js";
|
|
|
|
import "./player.js";
|
|
|
|
import "./queue.js";
|
|
|
|
|
2019-03-22 22:35:04 +08:00
|
|
|
import * as mpd from "./lib/mpd.js";
|
2020-03-09 05:11:46 +08:00
|
|
|
import * as mpdMock from "./lib/mpd-mock.js";
|
2019-03-29 05:52:57 +08:00
|
|
|
import * as html from "./lib/html.js";
|
2019-03-22 22:35:04 +08:00
|
|
|
|
2019-03-25 22:49:23 +08:00
|
|
|
import * as library from "./library.js";
|
|
|
|
import * as fs from "./fs.js";
|
2019-03-28 22:23:28 +08:00
|
|
|
import * as playlists from "./playlists.js";
|
2019-03-29 04:43:18 +08:00
|
|
|
import * as yt from "./yt.js";
|
2019-04-03 01:52:53 +08:00
|
|
|
import * as settings from "./settings.js";
|
2019-03-22 22:35:04 +08:00
|
|
|
|
2019-03-29 05:52:57 +08:00
|
|
|
function initIcons() {
|
2020-03-09 16:26:10 +08:00
|
|
|
Array.from(document.querySelectorAll("[data-icon]")).forEach(/** @param {HTMLElement} node */ node => {
|
2019-03-29 05:52:57 +08:00
|
|
|
let icon = html.icon(node.dataset.icon);
|
|
|
|
node.insertBefore(icon, node.firstChild);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:26:39 +08:00
|
|
|
async function initMpd() {
|
|
|
|
try {
|
|
|
|
await mpd.init();
|
|
|
|
return mpd;
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
return mpdMock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 05:11:46 +08:00
|
|
|
class App extends HTMLElement {
|
2020-03-09 16:26:10 +08:00
|
|
|
static get observedAttributes() { return ["component"]; }
|
|
|
|
|
2020-03-09 05:11:46 +08:00
|
|
|
constructor() {
|
|
|
|
super();
|
2019-03-26 19:35:47 +08:00
|
|
|
|
2020-03-09 16:26:10 +08:00
|
|
|
initIcons();
|
2020-03-09 05:11:46 +08:00
|
|
|
|
2020-03-09 21:26:39 +08:00
|
|
|
this._mpdPromise = initMpd().then(mpd => this.mpd = mpd);
|
2020-03-09 16:26:10 +08:00
|
|
|
}
|
2019-03-20 03:45:23 +08:00
|
|
|
|
2020-03-09 21:26:39 +08:00
|
|
|
async connectedCallback() {
|
2020-03-09 05:11:46 +08:00
|
|
|
const promises = ["cyp-player"].map(name => customElements.whenDefined(name));
|
2020-03-09 21:26:39 +08:00
|
|
|
promises.push(this._mpdPromise);
|
|
|
|
|
2020-03-09 05:11:46 +08:00
|
|
|
await Promise.all(promises);
|
2019-03-22 22:35:04 +08:00
|
|
|
|
2020-03-09 16:26:10 +08:00
|
|
|
this.dispatchEvent(new CustomEvent("load"));
|
|
|
|
|
2020-03-09 05:11:46 +08:00
|
|
|
const onHashChange = () => {
|
|
|
|
const hash = location.hash.substring(1);
|
2020-03-09 21:26:39 +08:00
|
|
|
this.setAttribute("component", hash || "queue");
|
2020-03-09 05:11:46 +08:00
|
|
|
}
|
|
|
|
window.addEventListener("hashchange", onHashChange);
|
|
|
|
onHashChange();
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:26:39 +08:00
|
|
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
|
|
switch (name) {
|
|
|
|
case "component":
|
|
|
|
location.hash = newValue;
|
|
|
|
const e = new CustomEvent("component-change");
|
|
|
|
this.dispatchEvent(e);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-09 05:11:46 +08:00
|
|
|
}
|
2020-03-09 01:06:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("cyp-app", App);
|