Skip to content

Commit

Permalink
feat: add slider before-after
Browse files Browse the repository at this point in the history
  • Loading branch information
UrijHoruzij committed Jan 12, 2023
1 parent 9bb7d0e commit 4333f81
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 38 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<p align="center">
<img src="./assets/logo.svg" alt="Super resolution logo" width="128" height="128">
<h1 align="center">Super resolution</h1>
</p>
<p align="center">
<a aria-label="GitHub release" href="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/UrijHoruzij/super-resolution/">
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/UrijHoruzij/super-resolution?color=62c089">
</a>
<a aria-label="License" href="https://github.com/UrijHoruzij/super-resolution/blob/master/LICENSE">
<img alt="GitHub" src="https://img.shields.io/github/license/UrijHoruzij/super-resolution?color=62c089">
</a>
</p>

## License

Super resolution is released under the [MIT License](https://github.com/UrijHoruzij/super-resolution/blob/master/LICENSE).
11 changes: 11 additions & 0 deletions assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions electron-builder.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"productName": "Super resolution",
"appId": "org.upscayl.superresolution",
"copyright": "Copyright © 2023 ${author}",
"artifactName": "${name}-${version}-${os}.${ext}",
"asar": true,
"extraFiles": [
Expand Down
23 changes: 13 additions & 10 deletions main/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ app.on('ready', async () => {
splashWindow = createWindow(
'splash',
{
icon: path.join(__dirname, '../resources/icon.png'),
width: 750,
height: 500,
show: false,
center: true,
frame: false,
resizable: false,
title: 'Super resolution',
backgroundColor: '#171918',
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
},
true,
);
splashWindow.on('ready-to-show', () => {
splashWindow.once('ready-to-show', () => {
splashWindow.show();
});
if (isDev) {
Expand All @@ -64,11 +65,12 @@ app.on('ready', async () => {
}

mainWindow = createWindow('main', {
// icon: join(__dirname, '../resources/icon.png'),
icon: path.join(__dirname, '../resources/icon.png'),
width: 1000,
height: 600,
show: false,
frame: false,
backgroundColor: '#171918',
webPreferences: {
nodeIntegration: true,
webSecurity: false,
Expand All @@ -77,11 +79,11 @@ app.on('ready', async () => {
});
// mainWindow.webContents.openDevTools();
mainWindow.removeMenu();
mainWindow.on('ready-to-show', () => {
mainWindow.once('ready-to-show', () => {
setTimeout(() => {
splashWindow.close();
mainWindow.show();
}, 1000);
}, 4000);
});
if (isDev) {
await mainWindow.loadURL(`http:https://localhost:3000/`);
Expand All @@ -92,12 +94,13 @@ app.on('ready', async () => {
autoUpdater.checkForUpdatesAndNotify();

ipcMain.on('upscayl', async () => {
const index = 0;
if (!flag && files.length > 0 && saveDirectory.length > 0) {
flag = true;
await upscayl(files[0], saveDirectory[0], mainWindow);
const fileName = path.parse(files[0]).name;
const fileExt = path.parse(files[0]).ext;
const outFile = `${saveDirectory[0]}/${fileName}_upscayl${fileExt}`;
for (const file of files) {
await upscayl(file, saveDirectory[0], mainWindow, index);
index++;
}
flag = false;
}
});
Expand All @@ -124,7 +127,7 @@ app.on('ready', async () => {
ipcMain.on('open-files', async (e) => {
const { filePaths } = await dialog.showOpenDialog({
filters: [{ name: 'Изображения', extensions: ['jpg', 'png', 'gif'] }],
properties: ['openFile', 'multiSelections'],
properties: ['openFile'],
});
files = [...filePaths];
const filesPathsPosix = filePaths.map((file) => file.split(path.sep).join(path.posix.sep));
Expand Down
9 changes: 7 additions & 2 deletions main/helpers/upscayl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs');
const path = require('path');
const { modelsPath, execPath } = require('./binaries');

const upscayl = (inputDir, outputDir, mainWindow) => {
const upscayl = (inputDir, outputDir, mainWindow, index) => {
mainWindow.setProgressBar(0.01);
let failed = false;
let outFile = '';
Expand All @@ -29,6 +29,7 @@ const upscayl = (inputDir, outputDir, mainWindow) => {
if (percentString.length) {
let percent = parseFloat(percentString[0].slice(0, -1)) / 100;
mainWindow.setProgressBar(percent);
mainWindow.webContents.send('upscayl-progress', percent * 100);
}
if (data.includes('invalid gpu') || data.includes('failed')) {
mainWindow.setProgressBar(-1);
Expand All @@ -45,7 +46,11 @@ const upscayl = (inputDir, outputDir, mainWindow) => {
});
upscayl.on('close', (code) => {
mainWindow.setProgressBar(-1);
if (failed) {
if (!failed) {
const out = outFile.split(path.sep).join(path.posix.sep);
mainWindow.webContents.send('upscayl-done', { after: out, index });
} else {
mainWindow.webContents.send('upscayl-error');
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"electron-settings": "^4.0.2",
"electron-store": "^8.1.0",
"electron-updater": "^5.2.1",
"ui-forest": "^1.11.1"
"ui-forest": "^1.11.4"
},
"devDependencies": {
"@commitlint/cli": "^17.0.0",
Expand Down
Binary file removed public/images/logo.png
Binary file not shown.
Binary file modified public/images/splash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resources/icon.ico
Binary file not shown.
Binary file added resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/Splash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Splash = (props) => {
<div className={styles.splash}>
<div className={styles.wrapper}>
<div className={styles.logo}>
<Image src={logo} alt={messages.splash.title} width={72} height={72} />
<Image src={logo} priority alt={messages.splash.title} width={72} height={72} />
<div className={styles.name}>{messages.splash.title}</div>
</div>
<div className={styles.copyright}>
Expand Down
18 changes: 16 additions & 2 deletions src/pages/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { Button } from 'ui-forest';
function Settings() {
const [messages, changeLang, lang, setLang] = useContext(LangContext);
const [updateStatus, setUpdateStatus] = useState(null);
const [downloadProgress, setDownloadProgress] = useState(0);
const [bytesPerSecond, setbytesPerSecond] = useState(0);

const firstUpdate = useRef(true);
const toggleLang = (e) => {
changeLang(e.target.value);
Expand Down Expand Up @@ -45,8 +48,12 @@ function Settings() {
}
};
useEffect(() => {
window.electron.on('update-status', (event, status) => {
window.electron.on('update-status', ({ status, bytesPerSecond, percent, totalevent }) => {
setUpdateStatus(status);
if (status === 'download-progress') {
setDownloadProgress(percent);
setbytesPerSecond(bytesPerSecond);
}
});
});
return (
Expand All @@ -70,7 +77,14 @@ function Settings() {
<td></td>
</tr>
<tr>
<td>{updateMessages()}</td>
<td>
{updateMessages()}
{updateStatus === 'download-progress' ? (
<div>
{bytesPerSecond / 1024}kB/s-{downloadProgress}%
</div>
) : null}
</td>
<td>
{updateStatus === 'update-downloaded' ? (
<Button onClick={updateClick}>{messages.settings.autoUpdater.updateBtn}</Button>
Expand Down
73 changes: 55 additions & 18 deletions src/pages/superResolution.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useEffect, useState, useContext } from 'react';
import { useEffect, useState, useContext } from 'react';
import Head from 'next/head';
import { Button, SliderBeforeAfter } from 'ui-forest';
import { Header, Sidebar, Main, LangContext } from '../components';
import Image from 'next/image';

const superResolutionPage = () => {
const [messages] = useContext(LangContext);
const [images, setImages] = useState([]);
const [outImages, setOutImages] = useState([]);
const [progress, setProgress] = useState(0);
const superResolution = () => {
setProgress(1);
window.electron.send('upscayl');
};
const openFile = () => {
Expand All @@ -19,30 +19,67 @@ const superResolutionPage = () => {
};
useEffect(() => {
window.electron.on('open-files', (event, files) => {
setImages(files);
setImages(
files.map((file) => {
return {
before: file,
};
}),
);
});
window.electron.on('upscayl-done', (event, upscaylImg) => {
setImages(
images.map((image, i) => {
if (i === upscaylImg.index) {
return {
before: image.before,
after: upscaylImg.after,
};
}
return {
before: image.before,
};
}),
);
setProgress(0);
});
window.electron.on('upscayl-error', (event) => {});

window.electron.on('upscayl-progress', (event, percent) => {
setProgress(percent);
});
});

const progressRender = () => {
if (progress > 0) {
return { filter: 'blur(8px)' };
} else {
return {};
}
};
return (
<>
<Head />
<Header title={messages.upscayl.title} />
<Sidebar />
<Main>
{images
? images.map((image, index) => {
return (
<SliderBeforeAfter
key={index}
width={400}
height={250}
urlSecondImage=""
urlFirstImage={image}></SliderBeforeAfter>
);

return <Image key={index} alt={index} width={150} height={150} src={image} />;
})
: null}
<div style={progressRender()}>
{images
? images.map((image, index) => {
if (image.after) {
return (
<SliderBeforeAfter
key={index}
size={250}
urlFirstImage={image.before}
urlSecondImage={image.after}></SliderBeforeAfter>
);
} else {
return <SliderBeforeAfter key={index} size={250} urlFirstImage={image.before}></SliderBeforeAfter>;
}
})
: null}
</div>
<Button onClick={openFile}>{messages.upscayl.openFile}</Button>
<Button onClick={openDirectory}>{messages.upscayl.openDirectory}</Button>
<Button onClick={superResolution}>{messages.upscayl.upscayle}</Button>
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4648,10 +4648,10 @@ typescript@^4.6.4:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.4.tgz#a2a3d2756c079abda241d75f149df9d561091e78"
integrity sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==

ui-forest@^1.11.1:
version "1.11.1"
resolved "https://registry.yarnpkg.com/ui-forest/-/ui-forest-1.11.1.tgz#663390935286d7f52c60d3250c9ac7b6711b753f"
integrity sha512-37nZBwMKwSsuh3t85oJexG8tv6G7XQfIrHL7IxKm1ty2/yfPY8PC1JcUpw/g5TquhDVWxdJNmd9awHm747roEA==
ui-forest@^1.11.4:
version "1.11.4"
resolved "https://registry.yarnpkg.com/ui-forest/-/ui-forest-1.11.4.tgz#59572aef7386503740645f83a1fab3d297323d5e"
integrity sha512-6mik6+hZJQoSvkhlDOPMDYtKMwNXAsTunr6Mlr97q8UscjT32hdTKqXtXgUXlehrDA39nE79F9vwhnD4TjPzow==
dependencies:
classnames "^2.3.1"
normalize.css "^8.0.1"
Expand Down

0 comments on commit 4333f81

Please sign in to comment.