Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Commit

Permalink
fix(__dirname): adds horrible wrapper hack for __dirname with webpack…
Browse files Browse the repository at this point in the history
… & electron & workers

This is an abominable hack which works around the fact webpack just does whatever the fuck it wants
with workers. We stall everything in the worker until we've sent it the correct path to the .asar,
then in the NDI store module we temporarily set the location of grandiose within the .asar.
Guaranteed this will come back to bite us in the arse.

fix #114
  • Loading branch information
2xAA committed May 23, 2020
1 parent 4510114 commit 2f46506
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
7 changes: 6 additions & 1 deletion src/application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import use from "./use";

import PromiseWorker from "promise-worker-transferable";

import { ipcRenderer } from "electron";
import { ipcRenderer, remote } from "electron";

let imageBitmap;
const imageBitmapQueue = [];
Expand All @@ -35,6 +35,11 @@ export default class ModV {
this.$worker = new Worker();
this.$asyncWorker = new PromiseWorker(this.$worker);

this.$worker.postMessage({
type: "__dirname",
payload: remote.app.getAppPath()
});

this.$worker.addEventListener("message", e => {
if (e.data.type === "tick" && this.ready) {
this.tick(e.data.payload);
Expand Down
37 changes: 24 additions & 13 deletions src/application/worker/index.worker.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
/* eslint-env worker node */
import registerPromiseWorker from "promise-worker/register";
import fs from "fs";
import store from "./store";
import loop from "./loop";
import { tick as frameTick } from "./frame-counter";
import { getFeatures, setFeatures } from "./audio-features";
import featureAssignmentPlugin from "../plugins/feature-assignment";

let lastKick = false;

(async function() {
self.addEventListener("unhandledrejection", e => {
console.log(e);
});
async function start() {
const registerPromiseWorker = require("promise-worker/register");
const fs = require("fs");
const store = require("./store").default;
const loop = require("./loop").default;
const { tick: frameTick } = require("./frame-counter");
const { getFeatures, setFeatures } = require("./audio-features");
// const featureAssignmentPlugin = require("../plugins/feature-assignment");

store.subscribe(mutation => {
const { type, payload } = mutation;
Expand Down Expand Up @@ -112,7 +109,7 @@ let lastKick = false;
store.dispatch("modules/registerModule", module);
}

store.dispatch("plugins/add", featureAssignmentPlugin);
// store.dispatch("plugins/add", featureAssignmentPlugin);

const webcamOutput = await store.dispatch("outputs/getAuxillaryOutput", {
name: "webcam",
Expand Down Expand Up @@ -256,4 +253,18 @@ let lastKick = false;
});

self.store = store;
})();
}

function handleDirname(e) {
const message = e.data;
const { type, payload } = message;

if (type === "__dirname") {
self.__dirname = payload;

self.removeEventListener("message", handleDirname);
start();
}
}

self.addEventListener("message", handleDirname);
11 changes: 10 additions & 1 deletion src/application/worker/store/modules/ndi.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import grandiose from "grandiose";
/* globals __dirname */

import uuidv4 from "uuid/v4";
import Vue from "vue";
import store from "../";

// eslint-disable-next-line
__dirname = `${__dirname}/node_modules/grandiose`;

const grandiose = require("grandiose");

// eslint-disable-next-line
__dirname = __dirname.replace("/node_modules/grandiose", "");

const state = {
discovering: false,

Expand Down

0 comments on commit 2f46506

Please sign in to comment.