mirror of
https://github.com/zen-browser/plugin.git
synced 2025-07-08 01:10:10 +02:00
Add plugin interface and package.json
This commit is contained in:
parent
59e0063784
commit
2561cfb10d
2 changed files with 107 additions and 0 deletions
90
lib/main.d.ts
vendored
Normal file
90
lib/main.d.ts
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
|
||||
export interface IZenPlugin {
|
||||
name: string;
|
||||
version: string;
|
||||
description: string;
|
||||
|
||||
settings: IPluginSettings;
|
||||
events: IPluginEvents;
|
||||
context: IPluginContextMenu[];
|
||||
}
|
||||
|
||||
export interface IPluginSetting {
|
||||
name: string;
|
||||
type: "string" | "number" | "boolean";
|
||||
default?: any;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface IWorkspace {
|
||||
uuid: string;
|
||||
name: string;
|
||||
icon?: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
export interface ISandboxedTab {
|
||||
getTitle(): string;
|
||||
getIcon(): string;
|
||||
getWorkspace(): IWorkspace;
|
||||
getPluginData(): any;
|
||||
setPluginData(data: any): void;
|
||||
|
||||
close(): void;
|
||||
select(): void;
|
||||
unload(): void;
|
||||
|
||||
readonly isSelected: boolean;
|
||||
}
|
||||
|
||||
export type IPluginEventKey = "onInit" | "onUnload" | "onTabChange" | "onTabClose"
|
||||
| "onTabOpen" | "onWorkspaceChange" | "onWorkspaceClose"
|
||||
| "onWorkspaceOpen" | "onPreferencesChange";
|
||||
|
||||
export type IPluginEventProps<T extends IPluginEventKey> =
|
||||
T extends "onInit" ? { }
|
||||
: T extends "onUnload" ? { }
|
||||
: T extends "onTabChange" ? { tabId: string }
|
||||
: T extends "onTabClose" ? { tabId: string }
|
||||
: T extends "onTabOpen" ? { tabId: string }
|
||||
: T extends "onWorkspaceChange" ? { workspace: IWorkspace }
|
||||
: T extends "onWorkspaceClose" ? { workspace: IWorkspace }
|
||||
: T extends "onWorkspaceOpen" ? { workspace: IWorkspace }
|
||||
: T extends "onPreferencesChange" ? { settings: IPluginSettings }
|
||||
: never;
|
||||
|
||||
export type IPluginEvent<T extends IPluginEventKey> = (props: IPluginEventProps<T>) => void;
|
||||
export type IPluginEvents = {
|
||||
[K in IPluginEventKey]?: IPluginEvent<K>;
|
||||
};
|
||||
|
||||
export type IPluginContextMenu = {
|
||||
type: "tab" | "link" | "toolbar" | "text";
|
||||
label: string;
|
||||
icon?: string;
|
||||
action: () => void;
|
||||
|
||||
get enabled(): boolean;
|
||||
set enabled(value: boolean);
|
||||
};
|
||||
|
||||
export type IPluginSettings = IPluginSetting[];
|
||||
export default IZenPlugin;
|
||||
|
||||
// API
|
||||
|
||||
export interface IZenAPI {
|
||||
getTabs(): ISandboxedTab[];
|
||||
getWorkspaces(): IWorkspace[];
|
||||
|
||||
getSetting(name: string): any;
|
||||
setSetting(name: string, value: any): void;
|
||||
|
||||
set plugin(plugin: IZenPlugin);
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
plugins: IZenAPI;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue