# event

## onPluginCreate(callback) <a href="#gylpl" id="gylpl"></a>

When the plugin window is created, Eagle will actively call this method. You can use this method to initialize the modules required by the plugin.

* `callback` Function
  * `plugin` Object - Plugin attributes
    * `manifest` Object - The complete configuration of the plugin's manifest.json.
    * `path` String - The path where the plugin is located

```javascript
eagle.onPluginCreate((plugin) => {
    console.log(plugin.manifest.name);
    console.log(plugin.manifest.version);
    console.log(plugin.manifest.logo);
    console.log(plugin.path);
});
```

{% hint style="info" %}
Tip: If the plugin can run without manifest information, you can also use `window.onload` for development.
{% endhint %}

## onPluginRun(callback) <a href="#gylpl" id="gylpl"></a>

When the user clicks on the plugin in the plugin panel, Eagle will actively call this method.

* `callback` Function

```javascript
eagle.onPluginRun(() => {
    console.log('eagle.onPluginRun');
});
```

## onPluginBeforeExit(callback) <a href="#z1a5y" id="z1a5y"></a>

Before the plugin window closes, Eagle will actively call this method.

* `callback` Function

```javascript
eagle.onPluginBeforeExit(() => {
    console.log("Plugin will exit");
});

// Prevent window from closing
window.onbeforeunload = (event) => {
    return event.returnValue = false;
};
```

{% hint style="info" %}
Tip: If you want to prevent the window from being closed, you can register the `window.onbeforeunload` method to avoid the window being closed.
{% endhint %}

## onPluginShow(callback) <a href="#w2vxi" id="w2vxi"></a>

When the plugin window is displayed, Eagle will actively call this method.

* `callback` Function

```javascript
eagle.onPluginShow(() => {
    console.log("Plugin window displayed");
});
```

## onPluginHide(callback) <a href="#zgvst" id="zgvst"></a>

When the plugin window is hidden, Eagle will actively call this method.

* `callback` Function

```javascript
eagle.onPluginHide(() => {
    console.log("Plugin window hidden");
});
```

## onLibraryChanged(callback) <a href="#g3tny" id="g3tny"></a>

When the user switches the resource library, Eagle will actively call this method.

* `callback` Function
  * `libraryPath` String - The current resource library path.

```javascript
eagle.onLibraryChanged((libraryPath) => {
    console.log(`Resource library switch detected, new resource library path: ${libraryPath}`);
});
```

{% hint style="info" %}
Tip: If you need to get more complete information about the resource library, you can use the `eagle.library.info()` method to obtain it.
{% endhint %}

{% hint style="warning" %}
**Note:** If the plugin execution process must rely on a relative resource library path, you may need to register this method and make corresponding adjustments when the resource library changes to avoid errors during program execution.
{% endhint %}

## onThemeChanged(callback) <a href="#xlf6z" id="xlf6z"></a>

When the main program theme color of Eagle changes, Eagle will actively call this method. If the plugin supports multiple color themes, you can use this method to make corresponding UI adjustments.

* `callback` Function
  * `theme` String - The name of the current theme color, such as `Auto`, `LIGHT`, `LIGHTGRAY`, `GRAY`, `DARK`, `BLUE`, `PURPLE`.

```javascript
eagle.onThemeChanged((theme) => {
    console.log(`Color theme has changed to: ${theme}`);
});
```

### &#x20;<a href="#nptwx" id="nptwx"></a>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.eagle.cool/plugin-api/api/event.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
