Difference between revisions of "Vortex API Events"

From Nexus Mods Wiki
Jump to: navigation, search
(Initial posting)
 
m (Events: Added remaining events)
Line 99: Line 99:
 
|}
 
|}
  
 +
=== Did Deploy ===
 +
Emitted asynchronously by Vortex after finishing a deployment.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| did-deploy
 +
|-
 +
| Parameters
 +
|<code>(profileId: string, newDeployment: { [modType: string]: IDeployedFile[] })</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.onAsync('did-deploy',
 +
    (profiled, newDeployment) => console.log(`Finished deploying mods for profile ${profileId}`)
 +
);
 +
 +
context.api.emitAndAwait('did-deploy', profileId, thisDeployment);
 +
</pre>
 +
|-
 +
|}
 +
 +
=== Profile Will Change ===
 +
Emitted by Vortex before switching between profiles.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| profile-will-change
 +
|-
 +
| Parameters
 +
|<code>(newProfileId: string, enqueue: (cb: () => Promise<void>) => void)</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.events.on('profile-will-change',
 +
    (newProfileId, enqueue: () => undefined) => console.log(`Preparing to switch to profile ${newProfileId}`)
 +
);
 +
</pre>
 +
|-
 +
| Notes
 +
|
 +
* The events <code>profile-will-change</code> and <code>profile-did-change</code> also fire when swapping between games, because each game has a separate profile.
 +
* The newProfileId property can be undefined if the user deletes the last profile for their active game.
 +
|-
 +
|}
 +
 +
=== Profile Did Change ===
 +
Emitted by Vortex after switching between profiles.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| profile-did-change
 +
|-
 +
| Parameters
 +
|<code>(newProfileId: string)</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.events.on('profile-did-change',
 +
    (newProfileId => console.log(`Finished switching to profile ${newProfileId}`)
 +
);
 +
</pre>
 +
|-
 +
| Notes
 +
|
 +
* The events <code>profile-will-change</code> and <code>profile-did-change</code> also fire when swapping between games, because each game has a separate profile.
 +
* The newProfileId property can be undefined if the user deletes the last profile for their active game.
 +
|-
 +
|}
 +
 +
=== Did Import Downloads ===
 +
Emitted by Vortex after adding new downloads to the downloads section.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| did-import-downloads
 +
|-
 +
| Parameters
 +
|<code>(dlIds: string[])</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.events.on('did-import-downloads',
 +
    (dlIds => console.log(`Imported ${dlIds.length} downloads`)
 +
);
 +
</pre>
 +
|-
 +
|}
 +
 +
=== Will Move Downloads ===
 +
Emitted by Vortex before the user relocates their download folder for a game.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| will-move-downloads
 +
|-
 +
| Parameters
 +
|''none''
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.events.on('profile-did-change',
 +
    (() => console.log('Vortex is preparing to move downloads.')
 +
);
 +
</pre>
 +
|-
 +
|}
 +
 +
=== Filehash Calculated ===
 +
Emitted by Vortex after the user adds a new file and its MD5 has been calculated.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| filehash-calculated
 +
|-
 +
| Parameters
 +
|<code>(filePath: string, fileMD5: string, fileSize: number)</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.events.on('filehash-calculated',
 +
    (filePath, fileMD5, fileSize) => console.log(`File at ${filePath} is ${fileSize} bytes with MD5 of ${fileMD5}`)
 +
);
 +
</pre>
 +
|-
 +
|}
 +
 +
=== Added Files ===
 +
Emitted asynchronously by Vortex if new files have been created in the mods folder and Vortex has attempted to identify where they came from.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| added-files
 +
|-
 +
| Parameters
 +
|<code>(profileId: string, newFiles: Array<{ filePath: string, candidates: string[] }>)</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.onAsync('added-files',
 +
    (profileId, newFiles) => {
 +
        const fileInfo = newFiles.map(f => `File${f.filePath} could be a part of the following mods ${f.candidates.join('\n')}`).join('\n');
 +
        console.log(`New files detected in the mods folder for ${profileId}\n${fileInfo}`);
 +
    })
 +
);
 +
</pre>
 +
|-
 +
|}
 +
 +
=== Mod Enabled ===
 +
