1// Copyright (C) 2023 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import { 16 createStore, 17 MetricVisualisation, 18 Plugin, 19 PluginContext, 20 PluginContextTrace, 21 PluginDescriptor, 22 Store, 23} from '../../public'; 24 25interface State { 26 foo: string; 27} 28 29// SKELETON: Rename this class to match your plugin. 30class Skeleton implements Plugin { 31 private store: Store<State> = createStore({foo: 'foo'}); 32 33 onActivate(_: PluginContext): void { 34 // 35 } 36 37 async onTraceLoad(ctx: PluginContextTrace): Promise<void> { 38 this.store = ctx.mountStore((_: unknown): State => { 39 return {foo: 'bar'}; 40 }); 41 42 this.store.edit((state) => { 43 state.foo = 'baz'; 44 }); 45 46 // This is an example of how to access the pluginArgs pushed by the 47 // postMessage when deep-linking to the UI. 48 if (ctx.openerPluginArgs !== undefined) { 49 console.log(`Postmessage args for ${ctx.pluginId}`, ctx.openerPluginArgs); 50 } 51 } 52 53 async onTraceUnload(_: PluginContextTrace): Promise<void> { 54 this.store.dispose(); 55 } 56 57 onDeactivate(_: PluginContext): void { 58 // 59 } 60 61 metricVisualisations(_: PluginContextTrace): MetricVisualisation[] { 62 return []; 63 } 64} 65 66export const plugin: PluginDescriptor = { 67 // SKELETON: Update pluginId to match the directory of the plugin. 68 pluginId: 'com.example.Skeleton', 69 plugin: Skeleton, 70}; 71