removed express backend & added new ipc

This commit is contained in:
2023-06-04 17:35:10 +02:00
parent b28d2dd68e
commit 8f7f6d71b7
11 changed files with 121 additions and 7275 deletions

View File

@@ -1,22 +0,0 @@
module.exports = {
packagerConfig: {},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {},
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
},
{
name: '@electron-forge/maker-deb',
config: {},
},
{
name: '@electron-forge/maker-rpm',
config: {},
},
],
};

File diff suppressed because it is too large Load Diff

View File

@@ -23,30 +23,19 @@
"electron:build": "vue-cli-service electron:build", "electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve", "electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps", "postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps", "postuninstall": "electron-builder install-app-deps"
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
}, },
"main": "background.js", "main": "background.js",
"dependencies": { "dependencies": {
"child_process": "^1.0.2", "child_process": "^1.0.2",
"core-js": "^3.8.3", "core-js": "^3.8.3",
"cors": "^2.8.5",
"electron-squirrel-startup": "^1.0.0", "electron-squirrel-startup": "^1.0.0",
"socket.io": "^4.6.2",
"socket.io-client": "^4.6.2",
"vue": "^3.2.13", "vue": "^3.2.13",
"vue-router": "^4.0.3" "vue-router": "^4.0.3"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.12.16", "@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16", "@babel/eslint-parser": "^7.12.16",
"@electron-forge/cli": "^6.1.1",
"@electron-forge/maker-deb": "^6.1.1",
"@electron-forge/maker-rpm": "^6.1.1",
"@electron-forge/maker-squirrel": "^6.1.1",
"@electron-forge/maker-zip": "^6.1.1",
"@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0", "@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-plugin-router": "~5.0.0", "@vue/cli-plugin-router": "~5.0.0",

View File

@@ -1,37 +1,11 @@
const express = require( 'express' ); module.exports = function ( win ) {
let app = express(); const dialog = require( 'electron' ).dialog;
const dialog = require( 'electron' ).dialog; const upscaling = require( './upscalingHandler.js' );
const cors = require( 'cors' ); const upscalingHandler = new upscaling();
const bodyParser = require( 'body-parser' ); const ipcMain = require( 'electron' ).ipcMain;
const exec = require( 'child_process' ).exec;
const upscaling = require( './upscalingHandler.js' );
const upscalingHandler = new upscaling();
const http = require( 'http' );
const server = require( 'socket.io' ).Server;
const Server = http.createServer( app );
const io = new server( Server, { ipcMain.on( 'selectInputFile', ( event, data ) => {
cors: { event.reply( 'selectInputFile', { 'data': dialog.showOpenDialogSync( {
origin: 'http://localhost:8080'
}
} );
app.use( bodyParser.urlencoded( { extended: false } ) );
app.use( bodyParser.json() );
app.use( cors() );
io.on( 'connection', ( socket ) => {
console.log( 'connected' );
} )
app.get( '/api/getEngines', ( request, response ) => {
console.log( 'engines' );
response.send( { 'data': 'not finished yet' } );
} );
app.get( '/api/getInputFile', ( request, response ) => {
response.send( { 'data': dialog.showOpenDialogSync( {
properties: [ 'openFile' ], properties: [ 'openFile' ],
title: 'Select an input file to upscale', title: 'Select an input file to upscale',
filters: [ filters: [
@@ -40,10 +14,10 @@ app.get( '/api/getInputFile', ( request, response ) => {
{ name: 'All Files', extensions: ['*'] } { name: 'All Files', extensions: ['*'] }
] ]
} ) } ); } ) } );
} ); } );
app.get( '/api/getOutputFile', ( request, response ) => { ipcMain.on( 'selectOutputFile', ( event, data ) => {
response.send( { 'data': dialog.showSaveDialogSync( { event.reply( 'selectOutputFile', { 'data': dialog.showSaveDialogSync( {
properties: [ 'promptToCreate' ], properties: [ 'promptToCreate' ],
title: 'Select an output file', title: 'Select an output file',
filters: [ filters: [
@@ -52,16 +26,15 @@ app.get( '/api/getOutputFile', ( request, response ) => {
{ name: 'All Files', extensions: ['*'] } { name: 'All Files', extensions: ['*'] }
] ]
} ) } ); } ) } );
} ); } );
app.post( '/api/startUpscaling', ( request, response ) => { ipcMain.on( 'startUpscaling', ( event, data ) => {
let checks = upscalingHandler.verifyDataIntegrity( request.body ); let checks = upscalingHandler.verifyDataIntegrity( JSON.parse( data ), ipcMain );
if ( checks[ 0 ] ) { if ( checks[ 0 ] ) {
response.send( { 'data': checks[ 1 ] } ); event.reply( 'startUpscaling', { 'data': checks[ 1 ] } );
upscalingHandler.upscale( request.body, io ); upscalingHandler.upscale( JSON.parse( data ), win );
} else { } else {
response.send( { 'data': checks[ 1 ] } ); event.reply( 'startUpscaling', { 'data': checks[ 1 ] } );
} }
} ); } );
}
Server.listen( 49369 );

View File

@@ -4,8 +4,8 @@ import { app, protocol, BrowserWindow } from 'electron';
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'; import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer'; import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer';
const isDevelopment = process.env.NODE_ENV !== 'production'; const isDevelopment = process.env.NODE_ENV !== 'production';
const path = require( 'path' );
require( './app.js' )
// Scheme must be registered before the app is ready // Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([ protocol.registerSchemesAsPrivileged([
@@ -22,7 +22,7 @@ async function createWindow() {
// Use pluginOptions.nodeIntegration, leave this alone // Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION, nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
} }
}) })
@@ -35,6 +35,7 @@ async function createWindow() {
// Load the index.html when not in development // Load the index.html when not in development
win.loadURL('app://./index.html') win.loadURL('app://./index.html')
} }
require( './app.js' )( win );
} }
// Quit when all windows are closed. // Quit when all windows are closed.

