diff --git a/main/index.js b/main/index.js index c784f12..36e9fbe 100644 --- a/main/index.js +++ b/main/index.js @@ -1,7 +1,7 @@ // Native const { join } = require("path"); const { format } = require("url"); -const { spawn } = require("child_process"); +const { spawn, spawnSync, execFile } = require("child_process"); const fs = require("fs"); const { execPath, modelsPath } = require("./binaries"); @@ -51,7 +51,7 @@ ipcMain.on("sendMessage", (_, message) => { console.log(message); }); -ipcMain.on("open", async () => { +ipcMain.on("open", async (command, payload) => { const { canceled, filePaths } = await dialog.showOpenDialog({ properties: ["openFile", "multiSelections"], }); @@ -78,7 +78,7 @@ ipcMain.on("open", async () => { }); // UPSCALE - let upscayl = spawn( + let upscayl = execFile( execPath, [ "-i", @@ -94,12 +94,15 @@ ipcMain.on("open", async () => { ], { cwd: null, - detached: false, + detached: true, + //stdio: 'ignore', } ); - upscayl.stdout.on("data", (stdout) => { - console.log("UPSCAYL: ", stdout.toString()); + //upscayl.unref() + upscayl.stdout.on('data', (stdout) => { + console.log("SOME SAMPLE OUTPUT") // TODO: SEND THE STDOUT TO RENDERER FROM HERE + command.sender.send("stdout", "this is not working") }); upscayl.stderr.on("data", (stderr) => { @@ -108,6 +111,7 @@ ipcMain.on("open", async () => { upscayl.on("close", (code) => { console.log("Done upscaling", code); + command.sender.send("stdout", "gelbana") }); return filePaths[0]; diff --git a/main/preload.js b/main/preload.js index 6bb2fab..6043493 100644 --- a/main/preload.js +++ b/main/preload.js @@ -7,4 +7,10 @@ contextBridge.exposeInMainWorld("electron", { ipcRenderer.on(command, (event, args) => { func(...args); }), + startListen: (func) => { + ipcRenderer.addListener("stdout",func) + }, + stopListen: (func) => { + ipcRenderer.removeListener("stdout",func) + }, }); diff --git a/renderer/pages/index.jsx b/renderer/pages/index.jsx index 7ecc0a5..9fc7e12 100644 --- a/renderer/pages/index.jsx +++ b/renderer/pages/index.jsx @@ -5,6 +5,8 @@ const Home = () => { const [loaded, setLoaded] = useState(false); useEffect(() => { + const handleMessage = (_event, args) => console.log(args) + window.electron.startListen(handleMessage) // send(command, payload) window.electron.send("sendMessage", { message: "Hello!" }); setLoaded(true); @@ -12,6 +14,9 @@ const Home = () => { window.electron.on("done", () => { console.log("DONE"); }); + return () => { + window.electron.stopListen(handleMessage) + } }, []); const imageHandler = async () => { diff --git a/upscaled/to_upscale.png b/upscaled/to_upscale.png index 0e5d7eb..e73c526 100644 Binary files a/upscaled/to_upscale.png and b/upscaled/to_upscale.png differ