Stop using some of the old code
This commit is contained in:
parent
27b0609d34
commit
045cd5a528
@ -18,31 +18,33 @@ export default class UWContent {
|
||||
commsHandlers: {
|
||||
[x: string]: ((a: any, b?: any) => void | Promise<void>)[]
|
||||
} = {
|
||||
'get-current-zoom': [() => this.pageInfo.requestCurrentZoom()],
|
||||
'set-ar': [(message) => this.pageInfo.setAr({type: message.arg, ratio: message.customArg}, message.playing)],
|
||||
'set-alignment': [(message) => {
|
||||
this.pageInfo.setVideoAlignment(message.arg, message.playing);
|
||||
this.pageInfo.restoreAr();
|
||||
}],
|
||||
'set-stretch': [(message) => this.pageInfo.setStretchMode(message.arg, message.playing, message.customArg)],
|
||||
'set-keyboard': [(message) => this.pageInfo.setKeyboardShortcutsEnabled(message.arg)],
|
||||
'autoar-start': [(message) => {
|
||||
if (message.enabled !== false) {
|
||||
this.pageInfo.initArDetection(message.playing);
|
||||
this.pageInfo.startArDetection(message.playing);
|
||||
} else {
|
||||
this.pageInfo.stopArDetection(message.playing);
|
||||
}
|
||||
}],
|
||||
'pause-processing': [(message) => this.pageInfo.pauseProcessing(message.playing)],
|
||||
'resume-processing': [(message) => this.pageInfo.resumeProcessing(message.autoArStatus, message.playing)],
|
||||
'set-zoom': [(message) => this.pageInfo.setZoom(message.arg, true, message.playing)],
|
||||
'change-zoom': [(message) => this.pageInfo.zoomStep(message.arg, message.playing)],
|
||||
'mark-player': [(message) => this.pageInfo.markPlayer(message.name, message.color)],
|
||||
'unmark-player': [() => this.pageInfo.unmarkPlayer()],
|
||||
// THIS SHOULD BE MIGRATED TO EVENT BUS
|
||||
// 'get-current-zoom': [() => this.pageInfo.requestCurrentZoom()],
|
||||
// 'set-ar': [(message) => this.pageInfo.setAr({type: message.arg, ratio: message.customArg}, message.playing)],
|
||||
// 'set-alignment': [(message) => {
|
||||
// this.pageInfo.setVideoAlignment(message.arg, message.playing);
|
||||
// this.pageInfo.restoreAr();
|
||||
// }],
|
||||
// 'set-stretch': [(message) => this.pageInfo.setStretchMode(message.arg, message.playing, message.customArg)],
|
||||
// 'set-keyboard': [(message) => this.pageInfo.setKeyboardShortcutsEnabled(message.arg)],
|
||||
// DEPRECATED — should be set with resizer.setAr()
|
||||
// 'autoar-start': [(message) => {
|
||||
// if (message.enabled !== false) {
|
||||
// this.pageInfo.initArDetection(message.playing);
|
||||
// this.pageInfo.startArDetection(message.playing);
|
||||
// } else {
|
||||
// this.pageInfo.stopArDetection(message.playing);
|
||||
// }
|
||||
// }],
|
||||
// 'pause-processing': [(message) => this.pageInfo.pauseProcessing(message.playing)],
|
||||
// 'resume-processing': [(message) => this.pageInfo.resumeProcessing(message.autoArStatus, message.playing)],
|
||||
// 'set-zoom': [(message) => this.pageInfo.setZoom(message.arg, true, message.playing)],
|
||||
// 'change-zoom': [(message) => this.pageInfo.zoomStep(message.arg, message.playing)],
|
||||
// 'mark-player': [(message) => this.pageInfo.markPlayer(message.name, message.color)],
|
||||
// 'unmark-player': [() => this.pageInfo.unmarkPlayer()],
|
||||
// 'autoar-set-manual-tick': [(message) => this.pageInfo.setManualTick(message.arg)],
|
||||
// 'autoar-tick': [() => this.pageInfo.tick()],
|
||||
'set-ar-persistence': [(message) => this.pageInfo.setArPersistence(message.arg)],
|
||||
// 'set-ar-persistence': [(message) => this.pageInfo.setArPersistence(message.arg)],
|
||||
}
|
||||
|
||||
constructor(){
|
||||
|
@ -47,7 +47,7 @@ class ActionHandler {
|
||||
|
||||
var ths = this;
|
||||
|
||||
var actions;
|
||||
var actions;
|
||||
try {
|
||||
if (this.settings.active.sites[window.location.hostname].actions) {
|
||||
actions = this.settings.active.sites[window.location.hostname].actions;
|
||||
@ -121,7 +121,7 @@ class ActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// events should be handled in handleEvent function. We need to do things this
|
||||
// events should be handled in handleEvent function. We need to do things this
|
||||
// way, otherwise we can't remove event listener
|
||||
// https://stackoverflow.com/a/19507086
|
||||
document.addEventListener('keydown', this );
|
||||
@ -137,7 +137,7 @@ class ActionHandler {
|
||||
case 'keydown':
|
||||
this.handleKeydown(event);
|
||||
break;
|
||||
case 'keyup':
|
||||
case 'keyup':
|
||||
this.handleKeyup(event);
|
||||
break;
|
||||
case 'mousemove':
|
||||
@ -210,7 +210,7 @@ class ActionHandler {
|
||||
}
|
||||
if (this.inputs.indexOf(activeElement.tagName.toLocaleLowerCase()) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (activeElement.getAttribute("role") === "textbox") {
|
||||
return true;
|
||||
}
|
||||
@ -245,8 +245,8 @@ class ActionHandler {
|
||||
isActionMatch(shortcut, event, isLatin = true) {
|
||||
// ASCII and symbols fall back to key code matching, because we don't know for sure that
|
||||
// regular matching by key is going to work
|
||||
return isLatin ?
|
||||
this.isActionMatchStandard(shortcut, event) :
|
||||
return isLatin ?
|
||||
this.isActionMatchStandard(shortcut, event) :
|
||||
this.isActionMatchStandard(shortcut, event) || this.isActionMatchKeyCode(shortcut, event);
|
||||
}
|
||||
|
||||
@ -255,59 +255,62 @@ class ActionHandler {
|
||||
|
||||
const isLatin = event.key ? this.isLatin(event.key) : true;
|
||||
|
||||
for (var action of actions) {
|
||||
if (this.isActionMatch(action.shortcut, event, isLatin)) {
|
||||
this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] found an action associated with keypress/event: ", "color: #ff0", action);
|
||||
console.warn('You need to migrate this to new commands');
|
||||
|
||||
for (var cmd of action.cmd) {
|
||||
if (action.scope === 'page') {
|
||||
if (cmd.action === "set-ar") {
|
||||
this.pageInfo.setAr({type: cmd.arg, ratio: cmd.customArg});
|
||||
} else if (cmd.action === "change-zoom") {
|
||||
this.pageInfo.zoomStep(cmd.arg);
|
||||
} else if (cmd.action === "set-zoom") {
|
||||
this.pageInfo.setZoom(cmd.arg);
|
||||
} else if (cmd.action === "set-stretch") {
|
||||
this.pageInfo.setStretchMode(cmd.arg);
|
||||
} else if (cmd.action === "toggle-pan") {
|
||||
this.pageInfo.setPanMode(cmd.arg)
|
||||
} else if (cmd.action === "pan") {
|
||||
if (videoData) {
|
||||
videoData.panHandler(event, true);
|
||||
}
|
||||
} else if (cmd.action === 'set-keyboard') {
|
||||
this.setKeyboardLocal(cmd.arg);
|
||||
}
|
||||
} else {
|
||||
let site = action.scope === 'site' ? window.location.hostname : '@global';
|
||||
// for (var action of actions) {
|
||||
// if (this.isActionMatch(action.shortcut, event, isLatin)) {
|
||||
// this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] found an action associated with keypress/event: ", "color: #ff0", action);
|
||||
|
||||
if (cmd.action === "set-stretch") {
|
||||
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-extension-mode") {
|
||||
this.settings.active.sites[site].mode = cmd.arg;
|
||||
} else if (cmd.action === "set-autoar-mode") {
|
||||
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') {
|
||||
this.settings.active.sites[site]['cropModePersistence'] = cmd.arg;
|
||||
this.pageInfo.setArPersistence(cmd.arg);
|
||||
this.settings.saveWithoutReload();
|
||||
}
|
||||
// for (var cmd of action.cmd) {
|
||||
// if (action.scope === 'page') {
|
||||
// if (cmd.action === "set-ar") {
|
||||
// // the entirety of this function should be moved to new command bus
|
||||
// // this.pageInfo.setAr({type: cmd.arg, ratio: cmd.customArg});
|
||||
// } else if (cmd.action === "change-zoom") {
|
||||
// this.pageInfo.zoomStep(cmd.arg);
|
||||
// } else if (cmd.action === "set-zoom") {
|
||||
// this.pageInfo.setZoom(cmd.arg);
|
||||
// } else if (cmd.action === "set-stretch") {
|
||||
// this.pageInfo.setStretchMode(cmd.arg);
|
||||
// } else if (cmd.action === "toggle-pan") {
|
||||
// this.pageInfo.setPanMode(cmd.arg)
|
||||
// } else if (cmd.action === "pan") {
|
||||
// if (videoData) {
|
||||
// videoData.panHandler(event, true);
|
||||
// }
|
||||
// } else if (cmd.action === 'set-keyboard') {
|
||||
// this.setKeyboardLocal(cmd.arg);
|
||||
// }
|
||||
// } else {
|
||||
// let site = action.scope === 'site' ? window.location.hostname : '@global';
|
||||
|
||||
if (cmd.action !== 'set-ar-persistence') {
|
||||
this.settings.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (cmd.action === "set-stretch") {
|
||||
// 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-extension-mode") {
|
||||
// this.settings.active.sites[site].mode = cmd.arg;
|
||||
// } else if (cmd.action === "set-autoar-mode") {
|
||||
// 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') {
|
||||
// this.settings.active.sites[site]['cropModePersistence'] = cmd.arg;
|
||||
// this.pageInfo.setArPersistence(cmd.arg);
|
||||
// this.settings.saveWithoutReload();
|
||||
// }
|
||||
|
||||
// če smo našli dejanje za to tipko, potem ne preiskujemo naprej
|
||||
// if we found an action for this key, we stop searching for a match
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if (cmd.action !== 'set-ar-persistence') {
|
||||
// this.settings.save();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // če smo našli dejanje za to tipko, potem ne preiskujemo naprej
|
||||
// // if we found an action for this key, we stop searching for a match
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
@ -375,23 +375,7 @@ class PageInfo {
|
||||
this.scheduleUrlCheck();
|
||||
}
|
||||
|
||||
initArDetection(playingOnly){
|
||||
if (playingOnly) {
|
||||
for(let vd of this.videos){
|
||||
if(vd.videoData.isPlaying()) {
|
||||
vd.videoData.initArDetection();
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
for(let vd of this.videos){
|
||||
vd.videoData.initArDetection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// to je treba klicat ob menjavi zavihkov
|
||||
// these need to be called on tab switch
|
||||
pauseProcessing(playingOnly){
|
||||
if (playingOnly) {
|
||||
@ -427,167 +411,6 @@ class PageInfo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
startArDetection(playingOnly){
|
||||
if (Debug.debug) {
|
||||
this.logger.log('info', 'debug', '[PageInfo::startArDetection()] starting automatic ar detection!')
|
||||
}
|
||||
if (playingOnly) {
|
||||
for(let vd of this.videos){
|
||||
if (vd.videoData.isPlaying()) {
|
||||
vd.videoData.startArDetection();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(let vd of this.videos){
|
||||
vd.videoData.startArDetection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stopArDetection(playingOnly){
|
||||
if (playingOnly) {
|
||||
for(let vd of this.videos){
|
||||
if (vd.videoData.isPlaying()) {
|
||||
vd.videoData.stopArDetection();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(let vd of this.videos){
|
||||
vd.videoData.stopArDetection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setAr(ar, playingOnly?: boolean){
|
||||
this.logger.log('info', 'debug', '[PageInfo::setAr] aspect ratio:', ar, "playing only?", playingOnly)
|
||||
|
||||
if (ar.type !== AspectRatioType.AutomaticUpdate && ar.type !== AspectRatioType.Automatic) {
|
||||
this.stopArDetection(playingOnly);
|
||||
} else {
|
||||
this.logger.log('info', 'debug', '[PageInfo::setAr] aspect ratio is auto');
|
||||
|
||||
try {
|
||||
for (let vd of this.videos) {
|
||||
if (!playingOnly || vd.videoData.isPlaying()) {
|
||||
vd.videoData.resetLastAr();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
this.logger.log('error', 'debug', "???", e);
|
||||
}
|
||||
this.initArDetection(playingOnly);
|
||||
this.startArDetection(playingOnly);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: find a way to only change aspect ratio for one video
|
||||
if (ar === AspectRatioType.Reset) {
|
||||
for (let vd of this.videos) {
|
||||
if (!playingOnly || vd.videoData.isPlaying()) {
|
||||
vd.videoData.resetAr();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let vd of this.videos) {
|
||||
if (!playingOnly || vd.videoData.isPlaying()) {
|
||||
vd.videoData.setAr(ar)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setVideoAlignment(videoAlignment, playingOnly) {
|
||||
if (playingOnly) {
|
||||
for(let vd of this.videos) {
|
||||
if (vd.videoData.isPlaying()) {
|
||||
vd.videoData.setVideoAlignment(videoAlignment)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(let vd of this.videos) {
|
||||
vd.videoData.setVideoAlignment(videoAlignment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setPanMode(mode, playingOnly?: boolean) {
|
||||
if (playingOnly) {
|
||||
for(let vd of this.videos) {
|
||||
if (vd.videoData.isPlaying()) {
|
||||
vd.videoData.setPanMode(mode);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(let vd of this.videos) {
|
||||
vd.videoData.setPanMode(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
restoreAr(playingOnly?: boolean) {
|
||||
if (playingOnly) {
|
||||
for(let vd of this.videos){
|
||||
if (vd.videoData.isPlaying()) {
|
||||
vd.videoData.restoreAr();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(let vd of this.videos){
|
||||
vd.videoData.restoreAr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setStretchMode(stretchMode, playingOnly?: boolean, fixedStretchRatio?: boolean){
|
||||
// TODO: find a way to only change aspect ratio for one video
|
||||
|
||||
if (playingOnly) {
|
||||
for(let vd of this.videos){
|
||||
if (vd.videoData.isPlaying()) {
|
||||
vd.videoData.setStretchMode(stretchMode, fixedStretchRatio)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(let vd of this.videos){
|
||||
vd.videoData.setStretchMode(stretchMode, fixedStretchRatio)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setZoom(zoomLevel, no_announce?: boolean, playingOnly?: boolean) {
|
||||
if (playingOnly) {
|
||||
for(let vd of this.videos) {
|
||||
if (vd.videoData.isPlaying()) {
|
||||
vd.videoData.setZoom(zoomLevel, no_announce);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(let vd of this.videos) {
|
||||
vd.videoData.setZoom(zoomLevel, no_announce);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zoomStep(step, playingOnly?: boolean) {
|
||||
for(let vd of this.videos){
|
||||
if (!playingOnly || vd.videoData.isPlaying()) {
|
||||
vd.videoData.zoomStep(step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
markPlayer(name, color) {
|
||||
for (let vd of this.videos) {
|
||||
vd.videoData.markPlayer(name,color);
|
||||
}
|
||||
}
|
||||
unmarkPlayer() {
|
||||
for (let vd of this.videos) {
|
||||
vd.videoData.unmarkPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
announceZoom(scale) {
|
||||
if (this.announceZoomTimeout) {
|
||||
clearTimeout(this.announceZoomTimeout);
|
||||
@ -597,20 +420,6 @@ class PageInfo {
|
||||
this.announceZoomTimeout = setTimeout(() => ths.comms.announceZoom(scale), this.settings.active.zoom.announceDebounce);
|
||||
}
|
||||
|
||||
sendPerformanceUpdate(performanceUpdate) {
|
||||
if(this.comms) {
|
||||
this.comms.sendPerformanceUpdate(performanceUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
requestCurrentZoom() {
|
||||
this.comms.announceZoom(this.currentZoomScale);
|
||||
}
|
||||
|
||||
setKeyboardShortcutsEnabled(state) {
|
||||
this.actionHandler.setKeyboardLocal(state);
|
||||
}
|
||||
|
||||
setArPersistence(persistenceMode) {
|
||||
// name of this function is mildly misleading — we don't really _set_ ar persistence. (Ar persistence
|
||||
// mode is set and saved via popup or keyboard shortcuts, if user defined them) We just save the current
|
||||
|
@ -472,7 +472,6 @@ class VideoData {
|
||||
|
||||
this.processDimensionsChanged();
|
||||
}
|
||||
|
||||
onVideoDimensionsChanged(mutationList, observer) {
|
||||
if (!mutationList || this.video === undefined) { // something's wrong
|
||||
if (observer && this.video) {
|
||||
@ -668,38 +667,6 @@ class VideoData {
|
||||
//#endregion
|
||||
|
||||
//#region shit that gets propagated to resizer and should be removed. Implement an event bus instead
|
||||
setLastAr(lastAr){
|
||||
if (this.invalid) {
|
||||
return;
|
||||
}
|
||||
this.resizer.setLastAr(lastAr);
|
||||
}
|
||||
|
||||
setAr(ar, lastAr?){
|
||||
if (this.invalid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ar.type === AspectRatioType.Fixed || ar.type === AspectRatioType.FitHeight || ar.type === AspectRatioType.FitHeight) {
|
||||
this.player.forceRefreshPlayerElement();
|
||||
}
|
||||
|
||||
this.resizer.setAr(ar, lastAr);
|
||||
}
|
||||
|
||||
resetAr() {
|
||||
if (this.invalid) {
|
||||
return;
|
||||
}
|
||||
this.resizer.reset();
|
||||
}
|
||||
|
||||
resetLastAr() {
|
||||
if (this.invalid) {
|
||||
return;
|
||||
}
|
||||
this.resizer.setLastAr('original');
|
||||
}
|
||||
|
||||
panHandler(event, forcePan?: boolean) {
|
||||
if (this.invalid) {
|
||||
@ -723,13 +690,6 @@ class VideoData {
|
||||
this.resizer.setPanMode(mode);
|
||||
}
|
||||
|
||||
setVideoAlignment(videoAlignment) {
|
||||
if (this.invalid) {
|
||||
return;
|
||||
}
|
||||
this.resizer.setVideoAlignment(videoAlignment);
|
||||
}
|
||||
|
||||
restoreAr(){
|
||||
if (this.invalid) {
|
||||
return;
|
||||
@ -737,34 +697,6 @@ class VideoData {
|
||||
this.resizer.restore();
|
||||
}
|
||||
|
||||
setStretchMode(stretchMode, fixedStretchRatio){
|
||||
if (this.invalid) {
|
||||
return;
|
||||
}
|
||||
this.resizer.setStretchMode(stretchMode, fixedStretchRatio);
|
||||
}
|
||||
|
||||
setZoom(zoomLevel, no_announce){
|
||||
if (this.invalid) {
|
||||
return;
|
||||
}
|
||||
this.resizer.setZoom(zoomLevel, no_announce);
|
||||
}
|
||||
|
||||
zoomStep(step){
|
||||
if (this.invalid) {
|
||||
return;
|
||||
}
|
||||
this.resizer.zoomStep(step);
|
||||
}
|
||||
|
||||
announceZoom(scale){
|
||||
if (this.invalid) {
|
||||
return;
|
||||
}
|
||||
this.pageInfo.announceZoom(scale);
|
||||
}
|
||||
|
||||
markPlayer(name, color) {
|
||||
if (this.invalid) {
|
||||
return;
|
||||
@ -773,6 +705,7 @@ class VideoData {
|
||||
this.player.markPlayer(name, color)
|
||||
}
|
||||
}
|
||||
|
||||
unmarkPlayer() {
|
||||
this.player.unmarkPlayer();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user