Skip to content
3 Death Saves

API and Hooks

Default Detach attaches its API to its module entry once Foundry is ready.

const api = game.modules.get('default-detach').api;

add and remove each take a kind of either 'app' or 'type'. 'app' targets the Individual Windows list and takes an application id. 'type' targets the Document Types list and takes a document-type key. When kind is omitted, the method acts on 'app'. list takes no arguments and returns both lists.

A document-type key is the document name on its own, such as Actor, or the document name and subtype joined by a slash, such as Actor/npc. A document with no subtype data uses the bare document name, as does a document whose subtype is the base document type.

Both lists are stored per user. add and remove change the selections of the user running the code, not the world.

await api.add(id, kind);

Adds an application id or a document-type key to its auto-detach list. Returns a promise. Adding an entry already on the list changes nothing.

The stored displayName comes from the applications the module has discovered this session, whether from a window that has rendered or from a module that declared its detachable windows to 3DS:ATLAS. An id the module has not discovered is stored with the id itself as its display name.

A list entry is applied when a window opens. Adding an id does not detach a window that is already open, and a window that cannot be detached is left alone.

await api.remove(id, kind);

Removes an application id or a document-type key from its auto-detach list. Returns a promise. Removing an entry that is not on the list changes nothing.

const { apps, types } = api.list();

Returns the current selections. apps is an array of objects with an id and a displayName. types is an array of document-type keys.

Both hooks receive the application being detached and its type. The type is an object with a key and a label, or null when the application has no document.

Hooks.on('default-detach.preDetach', (application, type) => {
if (type?.key === 'Actor/npc') return false;
});

Fires before a window detaches. Returning false cancels the detachment.

Hooks.on('default-detach.detached', (application, type) => {
console.log(`${application.id} detached`);
});

Fires after a window has detached.

Both hooks fire for manual detachment and for automatic detachment driven by your saved lists.