fix error, remove stuff, add stuff

This commit is contained in:
janis
2023-05-31 14:06:04 +02:00
parent bf4e85f6c1
commit 5099959082
6 changed files with 23 additions and 72 deletions

21
frontend/src/app.js Normal file
View File

@@ -0,0 +1,21 @@
const express = require( 'express' );
let app = express();
const path = require( 'path' );
const fs = require( 'fs' );
const bodyParser = require( 'body-parser' );
const exec = require( 'child_process' ).exec;
app.use( bodyParser.urlencoded( { extended: false } ) );
app.use( bodyParser.json() );
function execute(command, callback){
exec(command, function(error, stdout, stderr){ callback(stdout); });
};
app.get( '/api/getEngines', ( request, response ) => {
execute( 'ImageVideoUpscaler-cli -p', out => {
response.send( out );
} );
} );
app.listen( 8081 );

View File

@@ -3,63 +3,9 @@
import { app, protocol, BrowserWindow } from 'electron';
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer';
const electron = require( 'electron' );
const child_process = require( 'child_process' );
const dialog = electron.dialog;
const isDevelopment = process.env.NODE_ENV !== 'production';
// Src for run_script function: https://stackoverflow.com/a/57058495
// This function will output the lines from the script
// and will return the full combined output
// as well as exit code when it's done (using the callback).
function run_script(command, args, callback) {
var child = child_process.spawn(command, args, {
encoding: 'utf8',
shell: true
});
// You can also use a variable to save the output for when the script closes later
child.on('error', (error) => {
dialog.showMessageBox({
title: 'Title',
type: 'warning',
message: 'Error occured.\r\n' + error
});
});
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
//Here is the output
data=data.toString();
console.log(data);
});
child.stderr.setEncoding('utf8');
child.stderr.on('data', (data) => {
// Return some data to the renderer process with the mainprocess-response ID
mainWindow.webContents.send('mainprocess-response', data);
//Here is the output from the command
console.log(data);
});
child.on('close', (code) => {
//Here you can get the exit code of the script
switch (code) {
case 0:
dialog.showMessageBox({
title: 'Title',
type: 'info',
message: 'End process.\r\n'
});
break;
}
});
if (typeof callback === 'function')
callback();
}
require( './app.js' )
// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([

View File

@@ -6,12 +6,10 @@
</template>
<script>
import run_script from '@/background.js'
export default {
methods: {
run() {
run_script( 'ls' )
// run_script( 'ls' )
}
}
}