mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-13 20:48:12 +00:00
Basic external software download and run
This commit is contained in:
@ -1,5 +1,16 @@
|
|||||||
var commandExistsSync = require('command-exists').sync;
|
var commandExistsSync = require('command-exists').sync;
|
||||||
var app = require('electron').app;
|
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) => {
|
exports.getInstalledSoftware = (softwareList) => {
|
||||||
const installed = {};
|
const installed = {};
|
||||||
@ -19,12 +30,21 @@ exports.getInstalledSoftware = (softwareList) => {
|
|||||||
return installed;
|
return installed;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.install = (software) => {
|
ipcMain.on('installed-software-install', async function (event, software) {
|
||||||
var type = software.type;
|
const softwarePath = path.join(app.getAppPath(), software.binary);
|
||||||
|
|
||||||
if (type == 'web') {
|
|
||||||
|
|
||||||
|
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});
|
||||||
|
});
|
||||||
|
4
main.js
4
main.js
@ -6,6 +6,8 @@ const path = require('path');
|
|||||||
const url = require('url');
|
const url = require('url');
|
||||||
const yargs = require('yargs');
|
const yargs = require('yargs');
|
||||||
|
|
||||||
|
const { ipcMain } = require('electron')
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// 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.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
let mainWindow;
|
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
|
// 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.
|
// code. You can also put them in separate files and require them here.
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,6 +89,7 @@
|
|||||||
"karma-jasmine": "~2.0.1",
|
"karma-jasmine": "~2.0.1",
|
||||||
"karma-jasmine-html-reporter": "^1.4.0",
|
"karma-jasmine-html-reporter": "^1.4.0",
|
||||||
"license-checker": "^24.1.0",
|
"license-checker": "^24.1.0",
|
||||||
|
"node-fetch": "^2.3.0",
|
||||||
"node-sass": "^4.11.0",
|
"node-sass": "^4.11.0",
|
||||||
"popper.js": "^1.14.6",
|
"popper.js": "^1.14.6",
|
||||||
"prettier": "^1.15.2",
|
"prettier": "^1.15.2",
|
||||||
|
@ -21,9 +21,7 @@ export class InstalledSoftwareComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
install(software) {
|
install(software) {
|
||||||
this.installedSoftwareService.install({
|
this.installedSoftwareService.install(software);
|
||||||
type: 'web'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,14 +19,19 @@ export class InstalledSoftwareService {
|
|||||||
'SolarPuTTY.exe'
|
'SolarPuTTY.exe'
|
||||||
],
|
],
|
||||||
type: 'web',
|
type: 'web',
|
||||||
resource: 'exe',
|
resource: '.exe',
|
||||||
binary: 'SolarPuTTY.exe',
|
binary: 'SolarPuTTY.exe',
|
||||||
|
installation_arguments: ['--only-ask'],
|
||||||
installed: false
|
installed: false
|
||||||
}];
|
}];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private electronService: ElectronService
|
private electronService: ElectronService
|
||||||
) { }
|
) {
|
||||||
|
this.electronService.ipcRenderer.on('installed-software-installed', (event, data) => {
|
||||||
|
console.log("installed", data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
list() {
|
list() {
|
||||||
const installedSoftware = this.electronService.remote.require('./installed-software.js')
|
const installedSoftware = this.electronService.remote.require('./installed-software.js')
|
||||||
@ -39,8 +44,6 @@ export class InstalledSoftwareService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
install(software) {
|
install(software) {
|
||||||
const installedSoftware = this.electronService.remote.require('./installed-software.js')
|
this.electronService.ipcRenderer.send('installed-software-install', software);
|
||||||
.install(software);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user