kbm refactoring stuffs

This commit is contained in:
Tamius Han 2022-11-20 14:46:01 +01:00
parent c954f8b984
commit de9696471a
3 changed files with 44 additions and 8 deletions

View File

@ -0,0 +1,35 @@
import EventBus, { EventBusCommand } from '../EventBus';
import Logger from '../Logger';
import Settings from '../Settings';
export class KbmBase {
logger: Logger;
settings: Settings;
eventBus: EventBus;
// eventBusCommands: { [x: string]: EventBusCommand } = {
// 'kbm-enable': {
// function: () => this.enable()
// },
// 'kbm-disable': {
// function: () => this.disable()
// },
// 'kbm-set-config': {
// function: (data: {config: any, temporary?: boolean}) => this.setConfig(data.config, data.temporary),
// },
// 'uw-enable': {
// function: () => this.load()
// },
// 'uw-disable': {
// function: () => this.disable()
// },
// }
constructor(eventBus: EventBus, settings: Settings, logger: Logger) {
this.logger = logger;
this.settings = settings;
this.eventBus = eventBus;
}
}
export default KbmBase;

View File

@ -6,6 +6,7 @@ import PageInfo from '../video-data/PageInfo';
import Settings from '../Settings';
import VideoData from '../video-data/VideoData';
import EventBus, { EventBusCommand } from '../EventBus';
import KbmBase from './KbmBase';
if(process.env.CHANNEL !== 'stable'){
console.info("Loading KeyboardHandler");
@ -19,7 +20,7 @@ if(process.env.CHANNEL !== 'stable'){
* kbm-disable disables keyboard shortcuts and mouse panning
* kbm-set-config sets configuration for this module.
*/
export class KeyboardHandler {
export class KeyboardHandler extends KbmBase {
logger: Logger;
settings: Settings;
eventBus: EventBus;
@ -56,9 +57,7 @@ export class KeyboardHandler {
//#region lifecycle
constructor(eventBus: EventBus, settings: Settings, logger: Logger) {
this.logger = logger;
this.settings = settings;
this.eventBus = eventBus;
super(eventBus, settings, logger);
this.init();
}

View File

@ -1,6 +1,7 @@
import EventBus, { EventBusCommand } from '../EventBus';
import Logger from '../Logger';
import Settings from '../Settings';
import KbmBase from './KbmBase';
if(process.env.CHANNEL !== 'stable'){
console.info("Loading PlayerMouseHandler");
@ -10,10 +11,8 @@ if(process.env.CHANNEL !== 'stable'){
/**
* Handles keypress
*/
export class MouseHandler {
logger: Logger;
settings: Settings;
eventBus: EventBus;
export class MouseHandler extends KbmBase {
playerElement: HTMLElement;
eventBusCommands: { [x: string]: EventBusCommand } = {
@ -36,12 +35,15 @@ export class MouseHandler {
//#region lifecycle
constructor(playerElement: HTMLElement, eventBus: EventBus, settings: Settings, logger: Logger) {
super(eventBus, settings, logger);
this.logger = logger;
this.settings = settings;
this.eventBus = eventBus;
this.playerElement = playerElement;
this.init();
}
init() {