ultrawidify/src/ext/lib/uwui/PlayerUI.js

120 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-12-15 00:26:19 +01:00
import UI from './UI';
import VuexWebExtensions from 'vuex-webextensions';
import PlayerUiComponent from '../../../csui/PlayerUiComponent.vue';
if (process.env.CHANNEL !== 'stable'){
console.info("Loading: PlayerUi");
}
/**
* Class that handles in-player UI
*/
class PlayerUi extends UI {
/**
* Creates new in-player UI for ultrawidify
* @param {*} playerElement PlayerUI will be created as a child of this element
* @param {*} settings Extension settings (instanceof Settings)
*/
constructor (
playerElement,
settings
) {
super(
'ultrawidifyUi',
PlayerUi.getStoreConfig(),
PlayerUi.getUiConfig(playerElement),
PlayerUi.getCommsConfig()
);
this.settings = settings;
}
//#region constructor helpers
// we will move some things out of the constructor in order to keep things clean
static getStoreConfig() {
// NOTE: these are sample values and can be deleted. Currently, they're commented out
// so we won't have to look up the documentation in order to get them working
return {
plugins: [
VuexWebExtensions({
persistentStates: [
'showUi',
'resizerDebugData',
'playerDebugData',
2020-12-15 00:26:19 +01:00
],
}),
],
state: {
showUi: true,
},
mutations: {
'uw-toggle-ui'(state) {
state['showUi'] = !state['showUi'];
},
'uw-set-ui-visible'(state, payload) {
state['showUi'] = payload;
},
'uw-set-player-debug-data'(state, payload) {
state['playerDebugData'] = payload;
},
'uw-set-resizer-debug-data'(state, payload) {
state['resizerDebugData'] = payload;
},
2020-12-15 00:26:19 +01:00
},
actions: {
'uw-set-ui-visible'({commit}, payload) {
console.log('action!', commit, payload);
commit('uw-set-ui-visible', payload);
},
'uw-toggle-ui'({commit}) {
commit('uw-toggle-ui');
},
'uw-set-player-debug-data'({commit}, payload) {
commit('uw-set-player-debug-data ', payload);
},
'uw-set-resizer-debug-data'({commit}, payload) {
commit('uw-set-resizer-debug-data ', payload);
},
2020-12-15 00:26:19 +01:00
}
};
}
static getUiConfig(playerElement) {
return {
parentElement: playerElement,
component: PlayerUiComponent
}
}
static getCommsConfig() {
// NOTE: these are sample values and can be deleted. Currently, they're commented out
// so we won't have to look up the documentation in order to get them working
return {
handlers: {
// 'show-notification': [(message) => this.showNotification(message)],
}
}
}
//#endregion
//#region lifecycle
replace(playerElement) {
super.replace(this.getUiConfig(playerElement));
}
//#endregion
//#region debug methods
updateDebugInfo(component, data) {
this.vuexStore?.dispatch(`uw-set-${component}-debug-data`, data);
}
//#endregion
2020-12-15 00:26:19 +01:00
}
if (process.env.CHANNEL !== 'stable'){
console.info("PlayerUi loaded");
}
export default PlayerUi;