ChiriVulpes / MagicTranslator

Turning scanlation into a magical experience ✨
4 stars 1 forks source link

Executables built with "gulp build" fail due to packaging #142

Closed milleniumbug closed 2 years ago

milleniumbug commented 2 years ago

Packaging seems to put all the scripts, resources inside resources/app.asar, but inside Language.ts we're manually opening a file, resulting in "File not found" errors, and the application showing a blank screen.

image

One workaround is manually copying the lang directory to the target, but this is ugly, adds a manual step, and doesn't work well with other targets than "dir"

ChiriVulpes commented 2 years ago

Afaik this is supposed to just work, not entirely sure what's breaking here but it's probably something to do with paths stuff in whatever creates the BrowserWindow instance

milleniumbug commented 2 years ago

Changing from

const fallbackResponse = await FileSystem.readFile("./lang/en-US.quilt", "utf8");

to

const fallbackResponse = await FileSystem.readFile("./resources/app.asar/lang/en-US.quilt", "utf8");

makes it work, but again, it's a hack.

One thing I've noticed is that this is the only "application internal" file we're trying to load with FileSystem.readFile - everything else is either a.) user data read with FileSystem.readFile which doesn't have any problem as we use absolute paths, b.) user config loaded/stored with whatever magic Electron is using, which is good enough as it stores the config in OS-specific user directory, c.) internal assets loaded "implicitly" with this:

    mainWindow.loadURL("data:text/html;charset=UTF-8," + encodeURIComponent(`
        <link rel="stylesheet" href="style/index.css">
        <script>
            const { webFrame } = require("electron");
            webFrame.setVisualZoomLevelLimits(1, 1);
            webFrame.setLayoutZoomLevelLimits(0, 0);

            window.Stream = require("@wayward/goodstream").default;
            require("@wayward/goodstream/apply");

            window.nodeRequire = require;
            delete window.require;
            delete window.exports;
            delete window.module;
        </script>
        <script src="script/vendor/require.js"></script>
        <script>
            requirejs(["script/init/Decorator.js"], () => {
                requirejs(["script/index.js"]);
            });
        </script>
    `), { baseURLForDataURL: `chiri://${__dirname}/out`, extraHeaders: "pragma: no-cache\n" });

The __dirname part I can log easily and see what it is, but I have completely no idea what is going on with that /out - There is no directory at chiri://${__dirname}/out, and yet, it works.

ChiriVulpes commented 2 years ago

Is this still broken btw? This might have been fixed recently

milleniumbug commented 2 years ago

I think it still is, gonna check out after work.

npx gulp build is how I try running it btw.

milleniumbug commented 2 years ago

Building from scratch on Windows (so to eliminate of possibility of Linux-specific problems you don't have)

Your environment has been set up for using Node.js 16.15.1 (x64) and npm.

image

I made an experiment on how I can modify the content of win-unpacked so it runs. So basically, two things:

Conclusion: the problem still appears, in addition to a new one.

ChiriVulpes commented 2 years ago

Try now (on linux, I can confirm it works on windows)

milleniumbug commented 2 years ago

Can confirm that I can build a Windows executable from Linux, so that's good.