0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-06 14:50:21 -05:00

feat: close plugins when exiting the workspace

This commit is contained in:
alonso.torres 2024-05-23 13:39:16 +02:00 committed by Alonso Torres
parent 66ebaffb06
commit c7e1722459
3 changed files with 22 additions and 4 deletions

View file

@ -387,6 +387,7 @@ export interface EventsMap {
filechange: PenpotFile;
selectionchange: string[];
themechange: PenpotTheme;
finish: string;
}
export type PenpotTheme = 'light' | 'dark';
@ -433,8 +434,8 @@ export interface PenpotContext {
uploadMediaUrl(name: string, url: string): Promise<PenpotImageData>;
group(first: PenpotShape, ...rest: PenpotShape[]): PenpotGroup;
ungroup(first: PenpotShape, ...rest: PenpotShape[]): void;
group(shapes: PenpotShape[]): PenpotGroup;
ungroup(group: PenpotGroup, ...other: PenpotGroup[]): void;
createRectangle(): PenpotRectangle;
createFrame(): PenpotFrame;
@ -443,7 +444,8 @@ export interface PenpotContext {
addListener<T extends keyof EventsMap>(
type: T,
callback: (event: EventsMap[T]) => void
): void;
): symbol;
removeListener(listenerId: symbol): void;
}
/**
@ -451,7 +453,7 @@ export interface PenpotContext {
*
*/
export interface Penpot
extends Omit<PenpotContext, 'addListener' | 'group' | 'ungroup'> {
extends Omit<PenpotContext, 'addListener' | 'removeListener'> {
ui: {
/**
* Description of open

View file

@ -24,6 +24,7 @@ import { getValidUrl } from '../parse-manifest.js';
type Callback<T> = (message: T) => void;
export const validEvents = [
'finish',
'pagechange',
'filechange',
'selectionchange',
@ -232,6 +233,16 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot {
return context.createShapeFromSvg(svgString);
},
group(shapes: PenpotShape[]): PenpotGroup {
// checkPermission('page:write');
return context.group(shapes);
},
ungroup(group: PenpotGroup, ...other: PenpotGroup[]): void {
// checkPermission('page:write');
context.ungroup(group, ...other);
},
uploadMediaUrl(name: string, url: string) {
return context.uploadMediaUrl(name, url);
},

View file

@ -37,6 +37,11 @@ export const ɵloadPlugin = async function (manifest: Manifest) {
});
c.evaluate(code);
const listenerId: symbol = pluginContext.addListener('finish', () => {
lastApi?.closePlugin();
pluginContext?.removeListener(listenerId);
});
} else {
console.error('Cannot find Penpot Context');
}