Skip to main content

Module NativeHost

Expand description

NativeHost atoms - native OS-layer handlers.

One pub async fn per file. This mod.rs only declares sub-modules; no pub use. Dispatch-site callers bring each atom in via local use.

Modules§

Clipboard
Wire methods: clipboard operations via nativeHost:*Clipboard*. Backed by arboard for cross-platform text clipboard access. Binary clipboard (readClipboardBuffer, writeClipboardBuffer) returns empty/null - binary clipboard is rarely used by VS Code core.
Exit
nativeHost:exit - exit with an explicit code. VS Code calls this from NativeHostMainService.exit(code) when an extension or the workbench requests a non-zero exit (crash reporter, restart-on-crash sentinel, etc.).
FindFreePort
Wire method: nativeHost:findFreePort. Scans 100 ports starting from Arguments[0] (default 9000) and returns the first free one. Returns 0 when nothing is free in-range so callers can distinguish “search exhausted” from a genuine port 0.
GetColorScheme
Wire method: nativeHost:getColorScheme. Returns { dark, highContrast }. Dark-mode probe covers macOS AppleInterfaceStyle, Windows AppsUseLightTheme, and a Linux ladder (GTK color-scheme → GTK theme name → KDE_COLOR_SCHEME → xfconf). High-contrast probe is Windows HighContrast/Flags and the GNOME a11y high-contrast key; other OSes return false.
GetEnvironmentPaths
Wire method: nativeHost:getEnvironmentPaths. Returns paths used by VS Code’s ResolveConfiguration to locate user-data, logs, home, and temp directories. The session-timestamped logs subdirectory is created on first call so VS Code can write output files immediately.
InstallShellCommand
nativeHost:installShellCommand - create a land (or code) symlink in /usr/local/bin pointing at the running executable so the user can launch the editor from a terminal. Mirrors VS Code’s “Install ‘code’ command in PATH” command. Uses pkexec/osascript to acquire elevated privileges when /usr/local/bin is not writable by the current user.
IsFullscreen
Wire method: nativeHost:isFullscreen. Returns true if the main webview window is fullscreen. Missing window returns false - this is a read-only probe and should not error.
IsMaximized
Wire method: nativeHost:isMaximized. Returns true if the main webview window is maximized. Missing window returns false (matches VS Code’s behaviour on orphaned calls).
IsRunningUnderARM64Translation
Wire method: nativeHost:isRunningUnderARM64Translation. On macOS checks sysctl.proc_translated (Rosetta 2). Cached via OnceLock - translation status is stable for the process lifetime.
KillProcess
nativeHost:killProcess - send SIGKILL (Unix) or TerminateProcess (Windows) to a child process. VS Code uses this to forcibly stop language servers and debug adapters that don’t respond to graceful shutdown within their timeout.
MoveItemToTrash
Wire method: nativeHost:moveItemToTrash. Routes deletions to the OS trash bin so they are recoverable. macOS uses Finder via osascript; Linux prefers gio trash then trash; Windows uses PowerShell Shell.Application. Returns true on success.
OSProperties
Wire method: nativeHost:getOSProperties (cross-platform). Returns Electron-shaped { type, release, arch, platform, cpus } tuple. Cached for the process lifetime - OS type, version, arch, and CPU topology are stable; spawning sw_vers/uname on every call wastes ~10 ms each.
OSStatistics
Wire method: nativeHost:getOSStatistics. Returns Electron-shaped { totalmem, freemem, loadavg } snapshot. loadavg is the Unix triple; on Windows it’s [0,0,0] by policy so the caller gets a well-formed array.
OpenDevTools
nativeHost:openDevTools - open the WebKit inspector for the main window. Requires the devtools Tauri feature (already enabled in the debug profile via TAURI_DEV_TOOLS env or cargo feature flag).
OpenExternal
Wire method: native:openExternal, nativeHost:openExternal. Opens an http/https URL in the platform default browser.
PickFolder
Wire method: nativeHost:pickFolderAndOpen, :pickFileAndOpen, :pickFileFolderAndOpen, :pickWorkspaceAndOpen.
Quit
nativeHost:quit - save state and gracefully exit the process. VS Code calls this from ILifecycleMainService.quit() on Cmd+Q, File → Quit, and the “Quit” tray item.
Relaunch
nativeHost:relaunch - restart the process with the same argv. VS Code calls this from ILifecycleMainService.relaunch() when an extension update is applied, the user picks “Restart to Apply”, or the workbench triggers a self-restart after a crash.
Reload
nativeHost:reload - reload the webview without restarting the process. VS Code calls this from ILifecycleMainService.reload() for “Reload Window” (Developer menu / Cmd+Shift+P → Reload Window).
ShowItemInFolder
Wire method: native:showItemInFolder, nativeHost:showItemInFolder. Reveals a path in the platform file manager (Finder / Explorer / Linux FM).
ShowMessageBox
Wire method: nativeHost:showMessageBox. Surfaces a blocking modal message dialog via tauri_plugin_dialog. Returns { response: 0 } (OK pressed) or { response: 1 } (dismissed). VS Code destructures result.response to determine which button was chosen.
ShowOpenDialog
Wire method: nativeHost:showOpenDialog.
ShowSaveDialog
Wire methods: nativeHost:showSaveDialog, UserInterface.ShowSaveDialog.
ToggleDevTools
nativeHost:toggleDevTools - open the inspector if closed, close it if open. Used by the Help → Toggle Developer Tools menu item.
UninstallShellCommand
nativeHost:uninstallShellCommand - remove the land symlink from /usr/local/bin. Mirrors VS Code’s “Uninstall ‘code’ command from PATH”.