mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-21 02:01:19 +00:00
Move definition of external software to separate file
This commit is contained in:
parent
dc22510d30
commit
c1bdce4fce
@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ExternalSoftwareDefinitionService } from './external-software-definition.service';
|
||||
|
||||
describe('ExternalSoftwareDefinitionService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: ExternalSoftwareDefinitionService = TestBed.get(ExternalSoftwareDefinitionService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
59
src/app/services/external-software-definition.service.ts
Normal file
59
src/app/services/external-software-definition.service.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { PlatformService } from './platform.service';
|
||||
|
||||
@Injectable()
|
||||
export class ExternalSoftwareDefinitionService {
|
||||
|
||||
constructor(
|
||||
private platformService: PlatformService
|
||||
) { }
|
||||
|
||||
get() {
|
||||
if(this.platformService.isWindows()) {
|
||||
return this.getForWindows();
|
||||
}
|
||||
if(this.platformService.isDarwin()) {
|
||||
return this.getForDarwin();
|
||||
}
|
||||
return this.getForLinux();
|
||||
}
|
||||
|
||||
getForWindows() {
|
||||
const software = [{
|
||||
name: 'Wireshark',
|
||||
locations: [
|
||||
'C:\\Program Files\\Wireshark\\Wireshark.exe'
|
||||
],
|
||||
type: 'web',
|
||||
resource: 'https://1.na.dl.wireshark.org/win64/all-versions/Wireshark-win64-2.6.3.exe',
|
||||
binary: 'Wireshark.exe',
|
||||
sudo: true,
|
||||
installation_arguments: [],
|
||||
installed: false
|
||||
}
|
||||
];
|
||||
|
||||
const solarPutty = {
|
||||
name: 'SolarPuTTY',
|
||||
locations: [
|
||||
'SolarPuTTY.exe'
|
||||
],
|
||||
type: 'web',
|
||||
resource: '.exe',
|
||||
binary: 'SolarPuTTY.exe',
|
||||
sudo: false,
|
||||
installation_arguments: ['--only-ask'],
|
||||
installed: false
|
||||
};
|
||||
|
||||
return software;
|
||||
}
|
||||
|
||||
getForLinux() {
|
||||
return [];
|
||||
}
|
||||
|
||||
getForDarwin() {
|
||||
return [];
|
||||
}
|
||||
}
|
@ -1,44 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ElectronService } from 'ngx-electron';
|
||||
import { ExternalSoftwareDefinitionService } from './external-software-definition.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@Injectable()
|
||||
export class InstalledSoftwareService {
|
||||
private software = [{
|
||||
name: 'SolarPuTTY',
|
||||
locations: [
|
||||
'SolarPuTTY.exe'
|
||||
],
|
||||
type: 'web',
|
||||
resource: '.exe',
|
||||
binary: 'SolarPuTTY.exe',
|
||||
sudo: false,
|
||||
installation_arguments: ['--only-ask'],
|
||||
installed: false
|
||||
}, {
|
||||
name: 'Wireshark',
|
||||
locations: [
|
||||
'C:\\Program Files\\Wireshark\\Wireshark.exe'
|
||||
],
|
||||
type: 'web',
|
||||
resource: 'https://1.na.dl.wireshark.org/win64/all-versions/Wireshark-win64-2.6.3.exe',
|
||||
binary: 'Wireshark.exe',
|
||||
sudo: true,
|
||||
installation_arguments: [],
|
||||
installed: false
|
||||
}];
|
||||
|
||||
constructor(
|
||||
private electronService: ElectronService
|
||||
) {
|
||||
}
|
||||
private electronService: ElectronService,
|
||||
private externalSoftwareDefinition: ExternalSoftwareDefinitionService
|
||||
) { }
|
||||
|
||||
list() {
|
||||
const softwareDefinition = this.externalSoftwareDefinition.get();
|
||||
|
||||
const installedSoftware = this.electronService.remote.require('./installed-software.js')
|
||||
.getInstalledSoftware(this.software);
|
||||
.getInstalledSoftware(softwareDefinition);
|
||||
|
||||
return this.software.map((software) => {
|
||||
return softwareDefinition.map((software) => {
|
||||
software.installed = installedSoftware[software.name].length > 0;
|
||||
return software;
|
||||
});
|
||||
|
12
src/app/services/platform.service.spec.ts
Normal file
12
src/app/services/platform.service.spec.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { PlatformService } from './platform.service';
|
||||
|
||||
describe('PlatformService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: PlatformService = TestBed.get(PlatformService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
22
src/app/services/platform.service.ts
Normal file
22
src/app/services/platform.service.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ElectronService } from 'ngx-electron';
|
||||
|
||||
@Injectable()
|
||||
export class PlatformService {
|
||||
|
||||
constructor(
|
||||
private electronService: ElectronService
|
||||
) { }
|
||||
|
||||
isWindows() {
|
||||
return this.electronService.process.platform === 'win32';
|
||||
}
|
||||
|
||||
isLinux() {
|
||||
return this.electronService.process.platform === 'linux';
|
||||
}
|
||||
|
||||
isDarwin() {
|
||||
return this.electronService.process.platform === 'darwin';
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user