/* '(C) Ventis Media, Licensed under the Ventis Limited Reciprocal License - see: license.txt for details' */ "use strict"; var _widthEm = 30; // in em var _heightEm = 9.5; // in em var _width; // in px var _height; // in px var _opacity; var initOpacity = 100; var opacityStepSize = 1; var opacityStepDuration = 20; var _timeout; var _settingsChangeRegistered = false; var _params; var _hideTimeout; var lastCoverPath; function init(params) { resizeable = false; _params = params || {}; _width = emToPx(_widthEm); _height = emToPx(_heightEm); if (_params.width) _width = resolveToValue(_params.width, _width); if (_params.height) _height = resolveToValue(_params.height, _height); loadFromSettings(); } function loadFromSettings() { var sett = window.settings.get('Options'); var screen = app.utils.getMainMonitorInfo(); var _left = Math.floor((screen.availLeft + Math.floor((sett.InfoPopUp.Horizontal / 100) * (screen.availWidth - _width)))); var _top = Math.floor((screen.availTop + Math.floor((sett.InfoPopUp.Vertical / 100) * (screen.availHeight - _height)))); if (!_width || !_height || isNaN(_left) || isNaN(_top)) { return; } //For users that are concerned with processing/battery power (On my computer, a stepSize of 1 did NOT have significant CPU usage, however) if (sett.InfoPopUp.LessSmooth == true) opacityStepSize = 4; if (sett.InfoPopUp.FadeTime) { //For fade time under 10ms, make it disappear immediately if (sett.InfoPopUp.FadeTime < 10) opacityStepSize = 100; //For fade time under 1 second, increase opacity step size to save processing power else if (sett.InfoPopUp.FadeTime < 1000) { opacityStepSize = (sett.InfoPopUp.LessSmooth == true) ? 10 : 4; } //Calculate stepDuration based on fadeTime and the previously set opacityStepSize opacityStepDuration = Math.floor( sett.InfoPopUp.FadeTime * opacityStepSize * 0.01 ); } //console.log(`_left=${_left} _top=${_top} _width=${_width} _height=${_height}`); _timeout = sett.InfoPopUp.ShowTime; initOpacity = sett.InfoPopUp.Opacity; setBounds(_left, _top, _width, _height); if (!_params.ignoreSettings) { _opacity = sett.InfoPopUp.Opacity; window.opacity = _opacity; } } function showTrackInfo(params) { params = params || _params || {}; if (_hideTimeout) { clearTimeout(_hideTimeout); _hideTimeout = undefined; } _opacity = initOpacity; window.opacity = initOpacity; var thumbSize = 10 * Math.round(emToPx(12) / 10); var unknownAAWidth = 10 * Math.round(emToPx(7) / 10); if (!_settingsChangeRegistered && !params.ignoreSettings) { _settingsChangeRegistered = true; window.localListen(window.settings.observer, 'change', loadFromSettings); } var sd = params.sd || app.player.getFastCurrentTrack(sd); if (!sd) { ODS('*** dlgTrackInfo init - no SD'); //closeWindow(); return false; } var titleEl = qid('title'); var artistEl = qid('artist'); var albumEl = qid('album'); var artworkEl = qid('artwork'); var unknownAAEl = qid('unknownAA'); var ready = false; var applyCover = function (path) { lastCoverPath = path; if (path && (path !== '-')) { artworkEl.src = path; setVisibility(artworkEl, true); setVisibility(unknownAAEl, false); ready = true; } else { setVisibility(artworkEl, false); setVisibility(unknownAAEl, true); } }; titleEl.innerText = sd.title; artistEl.innerText = sd.artist; albumEl.innerText = sd.album; unknownAAEl.style.width = unknownAAWidth + 'px'; //unknownAAEl.style.height = thumbSize + 'px'; //artworkEl.style.width = thumbSize + 'px'; //artworkEl.style.height = thumbSize + 'px'; if (sd.getCachedThumb) { var path = sd.getCachedThumb(thumbSize, thumbSize); if (lastCoverPath !== path) { applyCover(path); } else ready = true; } if (!ready && sd.getThumbAsync) { sd.getThumbAsync(thumbSize, thumbSize, function (path) { if (window._cleanUpCalled) return; if (path && (path !== '-')) applyCover(path); else { // try to found picture for album if (sd.idalbum > 0) { app.getObject('album', { id: sd.idalbum, name: sd.album, artist: sd.albumArtist || sd.artist, canCreateNew: false }).then(function (album) { if (album) album.getThumbAsync(thumbSize, thumbSize, function (path) { applyCover(path); }); }); }; } }); } if (!ready) { setVisibility(artworkEl, false); setVisibility(unknownAAEl, true); } var _hidingcalled = false; var _mouseIn = false; //callSlowHide is now only called once var callSlowHide = function (time) { //clear any already-existing timeouts to slowHide clearTimeout(_hideTimeout); _hidingcalled = true; _hideTimeout = requestTimeout(doSlowHide, time); } var doSlowHide = function () { _hideTimeout = undefined; if (_mouseIn) { return; } _opacity -= opacityStepSize; if (_opacity <= 0) { //_hidingcalled is set to false here instead of at the top _hidingcalled = false; hide(); } else { window.opacity = _opacity; _hideTimeout = requestTimeout(doSlowHide, opacityStepDuration); } } var handleMouseOver = function (evt) { var b = window.bounds.windowRect; if ((evt.screenX > b.left) && (evt.screenX < b.right) && (evt.screenY > b.top) && (evt.screenY < b.bottom)) { var sett = window.settings.get('Options'); _mouseIn = true; _opacity = sett.InfoPopUp.Opacity; window.opacity = _opacity; } else { _mouseIn = false; } }.bind(this); var handleMouseOut = function (evt) { var b = window.bounds.windowRect; if ((evt.screenX > b.left) && (evt.screenX < b.right) && (evt.screenY > b.top) && (evt.screenY < b.bottom)) { _mouseIn = true; } else { _mouseIn = false; if (!_hidingcalled) callSlowHide(_timeout); } }.bind(this); var handleMouseClick = function () { //set opacity to 0 to end the doSlowHide loop _opacity = 0; hide(); }.bind(this); if (!params.disableAutoHide) { window.localListen(document.body, 'mouseover', handleMouseOver); window.localListen(document.body, 'mouseout', handleMouseOut); window.localListen(document.body, 'click', handleMouseClick); //Added check for hidingcalled if (!_hidingcalled) callSlowHide(_timeout); } if (!visible) { show(); } }; function setPos(x, y) { //ODS('--- set pos ' + x + ', ' + y); var screen = app.utils.getMainMonitorInfo(); window.bounds.left = screen.availLeft + Math.floor((x / 100) * (screen.availWidth - _width)); window.bounds.top = screen.availTop + Math.floor((y / 100) * (screen.availHeight - _height)); }