Stop using some of the old code

This commit is contained in:
Tamius Han 2021-11-25 20:00:32 +01:00
parent 27b0609d34
commit 045cd5a528
4 changed files with 84 additions and 337 deletions

View File

@ -18,31 +18,33 @@ export default class UWContent {
commsHandlers: { commsHandlers: {
[x: string]: ((a: any, b?: any) => void | Promise<void>)[] [x: string]: ((a: any, b?: any) => void | Promise<void>)[]
} = { } = {
'get-current-zoom': [() => this.pageInfo.requestCurrentZoom()], // THIS SHOULD BE MIGRATED TO EVENT BUS
'set-ar': [(message) => this.pageInfo.setAr({type: message.arg, ratio: message.customArg}, message.playing)], // 'get-current-zoom': [() => this.pageInfo.requestCurrentZoom()],
'set-alignment': [(message) => { // 'set-ar': [(message) => this.pageInfo.setAr({type: message.arg, ratio: message.customArg}, message.playing)],
this.pageInfo.setVideoAlignment(message.arg, message.playing); // 'set-alignment': [(message) => {
this.pageInfo.restoreAr(); // 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)], // 'set-stretch': [(message) => this.pageInfo.setStretchMode(message.arg, message.playing, message.customArg)],
'autoar-start': [(message) => { // 'set-keyboard': [(message) => this.pageInfo.setKeyboardShortcutsEnabled(message.arg)],
if (message.enabled !== false) { // DEPRECATED — should be set with resizer.setAr()
this.pageInfo.initArDetection(message.playing); // 'autoar-start': [(message) => {
this.pageInfo.startArDetection(message.playing); // if (message.enabled !== false) {
} else { // this.pageInfo.initArDetection(message.playing);
this.pageInfo.stopArDetection(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)], // 'pause-processing': [(message) => this.pageInfo.pauseProcessing(message.playing)],
'change-zoom': [(message) => this.pageInfo.zoomStep(message.arg, message.playing)], // 'resume-processing': [(message) => this.pageInfo.resumeProcessing(message.autoArStatus, message.playing)],
'mark-player': [(message) => this.pageInfo.markPlayer(message.name, message.color)], // 'set-zoom': [(message) => this.pageInfo.setZoom(message.arg, true, message.playing)],
'unmark-player': [() => this.pageInfo.unmarkPlayer()], // '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-set-manual-tick': [(message) => this.pageInfo.setManualTick(message.arg)],
// 'autoar-tick': [() => this.pageInfo.tick()], // 'autoar-tick': [() => this.pageInfo.tick()],
'set-ar-persistence': [(message) => this.pageInfo.setArPersistence(message.arg)], // 'set-ar-persistence': [(message) => this.pageInfo.setArPersistence(message.arg)],
} }
constructor(){ constructor(){

View File

@ -47,7 +47,7 @@ class ActionHandler {
var ths = this; var ths = this;
var actions; var actions;
try { try {
if (this.settings.active.sites[window.location.hostname].actions) { if (this.settings.active.sites[window.location.hostname].actions) {
actions = 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 // way, otherwise we can't remove event listener
// https://stackoverflow.com/a/19507086 // https://stackoverflow.com/a/19507086
document.addEventListener('keydown', this ); document.addEventListener('keydown', this );
@ -137,7 +137,7 @@ class ActionHandler {
case 'keydown': case 'keydown':
this.handleKeydown(event); this.handleKeydown(event);
break; break;
case 'keyup': case 'keyup':
this.handleKeyup(event); this.handleKeyup(event);
break; break;
case 'mousemove': case 'mousemove':
@ -210,7 +210,7 @@ class ActionHandler {
} }
if (this.inputs.indexOf(activeElement.tagName.toLocaleLowerCase()) !== -1) { if (this.inputs.indexOf(activeElement.tagName.toLocaleLowerCase()) !== -1) {
return true; return true;
} }
if (activeElement.getAttribute("role") === "textbox") { if (activeElement.getAttribute("role") === "textbox") {
return true; return true;
} }
@ -245,8 +245,8 @@ class ActionHandler {
isActionMatch(shortcut, event, isLatin = true) { isActionMatch(shortcut, event, isLatin = true) {
// ASCII and symbols fall back to key code matching, because we don't know for sure that // 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 // regular matching by key is going to work
return isLatin ? return isLatin ?
this.isActionMatchStandard(shortcut, event) : this.isActionMatchStandard(shortcut, event) :
this.isActionMatchStandard(shortcut, event) || this.isActionMatchKeyCode(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; const isLatin = event.key ? this.isLatin(event.key) : true;
for (var action of actions) { console.warn('You need to migrate this to new commands');
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);
for (var cmd of action.cmd) { // for (var action of actions) {
if (action.scope === 'page') { // if (this.isActionMatch(action.shortcut, event, isLatin)) {
if (cmd.action === "set-ar") { // this.logger.log('info', 'keyboard', "%c[ActionHandler::execAction] found an action associated with keypress/event: ", "color: #ff0", action);
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-stretch") { // for (var cmd of action.cmd) {
this.settings.active.sites[site].stretch = cmd.arg; // if (action.scope === 'page') {
} else if (cmd.action === "set-alignment") { // if (cmd.action === "set-ar") {
this.settings.active.sites[site].videoAlignment = cmd.arg; // // the entirety of this function should be moved to new command bus
} else if (cmd.action === "set-extension-mode") { // // this.pageInfo.setAr({type: cmd.arg, ratio: cmd.customArg});
this.settings.active.sites[site].mode = cmd.arg; // } else if (cmd.action === "change-zoom") {
} else if (cmd.action === "set-autoar-mode") { // this.pageInfo.zoomStep(cmd.arg);
this.settings.active.sites[site].autoar = cmd.arg; // } else if (cmd.action === "set-zoom") {
} else if (cmd.action === 'set-keyboard') { // this.pageInfo.setZoom(cmd.arg);
this.settings.active.sites[site].keyboardShortcutsEnabled = cmd.arg; // } else if (cmd.action === "set-stretch") {
} else if (cmd.action === 'set-ar-persistence') { // this.pageInfo.setStretchMode(cmd.arg);
this.settings.active.sites[site]['cropModePersistence'] = cmd.arg; // } else if (cmd.action === "toggle-pan") {
this.pageInfo.setArPersistence(cmd.arg); // this.pageInfo.setPanMode(cmd.arg)
this.settings.saveWithoutReload(); // } 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') { // if (cmd.action === "set-stretch") {
this.settings.save(); // 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 (cmd.action !== 'set-ar-persistence') {
// if we found an action for this key, we stop searching for a match // this.settings.save();
return; // }
} // }
} // }
// // č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;
// }
// }
} }

View File

@ -375,23 +375,7 @@ class PageInfo {
this.scheduleUrlCheck(); 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 // these need to be called on tab switch
pauseProcessing(playingOnly){ pauseProcessing(playingOnly){
if (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) { announceZoom(scale) {
if (this.announceZoomTimeout) { if (this.announceZoomTimeout) {
clearTimeout(this.announceZoomTimeout); clearTimeout(this.announceZoomTimeout);
@ -597,20 +420,6 @@ class PageInfo {
this.announceZoomTimeout = setTimeout(() => ths.comms.announceZoom(scale), this.settings.active.zoom.announceDebounce); 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) { setArPersistence(persistenceMode) {
// name of this function is mildly misleading — we don't really _set_ ar persistence. (Ar persistence // 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 // mode is set and saved via popup or keyboard shortcuts, if user defined them) We just save the current

View File

@ -472,7 +472,6 @@ class VideoData {
this.processDimensionsChanged(); this.processDimensionsChanged();
} }
onVideoDimensionsChanged(mutationList, observer) { onVideoDimensionsChanged(mutationList, observer) {
if (!mutationList || this.video === undefined) { // something's wrong if (!mutationList || this.video === undefined) { // something's wrong
if (observer && this.video) { if (observer && this.video) {
@ -668,38 +667,6 @@ class VideoData {
//#endregion //#endregion
//#region shit that gets propagated to resizer and should be removed. Implement an event bus instead //#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) { panHandler(event, forcePan?: boolean) {
if (this.invalid) { if (this.invalid) {
@ -723,13 +690,6 @@ class VideoData {
this.resizer.setPanMode(mode); this.resizer.setPanMode(mode);
} }
setVideoAlignment(videoAlignment) {
if (this.invalid) {
return;
}
this.resizer.setVideoAlignment(videoAlignment);
}
restoreAr(){ restoreAr(){
if (this.invalid) { if (this.invalid) {
return; return;
@ -737,34 +697,6 @@ class VideoData {
this.resizer.restore(); 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) { markPlayer(name, color) {
if (this.invalid) { if (this.invalid) {
return; return;
@ -773,6 +705,7 @@ class VideoData {
this.player.markPlayer(name, color) this.player.markPlayer(name, color)
} }
} }
unmarkPlayer() { unmarkPlayer() {
this.player.unmarkPlayer(); this.player.unmarkPlayer();
} }