chrome-devtools-frontend
Version:
Chrome DevTools UI
79 lines (63 loc) • 2.24 kB
text/typescript
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as Common from '../../core/common/common.js';
import type {RecorderExtensionEndpoint} from './RecorderExtensionEndpoint.js';
let instance: RecorderPluginManager|null = null;
export interface ViewDescriptor {
id: string;
title: string;
pagePath: string;
onShown: () => void;
onHidden: () => void;
}
export class RecorderPluginManager extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
static instance(): RecorderPluginManager {
if (!instance) {
instance = new RecorderPluginManager();
}
return instance;
}
addPlugin(plugin: RecorderExtensionEndpoint): void {
this.
this.dispatchEventToListeners(Events.PLUGIN_ADDED, plugin);
}
removePlugin(plugin: RecorderExtensionEndpoint): void {
this.
this.dispatchEventToListeners(Events.PLUGIN_REMOVED, plugin);
}
plugins(): RecorderExtensionEndpoint[] {
return Array.from(this.
}
registerView(descriptor: ViewDescriptor): void {
this.
this.dispatchEventToListeners(Events.VIEW_REGISTERED, descriptor);
}
views(): ViewDescriptor[] {
return Array.from(this.
}
getViewDescriptor(id: string): ViewDescriptor|undefined {
return this.
}
showView(id: string): void {
const descriptor = this.
if (!descriptor) {
throw new Error(`View with id ${id} is not found.`);
}
this.dispatchEventToListeners(Events.SHOW_VIEW_REQUESTED, descriptor);
}
}
export const enum Events {
PLUGIN_ADDED = 'pluginAdded',
PLUGIN_REMOVED = 'pluginRemoved',
VIEW_REGISTERED = 'viewRegistered',
SHOW_VIEW_REQUESTED = 'showViewRequested',
}
export interface EventTypes {
[ ]: RecorderExtensionEndpoint;
[ ]: RecorderExtensionEndpoint;
[ ]: ViewDescriptor;
[ ]: ViewDescriptor;
}