Basic external software download and run

This commit is contained in:
ziajka 2019-01-11 13:51:23 +01:00
parent 25e137a488
commit c3e70e7800
5 changed files with 38 additions and 16 deletions

View File

@ -1,5 +1,16 @@
var commandExistsSync = require('command-exists').sync;
var app = require('electron').app;
var fs = require('fs');
var util = require('util');
var fetch = require('node-fetch')
var stream = require('stream');
var path = require('path');
const { spawn } = require('child_process');
const { ipcMain } = require('electron')
var pipeline = util.promisify(stream.pipeline);
exports.getInstalledSoftware = (softwareList) => {
const installed = {};
@ -19,12 +30,21 @@ exports.getInstalledSoftware = (softwareList) => {
return installed;
}
exports.install = (software) => {
var type = software.type;
if (type == 'web') {
ipcMain.on('installed-software-install', async function (event, software) {
const softwarePath = path.join(app.getAppPath(), software.binary);
if (software.type == 'web') {
var response = await fetch(software.resource);
await pipeline(
response.body,
fs.createWriteStream(softwarePath)
);
}
console.log(app.getAppPath());
}
const command = `${softwarePath}`;
const child = spawn(command, software.installation_arguments);
child.on('exit', () => {
console.log("exited");
});
event.sender.send('installed-software-installed', { success: true});
});

View File

@ -6,6 +6,8 @@ const path = require('path');
const url = require('url');
const yargs = require('yargs');
const { ipcMain } = require('electron')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
@ -141,5 +143,3 @@ app.on('activate', function () {
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

View File

@ -89,6 +89,7 @@
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"license-checker": "^24.1.0",
"node-fetch": "^2.3.0",
"node-sass": "^4.11.0",
"popper.js": "^1.14.6",
"prettier": "^1.15.2",

View File

@ -21,9 +21,7 @@ export class InstalledSoftwareComponent implements OnInit {
}
install(software) {
this.installedSoftwareService.install({
type: 'web'
});
this.installedSoftwareService.install(software);
}
}

View File

@ -19,14 +19,19 @@ export class InstalledSoftwareService {
'SolarPuTTY.exe'
],
type: 'web',
resource: 'exe',
resource: '.exe',
binary: 'SolarPuTTY.exe',
installation_arguments: ['--only-ask'],
installed: false
}];
constructor(
private electronService: ElectronService
) { }
) {
this.electronService.ipcRenderer.on('installed-software-installed', (event, data) => {
console.log("installed", data);
});
}
list() {
const installedSoftware = this.electronService.remote.require('./installed-software.js')
@ -39,8 +44,6 @@ export class InstalledSoftwareService {
}
install(software) {
const installedSoftware = this.electronService.remote.require('./installed-software.js')
.install(software);
this.electronService.ipcRenderer.send('installed-software-install', software);
}
}