Cropping now also works from in-player UI

This commit is contained in:
Tamius Han 2021-10-19 22:49:13 +02:00
parent 2a747e11af
commit 3846d1a926
3 changed files with 67 additions and 12 deletions

View File

@ -49,6 +49,7 @@ import CropModePersistence from '../../common/enums/CropModePersistence.enum';
export default { export default {
data() { data() {
return { return {
exec: null,
scope: 'page', scope: 'page',
CropModePersistence: CropModePersistence, CropModePersistence: CropModePersistence,
} }
@ -63,7 +64,7 @@ export default {
'cropModePersistence', 'cropModePersistence',
], ],
created() { created() {
this.exec = new ExecAction(this.settings); this.exec = new ExecAction(this.settings, window.location.hostname, window.ultrawidify);
}, },
components: { components: {
ShortcutButton, ShortcutButton,
@ -78,7 +79,13 @@ export default {
BrowserDetect.runtime.openOptionsPage(); BrowserDetect.runtime.openOptionsPage();
}, },
execAction(action) { execAction(action) {
this.exec.exec(action, 'page', this.frame); console.log('execing action:', action, window.ultrawidify);
try {
this.exec.exec(action, 'page', this.frame, true);
} catch (error) {
console.error('[uw:VideoSettings.vue::execAction] failed to execute action. Error:', error);
}
}, },
parseShortcut(action) { parseShortcut(action) {
if (! action.scopes.page.shortcut) { if (! action.scopes.page.shortcut) {
@ -91,16 +98,13 @@ export default {
}, },
changeZoom(nz) { changeZoom(nz) {
nz = Math.pow(2, nz); nz = Math.pow(2, nz);
this.$emit('zoom-change', nz); this.$emit('zoom-change', nz);
// this.exec.exec( // this.exec.exec(
// {cmd: [{action: 'set-zoom', arg: nz}]}, // {cmd: [{action: 'set-zoom', arg: nz}]},
// 'page', // 'page',
// this.frame // this.frame
// ); // );
}, },
testAction() {
window.ultrawidify.videos[0].setAr({type: AspectRatioType.FitWidth});
}
} }
} }
</script> </script>

View File

@ -13,9 +13,11 @@ class ExecAction {
this.site = site; this.site = site;
} }
async exec(action, scope, frame) {
async exec(action, scope, frame, useBus) {
console.log('execing actioN!');
for (var cmd of action.cmd) { for (var cmd of action.cmd) {
if (scope === 'page') { if (!scope || scope === 'page') {
const message = { const message = {
forwardToContentScript: true, forwardToContentScript: true,
targetFrame: frame, targetFrame: frame,
@ -24,14 +26,18 @@ class ExecAction {
arg: cmd.arg, arg: cmd.arg,
customArg: cmd.customArg customArg: cmd.customArg
} }
Comms.sendMessage(message); if (useBus) {
window.ultrawidify.bus.sendMessage(message.cmd, message);
} else {
Comms.sendMessage(message);
}
} else { } else {
// set-ar-persistence sends stuff to content scripts as well (!) // set-ar-persistence sends stuff to content scripts as well (!)
// it's important to do that BEFORE the save step // it's important to do that BEFORE the save step
if (cmd.action === 'set-ar-persistence') { if (cmd.action === 'set-ar-persistence') {
// even when setting global defaults, we only send message to the current tab in // even when setting global defaults, we only send message to the current tab in
// order to avoid problems related to // order to avoid problems related to
const message = { const message = {
forwardToActive: true, forwardToActive: true,
targetFrame: frame, targetFrame: frame,
@ -41,7 +47,11 @@ class ExecAction {
} }
// this hopefully delays settings.save() until current crops are saved on the site // this hopefully delays settings.save() until current crops are saved on the site
// and thus avoid any fucky-wuckies // and thus avoid any fucky-wuckies
await Comms.sendMessage(message); if (useBus) {
window.ultrawidify.bus.sendMessage(message.cmd, message);
} else {
await Comms.sendMessage(message);
}
} }
let site = this.site; let site = this.site;

View File

@ -1,6 +1,14 @@
export default class UWGlobals { export default class UWGlobals {
constructor() { constructor() {
this.videos = []; this.videos = [];
this.busSubscriptions = [];
this.actionSubscriptions = {};
this.bus = {
sendMessage: (action, config) => this.propagateMessages(action, config),
subscribe: this.subscribeToAny,
subscribeToAction: this.subscribeToAction
}
} }
getNewVideoID() { getNewVideoID() {
@ -9,7 +17,7 @@ export default class UWGlobals {
while (true) { while (true) {
// 4-digit [a-z0-9] string. Should be unique per page on first try // 4-digit [a-z0-9] string. Should be unique per page on first try
random = (Math.random() * 1679616).toFixed().toString(36); random = (Math.random() * 1679616).toFixed().toString(36);
if (this.videos.findIndex(x => x.vdid === random) === -1) { if (this.videos.findIndex(x => x.vdid === random) === -1) {
return random; return random;
} }
@ -27,6 +35,39 @@ export default class UWGlobals {
return this.videos.find(x => x.vdid === id); return this.videos.find(x => x.vdid === id);
} }
importSubscriptionsFromCommsHandlers(commands) {
for (const action in commands) {
for (const command of commands[action]) {
this.subscribeToAction(action, command);
}
}
}
subscribeToAction(action, callback) {
if (!this.actionSubscriptions[action]) {
this.actionSubscriptions[action] = [];
}
this.actionSubscriptions[action].push(callback);
}
subscribeToAny(callback) {
this.busSubscriptions.push(callback);
}
propagateMessages(action, config) {
if (this.busSubscriptions) {
for (const subscription of this.busSubscriptions) {
subscription(action, config);
}
}
if (this.actionSubscriptions && this.actionSubscriptions[action]) {
for (const subscription of this.actionSubscriptions[action]) {
subscription(config);
}
}
}
destroy() { destroy() {
// todo: implement // todo: implement
} }