Skip to content

getMainWindow

Returns the app’s main window — the one the vault opened in, as opposed to any popout window.

Read from the root split, which is the one workspace container that always lives in the main window (every popout is a WorkspaceWindow under floatingSplit). Prefer this over the global window, which only happens to be the main window because plugin code runs in its context.

Before the workspace layout loads, there is no root split yet: Obsidian 1.15.1 loads community plugins (app.plugins.initialize()) before workspace.loadLayout() builds rootSplit, so a plugin enabled at startup runs its onload while rootSplit is still null. No popout exists at that point either, so the global window, the window plugin code runs in, is the main window, and that is what is returned then. WorkspaceRoot itself is built with that same window.

Import:

import { getMainWindow } from '@mnaoumov/obsidian-lib/workspace';

Signature:

function getMainWindow(app: App): Window

Parameters:

Parameter Type Description
app App The Obsidian app.

Returns: Window — The app’s main window.


Links to this page: