From 7e41768aba36af9217a0b5a637b0399c34f11ac8 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sat, 20 Feb 2021 00:09:17 +0100 Subject: [PATCH] Migrate actionhandler to ts --- .../{ActionHandler.js => ActionHandler.ts} | 35 ++++++++++++++----- src/ext/lib/video-data/PageInfo.ts | 10 +++--- src/ext/lib/video-data/VideoData.ts | 2 +- 3 files changed, 32 insertions(+), 15 deletions(-) rename src/ext/lib/{ActionHandler.js => ActionHandler.ts} (92%) diff --git a/src/ext/lib/ActionHandler.js b/src/ext/lib/ActionHandler.ts similarity index 92% rename from src/ext/lib/ActionHandler.js rename to src/ext/lib/ActionHandler.ts index dd34644..24a94af 100644 --- a/src/ext/lib/ActionHandler.js +++ b/src/ext/lib/ActionHandler.ts @@ -1,20 +1,37 @@ import Debug from '../conf/Debug'; import PlayerData from './video-data/PlayerData'; import ExtensionMode from '../../common/enums/ExtensionMode.enum'; +import Logger from './Logger'; +import PageInfo from './video-data/PageInfo'; +import Settings from './Settings'; +import VideoData from './video-data/VideoData'; if(process.env.CHANNEL !== 'stable'){ console.info("Loading ActionHandler"); } class ActionHandler { + logger: Logger; + pageInfo: PageInfo; + settings: Settings; + + + inputs: string[] = ['input', 'select', 'button', 'textarea']; + keyboardLocalDisabled: boolean = true; + + keyUpActions: any[] = []; + keyDownActions: any[] = []; + mouseMoveActions: any[] = []; + mouseScrollUpActions: any[] = []; + mouseScrollDownActions: any[] = []; + mouseEnterActions: any[] = []; + mouseLeaveActions: any[] = []; + constructor(pageInfo) { this.logger = pageInfo.logger; this.pageInfo = pageInfo; this.settings = pageInfo.settings; - - this.inputs = ['input', 'select', 'button', 'textarea']; - this.keyboardLocalDisabled = false; } init() { @@ -240,7 +257,7 @@ class ActionHandler { this.isActionMatchStandard(shortcut, event) || this.isActionMatchKeyCode(shortcut, event); } - execAction(actions, event, videoData) { + execAction(actions, event, videoData?: VideoData) { this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] Trying to find and execute action for event. Actions/event: ", "color: #ff0", actions, event); const isLatin = event.key ? this.isLatin(event.key) : true; @@ -275,10 +292,10 @@ class ActionHandler { this.settings.active.sites[site].stretch = cmd.arg; } else if (cmd.action === "set-alignment") { this.settings.active.sites[site].videoAlignment = cmd.arg; - } else if (cmd.action === "set-ExtensionMode") { - this.settings.active.sites[site].status = cmd.arg; + } else if (cmd.action === "set-extension-mode") { + this.settings.active.sites[site].mode = cmd.arg; } else if (cmd.action === "set-autoar-mode") { - this.settings.active.sites[site].arStatus = cmd.arg; + this.settings.active.sites[site].autoar = cmd.arg; } else if (cmd.action === 'set-keyboard') { this.settings.active.sites[site].keyboardShortcutsEnabled = cmd.arg; } else if (cmd.action === 'set-ar-persistence') { @@ -323,9 +340,9 @@ class ActionHandler { this.execAction(this.keyDownActions, event); } - handleMouseMove(event, videoData) { + handleMouseMove(event, videoData?: VideoData) { this.logger.log('info', 'keyboard', "[ActionHandler::handleMouseMove] mouse move is being handled.\nevent:", event, "\nvideo data:", videoData); - videoData.panHandler(event); + videoData?.panHandler(event); this.execAction(this.mouseMoveActions, event, videoData) } diff --git a/src/ext/lib/video-data/PageInfo.ts b/src/ext/lib/video-data/PageInfo.ts index 03a31af..c8c3940 100644 --- a/src/ext/lib/video-data/PageInfo.ts +++ b/src/ext/lib/video-data/PageInfo.ts @@ -439,7 +439,7 @@ class PageInfo { } } - setAr(ar, playingOnly){ + setAr(ar, playingOnly?: boolean){ this.logger.log('info', 'debug', '[PageInfo::setAr] aspect ratio:', ar, "playing only?", playingOnly) if (ar.type !== AspectRatioType.Automatic) { @@ -491,7 +491,7 @@ class PageInfo { } } - setPanMode(mode, playingOnly) { + setPanMode(mode, playingOnly?: boolean) { if (playingOnly) { for(let vd of this.videos) { if (vd.isPlaying()) { @@ -519,7 +519,7 @@ class PageInfo { } } - setStretchMode(stretchMode, playingOnly, fixedStretchRatio){ + setStretchMode(stretchMode, playingOnly?: boolean, fixedStretchRatio?: boolean){ // TODO: find a way to only change aspect ratio for one video if (playingOnly) { @@ -535,7 +535,7 @@ class PageInfo { } } - setZoom(zoomLevel, no_announce, playingOnly) { + setZoom(zoomLevel, no_announce?: boolean, playingOnly?: boolean) { if (playingOnly) { for(let vd of this.videos) { if (vd.isPlaying()) { @@ -549,7 +549,7 @@ class PageInfo { } } - zoomStep(step, playingOnly) { + zoomStep(step, playingOnly?: boolean) { for(let vd of this.videos){ if (!playingOnly || vd.isPlaying()) { vd.zoomStep(step); diff --git a/src/ext/lib/video-data/VideoData.ts b/src/ext/lib/video-data/VideoData.ts index 40ea0f4..d4fa060 100644 --- a/src/ext/lib/video-data/VideoData.ts +++ b/src/ext/lib/video-data/VideoData.ts @@ -606,7 +606,7 @@ class VideoData { this.resizer.setLastAr('original'); } - panHandler(event, forcePan) { + panHandler(event, forcePan?: boolean) { if (this.invalid) { return; }