mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
a7ebf1cd69
Organize code into domain/feature-specific folders and a shared API folder.
56 lines
1.6 KiB
TypeScript
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');
|
|
});
|