tauri-cordis 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,384 @@
1
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { pluginWindowsV1 } from "../services.mjs";
4
+ import { pluginId } from "./clients.mjs";
5
+ import { entryOf, installInjectableAccessor } from "./owner.mjs";
6
+ import { serviceError } from "./services.mjs";
7
+ import { SOURCE } from "./sources.mjs";
8
+
9
+ export const WINDOW_RULES_FILE = "window-rules.json";
10
+ export const MAX_WINDOWS_PER_PLUGIN = 8;
11
+ export const MAX_WINDOWS_TOTAL = 24;
12
+
13
+ const DEFAULT_RULES = Object.freeze({
14
+ disallowAlwaysOnTop: false,
15
+ disallowClickThrough: false,
16
+ hideAll: false,
17
+ });
18
+
19
+ function checkExperimental(ctx) {
20
+ const entry = entryOf(ctx);
21
+ const meta = entry?.options?.[SOURCE];
22
+ if (!meta || meta.source === "builtin") return;
23
+ const exp = meta.declared?.experimental ?? [];
24
+ if (exp.includes("windows/v1") || exp.includes("windows")) return;
25
+ throw Object.assign(new Error('ctx.windows requires fuyu.experimental to include "windows/v1"'), {
26
+ code: "experimental-required",
27
+ });
28
+ }
29
+
30
+ function readRulesFile(file) {
31
+ try {
32
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
33
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
34
+ const clean = {};
35
+ for (const [id, raw] of Object.entries(parsed)) {
36
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
37
+ clean[id] = {
38
+ disallowAlwaysOnTop: raw.disallowAlwaysOnTop === true,
39
+ disallowClickThrough: raw.disallowClickThrough === true,
40
+ hideAll: raw.hideAll === true,
41
+ };
42
+ }
43
+ return clean;
44
+ } catch {
45
+ return {};
46
+ }
47
+ }
48
+
49
+ function writeRulesFile(file, rules) {
50
+ mkdirSync(dirname(file), { recursive: true });
51
+ writeFileSync(file, `${JSON.stringify(rules, null, 2)}\n`);
52
+ }
53
+
54
+ function applyGuardrails(desired, rules) {
55
+ return {
56
+ ...desired,
57
+ alwaysOnTop: rules.disallowAlwaysOnTop ? false : Boolean(desired.alwaysOnTop),
58
+ clickThrough: rules.disallowClickThrough ? false : Boolean(desired.clickThrough),
59
+ visible: rules.hideAll ? false : Boolean(desired.visible),
60
+ };
61
+ }
62
+
63
+ export class PluginWindows {
64
+ constructor({ dir, services, usage = null }) {
65
+ this.file = join(dir, WINDOW_RULES_FILE);
66
+ this.services = services;
67
+ this.usage = usage;
68
+ this.rpc = null;
69
+ this.handle = null;
70
+ this.rules = readRulesFile(this.file);
71
+ this.windows = new Map();
72
+ this.listeners = new Map();
73
+ }
74
+
75
+ install(ctx) {
76
+ const manager = this;
77
+ const unaccess = installInjectableAccessor(ctx, "windows", function () {
78
+ const caller = this;
79
+ return Object.freeze({
80
+ create: (spec) => manager.create(caller, spec),
81
+ update: (id, patch) => manager.update(caller, id, patch),
82
+ show: (id) => manager.show(caller, id),
83
+ hide: (id) => manager.hide(caller, id),
84
+ focus: (id) => manager.focus(caller, id),
85
+ close: (id) => manager.close(caller, id),
86
+ list: () => manager.listForPlugin(caller),
87
+ onEvent: (listener) => manager.onEvent(caller, listener),
88
+ });
89
+ });
90
+ this.handle = this.services.provideBuiltin(ctx, pluginWindowsV1, {
91
+ getRules: (params) => this.getRules(params),
92
+ setRules: (params) => this.setRules(params),
93
+ list: (params) => this.listAll(params),
94
+ });
95
+ return () => {
96
+ void unaccess();
97
+ void this.handle?.dispose();
98
+ };
99
+ }
100
+
101
+ attach(rpc) {
102
+ this.rpc = rpc;
103
+ rpc.handle("windowEvent", (params) => this.deliverEvent(params));
104
+ }
105
+
106
+ async callRpc(method, params) {
107
+ if (!this.rpc) return null;
108
+ try {
109
+ return await this.rpc.call(method, params);
110
+ } catch (error) {
111
+ if (error?.code === "no-method" || error?.code === "peer-gone") return null;
112
+ throw error;
113
+ }
114
+ }
115
+
116
+ rulesFor(id) {
117
+ return { ...DEFAULT_RULES, ...(this.rules[id] ?? {}) };
118
+ }
119
+
120
+ totalCount() {
121
+ let total = 0;
122
+ for (const map of this.windows.values()) total += map.size;
123
+ return total;
124
+ }
125
+
126
+ async create(ctx, spec = {}) {
127
+ checkExperimental(ctx);
128
+ const owner = pluginId(ctx);
129
+ const id = spec?.id;
130
+ if (typeof id !== "string" || id.trim() === "") {
131
+ throw serviceError("bad-params", "ctx.windows.create needs a non-empty window id");
132
+ }
133
+ const title = typeof spec?.title === "string" && spec.title.trim() !== "" ? spec.title : id;
134
+ let bucket = this.windows.get(owner);
135
+ if (!bucket) this.windows.set(owner, (bucket = new Map()));
136
+ if (!bucket.has(id)) {
137
+ if (bucket.size >= MAX_WINDOWS_PER_PLUGIN) {
138
+ throw serviceError("limit", `plugin ${owner} already has ${MAX_WINDOWS_PER_PLUGIN} open windows`);
139
+ }
140
+ if (this.totalCount() >= MAX_WINDOWS_TOTAL) {
141
+ throw serviceError("limit", `the plugin host already has ${MAX_WINDOWS_TOTAL} open plugin windows`);
142
+ }
143
+ }
144
+ const desired = {
145
+ pluginId: owner,
146
+ id,
147
+ title,
148
+ kind: typeof spec.kind === "string" && spec.kind ? spec.kind : "overlay",
149
+ width: typeof spec.width === "number" && spec.width > 0 ? spec.width : 360,
150
+ height: typeof spec.height === "number" && spec.height > 0 ? spec.height : 280,
151
+ x: typeof spec.x === "number" ? spec.x : null,
152
+ y: typeof spec.y === "number" ? spec.y : null,
153
+ alwaysOnTop: Boolean(spec.alwaysOnTop),
154
+ clickThrough: Boolean(spec.clickThrough),
155
+ resizable: Boolean(spec.resizable),
156
+ visible: spec.visible === undefined ? true : Boolean(spec.visible),
157
+ };
158
+ const state = applyGuardrails(desired, this.rulesFor(owner));
159
+ const record = { id, desired, state };
160
+ const stopEffect = ctx.effect(() => {
161
+ bucket.set(id, record);
162
+ return () => {
163
+ if (bucket.get(id) !== record) return;
164
+ bucket.delete(id);
165
+ if (bucket.size === 0 && this.windows.get(owner) === bucket) this.windows.delete(owner);
166
+ void this.callRpc("pluginKernel.windowControl", { pluginId: owner, windowId: id, action: "close" }).catch(() => {});
167
+ this.emitChanged();
168
+ };
169
+ }, `ctx.windows.create(${id})`);
170
+ record.stopEffect = stopEffect;
171
+ await this.callRpc("pluginKernel.windowOpen", {
172
+ pluginId: owner,
173
+ windowId: id,
174
+ title: state.title,
175
+ kind: state.kind,
176
+ width: state.width,
177
+ height: state.height,
178
+ x: state.x,
179
+ y: state.y,
180
+ alwaysOnTop: state.alwaysOnTop,
181
+ clickThrough: state.clickThrough,
182
+ resizable: state.resizable,
183
+ visible: state.visible,
184
+ });
185
+ this.emitChanged();
186
+ return { ...state };
187
+ }
188
+
189
+ requireWindow(ctx, id) {
190
+ checkExperimental(ctx);
191
+ if (typeof id !== "string" || !id) throw serviceError("bad-params", "window id is required");
192
+ const owner = pluginId(ctx);
193
+ const record = this.windows.get(owner)?.get(id);
194
+ if (!record) throw serviceError("not-found", `window ${id} is not open for ${owner}`, { pluginId: owner, windowId: id });
195
+ return { owner, record };
196
+ }
197
+
198
+ async update(ctx, id, patch = {}) {
199
+ const { owner, record } = this.requireWindow(ctx, id);
200
+ if (typeof patch?.title === "string") record.desired.title = patch.title;
201
+ if (typeof patch?.width === "number" && patch.width > 0) record.desired.width = patch.width;
202
+ if (typeof patch?.height === "number" && patch.height > 0) record.desired.height = patch.height;
203
+ if (patch?.x === null || typeof patch?.x === "number") record.desired.x = patch.x;
204
+ if (patch?.y === null || typeof patch?.y === "number") record.desired.y = patch.y;
205
+ if (typeof patch?.alwaysOnTop === "boolean") record.desired.alwaysOnTop = patch.alwaysOnTop;
206
+ if (typeof patch?.clickThrough === "boolean") record.desired.clickThrough = patch.clickThrough;
207
+ if (typeof patch?.resizable === "boolean") record.desired.resizable = patch.resizable;
208
+ if (typeof patch?.visible === "boolean") record.desired.visible = patch.visible;
209
+ record.state = applyGuardrails(record.desired, this.rulesFor(owner));
210
+ const applied = {
211
+ ...(typeof patch?.title === "string" ? { title: record.state.title } : {}),
212
+ ...(typeof patch?.width === "number" ? { width: record.state.width } : {}),
213
+ ...(typeof patch?.height === "number" ? { height: record.state.height } : {}),
214
+ ...(patch?.x === null || typeof patch?.x === "number" ? { x: record.state.x } : {}),
215
+ ...(patch?.y === null || typeof patch?.y === "number" ? { y: record.state.y } : {}),
216
+ ...(typeof patch?.alwaysOnTop === "boolean" ? { alwaysOnTop: record.state.alwaysOnTop } : {}),
217
+ ...(typeof patch?.clickThrough === "boolean" ? { clickThrough: record.state.clickThrough } : {}),
218
+ ...(typeof patch?.resizable === "boolean" ? { resizable: record.state.resizable } : {}),
219
+ ...(typeof patch?.visible === "boolean" ? { visible: record.state.visible } : {}),
220
+ };
221
+ await this.callRpc("pluginKernel.windowControl", { pluginId: owner, windowId: id, action: "update", ...applied });
222
+ this.emitChanged();
223
+ return { ...record.state };
224
+ }
225
+
226
+ async show(ctx, id) {
227
+ const { owner, record } = this.requireWindow(ctx, id);
228
+ record.desired.visible = true;
229
+ record.state = applyGuardrails(record.desired, this.rulesFor(owner));
230
+ if (record.state.visible) {
231
+ await this.callRpc("pluginKernel.windowControl", { pluginId: owner, windowId: id, action: "show" });
232
+ }
233
+ this.emitChanged();
234
+ return { ...record.state };
235
+ }
236
+
237
+ async hide(ctx, id) {
238
+ const { owner, record } = this.requireWindow(ctx, id);
239
+ record.desired.visible = false;
240
+ record.state.visible = false;
241
+ await this.callRpc("pluginKernel.windowControl", { pluginId: owner, windowId: id, action: "hide" });
242
+ this.emitChanged();
243
+ return { ...record.state };
244
+ }
245
+
246
+ async focus(ctx, id) {
247
+ const { owner, record } = this.requireWindow(ctx, id);
248
+ if (record.state.visible) {
249
+ await this.callRpc("pluginKernel.windowControl", { pluginId: owner, windowId: id, action: "focus" });
250
+ }
251
+ return { ...record.state };
252
+ }
253
+
254
+ async close(ctx, id) {
255
+ checkExperimental(ctx);
256
+ if (typeof id !== "string" || !id) throw serviceError("bad-params", "window id is required");
257
+ const owner = pluginId(ctx);
258
+ const bucket = this.windows.get(owner);
259
+ const record = bucket?.get(id);
260
+ if (!record) return { closed: false };
261
+ bucket.delete(id);
262
+ if (bucket.size === 0 && this.windows.get(owner) === bucket) this.windows.delete(owner);
263
+ void record.stopEffect?.();
264
+ await this.callRpc("pluginKernel.windowControl", { pluginId: owner, windowId: id, action: "close" });
265
+ this.emitChanged();
266
+ return { closed: true };
267
+ }
268
+
269
+ listForPlugin(ctx) {
270
+ checkExperimental(ctx);
271
+ const owner = pluginId(ctx);
272
+ const bucket = this.windows.get(owner);
273
+ return bucket ? [...bucket.values()].map((record) => ({ ...record.state })) : [];
274
+ }
275
+
276
+ onEvent(ctx, listener) {
277
+ checkExperimental(ctx);
278
+ if (typeof listener !== "function") throw new TypeError("ctx.windows.onEvent needs a listener function");
279
+ const owner = pluginId(ctx);
280
+ const run = this.usage ? this.usage.wrap(owner, listener) : listener;
281
+ return ctx.effect(() => {
282
+ let set = this.listeners.get(owner);
283
+ if (!set) this.listeners.set(owner, (set = new Set()));
284
+ const hook = { ctx, run, active: true };
285
+ set.add(hook);
286
+ return () => {
287
+ hook.active = false;
288
+ set.delete(hook);
289
+ if (set.size === 0 && this.listeners.get(owner) === set) this.listeners.delete(owner);
290
+ };
291
+ }, "ctx.windows.onEvent()");
292
+ }
293
+
294
+ deliverEvent(params) {
295
+ const owner = params?.pluginId;
296
+ const windowId = params?.windowId;
297
+ if (typeof owner !== "string" || typeof windowId !== "string") return;
298
+ if (params.type === "closed") {
299
+ const bucket = this.windows.get(owner);
300
+ const record = bucket?.get(windowId);
301
+ if (record) {
302
+ bucket.delete(windowId);
303
+ if (bucket.size === 0 && this.windows.get(owner) === bucket) this.windows.delete(owner);
304
+ void record.stopEffect?.();
305
+ this.emitChanged();
306
+ }
307
+ }
308
+ const hooks = this.listeners.get(owner);
309
+ if (!hooks) return;
310
+ const { pluginId: _pluginId, ...event } = params;
311
+ for (const hook of [...hooks]) {
312
+ if (!hook.active) continue;
313
+ try {
314
+ hook.run(event);
315
+ } catch (error) {
316
+ hook.ctx.logger.error(error);
317
+ }
318
+ }
319
+ }
320
+
321
+ getRules(params = {}) {
322
+ const id = params?.id;
323
+ if (typeof id !== "string" || !id) throw serviceError("bad-params", "plugin-windows.getRules needs { id }");
324
+ return this.rulesFor(id);
325
+ }
326
+
327
+ async setRules(params = {}) {
328
+ const id = params?.id;
329
+ if (typeof id !== "string" || !id) throw serviceError("bad-params", "plugin-windows.setRules needs { id }");
330
+ const prev = this.rulesFor(id);
331
+ const next = {
332
+ disallowAlwaysOnTop: typeof params.disallowAlwaysOnTop === "boolean" ? params.disallowAlwaysOnTop : prev.disallowAlwaysOnTop,
333
+ disallowClickThrough: typeof params.disallowClickThrough === "boolean" ? params.disallowClickThrough : prev.disallowClickThrough,
334
+ hideAll: typeof params.hideAll === "boolean" ? params.hideAll : prev.hideAll,
335
+ };
336
+ if (!next.disallowAlwaysOnTop && !next.disallowClickThrough && !next.hideAll) {
337
+ delete this.rules[id];
338
+ } else {
339
+ this.rules[id] = next;
340
+ }
341
+ writeRulesFile(this.file, this.rules);
342
+ const bucket = this.windows.get(id);
343
+ if (bucket) {
344
+ for (const record of bucket.values()) {
345
+ const before = record.state;
346
+ const after = applyGuardrails(record.desired, next);
347
+ record.state = after;
348
+ if (next.hideAll && before.visible) {
349
+ await this.callRpc("pluginKernel.windowControl", { pluginId: id, windowId: record.id, action: "hide" });
350
+ } else if (!next.hideAll && !before.visible && after.visible) {
351
+ await this.callRpc("pluginKernel.windowControl", { pluginId: id, windowId: record.id, action: "show" });
352
+ }
353
+ if (before.alwaysOnTop !== after.alwaysOnTop || before.clickThrough !== after.clickThrough) {
354
+ await this.callRpc("pluginKernel.windowControl", {
355
+ pluginId: id,
356
+ windowId: record.id,
357
+ action: "update",
358
+ alwaysOnTop: after.alwaysOnTop,
359
+ clickThrough: after.clickThrough,
360
+ });
361
+ }
362
+ }
363
+ }
364
+ this.emitChanged({ id, ...next });
365
+ return { ...next };
366
+ }
367
+
368
+ listAll(params = {}) {
369
+ const filterId = typeof params?.id === "string" && params.id ? params.id : null;
370
+ const items = [];
371
+ for (const [owner, bucket] of this.windows.entries()) {
372
+ if (filterId && owner !== filterId) continue;
373
+ for (const record of bucket.values()) items.push({ ...record.state });
374
+ }
375
+ return { items };
376
+ }
377
+
378
+ emitChanged(rules) {
379
+ this.handle?.emit("changed", {
380
+ items: this.listAll().items,
381
+ ...(rules ? { rules } : {}),
382
+ });
383
+ }
384
+ }
package/src/index.d.mts CHANGED
@@ -1,13 +1,62 @@
1
1
  import type { RustApi } from "./host/index.mjs";
