fix various fuckies wuckies
This commit is contained in:
parent
a0e375d2dc
commit
3aabd298ec
@ -100,6 +100,8 @@ export default class UWContent {
|
||||
}
|
||||
);
|
||||
this.comms = new CommsClient('content-main-port', this.logger, this.eventBus);
|
||||
this.eventBus.setComms(this.comms);
|
||||
|
||||
|
||||
this.initPhase2();
|
||||
} catch (e) {
|
||||
|
@ -75,11 +75,15 @@ export default class UWServer {
|
||||
this.settings = new Settings({logger: this.logger});
|
||||
await this.settings.init();
|
||||
this.eventBus = new EventBus();
|
||||
|
||||
for (const action in this.eventBusCommands) {
|
||||
for (const command of this.eventBusCommands[action]) {
|
||||
this.eventBus.subscribe(action, command);
|
||||
}
|
||||
}
|
||||
|
||||
this.comms = new CommsServer(this);
|
||||
|
||||
|
||||
this.comms.subscribe('emit-logs', () => {}); // we don't need to do anything, this gets forwarded to UI content script as is
|
||||
|
||||
browser.tabs.onActivated.addListener((m) => {this.onTabSwitched(m)});
|
||||
} catch (e) {
|
||||
console.error(`Ultrawidify [server]: failed to start. Reason:`, e);
|
||||
|
@ -204,7 +204,7 @@ class ActionHandler {
|
||||
|
||||
for (const command of this.commands) {
|
||||
if (this.isActionMatch(command.shortcut, event, isLatin)) {
|
||||
this.eventBus.sendGlobal(command.action, command.arguments);
|
||||
this.eventBus.send(command.action, command.arguments);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -34,7 +34,7 @@ export default class EventBus {
|
||||
}
|
||||
//#endregion
|
||||
|
||||
setComms(comms: CommsClient): void {
|
||||
setComms(comms: CommsClient) {
|
||||
this.comms = comms;
|
||||
}
|
||||
|
||||
@ -78,20 +78,25 @@ export default class EventBus {
|
||||
}
|
||||
|
||||
send(command: string, config: any, context?: EventBusContext) {
|
||||
if (!this.commands ||!this.commands[command]) {
|
||||
// ensure send is not being called for commands that we have no subscriptions for
|
||||
// execute commands we have subscriptions for
|
||||
if (this.commands?.[command]) {
|
||||
for (const eventBusCommand of this.commands[command]) {
|
||||
eventBusCommand.function(config, context);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.comms && !context?.fromComms) {
|
||||
this.comms.sendMessage({command, config});
|
||||
}
|
||||
|
||||
if (context?.stopPropagation) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const eventBusCommand of this.commands[command]) {
|
||||
eventBusCommand.function(config, context);
|
||||
|
||||
if (eventBusCommand.isGlobal && !context?.stopPropagation) {
|
||||
// propagate commands across the bus
|
||||
this.sendUpstream(command, config, context);
|
||||
this.sendDownstream(command, config, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send, but intended for sending commands from iframe to content scripts
|
||||
@ -109,17 +114,11 @@ export default class EventBus {
|
||||
}
|
||||
|
||||
|
||||
sendGlobal(command: string, config: any, context?: EventBusContext) {
|
||||
this.send(command, config);
|
||||
this.sendUpstream(command, config);
|
||||
this.sendDownstream(command, config);
|
||||
}
|
||||
|
||||
|
||||
sendDownstream(command: string, config: any, context?: EventBusContext, sourceEventBus?: EventBus) {
|
||||
for (const eventBus of this.downstreamBuses) {
|
||||
if (eventBus !== sourceEventBus) {
|
||||
eventBus.send(command, config);
|
||||
// prevent eventBus.send from auto-propagating the command
|
||||
eventBus.send(command, config, {...context, stopPropagation: true});
|
||||
eventBus.sendDownstream(command, config);
|
||||
}
|
||||
}
|
||||
@ -127,12 +126,10 @@ export default class EventBus {
|
||||
|
||||
sendUpstream(command: string, config: any, context?: EventBusContext) {
|
||||
if (this.upstreamBus) {
|
||||
this.upstreamBus.send(command, config, context);
|
||||
// prevent eventBus.send from auto-propagating the command
|
||||
this.upstreamBus.send(command, config, {...context, stopPropagation: true});
|
||||
this.upstreamBus.sendUpstream(command, config, context);
|
||||
this.upstreamBus.sendDownstream(command, config, context, this);
|
||||
}
|
||||
if (!this.upstreamBus && this.comms && !context?.fromComms) {
|
||||
this.comms.sendMessage({command, config});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,6 @@ class CommsClient {
|
||||
try {
|
||||
this.logger = logger;
|
||||
this.eventBus = eventBus;
|
||||
this.eventBus.setComms(this);
|
||||
|
||||
this.port = browser.runtime.connect(null, {name: name});
|
||||
|
||||
|
@ -222,13 +222,13 @@ class CommsServer {
|
||||
async processReceivedMessage(message, port){
|
||||
this.logger.log('info', 'comms', "[CommsServer.js::processReceivedMessage] Received message from popup/content script!", message, "port", port);
|
||||
|
||||
this.eventBus.send(message, {port, fromComms: true});
|
||||
this.eventBus.send(message.command, message.config, {comms: {port}, fromComms: true});
|
||||
}
|
||||
|
||||
processReceivedMessage_nonpersistent(message, sender){
|
||||
this.logger.log('info', 'comms', "%c[CommsServer.js::processMessage_nonpersistent] Received message from background script!", "background-color: #11D; color: #aad", message, sender);
|
||||
|
||||
this.eventBus.send(message, {sender, fromComms: true});
|
||||
this.eventBus.send(message.command, message.config, {comms: {sender}, fromComms: true});
|
||||
}
|
||||
|
||||
// chrome shitiness mitigation
|
||||
|
@ -67,7 +67,7 @@ class PageInfo {
|
||||
actionHandler: any;
|
||||
//#endregion
|
||||
|
||||
constructor(comms, settings, logger, extensionMode, readOnly = false){
|
||||
constructor(eventBus: EventBus, settings: Settings, logger: Logger, extensionMode, readOnly = false){
|
||||
this.logger = logger;
|
||||
this.settings = settings;
|
||||
|
||||
@ -75,9 +75,8 @@ class PageInfo {
|
||||
this.extensionMode = extensionMode;
|
||||
this.readOnly = readOnly;
|
||||
|
||||
|
||||
if (comms){
|
||||
this.comms = comms;
|
||||
if (eventBus){
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
try {
|
||||
@ -88,18 +87,6 @@ class PageInfo {
|
||||
// do nothing. It's ok if there's no special settings for the player element or crop persistence
|
||||
}
|
||||
|
||||
// try getting default crop immediately.
|
||||
// const cropModePersistence = this.settings.getDefaultCropPersistenceMode(window.location.hostname);
|
||||
|
||||
// try {
|
||||
// if (cropModePersistence === CropModePersistence.Forever) {
|
||||
// this.defaultCrop = this.settings.active.sites[window.location.hostname].defaultCrop;
|
||||
// } else if (cropModePersistence === CropModePersistence.CurrentSession) {
|
||||
// this.defaultCrop = JSON.parse(sessionStorage.getItem('uw-crop-mode-session-persistence'));
|
||||
// }
|
||||
// } catch (e) {
|
||||
// // do nothing. It's ok if there's no special settings for the player element or crop persistence
|
||||
// }
|
||||
this.currentCrop = this.defaultCrop;
|
||||
|
||||
this.rescan(RescanReason.PERIODIC);
|
||||
@ -248,7 +235,7 @@ class PageInfo {
|
||||
|
||||
// if we're left without videos on the current page, we unregister the page.
|
||||
// if we have videos, we call register.
|
||||
if (this.comms) {
|
||||
if (this.eventBus) {
|
||||
// We used to send "register video" requests only on the first load, or if the number of
|
||||
// videos on the page has changed. However, since Chrome Web Store started to require every
|
||||
// extension requiring "broad permissions" to undergo manual review
|
||||
|
@ -65,8 +65,6 @@ class VideoData {
|
||||
}
|
||||
|
||||
constructor(video, settings, pageInfo){
|
||||
(window as any).ultrawidify.addVideo(this);
|
||||
|
||||
this.logger = pageInfo.logger;
|
||||
this.arSetupComplete = false;
|
||||
this.video = video;
|
||||
@ -98,7 +96,6 @@ class VideoData {
|
||||
}});
|
||||
}
|
||||
|
||||
|
||||
this.setupStageOne();
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ class Resizer {
|
||||
}
|
||||
|
||||
replaceCss(oldCssString, newCssString) {
|
||||
this.eventBus.send('replace-css', {oldCss: oldCssString, newCss: newCssString});
|
||||
this.eventBus.send('replace-css', {oldCssString, newCssString});
|
||||
}
|
||||
|
||||
prepareCss(css) {
|
||||
|
Loading…
Reference in New Issue
Block a user