Skip to content

Commit

Permalink
fix(integration): avoid fetching data from inactive integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGiddyLimit committed Aug 2, 2023
1 parent bf4d026 commit 2b4b810
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion module/js/integrations/ChrisPremades.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class IntegrationChrisPremades extends StartupHookMixin(IntegrationBase)
"vehicle",
]);

async pGetExpandedAddonData (
async _pGetExpandedAddonData (
{
propJson,
path,
Expand Down
21 changes: 20 additions & 1 deletion module/js/integrations/IntegrationBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class IntegrationBase {
_onHookInit () { /* Implement as required */ }
_onHookReady () { /* Implement as required */ }

/** @abstract */
async pGetExpandedAddonData (
{
propJson,
Expand All @@ -56,6 +55,26 @@ export class IntegrationBase {
ent,
isSilent = false,
},
) {
if (!this._isActive()) return null;
return this._pGetExpandedAddonData({
propJson,
path,
fnMatch,
ent,
isSilent,
});
}

/** @abstract */
async _pGetExpandedAddonData (
{
propJson,
path,
fnMatch,
ent,
isSilent = false,
},
) { throw new Error("Unimplemented!"); }

/* -------------------------------------------- */
Expand Down
10 changes: 9 additions & 1 deletion module/js/integrations/MidiSrd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {IntegrationBase} from "./IntegrationBase.js";
import {StartupHookMixin} from "../mixins/MixinStartupHooks.js";
import {SharedConsts} from "../../shared/SharedConsts.js";
import {ModuleSettingConsts} from "../ModuleSettingConsts.js";
import {Util} from "../Util.js";

/**
* Designed for use with `midi-srd` v11.0.0
Expand Down Expand Up @@ -42,7 +45,7 @@ export class IntegrationMidiSrd extends StartupHookMixin(IntegrationBase) {
static _PS_CACHE_PACK = {};
static _PACK_CACHE = {};

async pGetExpandedAddonData (
async _pGetExpandedAddonData (
{
propJson,
path,
Expand All @@ -56,6 +59,11 @@ export class IntegrationMidiSrd extends StartupHookMixin(IntegrationBase) {
const packId = this.constructor._PROP_TO_PACK[propJson];
if (!packId) return null;

if (!game.packs.get(packId)) { // Should never occur
if (game.settings.get(SharedConsts.MODULE_ID, ModuleSettingConsts.DEV_IS_DBG)) console.warn(...Util.LGT, `Could not find pack with ID "${packId}"!`);
return null;
}

await (this.constructor._PS_CACHE_PACK[packId] ||= this.constructor._pDoCachePack({packId}));

const cacheDoc = this.constructor._getCacheLookupNames({ent})
Expand Down

0 comments on commit 2b4b810

Please sign in to comment.