diff --git a/installed-software.js b/installed-software.js index 9a314e77..e9458c49 100644 --- a/installed-software.js +++ b/installed-software.js @@ -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()); -} \ No newline at end of file + const command = `${softwarePath}`; + const child = spawn(command, software.installation_arguments); + child.on('exit', () => { + console.log("exited"); + }); + event.sender.send('installed-software-installed', { success: true}); +}); diff --git a/main.js b/main.js index 44bb7ab5..74f42f20 100644 --- a/main.js +++ b/main.js @@ -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. - - diff --git a/package.json b/package.json index 27de9ca2..b36377e1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/app/components/installed-software/installed-software.component.ts b/src/app/components/installed-software/installed-software.component.ts index cf365156..3dcc9bff 100644 --- a/src/app/components/installed-software/installed-software.component.ts +++ b/src/app/components/installed-software/installed-software.component.ts @@ -21,9 +21,7 @@ export class InstalledSoftwareComponent implements OnInit { } install(software) { - this.installedSoftwareService.install({ - type: 'web' - }); + this.installedSoftwareService.install(software); } } diff --git a/src/app/services/installed-software.service.ts b/src/app/services/installed-software.service.ts index feb4e243..686993f0 100644 --- a/src/app/services/installed-software.service.ts +++ b/src/app/services/installed-software.service.ts @@ -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); } }