mirror of
https://github.com/upscayl/upscayl.git
synced 2025-02-25 22:47:59 +01:00
Refactor code and add upscayl kill
This commit is contained in:
parent
4621b07d0c
commit
72e2788a8b
@ -449,6 +449,7 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
|||||||
mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString());
|
mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString());
|
||||||
if (data.includes("invalid gpu") || data.includes("failed")) {
|
if (data.includes("invalid gpu") || data.includes("failed")) {
|
||||||
logit("❌ INVALID GPU OR FAILED");
|
logit("❌ INVALID GPU OR FAILED");
|
||||||
|
upscayl.kill();
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
if (data.includes("has alpha channel")) {
|
if (data.includes("has alpha channel")) {
|
||||||
@ -460,6 +461,7 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
|||||||
if (!mainWindow) return;
|
if (!mainWindow) return;
|
||||||
mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString());
|
mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString());
|
||||||
failed = true;
|
failed = true;
|
||||||
|
upscayl.kill();
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
const onClose = async () => {
|
const onClose = async () => {
|
||||||
@ -647,6 +649,7 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
|
|||||||
mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data);
|
mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data);
|
||||||
// IF PROGRESS HAS ERROR, UPSCAYL FAILED
|
// IF PROGRESS HAS ERROR, UPSCAYL FAILED
|
||||||
if (data.includes("invalid gpu") || data.includes("failed")) {
|
if (data.includes("invalid gpu") || data.includes("failed")) {
|
||||||
|
upscayl.kill();
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
if (data.includes("has alpha channel")) {
|
if (data.includes("has alpha channel")) {
|
||||||
@ -661,28 +664,7 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
|
|||||||
mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data);
|
mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data);
|
||||||
// SET FAILED TO TRUE
|
// SET FAILED TO TRUE
|
||||||
failed = true;
|
failed = true;
|
||||||
return;
|
upscayl.kill();
|
||||||
};
|
|
||||||
|
|
||||||
const onData2 = (data) => {
|
|
||||||
if (!mainWindow) return;
|
|
||||||
// CONVERT DATA TO STRING
|
|
||||||
data = data.toString();
|
|
||||||
// SEND UPSCAYL PROGRESS TO RENDERER
|
|
||||||
mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data);
|
|
||||||
// IF PROGRESS HAS ERROR, UPSCAYL FAILED
|
|
||||||
if (data.includes("invalid gpu") || data.includes("failed")) {
|
|
||||||
failed2 = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onError2 = (data) => {
|
|
||||||
if (!mainWindow) return;
|
|
||||||
data.toString();
|
|
||||||
// SEND UPSCAYL PROGRESS TO RENDERER
|
|
||||||
mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data);
|
|
||||||
// SET FAILED TO TRUE
|
|
||||||
failed2 = true;
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -696,11 +678,11 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
|
|||||||
const newImage = await Jimp.read(isAlpha ? outFile + ".png" : outFile);
|
const newImage = await Jimp.read(isAlpha ? outFile + ".png" : outFile);
|
||||||
try {
|
try {
|
||||||
newImage
|
newImage
|
||||||
|
.quality(100 - quality)
|
||||||
.scaleToFit(
|
.scaleToFit(
|
||||||
originalImage.getWidth() * parseInt(payload.scale),
|
originalImage.getWidth() * parseInt(payload.scale),
|
||||||
originalImage.getHeight() * parseInt(payload.scale)
|
originalImage.getHeight() * parseInt(payload.scale)
|
||||||
)
|
)
|
||||||
.quality(100 - quality)
|
|
||||||
.write(isAlpha ? outFile + ".png" : outFile);
|
.write(isAlpha ? outFile + ".png" : outFile);
|
||||||
mainWindow.setProgressBar(-1);
|
mainWindow.setProgressBar(-1);
|
||||||
mainWindow.webContents.send(
|
mainWindow.webContents.send(
|
||||||
@ -740,8 +722,28 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
|
|||||||
|
|
||||||
childProcesses.push(upscayl2);
|
childProcesses.push(upscayl2);
|
||||||
|
|
||||||
upscayl2.process.stderr.on("data", onData2);
|
upscayl2.process.stderr.on("data", (data) => {
|
||||||
upscayl2.process.on("error", onError2);
|
if (!mainWindow) return;
|
||||||
|
// CONVERT DATA TO STRING
|
||||||
|
data = data.toString();
|
||||||
|
// SEND UPSCAYL PROGRESS TO RENDERER
|
||||||
|
mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data);
|
||||||
|
// IF PROGRESS HAS ERROR, UPSCAYL FAILED
|
||||||
|
if (data.includes("invalid gpu") || data.includes("failed")) {
|
||||||
|
upscayl2.kill();
|
||||||
|
failed2 = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
upscayl2.process.on("error", (data) => {
|
||||||
|
if (!mainWindow) return;
|
||||||
|
data.toString();
|
||||||
|
// SEND UPSCAYL PROGRESS TO RENDERER
|
||||||
|
mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data);
|
||||||
|
// SET FAILED TO TRUE
|
||||||
|
failed2 = true;
|
||||||
|
upscayl2.kill();
|
||||||
|
return;
|
||||||
|
});
|
||||||
upscayl2.process.on("close", onClose2);
|
upscayl2.process.on("close", onClose2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user