Move definition of external software to separate file

This commit is contained in:
ziajka 2019-01-23 16:08:08 +01:00
parent dc22510d30
commit c1bdce4fce
5 changed files with 114 additions and 32 deletions

View File

@ -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();
});
});

View 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 [];
}
}

View File

@ -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;
});

View 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();
});
});

View 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';
}
}