Get event bus to work (for some values of work)

This commit is contained in:
Tamius Han 2021-10-26 23:13:11 +02:00
parent 209e4221d2
commit 13bd280062
8 changed files with 56 additions and 24 deletions

View File

@ -64,6 +64,7 @@
<template v-if="settingsInitialized"> <template v-if="settingsInitialized">
<VideoSettings <VideoSettings
:settings="settings" :settings="settings"
:eventBus="eventBus"
></VideoSettings> ></VideoSettings>
<!-- <ResizerDebugPanel :debugData="debugData"> <!-- <ResizerDebugPanel :debugData="debugData">
</ResizerDebugPanel> --> </ResizerDebugPanel> -->
@ -155,9 +156,6 @@ export default {
console.log("settings:", this.settings) console.log("settings:", this.settings)
console.log("windowPD", window.ultrawidify); console.log("windowPD", window.ultrawidify);
console.log("this:", this); console.log("this:", this);
console.log('eventBus:', this.eventBus);
} catch (e) { } catch (e) {
console.error('Failed to initiate ultrawidify player ui.', e); console.error('Failed to initiate ultrawidify player ui.', e);
} }

View File

@ -11,7 +11,7 @@
:key="index" :key="index"
:label="(action.scopes.page && action.scopes.page.label) ? action.scopes.page.label : action.label" :label="(action.scopes.page && action.scopes.page.label) ? action.scopes.page.label : action.label"
:shortcut="parseShortcut(action)" :shortcut="parseShortcut(action)"
@click.native="execAction(action)" @click="execAction(action)"
> >
</ShortcutButton> </ShortcutButton>
</div> </div>
@ -27,7 +27,7 @@
:key="index" :key="index"
:label="(action.scopes.page && action.scopes.page.label) ? action.scopes.page.label : action.label" :label="(action.scopes.page && action.scopes.page.label) ? action.scopes.page.label : action.label"
:shortcut="parseShortcut(action)" :shortcut="parseShortcut(action)"
@click.native="execAction(action)" @click="execAction(action)"
> >
</ShortcutButton> </ShortcutButton>
</div> </div>
@ -233,6 +233,7 @@ export default {
'frame', 'frame',
'zoom', 'zoom',
'cropModePersistence', 'cropModePersistence',
'eventBus'
], ],
created() { created() {
this.exec = new ExecAction(this.settings, window.location.hostname); this.exec = new ExecAction(this.settings, window.location.hostname);
@ -252,6 +253,17 @@ export default {
BrowserDetect.runtime.openOptionsPage(); BrowserDetect.runtime.openOptionsPage();
}, },
execAction(action) { execAction(action) {
// TODO: migrate all actions to the new way of doing things
if (action.cmd[0].action === 'set-ar') {
this.eventBus?.send('set-ar', {
type: action.cmd[0].arg,
ratio: action.cmd[0].customArg
});
return;
}
console.log('execing action:', action, window.ultrawidify); console.log('execing action:', action, window.ultrawidify);
try { try {

View File

@ -724,9 +724,9 @@ class ArDetector {
let newCanvasWidth = window.innerHeight * (this.video.videoWidth / this.video.videoHeight); let newCanvasWidth = window.innerHeight * (this.video.videoWidth / this.video.videoHeight);
let newCanvasHeight = window.innerHeight; let newCanvasHeight = window.innerHeight;
if (this.conf.resizer.videoAlignment === VideoAlignmentType.Center) { if (this.conf.resizer.videoAlignment.x === VideoAlignmentType.Center) {
this.canvasDrawWindowHOffset = Math.round((window.innerWidth - newCanvasWidth) * 0.5); this.canvasDrawWindowHOffset = Math.round((window.innerWidth - newCanvasWidth) * 0.5);
} else if (this.conf.resizer.videoAlignment === VideoAlignmentType.Left) { } else if (this.conf.resizer.videoAlignment.x === VideoAlignmentType.Left) {
this.canvasDrawWindowHOffset = 0; this.canvasDrawWindowHOffset = 0;
} else { } else {
this.canvasDrawWindowHOffset = window.innerWidth - newCanvasWidth; this.canvasDrawWindowHOffset = window.innerWidth - newCanvasWidth;

View File

@ -16,16 +16,19 @@ class PlayerNotificationUi extends UI {
constructor ( constructor (
playerElement, playerElement,
settings settings,
) { eventBus,
) {
super( super(
'notification', 'notification',
PlayerNotificationUi.getStoreConfig(), PlayerNotificationUi.getStoreConfig(),
PlayerNotificationUi.getUiConfig(playerElement), PlayerNotificationUi.getUiConfig(playerElement),
PlayerNotificationUi.getCommsConfig() PlayerNotificationUi.getCommsConfig(),
eventBus
); );
this.settings = settings; this.settings = settings;
this.eventBus = eventBus;
} }
@ -85,9 +88,9 @@ class PlayerNotificationUi extends UI {
/** /**
* Show notification on screen. * Show notification on screen.
* *
* @param notificationConfig notification config (or ID of notification config in /common/data/notifications.js) * @param notificationConfig notification config (or ID of notification config in /common/data/notifications.js)
* *
* notificationConfig should resemble this: * notificationConfig should resemble this:
* { * {
* timeout: number how long we'll be displaying the notification. If empty, 10s. -1: until user dismisses it * timeout: number how long we'll be displaying the notification. If empty, 10s. -1: until user dismisses it
@ -104,7 +107,7 @@ class PlayerNotificationUi extends UI {
* // more of notificationActions but with special case * // more of notificationActions but with special case
* ] * ]
* } * }
* *
* When notificationConfig is a string, the function will add two additional notifications on the notificationActionsPile * When notificationConfig is a string, the function will add two additional notifications on the notificationActionsPile
* * never show this notification ever again on any site * * never show this notification ever again on any site
* * never show this notification again on this site * * never show this notification again on this site
@ -170,7 +173,7 @@ class PlayerNotificationUi extends UI {
} }
isNotificationMuted(notificationId) { isNotificationMuted(notificationId) {
return this.settings.active.mutedNotifications?.[notificationId]?.$global return this.settings.active.mutedNotifications?.[notificationId]?.$global
|| this.settings.active.mutedNotifications?.[notificationId]?.[window.location.hostname]; || this.settings.active.mutedNotifications?.[notificationId]?.[window.location.hostname];
} }
} }

View File

@ -18,13 +18,15 @@ class PlayerUi extends UI {
*/ */
constructor ( constructor (
playerElement, playerElement,
settings settings,
) { eventBus,
) {
super( super(
'ultrawidifyUi', 'ultrawidifyUi',
PlayerUi.getStoreConfig(), PlayerUi.getStoreConfig(),
PlayerUi.getUiConfig(playerElement), PlayerUi.getUiConfig(playerElement),
PlayerUi.getCommsConfig() PlayerUi.getCommsConfig(),
eventBus
); );
this.settings = settings; this.settings = settings;

View File

@ -14,11 +14,13 @@ class UI {
storeConfig, storeConfig,
uiConfig, // {component, parentElement?} uiConfig, // {component, parentElement?}
commsConfig, commsConfig,
eventBus
) { ) {
this.interfaceId = interfaceId; this.interfaceId = interfaceId;
this.commsConfig = commsConfig; this.commsConfig = commsConfig;
this.storeConfig = storeConfig; this.storeConfig = storeConfig;
this.uiConfig = uiConfig; this.uiConfig = uiConfig;
this.eventBus = eventBus;
this.init(); this.init();
} }
@ -62,10 +64,25 @@ class UI {
this.element = rootDiv; this.element = rootDiv;
const app = createApp(this.uiConfig.component).use(mdiVue, {icons: mdijs}); const app = createApp(this.uiConfig.component)
.use(mdiVue, {icons: mdijs})
.use({ // hand eventBus to the component
install: (app, options) => {
app.mixin({
data() {
return {
eventBus: options.eventBus
}
}
})
}
}, {eventBus: this.eventBus});
if (this.vuexStore) { if (this.vuexStore) {
app.use(this.vuexStore); app.use(this.vuexStore);
} }
this.app = app;
app.mount(`#${uwid}`); app.mount(`#${uwid}`);
} }

View File

@ -94,7 +94,7 @@ class PlayerData {
this.invalid = false; this.invalid = false;
this.element = this.getPlayer(); this.element = this.getPlayer();
this.notificationService = new PlayerNotificationUi(this.element, this.settings); this.notificationService = new PlayerNotificationUi(this.element, this.settings, this.eventBus);
this.ui = new PlayerUi(this.element, this.settings, this.eventBus); this.ui = new PlayerUi(this.element, this.settings, this.eventBus);
this.ui.init(); this.ui.init();

View File

@ -56,7 +56,7 @@ class Resizer {
//#region event bus configuration //#region event bus configuration
private eventBusCommands = { private eventBusCommands = {
'set-ar': [{ 'set-ar': [{
function: (config: any) => this.setAr(config.type, config.ratio) function: (config: any) => this.setAr(config)
}], }],
'set-alignment': [{ 'set-alignment': [{
function: (config: any) => { function: (config: any) => {
@ -81,6 +81,8 @@ class Resizer {
this.logger = videoData.logger; this.logger = videoData.logger;
this.video = videoData.video; this.video = videoData.video;
this.settings = videoData.settings; this.settings = videoData.settings;
this.eventBus = videoData.eventBus;
this.initEventBus();
this.scaler = new Scaler(this.conf); this.scaler = new Scaler(this.conf);
this.stretcher = new Stretcher(this.conf); this.stretcher = new Stretcher(this.conf);
@ -98,8 +100,7 @@ class Resizer {
this.userCssClassName = videoData.userCssClassName; this.userCssClassName = videoData.userCssClassName;
this.eventBus = videoData.eventBus;
this.initEventBus();
} }
initEventBus() { initEventBus() {
@ -179,7 +180,6 @@ class Resizer {
return ar; return ar;
} }
updateAr(ar) { updateAr(ar) {
if (!ar) { if (!ar) {
return; return;
@ -387,7 +387,7 @@ class Resizer {
resetPan() { resetPan() {
this.pan = {x: 0, y: 0}; this.pan = {x: 0, y: 0};
this.videoAlignment.x = this.settings.getDefaultVideoAlignment(window.location.hostname); this.videoAlignment = {x: this.settings.getDefaultVideoAlignment(window.location.hostname), y: VideoAlignmentType.Center};
} }
setPan(relativeMousePosX, relativeMousePosY){ setPan(relativeMousePosX, relativeMousePosY){