angular/devtools/projects/shell-browser/src/app/detect-angular-for-extension-icon.ts
Joey Perrott 9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00

55 lines
1.3 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 {AngularDetection} from 'protocol';
import {
appIsAngular,
appIsAngularInDevMode,
appIsAngularIvy,
appIsSupportedAngularVersion,
} from 'shared-utils';
import {SamePageMessageBus} from './same-page-message-bus';
const detectAngularMessageBus = new SamePageMessageBus(
`angular-devtools-detect-angular-${location.href}`,
`angular-devtools-content-script-${location.href}`,
);
function detectAngular(win: Window): void {
const isAngular = appIsAngular();
const isSupportedAngularVersion = appIsSupportedAngularVersion();
const isDebugMode = appIsAngularInDevMode();
const isIvy = appIsAngularIvy();
const detection: AngularDetection = {
isIvy,
isAngular,
isDebugMode,
isSupportedAngularVersion,
isAngularDevTools: true,
};
// For the background script to toggle the icon.
win.postMessage(detection, '*');
// For the content script to inject the backend.
detectAngularMessageBus.emit('detectAngular', [
{
isIvy,
isAngular,
isDebugMode,
isSupportedAngularVersion,
isAngularDevTools: true,
},
]);
setTimeout(() => detectAngular(win), 1000);
}
detectAngular(window);