Skip to content

Commit

Permalink
feat: Fixed cache breaker so it's near instant (well almost), also ch…
Browse files Browse the repository at this point in the history
…anged interval to 15 seconds
  • Loading branch information
itssimple committed Aug 22, 2021
1 parent 3597771 commit 5fbf5fd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var firstLaunch = true;
var mainWindowId = null;
var overlayWindowId = null;

const destiny2ClassId = 21812;

function openWindow(event, originEvent) {
if (event) {
log("WINDOW", "Got launch event: ", event);
Expand Down Expand Up @@ -84,7 +86,7 @@ function parseQueryString(queryString) {
}

function gameLaunched(game) {
if (game && game.classId == 21812) {
if (game && game.classId == destiny2ClassId) {
log("GAME:LAUNCH", game);
eventEmitter.emit("game-launched", game);
}
Expand Down Expand Up @@ -193,7 +195,7 @@ if (firstLaunch) {

window.eventEmitter.addEventListener("main-window-closed", function () {
overwolf.games.getRunningGameInfo(function (data) {
if (data == null) {
if (data == null || data.classId != destiny2ClassId) {
exitApp("No game running, no need to run in the background");
}
});
Expand Down
43 changes: 41 additions & 2 deletions src/scripts/destiny2/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ function DestinyApiClient(d2ApiClient) {
profileCurrency: _profile.profileCurrencies.data.items,
profilePlugSets: _profile.profilePlugSets.data.plugs,
profileCollectibles: _profile.profileCollectibles.data,
profile: _profile.profile.data,
};

return lastPlayedCharacter;
Expand Down Expand Up @@ -552,15 +553,40 @@ function DestinyApiClient(d2ApiClient) {
});
};

this.lockItem = async function (
membershipType,
characterId,
itemId,
lockState
) {
return new Promise(async (resolve, reject) => {
await pluginClient.POSTJson(
`${destinyApiUrl}/Destiny2/Actions/Items/SetLockState/`,
JSON.stringify({
membershipType: membershipType,
characterId: characterId,
itemId: itemId,
state: lockState,
}),
await getUserToken(),
(result) => {
if (result.statusCode === 200) {
resolve(result.content);
} else {
reject(result);
}
}
);
});
};

this.getNamedDataObject = async function (forceRefresh = false) {
let _lastPlayer = await self.getLastPlayedCharacter(forceRefresh);

if (_lastPlayer == null) {
return null;
}

await self.equipItems(_lastPlayer);

let namedDataObject = {
..._lastPlayer,
};
Expand Down Expand Up @@ -603,6 +629,19 @@ function DestinyApiClient(d2ApiClient) {

namedDataObject = self.mapHashesToDefinitionsInObject(namedDataObject);

const lockableItems = _lastPlayer.characterInventory.filter(
(i) => i.lockable && i.inventoryitemItemType == 3
);

if (lockableItems.length > 0) {
await self.lockItem(
_lastPlayer.characterInfo.membershipType,
_lastPlayer.characterInfo.characterId,
lockableItems[0].itemInstanceId,
lockableItems[0].state
);
}

eventEmitter.emit("destiny2-api-update", namedDataObject);

return namedDataObject;
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/overlayWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ eventEmitter.addEventListener("visible-items-changed", (visibleItems) => {

setInterval(async function () {
await destinyApiClient.getTrackableData(true);
}, 30 * 1000);
}, 15 * 1000);

0 comments on commit 5fbf5fd

Please sign in to comment.