2020-05-19 14:35:51 -07:00
|
|
|
define(['apphost', 'userSettings', 'browser', 'events', 'backdrop', 'globalize', 'require', 'appSettings'], function (appHost, userSettings, browser, events, backdrop, globalize, require, appSettings) {
|
2019-01-10 05:39:37 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var themeStyleElement;
|
|
|
|
var currentThemeId;
|
2019-02-24 16:44:41 -07:00
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
function unloadTheme() {
|
|
|
|
var elem = themeStyleElement;
|
2019-01-10 05:39:37 -07:00
|
|
|
if (elem) {
|
|
|
|
elem.parentNode.removeChild(elem);
|
|
|
|
themeStyleElement = null;
|
|
|
|
currentThemeId = null;
|
|
|
|
}
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
2019-02-24 16:44:41 -07:00
|
|
|
function loadUserSkin(options) {
|
|
|
|
options = options || {};
|
|
|
|
if (options.start) {
|
2019-03-16 08:48:53 -07:00
|
|
|
Emby.Page.invokeShortcut(options.start);
|
2019-02-24 16:44:41 -07:00
|
|
|
} else {
|
2019-03-16 08:48:53 -07:00
|
|
|
Emby.Page.goHome();
|
2019-01-10 05:39:37 -07:00
|
|
|
}
|
2019-11-22 08:29:38 -07:00
|
|
|
}
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2019-02-24 16:44:41 -07:00
|
|
|
function getThemes() {
|
|
|
|
return [{
|
2020-05-04 03:44:12 -07:00
|
|
|
name: 'Apple TV',
|
|
|
|
id: 'appletv'
|
2019-02-24 16:44:41 -07:00
|
|
|
}, {
|
2020-05-04 03:44:12 -07:00
|
|
|
name: 'Blue Radiance',
|
|
|
|
id: 'blueradiance'
|
2019-02-24 16:44:41 -07:00
|
|
|
}, {
|
2020-05-04 03:44:12 -07:00
|
|
|
name: 'Dark',
|
|
|
|
id: 'dark',
|
2019-02-24 16:44:41 -07:00
|
|
|
isDefault: true,
|
|
|
|
isDefaultServerDashboard: true
|
2019-03-29 15:24:06 -07:00
|
|
|
}, {
|
2020-05-04 03:44:12 -07:00
|
|
|
name: 'Light',
|
|
|
|
id: 'light'
|
2019-04-17 15:18:18 -07:00
|
|
|
}, {
|
2020-05-04 03:44:12 -07:00
|
|
|
name: 'Purple Haze',
|
|
|
|
id: 'purplehaze'
|
2019-02-24 16:44:41 -07:00
|
|
|
}, {
|
2020-05-04 03:44:12 -07:00
|
|
|
name: 'Windows Media Center',
|
|
|
|
id: 'wmc'
|
2019-02-24 16:44:41 -07:00
|
|
|
}];
|
2019-11-22 08:29:38 -07:00
|
|
|
}
|
2018-10-22 15:05:09 -07:00
|
|
|
|
2019-01-10 05:39:37 -07:00
|
|
|
var skinManager = {
|
2019-02-24 16:44:41 -07:00
|
|
|
getThemes: getThemes,
|
|
|
|
loadUserSkin: loadUserSkin
|
2019-01-10 05:39:37 -07:00
|
|
|
};
|
|
|
|
|
2019-03-29 15:50:16 -07:00
|
|
|
function getThemeStylesheetInfo(id, isDefaultProperty) {
|
2019-01-10 05:39:37 -07:00
|
|
|
var themes = skinManager.getThemes();
|
|
|
|
var defaultTheme;
|
|
|
|
var selectedTheme;
|
|
|
|
|
|
|
|
for (var i = 0, length = themes.length; i < length; i++) {
|
2018-10-22 15:05:09 -07:00
|
|
|
var theme = themes[i];
|
2019-01-10 05:39:37 -07:00
|
|
|
if (theme[isDefaultProperty]) {
|
|
|
|
defaultTheme = theme;
|
|
|
|
}
|
|
|
|
if (id === theme.id) {
|
|
|
|
selectedTheme = theme;
|
|
|
|
}
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-01-10 05:39:37 -07:00
|
|
|
|
|
|
|
selectedTheme = selectedTheme || defaultTheme;
|
2018-10-22 15:05:09 -07:00
|
|
|
return {
|
2019-12-11 07:43:48 -07:00
|
|
|
stylesheetPath: require.toUrl('themes/' + selectedTheme.id + '/theme.css'),
|
2018-10-22 15:05:09 -07:00
|
|
|
themeId: selectedTheme.id
|
2019-01-10 05:39:37 -07:00
|
|
|
};
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
2019-01-10 05:39:37 -07:00
|
|
|
var themeResources = {};
|
|
|
|
var lastSound = 0;
|
|
|
|
var currentSound;
|
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
function loadThemeResources(id) {
|
2019-01-10 05:39:37 -07:00
|
|
|
lastSound = 0;
|
|
|
|
if (currentSound) {
|
|
|
|
currentSound.stop();
|
|
|
|
currentSound = null;
|
|
|
|
}
|
|
|
|
|
2020-06-16 13:45:03 -07:00
|
|
|
backdrop.clearBackdrop();
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onThemeLoaded() {
|
2019-01-10 05:39:37 -07:00
|
|
|
document.documentElement.classList.remove('preload');
|
2018-10-22 15:05:09 -07:00
|
|
|
try {
|
2020-05-04 03:44:12 -07:00
|
|
|
var color = getComputedStyle(document.querySelector('.skinHeader')).getPropertyValue('background-color');
|
2019-01-10 05:39:37 -07:00
|
|
|
if (color) {
|
|
|
|
appHost.setThemeColor(color);
|
|
|
|
}
|
2019-03-19 17:03:11 -07:00
|
|
|
} catch (err) {
|
2020-02-15 19:44:43 -07:00
|
|
|
console.error('error setting theme color: ' + err);
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 05:39:37 -07:00
|
|
|
skinManager.setTheme = function (id, context) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
if (currentThemeId && currentThemeId === id) {
|
|
|
|
resolve();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var isDefaultProperty = context === 'serverdashboard' ? 'isDefaultServerDashboard' : 'isDefault';
|
2019-03-29 15:50:16 -07:00
|
|
|
var info = getThemeStylesheetInfo(id, isDefaultProperty);
|
2019-01-10 05:39:37 -07:00
|
|
|
if (currentThemeId && currentThemeId === info.themeId) {
|
|
|
|
resolve();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var linkUrl = info.stylesheetPath;
|
|
|
|
unloadTheme();
|
|
|
|
|
2020-02-16 06:11:36 -07:00
|
|
|
var link = document.createElement('link');
|
2019-01-10 05:39:37 -07:00
|
|
|
link.setAttribute('rel', 'stylesheet');
|
|
|
|
link.setAttribute('type', 'text/css');
|
|
|
|
link.onload = function () {
|
|
|
|
onThemeLoaded();
|
|
|
|
resolve();
|
|
|
|
};
|
|
|
|
|
|
|
|
link.setAttribute('href', linkUrl);
|
|
|
|
document.head.appendChild(link);
|
|
|
|
themeStyleElement = link;
|
|
|
|
currentThemeId = info.themeId;
|
|
|
|
loadThemeResources(info.themeId);
|
|
|
|
|
|
|
|
onViewBeforeShow({});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
function onViewBeforeShow(e) {
|
2019-01-10 05:39:37 -07:00
|
|
|
if (e.detail && e.detail.type === 'video-osd') {
|
2020-05-14 05:18:50 -07:00
|
|
|
// This removes the space that the scrollbar takes while playing a video
|
2020-05-16 15:11:37 -07:00
|
|
|
document.body.classList.remove('force-scroll');
|
2019-01-10 05:39:37 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (themeResources.backdrop) {
|
|
|
|
backdrop.setBackdrop(themeResources.backdrop);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!browser.mobile && userSettings.enableThemeSongs()) {
|
|
|
|
if (lastSound === 0) {
|
|
|
|
if (themeResources.themeSong) {
|
|
|
|
playSound(themeResources.themeSong);
|
|
|
|
}
|
|
|
|
} else if ((new Date().getTime() - lastSound) > 30000) {
|
|
|
|
if (themeResources.effect) {
|
|
|
|
playSound(themeResources.effect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 05:18:50 -07:00
|
|
|
// This keeps the scrollbar always present in all pages, so we avoid clipping while switching between pages
|
|
|
|
// that need the scrollbar and pages that don't.
|
2020-05-16 15:11:37 -07:00
|
|
|
document.body.classList.add('force-scroll');
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
2019-01-10 05:39:37 -07:00
|
|
|
document.addEventListener('viewshow', onViewBeforeShow);
|
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
function playSound(path, volume) {
|
2019-01-10 05:39:37 -07:00
|
|
|
lastSound = new Date().getTime();
|
|
|
|
require(['howler'], function (howler) {
|
2020-02-25 16:33:38 -07:00
|
|
|
/* globals Howl */
|
2018-10-22 15:05:09 -07:00
|
|
|
try {
|
|
|
|
var sound = new Howl({
|
|
|
|
src: [path],
|
2019-01-10 05:39:37 -07:00
|
|
|
volume: volume || 0.1
|
2018-10-22 15:05:09 -07:00
|
|
|
});
|
2019-01-10 05:39:37 -07:00
|
|
|
sound.play();
|
|
|
|
currentSound = sound;
|
2019-03-29 15:50:16 -07:00
|
|
|
} catch (err) {
|
2020-02-15 19:44:43 -07:00
|
|
|
console.error('error playing sound: ' + err);
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return skinManager;
|
2019-02-02 07:35:56 -07:00
|
|
|
});
|