# Environment

Source: https://developers.inkdrop.app/modules/environment

The top-level object representing the Inkdrop application in the renderer process — packages, themes, menus, the local database, and the window.
Your plugin receives it as the first argument of `activate(env)`.

```ts
import type { Environment, IInkdropPlugin } from '@inkdropapp/types'

class YourPlugin implements IInkdropPlugin {
  activate(env: Environment) {
    env.notifications.addInfo(`Running Inkdrop ${env.appVersion}`)
  }
  deactivate(env: Environment) {
    env.notifications.addInfo('Your plugin is deactivated')
  }
}

export default new YourPlugin()
```

The same instance is also exposed globally as `inkdrop`, but that global is deprecated and will be sandboxed away in a future release, so take `env` from `activate()` instead.

---

## Properties

- **appVersion** (string)

  The application version string.
- **clipboard** (object)

  The system clipboard proxy. See [IPCClipboard](https://github.com/inkdropapp/types/blob/main/src/ipc/clipboard.d.ts) for the available methods.
- **commands** (object)

  A [CommandRegistry](https://developers.inkdrop.app/modules/command-registry) instance.
- **components** (object)

  A [ComponentManager](https://developers.inkdrop.app/modules/component-manager) instance.
- **config** (object)

  A [Config](https://developers.inkdrop.app/modules/config) instance.
- **contextMenu** (object)

  A [ContextMenuManager](https://developers.inkdrop.app/modules/context-menu-manager) instance.
- **devMode** (boolean)

  Boolean, true if Development Mode is enabled, false if disabled.
- **dialog** (object)

  The native dialog box proxy. See [IPCDialog](https://github.com/inkdropapp/types/blob/main/src/ipc/dialog.d.ts) for the available methods.
- **keymaps** (object)

  A [KeymapManager](https://developers.inkdrop.app/modules/keymap-manager) instance.
- **layouts** (object)

  A [LayoutManager](https://developers.inkdrop.app/modules/layout-manager) instance.
- **localDB** (object)

  The local database proxy, with [notes](https://developers.inkdrop.app/data-access/notes), [books](https://developers.inkdrop.app/data-access/books), [tags](https://developers.inkdrop.app/data-access/tags), [files](https://developers.inkdrop.app/data-access/files) and [utils](https://developers.inkdrop.app/data-access/utils) sub-objects plus [change events](https://developers.inkdrop.app/data-access/events). See [Accessing the local database](https://developers.inkdrop.app/guides/access-the-local-database).
- **markdownRenderer** (object)

  A [MarkdownRenderer](https://developers.inkdrop.app/modules/markdown-renderer) instance.
- **menu** (object)

  A [MenuManager](https://developers.inkdrop.app/modules/menu-manager) instance.
- **notifications** (object)

  A [NotificationManager](https://developers.inkdrop.app/modules/notification-manager) instance.
- **packages** (object)

  A [PackageManager](https://developers.inkdrop.app/modules/package-manager) instance.
- **resourcePath** (string)

  A path to the app's bundled resource directory. For example, usually `"/Applications/Inkdrop.app/Contents/Resources/app.asar"` on macOS.
- **store** (object)

  The [Redux store](https://redux.js.org/api/store) holding the [app state](https://developers.inkdrop.app/states). Use `store.getState()` to read it and `store.dispatch()` to run an [action](https://developers.inkdrop.app/actions) — see [Getting & modifying the app state](https://developers.inkdrop.app/guides/flux-architecture).
- **styles** (object)

  A [StyleManager](https://developers.inkdrop.app/modules/style-manager) instance.
- **telescope** (object)

  A [TelescopeManager](https://developers.inkdrop.app/modules/telescope-manager) instance.
- **themes** (object)

  A [ThemeManager](https://developers.inkdrop.app/modules/theme-manager) instance.
- **userDataPath** (string)

  The path to [the user's data directory](https://docs.inkdrop.app/reference/user-data-directory).
- **window** (object)

  The IPC proxy for the current window.

---

## Editor Load Event `onEditorLoad(callback)`

Invoke the given callback when the editor has been loaded.

> **Note:**
>
> Prefer [`ensureEditorLoaded(callback)`](#ensure-editor-loaded), which also covers the case where an editor is already loaded by the time your plugin subscribes.

### Parameters

- **callback(editor)** (function, required)

  Function to be called when the editor loads, where `editor` is the [EditorView](https://codemirror.net/docs/ref/#view.EditorView) instance that was loaded.

### Returns

Returns a [Disposable](https://developers.inkdrop.app/event-subscription/disposable) on which `.dispose()` can be called to unsubscribe.

---

## Editor Unload Event `onEditorUnload(callback)`

Invoke the given callback when the editor has been unloaded.

### Parameters

- **callback()** (function, required)

  Function to be called when the editor unloads.

### Returns

Returns a [Disposable](https://developers.inkdrop.app/event-subscription/disposable) on which `.dispose()` can be called to unsubscribe.

---

## Ensure Editor Loaded `ensureEditorLoaded(callback)`

Run the given callback with the active editor, waiting for one if needed.
If an editor is already loaded, the callback is invoked immediately; otherwise it is invoked once when the next editor loads, after which the subscription disposes itself.

### Parameters

- **callback(editor)** (function, required)

  Function to be called with the loaded [EditorView](https://codemirror.net/docs/ref/#view.EditorView).

### Returns

Nothing. In windows without an editor the callback simply never fires rather than throwing.

---

## App Readiness Event `onAppReady(callback)`

Invoke the given callback when the app is ready.

### Parameters

- **callback()** (function, required)

  Function to be called when the app is ready.

### Returns

Returns a [Disposable](https://developers.inkdrop.app/event-subscription/disposable) on which `.dispose()` can be called to unsubscribe.

---

## App Quit Event `onAppQuit(callback)`

Invoke the given callback when the app is about to quit.

### Parameters

- **callback()** (function, required)

  Function to be called before the app quits.

### Returns

Returns a [Disposable](https://developers.inkdrop.app/event-subscription/disposable) on which `.dispose()` can be called to unsubscribe.

---

## Is Editor Active `isEditorActive()`

Check if the editor is currently active.

### Returns

Returns a Boolean indicating whether the editor is active.

---

## Get Active Editor `getActiveEditor()`

Retrieve the active editor instance.

### Returns

Returns the active [EditorView](https://codemirror.net/docs/ref/#view.EditorView) if the editor is active, otherwise `null` or `undefined`.

---

## Get Active Editor with Error Handling `getActiveEditorOrThrowError()`

Retrieve the active editor instance or throw an error if it's not available.

### Returns

Returns the active [EditorView](https://codemirror.net/docs/ref/#view.EditorView) if the editor is active, otherwise throws an error.

---

## Set Active Editor `setActiveEditor(editor)`

Set the currently active editor instance.

### Parameters

- **editor** (EditorView, required)

  The [EditorView](https://codemirror.net/docs/ref/#view.EditorView) to set as the active editor, or `null` to clear it.

---