Emitted by Vortex when a mod is toggled from disabled to enabled.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| mod-enabled
 +
|-
 +
| Parameters
 +
|<code>(profileId: string, modId: string)</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.events.on('mod-enabled', (profileId, modId) => console.log(`Mod ${modId} enabled in ${profileId}`)
 +
);
 +
</pre>
 +
|-
 +
|}
 +
 +
=== Mod Disabled ===
 +
Emitted by Vortex when a mod is toggled from enabled to disabled.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| mod-disabled
 +
|-
 +
| Parameters
 +
|<code>(profileId: string, modId: string)</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.events.on('mod-disabled', (profileId, modId) => console.log(`Mod ${modId} disabled in ${profileId}`)
 +
);
 +
</pre>
 +
|-
 +
|}
 +
 +
=== Mod Content Changed ===
 +
Emitted when Vortex determines the files inside a mod were changed (files might have been deleted or added). Primarily useful to update caches.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| mod-content-changed
 +
|-
 +
| Parameters
 +
|<code>(profileId: string, modId: string)</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.events.on('mod-content-changed', (profileId, modId) => console.log(`Mod ${modId} in ${profileId} changed`)
 +
);
 +
</pre>
 +
|-
 +
|}
 +
 +
=== Will Purge ===
 +
Emitted by Vortex before purging deployed mods.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| will-purge
 +
|-
 +
| Parameters
 +
|<code>(profileId: string, deployment: IDeployment)</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.events.on('will-purge', (profileId, deployment) => console.log(`Preparing to purge on profile ${profileId}`)
 +
);
 +
</pre>
 +
|-
 +
|}
 +
 +
=== Did Purge ===
 +
Emitted by Vortex after purging deployed mods.
 +
{| class="wikitable" style="width:80%"
 +
| style="width:10%" | Name
 +
| did-purge
 +
|-
 +
| Parameters
 +
|<code>(profileId: string)</code>
 +
|-
 +
| Example
 +
|<pre>
 +
context.api.events.on('did-purge', (profileId) => console.log(`Finished purge on profile ${profileId}`)
 +
);
 +
</pre>
 +
|-
 +
|}
  
 
== Commands ==
 
== Commands ==

Revision as of 15:46, 16 June 2020

This page will document all the events Vortex can send and receive using the Vortex API.

Interacting with events

You can both catch and emit all events inside Vortex. The Vortex API is accessed as a property of the context object.

In order to have your extension respond to an event you can use the following:

context.api.events.on('eventName', callback);

context.api.onAsync('eventName', callback);

To emit an event (or command) yourself use the following:

context.api.events.emit('eventName', callback);

context.api.emitAndAwait('eventName', callback);

Notice that the asynchronous version is called from the API object directly, rather than from the events property.

Events

Mods Enabled

Emitted by Vortex when one or more mods are enabled.

Name mods-enabled
Parameters (mods: string[], enabled: boolean, gameId: string)
Example
context.api.events.on('mods-enabled', 
    (mods, enabled, gameId) => console.log(`${mods.count} mods ${enabled ? 'enabled' : 'disabled'} in ${gameId}`) 
);

Game Mode Activated

Emitted by Vortex when switching the currently managed game, including when the application first starts.

Name gamemode-activated
Parameters (gameId: string)
Example
context.api.events.on('gamemode-activated', 
    (gameId) => console.log(`Activated game mode in ${gameId}`) 
);
Notes
  • The gameId property can be undefined. This usually happens when the user deletes their last profile for an active game.

Startup

Emitted by Vortex when the application first starts.

Name startup
Parameters none
Example
context.api.events.on('startup', 
    () => console.log('Vortex is starting up.') 
);

Will Deploy

Emitted asynchronously by Vortex before starting a deployment.

Name will-deploy
Parameters (profileId: string, oldDeployment: { [modType: string]: IDeployedFile[] })
Example
context.api.onAsync('will-deploy', 
    (profiled, oldDeployment) => console.log(`About to deploy mods for profile ${profileId}`) 
);

context.api.emitAndAwait('will-deploy', profileId, lastDeployment);

Did Deploy

Emitted asynchronously by Vortex after finishing a deployment.

