VulpesOS/gaia/dev_apps/music-oga/js/ui/title_bar.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

140 lines
3.5 KiB
JavaScript
Executable file

/* exported TitleBar */
/* global LazyLoader, ModeManager, MODE_PICKER, MODE_PLAYER, PlayerView,
AlbumArtCache, App */
'use strict';
var TitleBar = {
get view() {
return document.getElementById('title');
},
get titleText() {
return document.querySelector('#title-text bdi');
},
get playerIcon() {
return document.getElementById('title-player');
},
get doneButton() {
return document.getElementById('title-done');
},
get scanProgress() {
return document.getElementById('scan-progress');
},
get scanSpinner() {
return document.getElementById('scan-spinner');
},
get scanCount() {
return document.getElementById('scan-count');
},
get scanArtist() {
return document.getElementById('scan-artist');
},
get scanTitle() {
return document.getElementById('scan-title');
},
init: function tb_init() {
this.view.addEventListener('click', this);
this.view.addEventListener('action', this.onActionBack);
},
changeTitleText: function tb_changeTitleText(content) {
this.titleText.textContent = content;
},
showBackArrow: function(show) {
if (show) { this.view.setAttribute('action', 'back'); }
else { this.view.removeAttribute('action'); }
},
onActionBack: function() {
if (App.pendingPick) {
if (ModeManager.currentMode === MODE_PICKER) {
App.pendingPick.postError('pick cancelled');
return;
}
PlayerView.stop();
}
ModeManager.pop();
},
showScanProgress: function(info) {
this.scanProgress.classList.remove('hidden');
this.scanSpinner.classList.remove('hidden');
this.scanCount.textContent = info.count;
this.scanArtist.textContent = info.artist || '';
this.scanTitle.textContent = info.title || '';
},
hideScanProgress: function() {
this.scanSpinner.classList.add('hidden');
// The setTimeout is a workaround for bug 1166500
setTimeout(function() {
this.scanProgress.classList.add('hidden');
}.bind(this), 100);
},
handleEvent: function tb_handleEvent(evt) {
var target = evt.target;
function cleanupPick() {
PlayerView.stop();
}
switch (evt.type) {
case 'click':
if (!target) {
return;
}
switch (target.id) {
case 'title-player':
// We can't to switch to player mode when there are no songs queued.
if (PlayerView.isQueued) {
ModeManager.push(MODE_PLAYER);
}
break;
case 'title-done':
var currentFileInfo = PlayerView.currentFileInfo;
LazyLoader.load('js/metadata/album_art_cache.js').then(() => {
return AlbumArtCache.getThumbnailBlob(currentFileInfo);
}).then((picture) => {
var currentMetadata = currentFileInfo.metadata;
var playingBlob = PlayerView.playingBlob;
App.pendingPick.postResult({
type: playingBlob.type,
blob: playingBlob,
name: currentMetadata.title || '',
// We only pass some metadata attributes so we don't share
// personal details like # of times played and ratings.
metadata: {
title: currentMetadata.title,
artist: currentMetadata.artist,
album: currentMetadata.album,
picture: picture
}
});
cleanupPick();
});
break;
}
break;
default:
return;
}
}
};