Improve editor, plugin updates, and window transfers for 0.1.41
This commit is contained in:
@@ -4,7 +4,6 @@ import { registerCompletionInput } from "../completion/input.ts";
|
||||
import { showActionMenu } from "../ui/managedActionMenu.ts";
|
||||
import { backgroundHub } from "./backgrounds.ts";
|
||||
import type { BackgroundFiles } from "./backgroundContracts.ts";
|
||||
import { pluginTranslation } from "./translation.ts";
|
||||
import type { Dispose, PluginApi, PluginCommand, PluginModule, PluginView, PluginDocumentType, PluginDocumentContext } from "./sdk.ts";
|
||||
|
||||
export function deadline<T>(work: Promise<T>, milliseconds = 5000): Promise<T> {
|
||||
@@ -55,7 +54,6 @@ export class ExternalSession {
|
||||
};
|
||||
const api: PluginApi = {
|
||||
id: this.id, signal: this.controller.signal,
|
||||
i18n: pluginTranslation(() => this.check(), off => { this.contributions.push(off); }),
|
||||
...(this.services.backgrounds ? { backgrounds: {
|
||||
version: 1 as const,
|
||||
chooseFolder: () => this.backgroundRequest(() => this.services.backgrounds!.chooseFolder()),
|
||||
@@ -101,7 +99,7 @@ export class ExternalSession {
|
||||
},
|
||||
contribute: (key, value) => { this.check(); this.contributions.push(this.registry.register(this.id, key, value)); },
|
||||
registerCommand: item => { if (item.category !== undefined && !["open", "action"].includes(item.category)) throw new Error("Unknown plugin command category."); if (typeof item.run !== "function") throw new Error("A command needs a run function."); register(this.commands, item); },
|
||||
registerView: item => { if ([item.settings, item.launcher, item.navigation, item.toolbar].some(value => value !== undefined && typeof value !== "boolean")) throw new Error("Plugin view access options must be boolean."); if (item.placement !== undefined && !["dialog", "editor", "sidebar"].includes(item.placement)) throw new Error("Unknown plugin view placement."); if (typeof item.mount !== "function") throw new Error("A view needs a mount function."); register(this.views, item); },
|
||||
registerView: item => { if ([item.settings, item.launcher, item.navigation, item.toolbar].some(value => value !== undefined && typeof value !== "boolean")) throw new Error("Plugin view access options must be boolean."); if (item.placement !== undefined && !["dialog", "editor", "sidebar"].includes(item.placement)) throw new Error("Unknown plugin view placement."); if (item.launch !== undefined && typeof item.launch !== "function") throw new Error("A view launch handler must be a function."); if (typeof item.mount !== "function") throw new Error("A view needs a mount function."); register(this.views, item); },
|
||||
registerTabDrop: receive => { this.check(); if (typeof receive !== "function" || this.receiveTab) throw new Error("Invalid or duplicate tab receiver."); this.receiveTab = receive; },
|
||||
updateViewTitle: (id, title) => {
|
||||
this.check(); const view = this.views.get(id);
|
||||
@@ -171,6 +169,13 @@ export class ExternalSession {
|
||||
await deadline(this.activation);
|
||||
}
|
||||
async run(id: string) { this.check(); const command = this.commands.get(id); if (!command) throw new Error("Unknown plugin command."); await command.run(); }
|
||||
async launch(id: string) {
|
||||
this.check();
|
||||
const view = this.views.get(id);
|
||||
if (!view) throw new Error("Unknown plugin view.");
|
||||
if (view.launch) await view.launch();
|
||||
else this.show(id);
|
||||
}
|
||||
private backgroundRequest<T>(request: () => Promise<T>): Promise<T> {
|
||||
this.check();
|
||||
return request().then(value => { this.check(); return value; });
|
||||
|
||||
Reference in New Issue
Block a user