2020-08-16 20:24:45 +02:00
|
|
|
|
|
|
|
import { appHost } from './apphost';
|
2020-08-14 06:36:46 +02:00
|
|
|
import browser from '../scripts/browser';
|
2020-10-18 18:58:09 +01:00
|
|
|
import appSettings from '../scripts/settings/appSettings';
|
2020-09-08 02:05:02 -04:00
|
|
|
import { Events } from 'jellyfin-apiclient';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-04 13:47:40 +01:00
|
|
|
function setLayout(instance, layout, selectedLayout) {
|
|
|
|
if (layout === selectedLayout) {
|
|
|
|
instance[layout] = true;
|
|
|
|
document.documentElement.classList.add('layout-' + layout);
|
|
|
|
} else {
|
|
|
|
instance[layout] = false;
|
|
|
|
document.documentElement.classList.remove('layout-' + layout);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-08-04 13:47:40 +01:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-04 13:47:40 +01:00
|
|
|
class LayoutManager {
|
2021-06-11 14:49:57 +02:00
|
|
|
tv = false;
|
|
|
|
mobile = false;
|
|
|
|
desktop = false;
|
|
|
|
|
2020-08-04 13:47:40 +01:00
|
|
|
setLayout(layout, save) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!layout || layout === 'auto') {
|
|
|
|
this.autoLayout();
|
|
|
|
|
|
|
|
if (save !== false) {
|
2020-10-18 18:58:09 +01:00
|
|
|
appSettings.set('layout', '');
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setLayout(this, 'mobile', layout);
|
|
|
|
setLayout(this, 'tv', layout);
|
|
|
|
setLayout(this, 'desktop', layout);
|
|
|
|
|
|
|
|
if (save !== false) {
|
2020-10-18 18:58:09 +01:00
|
|
|
appSettings.set('layout', layout);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 02:05:02 -04:00
|
|
|
Events.trigger(this, 'modechange');
|
2020-08-04 13:47:40 +01:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
getSavedLayout() {
|
2020-10-18 18:58:09 +01:00
|
|
|
return appSettings.get('layout');
|
2020-08-04 13:47:40 +01:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-04 13:47:40 +01:00
|
|
|
autoLayout() {
|
2019-01-10 15:39:37 +03:00
|
|
|
// Take a guess at initial layout. The consuming app can override
|
|
|
|
if (browser.mobile) {
|
|
|
|
this.setLayout('mobile', false);
|
2020-04-24 21:44:18 +02:00
|
|
|
} else if (browser.tv || browser.xboxOne || browser.ps4) {
|
2019-01-10 15:39:37 +03:00
|
|
|
this.setLayout('tv', false);
|
|
|
|
} else {
|
|
|
|
this.setLayout(this.defaultLayout || 'tv', false);
|
|
|
|
}
|
2020-08-04 13:47:40 +01:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-04 13:47:40 +01:00
|
|
|
init() {
|
|
|
|
const saved = this.getSavedLayout();
|
2019-01-10 15:39:37 +03:00
|
|
|
if (saved) {
|
|
|
|
this.setLayout(saved, false);
|
|
|
|
} else {
|
|
|
|
this.autoLayout();
|
|
|
|
}
|
2020-08-04 13:47:40 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
const layoutManager = new LayoutManager();
|
|
|
|
|
|
|
|
if (appHost.getDefaultLayout) {
|
|
|
|
layoutManager.defaultLayout = appHost.getDefaultLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
layoutManager.init();
|
|
|
|
|
|
|
|
export default layoutManager;
|