From 3e5a055f7f7b92f714cf3c19139267f3e6c64fe5 Mon Sep 17 00:00:00 2001 From: Feenix <25067102+NayamAmarshe@users.noreply.github.com> Date: Tue, 23 Aug 2022 19:37:40 +0530 Subject: [PATCH] Broken exec --- main/binaries.js | 11 +++++------ main/index.js | 6 +++++- package.json | 8 +++++--- yarn.lock | 5 +++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/main/binaries.js b/main/binaries.js index 92c9e79..9bf74ee 100644 --- a/main/binaries.js +++ b/main/binaries.js @@ -1,14 +1,13 @@ +const { join, dirname } = require("path"); const path = require("path"); -const { rootPath } = require("electron-root-path"); -const { isPackaged } = require("electron-is-packaged"); const { getPlatform } = require("./getPlatform"); +const appRootDir = require("app-root-dir"); const IS_PROD = process.env.NODE_ENV === "production"; -const binariesPath = - IS_PROD && isPackaged // the path to a bundled electron app. - ? path.join(rootPath, "./Contents", "./Resources", "./bin") - : path.join(rootPath, "./resources", getPlatform(), "./bin"); +const binariesPath = IS_PROD + ? join(dirname(appRootDir.get()), "..", "Resources", "bin") + : join(appRootDir.get(), "resources", getPlatform(), "bin"); const execPath = path.resolve(path.join(binariesPath, "./upscayl")); const modelsPath = path.resolve(path.join(binariesPath, "./models")); diff --git a/main/index.js b/main/index.js index 1c5e084..979ded2 100644 --- a/main/index.js +++ b/main/index.js @@ -1,10 +1,11 @@ // Native -const { join, parse } = require("path"); +const { join, parse, dirname } = require("path"); const { format } = require("url"); const { spawn } = require("child_process"); const fs = require("fs"); const sizeOf = require("image-size"); const { autoUpdater } = require("electron-updater"); +const appRootDir = require("app-root-dir"); const { execPath, modelsPath } = require("./binaries"); @@ -21,11 +22,13 @@ const isDev = require("electron-is-dev"); const prepareNext = require("electron-next"); const commands = require("./commands"); const sharp = require("sharp"); +const { getPlatform } = require("./getPlatform"); // Prepare the renderer once the app is ready let mainWindow; app.on("ready", async () => { await prepareNext("./renderer"); + console.log("PATH: ", join(dirname(appRootDir.get()), "Resources", "bin")); mainWindow = new BrowserWindow({ width: 1100, @@ -108,6 +111,7 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => { const fileExt = parse(fullfileName).ext; // UPSCALE + console.log("EXEC: ", execPath); let upscayl = spawn( execPath, [ diff --git a/package.json b/package.json index c292e79..870bafe 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "start": "electron .", "build": "next build renderer && next export renderer", "pack-app": "npm run build && electron-builder --dir", - "dist": "npm run build && electron-builder -l --publish always" + "dist": "npm run build && electron-builder", + "publish": "GH_TOKEN=<> npm run build && electron-builder -l --publish always" }, "build": { "productName": "Upscayl", @@ -48,8 +49,8 @@ ] }, { - "from": "resources", - "to": "resources", + "from": "resources/${os}/bin", + "to": "resources/Resources/bin", "filter": [ "**/*" ] @@ -84,6 +85,7 @@ "tailwindcss": "^3.1.8" }, "dependencies": { + "app-root-dir": "^1.0.2", "electron-is-dev": "^2.0.0", "electron-is-packaged": "^1.0.2", "electron-next": "^3.1.5", diff --git a/yarn.lock b/yarn.lock index b91a491..db8a75d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -360,6 +360,11 @@ app-builder-lib@23.3.3: tar "^6.1.11" temp-file "^3.4.0" +app-root-dir@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/app-root-dir/-/app-root-dir-1.0.2.tgz#38187ec2dea7577fff033ffcb12172692ff6e118" + integrity sha512-jlpIfsOoNoafl92Sz//64uQHGSyMrD2vYG5d8o2a4qGvyNCvXur7bzIsWtAC/6flI2RYAp3kv8rsfBtaLm7w0g== + app-root-path@>=2.0.1: version "3.0.0" resolved "https://registry.npmjs.org/app-root-path/-/app-root-path-3.0.0.tgz"