2
2
  import type { SlotName } from "./protocol.mjs";
3
- import type { ServicesApi } from "./services.mjs";
3
+ import type { Json, PluginWindowState, ServicesApi } from "./services.mjs";
4
4
 
5
5
  export { Context, Service } from "../vendor/cordis/core/lib/index.js";
6
6
  export type * from "./services.mjs";
7
7
  export type { RustApi, RustCallOptions } from "./host/index.mjs";
8
8
 
9
+ export interface PluginWindowSpec {
10
+ id: string;
11
+ title?: string;
12
+ kind?: string;
13
+ width?: number;
14
+ height?: number;
15
+ x?: number | null;
16
+ y?: number | null;
17
+ alwaysOnTop?: boolean;
18
+ clickThrough?: boolean;
19
+ resizable?: boolean;
20
+ visible?: boolean;
21
+ }
22
+
23
+ export interface PluginWindowPatch {
24
+ title?: string;
25
+ width?: number;
26
+ height?: number;
27
+ x?: number | null;
28
+ y?: number | null;
29
+ alwaysOnTop?: boolean;
30
+ clickThrough?: boolean;
31
+ resizable?: boolean;
32
+ visible?: boolean;
33
+ }
34
+
35
+ export interface PluginWindowEvent {
36
+ windowId: string;
37
+ type: string;
38
+ [key: string]: unknown;
39
+ }
40
+
41
+ export type HttpInput = string | { readonly href: string } | { readonly url: string };
42
+
43
+ export interface HttpResponseLike {
44
+ readonly ok: boolean;
45
+ readonly status: number;
46
+ readonly statusText: string;
47
+ readonly url: string;
48
+ readonly headers: unknown;
49
+ text(): Promise<string>;
50
+ json(): Promise<any>;
51
+ arrayBuffer(): Promise<ArrayBuffer>;
52
+ [key: string]: any;
53
+ }
54
+
55
+ export type HttpFetch = (input: any, init?: Record<string, any>) => Promise<HttpResponseLike>;
56
+
9
57
  declare module "../vendor/cordis/core/lib/index.js" {
10
58
  interface Context {
59
+ dataDir: string;
11
60
  setTimeout(callback: (...args: any[]) => void, ms?: number, ...args: any[]): () => Promise<void>;
12
61
  setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): () => Promise<void>;
13
62
  sleep(ms: number): Promise<void>;
@@ -16,6 +65,32 @@ declare module "../vendor/cordis/core/lib/index.js" {
16
65
  handle(method: string, handler: (params: any, caller: { window: string }) => unknown): () => Promise<void>;
17
66
  publish(topic: string, data?: unknown): void;
18
67
  };
68
+ commands: {
69
+ register(
70
+ commandId: string,
71
+ handler: (args?: any) => unknown,
72
+ meta?: { title?: Record<string, string>; keybinding?: string },
73
+ ): () => Promise<void>;
74
+ };
75
+ config: {
76
+ get<T extends Record<string, any> = Record<string, Json>>(): T;
77
+ set<T extends Record<string, any> = Record<string, Json>>(patch: Partial<T>): Promise<T>;
78
+ reset<T extends Record<string, any> = Record<string, Json>>(): Promise<T>;
79
+ onChange<T extends Record<string, any> = Record<string, Json>>(listener: (values: T) => void): () => Promise<void>;
80
+ };
81
+ http: {
82
+ fetch: HttpFetch;
83
+ };
84
+ windows: {
85
+ create(spec: PluginWindowSpec): Promise<PluginWindowState>;
86
+ update(id: string, patch: PluginWindowPatch): Promise<PluginWindowState>;
87
+ show(id: string): Promise<PluginWindowState>;
88
+ hide(id: string): Promise<PluginWindowState>;
89
+ focus(id: string): Promise<PluginWindowState>;
90
+ close(id: string): Promise<{ closed: boolean }>;
91
+ list(): PluginWindowState[];
92
+ onEvent(listener: (event: PluginWindowEvent) => void): () => Promise<void>;
93
+ };
19
94
  /**
20
95
  * Versioned services between plugins in the host (`timers/v1`). `provide` registers one until this plugin
21
96
  * stops; `get` returns a client whose methods find the current provider on every call. Users that need a
@@ -24,6 +24,7 @@ export interface SlotDefinition {
24
24
  readonly perPlugin: number;
25
25
  readonly groupBy?: string;
26
26
  readonly meta: readonly string[];
27
+ readonly experimental?: boolean;
27
28
  }
28
29
  export type SlotName =
29
30
  | "island.page/v1"
@@ -39,5 +40,6 @@ export type SlotName =
39
40
  | "island.dev/v1"
40
41
  | "settings.category/v1"
41
42
  | "settings.section/v1"
42
- | "settings.runner/v1";
43
+ | "settings.runner/v1"
44
+ | "plugin-window.view/v1";
43
45
  export declare const SLOTS: { readonly [Name in SlotName]: SlotDefinition };
package/src/protocol.mjs CHANGED
@@ -53,4 +53,5 @@ export const SLOTS = {
53
53
  "settings.category/v1": { kind: "list", perPlugin: 2, meta: ["group", "icon", "tabs", "available", "feature", "aliases"] },
54
54
  "settings.section/v1": { kind: "list", perPlugin: 4, groupBy: "category", meta: ["category"] },
55
55
  "settings.runner/v1": { kind: "list", perPlugin: 1, meta: [] },
56
+ "plugin-window.view/v1": { kind: "list", perPlugin: 8, meta: ["windowId", "title"], experimental: true },
56
57
  };
@@ -123,3 +123,97 @@ export declare function defineService<M extends MethodTable<M>, E extends EventT
123
123
  ): ServiceDefinition<M, E, P>;
124
124
 
125
125
  export declare function isServiceDefinition(value: unknown): value is ServiceDefinition;
126
+
127
+ export type CommandItem = {
128
+ pluginId: string;
129
+ pluginName: Record<string, string> | null;
130
+ id: string;
131
+ title: Record<string, string>;
132
+ defaultKeybinding: string | null;
133
+ keybinding: string | null;
134
+ active: boolean;
135
+ conflicts: string[];
136
+ };
137
+
138
+ export type CommandsMethods = {
139
+ list(): { items: CommandItem[] };
140
+ run(params: { plugin: string; command: string; args?: Json }): Json;
141
+ setKeybinding(params: { plugin: string; command: string; keybinding: string | null }): { items: CommandItem[] };
142
+ };
143
+
144
+ export type CommandsEvents = {
145
+ changed: { items: CommandItem[] };
146
+ };
147
+
148
+ export declare const commandsV1: ServiceDefinition<CommandsMethods, CommandsEvents, {}>;
149
+
150
+ export type PluginConfigPropertySchema = {
151
+ type: "boolean" | "string" | "number" | "integer";
152
+ title?: string | Record<string, string>;
153
+ description?: string | Record<string, string>;
154
+ default?: boolean | string | number;
155
+ enum?: Array<string | number>;
156
+ minimum?: number;
157
+ maximum?: number;
158
+ };
159
+
160
+ export type PluginConfigSchema = {
161
+ type?: "object";
162
+ properties?: Record<string, PluginConfigPropertySchema>;
163
+ [key: string]: Json | undefined;
164
+ };
165
+
166
+ export type PluginConfigValues = Record<string, Json>;
167
+
168
+ export type PluginConfigEntry = {
169
+ id: string;
170
+ schema: PluginConfigSchema | null;
171
+ values: PluginConfigValues;
172
+ defaults: PluginConfigValues;
173
+ };
174
+
175
+ export type PluginConfigMethods = {
176
+ list(): { items: PluginConfigEntry[] };
177
+ get(params: { id: string }): PluginConfigEntry;
178
+ set(params: { id: string; values: PluginConfigValues }): PluginConfigEntry;
179
+ reset(params: { id: string }): PluginConfigEntry;
180
+ };
181
+
182
+ export type PluginConfigEvents = {
183
+ changed: { id: string; values: PluginConfigValues };
184
+ };
185
+
186
+ export declare const pluginConfigV1: ServiceDefinition<PluginConfigMethods, PluginConfigEvents, {}>;
187
+
188
+ export type PluginWindowRules = {
189
+ disallowAlwaysOnTop: boolean;
190
+ disallowClickThrough: boolean;
191
+ hideAll: boolean;
192
+ };
193
+
194
+ export type PluginWindowState = {
195
+ pluginId: string;
196
+ id: string;
197
+ title: string;
198
+ kind: string;
199
+ width: number;
200
+ height: number;
201
+ x: number | null;
202
+ y: number | null;
203
+ alwaysOnTop: boolean;
204
+ clickThrough: boolean;
205
+ resizable: boolean;
206
+ visible: boolean;
207
+ };
208
+
209
+ export type PluginWindowsMethods = {
210
+ getRules(params: { id: string }): PluginWindowRules;
211
+ setRules(params: { id: string; disallowAlwaysOnTop?: boolean; disallowClickThrough?: boolean; hideAll?: boolean }): PluginWindowRules;
212
+ list(params?: { id?: string }): { items: PluginWindowState[] };
213
+ };
214
+
215
+ export type PluginWindowsEvents = {
216
+ changed: { items: PluginWindowState[]; rules?: { id: string } & PluginWindowRules };
217
+ };
218
+
219
+ export declare const pluginWindowsV1: ServiceDefinition<PluginWindowsMethods, PluginWindowsEvents, {}>;
package/src/services.mjs CHANGED
@@ -46,3 +46,18 @@ export function isServiceDefinition(value) {
46
46
  typeof value.events === "object",
47
47
  );
48
48
  }
49
+
50
+ export const commandsV1 = defineService("commands/v1", {
51
+ methods: { list: true, run: true, setKeybinding: true },
52
+ events: { changed: true },
53
+ });
54
+
55
+ export const pluginConfigV1 = defineService("plugin-config/v1", {
56
+ methods: { list: true, get: true, set: true, reset: true },
57
+ events: { changed: true },
58
+ });
59
+
60
+ export const pluginWindowsV1 = defineService("plugin-windows/v1", {
61
+ methods: { getRules: true, setRules: true, list: true },
62
+ events: { changed: true },
63
+ });