Improve control of installation

This commit is contained in:
ziajka
2019-01-14 14:07:42 +01:00
parent 157e3150b5
commit 6527554aa3
4 changed files with 24 additions and 20 deletions

View File

@ -59,9 +59,7 @@ ipcMain.on('installed-software-install', async function (event, software) {
message: error.message message: error.message
}); });
} }
} }
} }
let child; let child;
@ -74,16 +72,17 @@ ipcMain.on('installed-software-install', async function (event, software) {
} }
child.on('exit', () => { child.on('exit', () => {
console.log("exited"); event.sender.send(responseChannel, {
success: true
});
}); });
child.on('error', (err) => { child.on('error', (err) => {
console.log(err); event.sender.send(responseChannel, {
success: false,
message: err.message
});
}); });
child.stdin.end(); child.stdin.end();
event.sender.send(responseChannel, {
success: true
});
}); });

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Output, EventEmitter, Input, OnDestroy } from '@angular/core'; import { Component, OnInit, Output, EventEmitter, Input, OnDestroy, OnChanges } from '@angular/core';
import { ElectronService } from 'ngx-electron'; import { ElectronService } from 'ngx-electron';
@Component({ @Component({
@ -6,7 +6,7 @@ import { ElectronService } from 'ngx-electron';
templateUrl: './install-software.component.html', templateUrl: './install-software.component.html',
styleUrls: ['./install-software.component.scss'] styleUrls: ['./install-software.component.scss']
}) })
export class InstallSoftwareComponent implements OnInit, OnDestroy { export class InstallSoftwareComponent implements OnInit, OnDestroy, OnChanges {
@Input('software') @Input('software')
software: any; software: any;
@ -26,13 +26,15 @@ export class InstallSoftwareComponent implements OnInit, OnDestroy {
this.updateButton(); this.updateButton();
this.installedChanged.emit(data); this.installedChanged.emit(data);
}); });
this.updateButton();
} }
ngOnDestroy() { ngOnDestroy() {
this.electronService.ipcRenderer.removeAllListeners(this.responseChannel); this.electronService.ipcRenderer.removeAllListeners(this.responseChannel);
} }
ngOnChanges() {
this.updateButton();
}
install() { install() {
this.disabled = true; this.disabled = true;
@ -44,7 +46,7 @@ export class InstallSoftwareComponent implements OnInit, OnDestroy {
return `installed-software-installed-${this.software.name}`; return `installed-software-installed-${this.software.name}`;
} }
updateButton() { private updateButton() {
this.disabled = this.software.installed; this.disabled = this.software.installed;
if (this.software.installed) { if (this.software.installed) {

View File

@ -15,11 +15,6 @@
<mat-header-cell *matHeaderCellDef></mat-header-cell> <mat-header-cell *matHeaderCellDef></mat-header-cell>
<mat-cell *matCellDef="let row;" style="text-align: right"> <mat-cell *matCellDef="let row;" style="text-align: right">
<app-install-software [software]="row" (installedChanged)="onInstalled($event)"></app-install-software> <app-install-software [software]="row" (installedChanged)="onInstalled($event)"></app-install-software>
<!-- <button *ngIf="row.installed" 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> </mat-cell>
</ng-container> </ng-container>

View File

@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { InstalledSoftwareService } from '../../services/installed-software.service'; import { InstalledSoftwareService } from '../../services/installed-software.service';
import { DataSource } from '@angular/cdk/table'; import { DataSource } from '@angular/cdk/table';
import { Observable, of, BehaviorSubject } from 'rxjs'; import { Observable, of, BehaviorSubject } from 'rxjs';
@ -13,7 +13,8 @@ export class InstalledSoftwareComponent implements OnInit {
displayedColumns = ['name', 'actions']; displayedColumns = ['name', 'actions'];
constructor( constructor(
private installedSoftwareService: InstalledSoftwareService private installedSoftwareService: InstalledSoftwareService,
private changeDetectorRef: ChangeDetectorRef
) { } ) { }
ngOnInit() { ngOnInit() {
@ -22,6 +23,13 @@ export class InstalledSoftwareComponent implements OnInit {
onInstalled(event) { onInstalled(event) {
this.dataSource.refresh(); this.dataSource.refresh();
console.log("On installed", event);
/**
* During software installation we are not performing any user action
* in browser hence Angular doesn't know something suppose to change.
* Here we ask to detect changes manually.
*/
this.changeDetectorRef.detectChanges();
} }
} }