Name did-deploy
Parameters (profileId: string, newDeployment: { [modType: string]: IDeployedFile[] })
Example
context.api.onAsync('did-deploy', 
    (profiled, newDeployment) => console.log(`Finished deploying mods for profile ${profileId}`) 
);

context.api.emitAndAwait('did-deploy', profileId, thisDeployment);

Profile Will Change

Emitted by Vortex before switching between profiles.

Name profile-will-change
Parameters (newProfileId: string, enqueue: (cb: () => Promise<void>) => void)
Example
context.api.events.on('profile-will-change', 
    (newProfileId, enqueue: () => undefined) => console.log(`Preparing to switch to profile ${newProfileId}`) 
);
Notes
  • The events profile-will-change and profile-did-change also fire when swapping between games, because each game has a separate profile.
  • The newProfileId property can be undefined if the user deletes the last profile for their active game.

Profile Did Change

Emitted by Vortex after switching between profiles.

Name profile-did-change
Parameters (newProfileId: string)
Example
context.api.events.on('profile-did-change', 
    (newProfileId => console.log(`Finished switching to profile ${newProfileId}`) 
);
Notes
  • The events profile-will-change and profile-did-change also fire when swapping between games, because each game has a separate profile.
  • The newProfileId property can be undefined if the user deletes the last profile for their active game.

Did Import Downloads

Emitted by Vortex after adding new downloads to the downloads section.

Name did-import-downloads
Parameters (dlIds: string[])
Example
context.api.events.on('did-import-downloads', 
    (dlIds => console.log(`Imported ${dlIds.length} downloads`) 
);

Will Move Downloads

Emitted by Vortex before the user relocates their download folder for a game.

Name will-move-downloads
Parameters none
Example
context.api.events.on('profile-did-change', 
    (() => console.log('Vortex is preparing to move downloads.') 
);

Filehash Calculated

Emitted by Vortex after the user adds a new file and its MD5 has been calculated.

Name filehash-calculated
Parameters (filePath: string, fileMD5: string, fileSize: number)
Example
context.api.events.on('filehash-calculated', 
    (filePath, fileMD5, fileSize) => console.log(`File at ${filePath} is ${fileSize} bytes with MD5 of ${fileMD5}`) 
);

Added Files

Emitted asynchronously by Vortex if new files have been created in the mods folder and Vortex has attempted to identify where they came from.

Name added-files
Parameters (profileId: string, newFiles: Array<{ filePath: string, candidates: string[] }>)
Example
context.api.onAsync('added-files', 
    (profileId, newFiles) => {
        const fileInfo = newFiles.map(f => `File${f.filePath} could be a part of the following mods ${f.candidates.join('\n')}`).join('\n');
        console.log(`New files detected in the mods folder for ${profileId}\n${fileInfo}`);
    }) 
);

Mod Enabled

Emitted by Vortex when a mod is toggled from disabled to enabled.

Name mod-enabled
Parameters (profileId: string, modId: string)
Example
context.api.events.on('mod-enabled', (profileId, modId) => console.log(`Mod ${modId} enabled in ${profileId}`) 
);

Mod Disabled

Emitted by Vortex when a mod is toggled from enabled to disabled.

Name mod-disabled
Parameters (profileId: string, modId: string)
Example
context.api.events.on('mod-disabled', (profileId, modId) => console.log(`Mod ${modId} disabled in ${profileId}`) 
);

Mod Content Changed

Emitted when Vortex determines the files inside a mod were changed (files might have been deleted or added). Primarily useful to update caches.

Name mod-content-changed
Parameters (profileId: string, modId: string)
Example
context.api.events.on('mod-content-changed', (profileId, modId) => console.log(`Mod ${modId} in ${profileId} changed`) 
);

Will Purge

Emitted by Vortex before purging deployed mods.

Name will-purge
Parameters (profileId: string, deployment: IDeployment)
Example
context.api.events.on('will-purge', (profileId, deployment) => console.log(`Preparing to purge on profile ${profileId}`) 
);

Did Purge

Emitted by Vortex after purging deployed mods.

Name did-purge
Parameters (profileId: string)
Example
context.api.events.on('did-purge', (profileId) => console.log(`Finished purge on profile ${profileId}`) 
);

Commands

Internal Events