|
1 | | -import { request } from "./comms"; |
| 1 | +import { JsonValue } from "./commonTypes"; |
| 2 | +import { addNotificationListener, notify, request } from "./comms"; |
2 | 3 | import type { |
3 | 4 | GetTablesRequest, |
4 | 5 | GetColumnsRequest, |
@@ -213,7 +214,34 @@ export async function openTab(type: OpenTabRequest['args']['type'], args?: Omit< |
213 | 214 | return await request({ name: "openTab", args: { type, ...args } }); |
214 | 215 | } |
215 | 216 |
|
216 | | -/** Clipboard interface. */ |
| 217 | +/** @since Beekeeper Studio 5.4.0 */ |
| 218 | +export const broadcast = { |
| 219 | + post<T extends JsonValue = JsonValue>(message: T) { |
| 220 | + return notify("broadcast", { message }); |
| 221 | + }, |
| 222 | + on<T extends JsonValue = JsonValue>(handler: (message: T) => void) { |
| 223 | + addNotificationListener<T>("broadcast", (params) => { |
| 224 | + handler(params.message); |
| 225 | + }); |
| 226 | + }, |
| 227 | +} |
| 228 | + |
| 229 | +/** @since Beekeeper Studio 5.3.0 */ |
| 230 | +export const log = { |
| 231 | + error(err: string | Error) { |
| 232 | + return notify("pluginError", { |
| 233 | + name: err.name || "Error", |
| 234 | + message: err.message || err, |
| 235 | + stack: err.stack, |
| 236 | + }); |
| 237 | + }, |
| 238 | +} |
| 239 | + |
| 240 | +/** |
| 241 | + * Clipboard interface. |
| 242 | + * |
| 243 | + * @since Beekeeper Studio 5.3.0 |
| 244 | + **/ |
217 | 245 | export const clipboard = { |
218 | 246 | /** Write text to the Electron clipboard. */ |
219 | 247 | async writeText(text: string): Promise<void> { |
|
0 commit comments