Shell
host.shell: open another extension's view, open links outside SpaceMIX, copy to the clipboard and let the user save a file.
The sandboxed frame can't open windows, navigate, or save files. host.shell does those through the app around
it.
interface SpacemixHost {
shell: ShellApi; // always present
}
interface ShellApi {
open(extensionId: string): Promise<void>;
openUrl(url: string): Promise<void>;
copy(text: string): Promise<void>;
save(filename: string, data: string | ArrayBuffer | Uint8Array, mime?: string): Promise<void>;
}
Permission: none.
host.shell.open
open(extensionId: string): Promise<void>;
Shows another extension's view, if it's installed. Resolves without doing anything when it isn't (no error), so
it is safe to call for an optional companion. It can't pass a target or route. Bridge method: shell.open.
Errors: The extension id must be a string.
host.shell.openUrl
openUrl(url: string): Promise<void>;
Opens a link outside SpaceMIX: http: and https: in the system browser on desktop or a new tab in a browser;
mailto: and tel: in the system's mail or phone app. Any other scheme rejects with
Only http(s), mailto: and tel: links can be opened.; a string that isn't a URL rejects. Bridge method:
shell.openUrl.
You rarely need to call it: the frame runtime routes left clicks on <a href> links with those schemes here by
itself, unless your own handler calls preventDefault, the link has download, or it only jumps to a #hash in
the frame's document.
host.shell.copy
copy(text: string): Promise<void>;
Copies text to the clipboard. The host writes it; if the host's clipboard refuses (its document isn't focused),
the frame tries its own clipboard and rejects only if both fail. Call it from a click. Bridge method:
shell.copy.
host.shell.save
save(filename: string, data: string | ArrayBuffer | Uint8Array, mime?: string): Promise<void>;
Lets the user save a file: the native save dialog in the desktop app (resolves without writing anything if they
cancel), a download in a browser. filename is a suggestion; folders are stripped and an empty name becomes
download. A string is saved as UTF-8. mime (default application/octet-stream) is used for the browser
download. Bridge method: shell.save.
Example
import { host } from "@spacemix/sdk";
export async function exportCsv(rows: string[][]): Promise<void> {
const csv = rows.map((r) => r.map((c) => `"${c.replace(/"/g, '""')}"`).join(",")).join("\n");
await host.shell.save("export.csv", csv, "text/csv");
}
Stability
Stable.