Files
angular__angular/devtools/projects/shell-browser/src/app/backend.ts
T
hawkgs a7ebf1cd69 refactor(devtools): reorganize backend code
Organize code into domain/feature-specific folders and a shared API folder.
2026-07-20 11:15:53 +02:00

56 lines
1.6 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 {initializeMessageBus} from '../../../ng-devtools-backend';
import {removeHighlightsByType} from '../../../ng-devtools-backend/src/lib/shared/highlighter';
import {HighlightType} from '../../../ng-devtools-backend/src/lib/shared/highlighter/highlights';
import {initializeExtendedWindowOperations} from './chrome-window-extensions';
import {getBackendUri, getContentScriptUri} from './comm-utils';
import {SamePageMessageBus} from './same-page-message-bus';
const messageBus = new SamePageMessageBus(
'[Backend=>ContentScript]',
getBackendUri(),
getContentScriptUri(),
);
let initialized = false;
messageBus.on('handshake', () => {
if (initialized) {
return;
}
initialized = true;
initializeMessageBus(messageBus);
initializeExtendedWindowOperations();
let inspectorRunning = false;
messageBus.on('inspectorStart', () => {
inspectorRunning = true;
});
messageBus.on('inspectorEnd', () => {
inspectorRunning = false;
});
// handles case when mouse leaves chrome extension too quickly. unHighlight() is not a very
// expensive function and has an if check so it's DOM api call is not called more than necessary
document.addEventListener(
'mousemove',
() => {
if (!inspectorRunning) {
removeHighlightsByType(HighlightType.InspectElement);
}
},
false,
);
messageBus.emit('backendReady');
});