-
-
Notifications
You must be signed in to change notification settings - Fork 228
/
standby.component.ts
63 lines (56 loc) · 1.94 KB
/
standby.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Component, OnDestroy, OnInit } from '@angular/core';
import { AppService } from '../app.service';
import { ConfigService } from '../config/config.service';
import { PSUState } from '../model';
import { EnclosureService } from '../services/enclosure/enclosure.service';
import { SystemService } from '../services/system/system.service';
@Component({
selector: 'app-standby',
templateUrl: './standby.component.html',
styleUrls: ['./standby.component.scss'],
})
export class StandbyComponent implements OnInit, OnDestroy {
public connecting = false;
public showConnectionError = false;
private displaySleepTimeout: ReturnType<typeof setTimeout>;
private connectErrorTimeout: ReturnType<typeof setTimeout>;
public constructor(
private configService: ConfigService,
private service: AppService,
private enclosureService: EnclosureService,
private systemService: SystemService,
) {}
public ngOnInit(): void {
setTimeout(() => {
if (this.configService.getAutomaticScreenSleep()) {
this.displaySleepTimeout = setTimeout(this.service.turnDisplayOff.bind(this.service), 300000);
}
});
}
public ngOnDestroy(): void {
clearTimeout(this.displaySleepTimeout);
clearTimeout(this.connectErrorTimeout);
if (this.configService.getAutomaticScreenSleep()) {
this.service.turnDisplayOn();
}
}
public reconnect(): void {
this.connecting = true;
if (this.configService.getAutomaticPrinterPowerOn()) {
this.enclosureService.setPSUState(PSUState.ON);
setTimeout(this.connectPrinter.bind(this), 5000);
} else {
this.connectPrinter();
}
}
private connectPrinter(): void {
this.systemService.connectPrinter();
this.connectErrorTimeout = setTimeout(() => {
this.showConnectionError = true;
this.connectErrorTimeout = setTimeout(() => {
this.showConnectionError = false;
this.connecting = false;
}, 30000);
}, 15000);
}
}