angular/devtools/projects/shell-browser/src/app/app.component.ts
Matthieu Riegler 30766d6b77 refactor(devtools): Migrate with the schematic. (#58160)
All components, directives and pipes will now use standalone as default. Non-standalone decorators have now .

PR Close #58160
2024-10-14 14:58:57 +00:00

46 lines
1.5 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectorRef, Component, inject, OnInit} from '@angular/core';
import {Events, MessageBus} from 'protocol';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
standalone: false,
})
export class AppComponent implements OnInit {
private _cd = inject(ChangeDetectorRef);
private readonly _messageBus = inject<MessageBus<Events>>(MessageBus);
private onProfilingStartedListener = () => {
this._messageBus.emit('enableTimingAPI');
};
private onProfilingStoppedListener = () => {
this._messageBus.emit('disableTimingAPI');
};
ngOnInit(): void {
chrome.devtools.network.onNavigated.addListener(() => {
window.location.reload();
});
const chromeDevToolsPerformance = chrome.devtools.performance;
chromeDevToolsPerformance?.onProfilingStarted?.addListener?.(this.onProfilingStartedListener);
chromeDevToolsPerformance?.onProfilingStopped?.addListener?.(this.onProfilingStoppedListener);
this._cd.detectChanges();
}
ngOnDestroy(): void {
const chromeDevToolsPerformance = chrome.devtools.performance;
chromeDevToolsPerformance?.onProfilingStarted?.removeListener?.(
this.onProfilingStartedListener,
);
chromeDevToolsPerformance?.onProfilingStopped?.removeListener?.(
this.onProfilingStoppedListener,
);
}
}