2021-12-10 02:37:01 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2021-12-10 02:37:01 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-12-09 05:44:17 +00:00
|
|
|
import {animate, style, transition, trigger} from '@angular/animations';
|
2024-11-01 07:27:33 +00:00
|
|
|
import {Component, computed, inject, OnDestroy, OnInit, signal} from '@angular/core';
|
2025-03-27 15:26:53 +00:00
|
|
|
import {Events, MessageBus, SupportedApis} from 'protocol';
|
2021-12-09 05:44:17 +00:00
|
|
|
import {interval} from 'rxjs';
|
|
|
|
|
|
2025-01-15 12:42:01 +00:00
|
|
|
import {FrameManager} from './application-services/frame_manager';
|
|
|
|
|
import {ThemeService} from './application-services/theme_service';
|
2024-03-05 03:55:01 +00:00
|
|
|
import {MatTooltip, MatTooltipModule} from '@angular/material/tooltip';
|
2024-01-19 21:52:14 +00:00
|
|
|
import {DevToolsTabsComponent} from './devtools-tabs/devtools-tabs.component';
|
2024-03-05 03:55:01 +00:00
|
|
|
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
|
|
|
|
import {Frame} from './application-environment';
|
2025-01-15 12:42:01 +00:00
|
|
|
import {BrowserStylesService} from './application-services/browser_styles_service';
|
|
|
|
|
import {WINDOW_PROVIDER} from './application-providers/window_provider';
|
2024-03-05 03:55:01 +00:00
|
|
|
|
|
|
|
|
const DETECT_ANGULAR_ATTEMPTS = 10;
|
|
|
|
|
|
|
|
|
|
enum AngularStatus {
|
|
|
|
|
/**
|
|
|
|
|
* This page may have Angular but we don't know yet. We're still trying to detect it.
|
|
|
|
|
*/
|
|
|
|
|
UNKNOWN,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* We've given up on trying to detect Angular. We tried ${DETECT_ANGULAR_ATTEMPTS} times and
|
|
|
|
|
* failed.
|
|
|
|
|
*/
|
|
|
|
|
DOES_NOT_EXIST,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Angular was detected somewhere on the page.
|
|
|
|
|
*/
|
|
|
|
|
EXISTS,
|
|
|
|
|
}
|
2020-01-27 18:40:18 +00:00
|
|
|
|
2024-04-05 22:24:43 +00:00
|
|
|
const LAST_SUPPORTED_VERSION = 9;
|
|
|
|
|
|
2020-01-27 18:40:18 +00:00
|
|
|
@Component({
|
|
|
|
|
selector: 'ng-devtools',
|
|
|
|
|
templateUrl: './devtools.component.html',
|
2020-03-29 03:28:36 +00:00
|
|
|
styleUrls: ['./devtools.component.scss'],
|
2020-02-04 15:34:34 +00:00
|
|
|
animations: [
|
2021-12-09 05:44:17 +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-02-07 21:25:16 +00:00
|
|
|
],
|
2024-03-05 03:55:01 +00:00
|
|
|
imports: [DevToolsTabsComponent, MatTooltip, MatProgressSpinnerModule, MatTooltipModule],
|
2025-01-15 12:42:01 +00:00
|
|
|
providers: [WINDOW_PROVIDER, ThemeService],
|
2020-01-27 18:40:18 +00:00
|
|
|
})
|
|
|
|
|
export class DevToolsComponent implements OnInit, OnDestroy {
|
2024-11-01 07:27:33 +00:00
|
|
|
readonly AngularStatus = AngularStatus;
|
|
|
|
|
readonly angularStatus = signal(AngularStatus.UNKNOWN);
|
|
|
|
|
readonly angularVersion = signal<string | undefined>(undefined);
|
|
|
|
|
readonly angularIsInDevMode = signal(true);
|
|
|
|
|
readonly hydration = signal(false);
|
2025-03-27 15:26:53 +00:00
|
|
|
readonly supportedApis = signal<SupportedApis>({
|
|
|
|
|
profiler: false,
|
|
|
|
|
dependencyInjection: false,
|
|
|
|
|
routes: false,
|
|
|
|
|
});
|
2024-11-01 07:27:33 +00:00
|
|
|
readonly ivy = signal<boolean | undefined>(undefined);
|
|
|
|
|
|
|
|
|
|
readonly supportedVersion = computed(() => {
|
2024-04-05 22:24:43 +00:00
|
|
|
const version = this.angularVersion();
|
|
|
|
|
if (!version) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const majorVersion = parseInt(version.toString().split('.')[0], 10);
|
|
|
|
|
|
|
|
|
|
// Check that major version is either greater or equal to the last supported version
|
|
|
|
|
// or that the major version is 0 for the (0.0.0-PLACEHOLDER) dev build case.
|
|
|
|
|
return (majorVersion >= LAST_SUPPORTED_VERSION || majorVersion === 0) && this.ivy();
|
|
|
|
|
});
|
2020-03-18 00:48:29 +00:00
|
|
|
|
2024-03-05 03:55:01 +00:00
|
|
|
private readonly _messageBus = inject<MessageBus<Events>>(MessageBus);
|
|
|
|
|
private readonly _themeService = inject(ThemeService);
|
|
|
|
|
private readonly _frameManager = inject(FrameManager);
|
2025-01-15 12:42:01 +00:00
|
|
|
private readonly _browserStyles = inject(BrowserStylesService);
|
2020-01-27 18:40:18 +00:00
|
|
|
|
2020-04-16 20:32:12 +00:00
|
|
|
private _interval$ = interval(500).subscribe((attempt) => {
|
2024-03-05 03:55:01 +00:00
|
|
|
if (attempt === DETECT_ANGULAR_ATTEMPTS) {
|
2024-11-01 07:27:33 +00:00
|
|
|
this.angularStatus.set(AngularStatus.DOES_NOT_EXIST);
|
2020-04-16 20:32:12 +00:00
|
|
|
}
|
|
|
|
|
this._messageBus.emit('queryNgAvailability');
|
|
|
|
|
});
|
2020-01-27 18:40:18 +00:00
|
|
|
|
2024-03-05 03:55:01 +00:00
|
|
|
inspectFrame(frame: Frame) {
|
|
|
|
|
this._frameManager.inspectFrame(frame);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-29 00:29:23 +00:00
|
|
|
ngOnInit(): void {
|
2021-02-25 10:34:39 +00:00
|
|
|
this._themeService.initializeThemeWatcher();
|
2025-01-15 12:42:01 +00:00
|
|
|
this._browserStyles.initBrowserSpecificStyles();
|
2021-02-25 10:34:39 +00:00
|
|
|
|
2025-03-27 15:26:53 +00:00
|
|
|
this._messageBus.once('ngAvailability', ({version, devMode, ivy, hydration, supportedApis}) => {
|
2024-11-01 07:27:33 +00:00
|
|
|
this.angularStatus.set(version ? AngularStatus.EXISTS : AngularStatus.DOES_NOT_EXIST);
|
2024-04-05 22:24:43 +00:00
|
|
|
this.angularVersion.set(version);
|
2024-11-01 07:27:33 +00:00
|
|
|
this.angularIsInDevMode.set(devMode);
|
2024-04-05 22:24:43 +00:00
|
|
|
this.ivy.set(ivy);
|
2020-01-27 18:40:18 +00:00
|
|
|
this._interval$.unsubscribe();
|
2024-11-01 07:27:33 +00:00
|
|
|
this.hydration.set(hydration);
|
2025-03-27 15:26:53 +00:00
|
|
|
this.supportedApis.set(supportedApis);
|
2020-01-27 18:40:18 +00:00
|
|
|
});
|
2022-05-18 15:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-29 00:29:23 +00:00
|
|
|
ngOnDestroy(): void {
|
2020-01-27 18:40:18 +00:00
|
|
|
this._interval$.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
}
|