Basic list of installed software

This commit is contained in:
ziajka 2019-01-09 13:45:37 +01:00
parent 77a47e8fd2
commit c1b76d8d4d
7 changed files with 79 additions and 25 deletions

View File

@ -13,6 +13,7 @@ files:
- main.js
- renderer.js
- sentry.js
- installed-software.js
- package.json
mac:

20
installed-software.js Normal file
View File

@ -0,0 +1,20 @@
var commandExistsSync = require('command-exists').sync;
exports.getInstalledSoftware = (softwareList) => {
const installed = {};
for(var software of softwareList) {
var name = software.name;
var commands = software.commands;
installed[name] = [];
for(var command of commands) {
var exists = commandExistsSync(command);
if(exists) {
installed[name].push(command);
}
}
}
return installed;
}

View File

@ -51,6 +51,7 @@
"angular2-hotkeys": "^2.1.4",
"angular2-indexeddb": "^1.2.3",
"bootstrap": "4.2.1",
"command-exists": "^1.2.8",
"core-js": "^2.6.1",
"css-tree": "^1.0.0-alpha.29",
"d3-ng2-service": "^2.1.0",

View File

@ -3,34 +3,20 @@
<h1>Installed software</h1>
</div>
<div class="default-content">
<!-- <div class="example-container mat-elevation-z8">
<div class="example-container mat-elevation-z8">
<mat-table #table [dataSource]="dataSource">
<ng-container matColumnDef="id">
<mat-header-cell *matHeaderCellDef> ID </mat-header-cell>
<mat-cell *matCellDef="let row;"> {{row.id}} </mat-cell>
</ng-container>
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
<mat-cell *matCellDef="let row;"> <a [routerLink]="['/server', row.id, 'projects']" class="table-link">{{row.name}}</a></mat-cell>
</ng-container>
<ng-container matColumnDef="ip">
<mat-header-cell *matHeaderCellDef> IP </mat-header-cell>
<mat-cell *matCellDef="let row;"> {{row.ip}} </mat-cell>
</ng-container>
<ng-container matColumnDef="port">
<mat-header-cell *matHeaderCellDef> Port </mat-header-cell>
<mat-cell *matCellDef="let row;"> {{row.port}} </mat-cell>
<mat-cell *matCellDef="let row;">{{ row.name }}</mat-cell>
</ng-container>
<ng-container matColumnDef="actions">
<mat-header-cell *matHeaderCellDef> Actions </mat-header-cell>
<mat-header-cell *matHeaderCellDef></mat-header-cell>
<mat-cell *matCellDef="let row;" style="text-align: right">
<button mat-icon-button (click)="deleteServer(row)">
<mat-icon aria-label="Remove server">delete</mat-icon>
<button mat-button color="primary" (click)="install(row)" disabled="row.installed">
<ng-container *ngIf="row.installed">Installed</ng-container>
<ng-container *ngIf="!row.installed">Install</ng-container>
</button>
</mat-cell>
</ng-container>
@ -40,9 +26,6 @@
</mat-table>
</div>
<div class="buttons-bar">
<button mat-raised-button color="primary" (click)="createModal()">Add server</button>
</div> -->
</div>
</div>

View File

@ -1,4 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { InstalledSoftwareService } from '../../services/installed-software.service';
import { DataSource } from '@angular/cdk/table';
import { Observable, of } from 'rxjs';
@Component({
selector: 'app-installed-software',
@ -6,10 +9,29 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./installed-software.component.scss']
})
export class InstalledSoftwareComponent implements OnInit {
dataSource: InstalledSoftwareDataSource;
displayedColumns = ['name', 'actions'];
constructor() { }
constructor(
private installedSoftwareService: InstalledSoftwareService
) { }
ngOnInit() {
this.dataSource = new InstalledSoftwareDataSource(this.installedSoftwareService);
}
}
export class InstalledSoftwareDataSource extends DataSource<any> {
constructor(private installedSoftwareService: InstalledSoftwareService) {
super();
}
connect(): Observable<any[]> {
const installed = this.installedSoftwareService.list();
return of(installed);
}
disconnect() {}
}

View File

@ -1,9 +1,31 @@
import { Injectable } from '@angular/core';
import { ElectronService } from 'ngx-electron';
@Injectable({
providedIn: 'root'
})
export class InstalledSoftwareService {
private software = [{
name: 'ls',
commands: ['ls']
}, {
name: 'telnet',
commands: ['telnet']
}]
constructor() { }
constructor(
private electronService: ElectronService
) { }
list() {
const installedSoftware = this.electronService.remote.require('./installed-software.js')
.getInstalledSoftware(this.software);
return this.software.map((software) => {
return {
name: software.name,
installed: installedSoftware[software.name].length > 0
}
});
}
}

View File

@ -2061,6 +2061,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"
command-exists@^1.2.8:
version "1.2.8"
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.8.tgz#715acefdd1223b9c9b37110a149c6392c2852291"
integrity sha512-PM54PkseWbiiD/mMsbvW351/u+dafwTJ0ye2qB60G1aGQP9j3xK2gmMDc+R34L3nDtx4qMCitXT75mkbkGJDLw==
commander@2, commander@^2.12.1:
version "2.19.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"