2020-03-23 15:45:01 +00:00
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
2020-01-27 18:40:18 +00:00
|
|
|
import { MessageBus, Events } from 'protocol';
|
|
|
|
|
import { interval } from 'rxjs';
|
2020-02-04 15:34:34 +00:00
|
|
|
import { animate, style, transition, trigger } from '@angular/animations';
|
2020-03-13 04:15:17 +00:00
|
|
|
import { take } from 'rxjs/operators';
|
2020-01-27 18:40:18 +00:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ng-devtools',
|
|
|
|
|
templateUrl: './devtools.component.html',
|
|
|
|
|
styleUrls: ['./devtools.component.css'],
|
2020-02-04 15:34:34 +00:00
|
|
|
animations: [
|
2020-02-07 21:25:16 +00:00
|
|
|
trigger('enterAnimation', [
|
|
|
|
|
transition(':enter', [style({ opacity: 0 }), animate('200ms', style({ opacity: 1 }))]),
|
|
|
|
|
transition(':leave', [style({ opacity: 1 }), animate('200ms', style({ opacity: 0 }))]),
|
|
|
|
|
]),
|
|
|
|
|
],
|
2020-01-27 18:40:18 +00:00
|
|
|
})
|
|
|
|
|
export class DevToolsComponent implements OnInit, OnDestroy {
|
|
|
|
|
angularExists: boolean | null = null;
|
2020-02-07 18:39:15 +00:00
|
|
|
angularVersion: string | boolean | undefined = undefined;
|
|
|
|
|
prodMode: boolean;
|
2020-03-18 00:48:29 +00:00
|
|
|
|
|
|
|
|
constructor(private _messageBus: MessageBus<Events>) {}
|
2020-01-27 18:40:18 +00:00
|
|
|
|
2020-03-13 04:15:17 +00:00
|
|
|
private _interval$ = interval(500)
|
|
|
|
|
.pipe(take(10))
|
|
|
|
|
.subscribe({
|
2020-03-18 00:48:29 +00:00
|
|
|
next: () => this._messageBus.emit('queryNgAvailability'),
|
2020-03-13 04:15:17 +00:00
|
|
|
complete: () => {
|
|
|
|
|
if (this.angularExists === null) {
|
|
|
|
|
this.angularExists = false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
2020-01-27 18:40:18 +00:00
|
|
|
|
2020-01-29 00:29:23 +00:00
|
|
|
ngOnInit(): void {
|
2020-01-27 18:40:18 +00:00
|
|
|
console.log('Initialized the devtools UI');
|
|
|
|
|
|
2020-03-18 00:48:29 +00:00
|
|
|
this._messageBus.once('ngAvailability', ({ version, prodMode }) => {
|
2020-01-29 00:29:23 +00:00
|
|
|
this.angularExists = !!version;
|
2020-01-29 17:10:57 +00:00
|
|
|
this.angularVersion = version;
|
2020-02-07 18:39:15 +00:00
|
|
|
this.prodMode = prodMode;
|
2020-01-27 18:40:18 +00:00
|
|
|
this._interval$.unsubscribe();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 18:39:15 +00:00
|
|
|
majorAngularVersion(): number {
|
2020-03-20 18:54:37 +00:00
|
|
|
if (!this.angularVersion) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2020-02-07 18:39:15 +00:00
|
|
|
return +this.angularVersion.toString().split('.')[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get supportedVersion(): boolean {
|
2020-03-11 00:47:49 +00:00
|
|
|
return (this.majorAngularVersion() >= 9 || this.majorAngularVersion() === 0) && !this.prodMode;
|
2020-02-07 18:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-29 00:29:23 +00:00
|
|
|
ngOnDestroy(): void {
|
2020-01-27 18:40:18 +00:00
|
|
|
this._interval$.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
}
|