Skip to content

Commit

Permalink
Merge pull request #50 from Nexus-Mods/bugfix-deployment-event-handle…
Browse files Browse the repository at this point in the history
…rs-execution

Fixed deploy event handlers executing while managing other games
  • Loading branch information
insomnious authored Dec 12, 2024
2 parents 3c51e93 + 63f754d commit c09ba41
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.10.3 - 2024-11-07
## [1.10.4] - 2024-12-09

- Fixed deployment event handlers executing while other games are managed

## [1.10.3] - 2024-11-07
- Fixed engine injectors (SFSE excluded) being erroneously flagged as the Game Pass ASI Loader

## [1.10.2] - 2024-09-30
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starfield",
"version": "1.10.3",
"version": "1.10.4",
"description": "Vortex Extension for Starfield",
"author": "Nexus Mods",
"private": true,
Expand Down
19 changes: 14 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ const removePluginsWrap = (api: types.IExtensionApi) => {
);
};

const isCorrectGame = (api: types.IExtensionApi, profileId: string) => {
const state = api.getState();
const profile = selectors.profileById(state, profileId);
return profile?.gameId === GAME_ID;
};

function main(context: types.IExtensionContext) {
context.registerReducer(['settings', 'starfield'], settingsReducer);
// register a whole game, basic metadata and folder paths
Expand Down Expand Up @@ -249,9 +255,7 @@ async function onGameModeActivated(api: types.IExtensionApi) {
}

async function onDidDeployEvent(api: types.IExtensionApi, profileId: string, deployment: types.IDeploymentManifest): Promise<void> {
const state = api.getState();
const gameId = selectors.profileById(state, profileId)?.gameId;
if (gameId !== GAME_ID) {
if (!isCorrectGame(api, profileId)) {
return Promise.resolve();
}
await testDeprecatedFomod(api, false);
Expand All @@ -261,19 +265,24 @@ async function onDidDeployEvent(api: types.IExtensionApi, profileId: string, dep
}

async function onWillPurgeEvent(api: types.IExtensionApi, profileId: string): Promise<void> {
if (!isCorrectGame(api, profileId)) {
return Promise.resolve();
}
const pluginsPath = await resolvePluginsFilePath(api);
return fs.copyAsync(pluginsPath, PLUGINS_BACKUP, { overwrite: true }).catch((err) => null);
}

async function onDidPurgeEvent(api: types.IExtensionApi, profileId: string): Promise<void> {
if (!isCorrectGame(api, profileId)) {
return Promise.resolve();
}
return linkAsiLoader(api, ASI_LOADER_BACKUP, TARGET_ASI_LOADER_NAME);
}

async function onWillDeployEvent(api: types.IExtensionApi, profileId: any, deployment: types.IDeploymentManifest): Promise<void> {
const state = api.getState();
const pluginEnabler = util.getSafe(state, ['settings', 'starfield', 'pluginEnabler'], false);
const profile = selectors.activeProfile(state);
if (profile?.gameId !== GAME_ID || pluginEnabler === false) {
if (!isCorrectGame(api, profileId) || pluginEnabler === false) {
return Promise.resolve();
}
const discovery = selectors.discoveryByGame(state, GAME_ID);
Expand Down

0 comments on commit c09ba41

Please sign in to comment.