Skip to content

OTools API

所有插件统一通过 window.otools 调用能力。

能力分组包含内容
系统能力剪贴板、文件与路径、通知、Shell 打开与管理
运行时信息平台、版本、插件 UUID、运行环境变量
Native 能力原生插件加载、调用、探测、热更新
插件状态本地状态与同步状态、支持 scheme 多文件存储

1. 运行时与环境信息

ts
const appName = otools.getAppName();
const appVersion = otools.getAppVersion();
const nativeId = otools.getNativeId();
const pluginUuid = otools.getPluginUuid();

const isDev = otools.isDev();
const platform = otools.isMacOS() ? 'macos' : otools.isWindows() ? 'windows' : 'linux';

const desktopPath = otools.getPath('desktop');

2. 剪贴板与文件能力

ts
otools.copyText('Hello OTools');
otools.copyFile(['/path/a.txt', '/path/b.png']);
otools.copyImage('data:image/png;base64,...');
const files = otools.getCopyedFiles();

3. 系统与 Shell

ts
otools.showNotification('构建完成');
otools.shellOpenPath('/Users/you/Desktop');
otools.shellShowItemInFolder('/Users/you/Downloads/file.zip');
otools.shellTrashItem('/Users/you/Downloads/old.log');
otools.shellOpenExternal('https://otools.lingyun.net');
otools.shellBeep();

4. Native 能力调用

ts
const result = await otools.invokeNative('ping', { from: 'plugin' });
const raw = await otools.invokeNativeRaw('echo', { hello: 'world' });

await otools.reloadNative();
const probe = await otools.probeNative();

跨插件调用:

ts
await otools.invokeNativePlugin('plugin-uuid', 'ping');
await otools.reloadNativePlugin('plugin-uuid');

5. 插件状态存储

支持 本地状态同步状态 两套存储;同时支持 scheme 形成多份 JSON 存储。

ts
const plugin = otools.getPluginUuid();

// local state
await otools.savePluginLocalState(plugin, { mode: 'focus' }, 'workspace');
const localState = await otools.getPluginLocalState(plugin, 'workspace');

// local state value
await otools.savePluginLocalStateValue(plugin, 'theme', 'dark', 'workspace');
const theme = await otools.getPluginLocalStateValue(plugin, 'theme', 'workspace');

// sync state
await otools.savePluginSyncState(plugin, { version: 1 }, 'profile');
const syncState = await otools.getPluginSyncState(plugin, 'profile');

提示:scheme 不传时默认 state.json,传入 workspace 会生成 workspace.json

OTools 海洋生态 · 高性能AI工作流平台