diff --git a/src/ext/lib/kbm/KbmBase.ts b/src/ext/lib/kbm/KbmBase.ts new file mode 100644 index 0000000..9aed36d --- /dev/null +++ b/src/ext/lib/kbm/KbmBase.ts @@ -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; diff --git a/src/ext/lib/kbm/KeyboardHandler.ts b/src/ext/lib/kbm/KeyboardHandler.ts index 49996bf..6c63a3d 100644 --- a/src/ext/lib/kbm/KeyboardHandler.ts +++ b/src/ext/lib/kbm/KeyboardHandler.ts @@ -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(); } diff --git a/src/ext/lib/kbm/PlayerMouseHandler.ts b/src/ext/lib/kbm/PlayerMouseHandler.ts index 545b1a4..e7c4bf6 100644 --- a/src/ext/lib/kbm/PlayerMouseHandler.ts +++ b/src/ext/lib/kbm/PlayerMouseHandler.ts @@ -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() {