Cropping now also works from in-player UI
This commit is contained in:
parent
2a747e11af
commit
3846d1a926
@ -49,6 +49,7 @@ import CropModePersistence from '../../common/enums/CropModePersistence.enum';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
exec: null,
|
||||
scope: 'page',
|
||||
CropModePersistence: CropModePersistence,
|
||||
}
|
||||
@ -63,7 +64,7 @@ export default {
|
||||
'cropModePersistence',
|
||||
],
|
||||
created() {
|
||||
this.exec = new ExecAction(this.settings);
|
||||
this.exec = new ExecAction(this.settings, window.location.hostname, window.ultrawidify);
|
||||
},
|
||||
components: {
|
||||
ShortcutButton,
|
||||
@ -78,7 +79,13 @@ export default {
|
||||
BrowserDetect.runtime.openOptionsPage();
|
||||
},
|
||||
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) {
|
||||
if (! action.scopes.page.shortcut) {
|
||||
@ -91,16 +98,13 @@ export default {
|
||||
},
|
||||
changeZoom(nz) {
|
||||
nz = Math.pow(2, nz);
|
||||
this.$emit('zoom-change', nz);
|
||||
this.$emit('zoom-change', nz);
|
||||
// this.exec.exec(
|
||||
// {cmd: [{action: 'set-zoom', arg: nz}]},
|
||||
// 'page',
|
||||
// this.frame
|
||||
// );
|
||||
},
|
||||
testAction() {
|
||||
window.ultrawidify.videos[0].setAr({type: AspectRatioType.FitWidth});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -13,9 +13,11 @@ class ExecAction {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
async exec(action, scope, frame) {
|
||||
|
||||
async exec(action, scope, frame, useBus) {
|
||||
console.log('execing actioN!');
|
||||
for (var cmd of action.cmd) {
|
||||
if (scope === 'page') {
|
||||
if (!scope || scope === 'page') {
|
||||
const message = {
|
||||
forwardToContentScript: true,
|
||||
targetFrame: frame,
|
||||
@ -24,14 +26,18 @@ class ExecAction {
|
||||
arg: cmd.arg,
|
||||
customArg: cmd.customArg
|
||||
}
|
||||
Comms.sendMessage(message);
|
||||
if (useBus) {
|
||||
window.ultrawidify.bus.sendMessage(message.cmd, message);
|
||||
} else {
|
||||
Comms.sendMessage(message);
|
||||
}
|
||||
} else {
|
||||
|
||||
// set-ar-persistence sends stuff to content scripts as well (!)
|
||||
// it's important to do that BEFORE the save step
|
||||
if (cmd.action === 'set-ar-persistence') {
|
||||
// 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 = {
|
||||
forwardToActive: true,
|
||||
targetFrame: frame,
|
||||
@ -41,7 +47,11 @@ class ExecAction {
|
||||
}
|
||||
// this hopefully delays settings.save() until current crops are saved on the site
|
||||
// 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;
|
||||
|
@ -1,6 +1,14 @@
|
||||
export default class UWGlobals {
|
||||
|
||||
constructor() {
|
||||
this.videos = [];
|
||||
this.busSubscriptions = [];
|
||||
this.actionSubscriptions = {};
|
||||
this.bus = {
|
||||
sendMessage: (action, config) => this.propagateMessages(action, config),
|
||||
subscribe: this.subscribeToAny,
|
||||
subscribeToAction: this.subscribeToAction
|
||||
}
|
||||
}
|
||||
|
||||
getNewVideoID() {
|
||||
@ -9,7 +17,7 @@ export default class UWGlobals {
|
||||
while (true) {
|
||||
// 4-digit [a-z0-9] string. Should be unique per page on first try
|
||||
random = (Math.random() * 1679616).toFixed().toString(36);
|
||||
|
||||
|
||||
if (this.videos.findIndex(x => x.vdid === random) === -1) {
|
||||
return random;
|
||||
}
|
||||
@ -27,6 +35,39 @@ export default class UWGlobals {
|
||||
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() {
|
||||
// todo: implement
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user