-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.ts
More file actions
151 lines (135 loc) · 4.28 KB
/
Copy pathruntime.ts
File metadata and controls
151 lines (135 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import type { PluginCredentialVault } from './credentials.js';
import type { PluginPaths, PluginPathRoots } from './paths.js';
import type { ContributeData, PluginDefinition, PluginInfo } from './types.js';
export type MessageLocation = 'server' | 'browser';
export type PluginMethod = (...args: unknown[]) => unknown;
export interface PluginRuntimePluginHost {
define(definition: PluginDefinition): void;
getInfo(name: string): PluginInfo | undefined;
listLoaded(): string[];
listRegistered(): string[];
callPlugin(name: string, method: string, ...args: unknown[]): unknown;
}
export interface PluginRuntimeMessageHost {
registerRequest(
plugin: string,
name: string,
handler: PluginMethod,
location?: MessageLocation,
methods?: string[],
): void;
registerBroadcast(
plugin: string,
topic: string,
handler: PluginMethod,
location?: MessageLocation,
methods?: string[],
): void;
unregisterRequest(plugin: string, name: string): void;
unregisterBroadcast(plugin: string, topic: string): void;
request(plugin: string, name: string, ...args: unknown[]): Promise<unknown>;
broadcast(topic: string, ...args: unknown[]): void;
}
export interface PluginRuntimeMenuHost {
attach(pluginName: string, contribute: ContributeData): void;
detach(pluginName: string): void;
setDefaults(items: any[]): void;
clearDefaults(): void;
reset(): void;
getState(): any;
}
export interface PluginRuntimePanelHost {
register(name: string, modulePath: string, constraints?: any, owner?: string): void;
unregister(name: string): void;
getInfo(name: string): any;
getRegistration(name: string): any;
list(): any[];
}
export interface PluginRuntimeHost {
readonly sessionId: string;
application: {
request(plugin: string, name: string, ...args: unknown[]): Promise<unknown>;
};
plugin: PluginRuntimePluginHost;
panel: PluginRuntimePanelHost;
menu: PluginRuntimeMenuHost;
message: PluginRuntimeMessageHost;
}
export interface PluginRuntime extends PluginRuntimeHost {
readonly paths: PluginPaths;
readonly credentials?: PluginCredentialVault;
}
export type ApplicationHostMode = 'desktop' | 'web';
export interface NotificationInput {
title: string;
body?: string;
level?: 'info' | 'success' | 'warning' | 'error';
source?: string;
durationMs?: number;
persistent?: boolean;
}
export interface NotificationRecord {
id: string;
pluginOwner?: string;
title: string;
body: string;
level: 'info' | 'success' | 'warning' | 'error';
source: string | null;
durationMs: number | null;
persistent: boolean;
createdAt: string;
read: boolean;
}
export interface NotificationSnapshot {
notifications: NotificationRecord[];
unreadCount: number;
}
export interface NotificationHostCapability {
create(input: NotificationInput): Promise<NotificationRecord>;
list(): Promise<NotificationSnapshot>;
markRead(id: string): Promise<NotificationRecord>;
markAllRead(): Promise<{ unreadCount: number }>;
remove(id: string): Promise<void>;
}
export interface ApplicationPluginRuntime {
readonly paths: PluginPaths;
plugin: PluginRuntimePluginHost;
menu: Pick<PluginRuntimeMenuHost, 'attach' | 'detach' | 'getState'>;
message: PluginRuntimeMessageHost;
service: {
register(name: string, value: unknown): void;
unregister(name: string): void;
get<T = unknown>(name: string): T | undefined;
};
host: Readonly<{
mode: ApplicationHostMode;
readonly notifications: NotificationHostCapability;
}>;
}
export interface ApplicationPluginRuntimeHost {
plugin: PluginRuntimePluginHost;
menu: ApplicationPluginRuntime['menu'];
message: PluginRuntimeMessageHost;
service: {
register(owner: string, name: string, value: unknown): void;
unregister(owner: string, name: string): void;
get<T = unknown>(name: string): T | undefined;
};
host: ApplicationPluginRuntime['host'];
}
export interface PluginPathLoadConfiguration {
readonly roots: PluginPathRoots;
readonly legacyDataDirectories: readonly string[];
}
export type PluginLoadOptions =
| {
scope: 'session';
host: PluginRuntimeHost;
paths: PluginPathLoadConfiguration;
credentials?: PluginCredentialVault;
}
| {
scope: 'application';
host: ApplicationPluginRuntimeHost;
paths: PluginPathLoadConfiguration;
};