View File

@@ -1,29 +0,0 @@
import { reactive } from "vue";
import { io } from "socket.io-client";
export const state = reactive({
connected: false,
fooEvents: [],
barEvents: []
});
// "undefined" means the URL will be computed from the `window.location` object
const URL = process.env.NODE_ENV === "production" ? undefined : "http://localhost:49369";
export const socket = io(URL);
socket.on("connect", () => {
state.connected = true;
});
socket.on("disconnect", () => {
state.connected = false;
});
socket.on("foo", (...args) => {
state.fooEvents.push(args);
});
socket.on("bar", (...args) => {
state.barEvents.push(args);
});

View File

@@ -17,7 +17,7 @@ class UpscalingHandler {
this.os = process.platform this.os = process.platform
} }
upscale( options, io ) { upscale( options, win ) {
// required options: engine, algorithm, scale, sharpening, InputFile & OutputFile // required options: engine, algorithm, scale, sharpening, InputFile & OutputFile
// Options is an object! // Options is an object!
@@ -46,7 +46,7 @@ class UpscalingHandler {
child.stdout.on( 'data', data => { child.stdout.on( 'data', data => {
console.log( '' + data ); console.log( '' + data );
io.emit( 'progress', '\n' + data ); win.send( 'progress', '\n' + data );
} ); } );
child.stderr.on( 'data', ( data ) => { child.stderr.on( 'data', ( data ) => {

View File

@@ -28,7 +28,7 @@
<div class="output-box-wrapper"> <div class="output-box-wrapper">
<p id="cmd" @click="showCmdOutput()">Command output</p> <p id="cmd" @click="showCmdOutput()">Command output</p>
<div class="output-box" v-html="output" id="output"> <div class="output-box" id="output" v-html="output">
</div> </div>
</div> </div>
@@ -65,7 +65,7 @@
</template> </template>
<script> <script>
import { socket } from "@/socket"; import { ipcRenderer } from 'electron';
export default { export default {
name: 'HomeView', name: 'HomeView',
@@ -79,42 +79,33 @@ export default {
}, },
methods: { methods: {
runCommand ( command ) { runCommand ( command ) {
fetch( 'http://127.0.0.1:49369/api/get' + command ).then( res => { ipcRenderer.send( 'select' + command );
res.json().then( data => { ipcRenderer.on( 'select' + command, ( event, data ) => {
this.upscaleSettings[ command ] = data[ 'data' ]; this.upscaleSettings[ command ] = data[ 'data' ];
} ).catch( error => {
console.log( error );
} );
} ); } );
}, },
start() { start() {
let fetchOptions = { this.output = '';
method: 'post', ipcRenderer.send( 'startUpscaling', JSON.stringify ( this.upscaleSettings ) );
body: JSON.stringify( this.upscaleSettings ), ipcRenderer.on( 'startUpscaling', ( event, data ) => {
headers: {
'Content-Type': 'application/json',
'charset': 'utf-8'
},
}
fetch( 'http://127.0.0.1:49369/api/startUpscaling', fetchOptions ).then( res => {
res.json().then( data => {
console.log( this.upscaleSettings );
if ( data.data == 'upscaling' ) { if ( data.data == 'upscaling' ) {
try {
document.getElementById( 'processing' ).showModal(); document.getElementById( 'processing' ).showModal();
} catch ( error ) {
console.log( error );
}
} else if ( data.data == 'dataMissing' ) { } else if ( data.data == 'dataMissing' ) {
document.getElementById( 'wrong' ).showModal(); document.getElementById( 'wrong' ).showModal();
} else { } else {
document.getElementById( 'fileExtension' ).showModal(); document.getElementById( 'fileExtension' ).showModal();
} }
} ).catch( error => {
console.log( error );
} )
} ); } );
this.output = '';
socket.on( 'progress', ( ...args) => { let self = this;
this.output += args + '<br>';
} ) ipcRenderer.on( 'progress', function ( evt, message ) {
self.output += message;
});
}, },
showCmdOutput () { showCmdOutput () {
document.getElementById( 'output' ).classList.toggle( 'shown' ); document.getElementById( 'output' ).classList.toggle( 'shown' );
@@ -125,12 +116,6 @@ export default {
this.fixed = true; this.fixed = true;
} }
}, },
created() {
socket.connect();
},
deactivated() {
socket.disconnect();
}
} }
</script> </script>

View File

@@ -1,4 +1,7 @@
const { defineConfig } = require('@vue/cli-service') module.exports = {
module.exports = defineConfig({ pluginOptions: {
transpileDependencies: true electronBuilder: {
}) nodeIntegration: true
}
}
}

0
packaging/startTesting.sh Normal file → Executable file
View File

2
packaging/stopTesting.sh Normal file → Executable file
View File

@@ -4,12 +4,12 @@ cd ../frontend
rm -rf ./bin rm -rf ./bin
rm -rf ./config rm -rf ./config
rm -rf ./lib-dynload
rm -rf ./libdynload rm -rf ./libdynload
rm ./image* rm ./image*
rm ./lib* rm ./lib*
rm ./ld* rm ./ld*
rm ./base_library.zip rm ./base_library.zip
rm ./imagevideoupscaler-cli.py
rm ./LICENSE rm ./LICENSE
cd .. cd ..