Skip to content

Commit

Permalink
feat: Added hotkey to toggle overlay (Default Shift+F10)
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Apr 7, 2022
1 parent 5473611 commit 73722f8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 18 deletions.
17 changes: 9 additions & 8 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
"splash_image": "resources/images/splash.png",
"launcher_icon": "resources/images/gtt-logo.ico"
},
"permissions": [
"GameInfo",
"Extensions",
"FileSystem",
"Hotkeys",
"Web",
"Streaming"
],
"permissions": ["GameInfo", "Extensions", "FileSystem", "Hotkeys", "Web", "Streaming"],
"data": {
"game_targeting": {
"type": "dedicated",
Expand Down Expand Up @@ -119,6 +112,14 @@
"file": "plugin/Destiny2.GoalTracker.Client.dll",
"class": "Destiny2.GoalTracker.Client.ApiClient"
}
},
"hotkeys": {
"toggle_Destiny2_Overlay": {
"title": "Toggle Destiny 2 Overlay",
"action-type": "custom",
"default": "Shift+F10",
"passthrough": true
}
}
}
}
17 changes: 9 additions & 8 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
"splash_image": "resources/images/splash.png",
"launcher_icon": "resources/images/gtt-logo.ico"
},
"permissions": [
"GameInfo",
"Extensions",
"FileSystem",
"Hotkeys",
"Web",
"Streaming"
],
"permissions": ["GameInfo", "Extensions", "FileSystem", "Hotkeys", "Web", "Streaming"],
"data": {
"game_targeting": {
"type": "dedicated",
Expand Down Expand Up @@ -119,6 +112,14 @@
"file": "plugin/Destiny2.GoalTracker.Client.dll",
"class": "Destiny2.GoalTracker.Client.ApiClient"
}
},
"hotkeys": {
"toggle_Destiny2_Overlay": {
"title": "Toggle Destiny 2 Overlay",
"action-type": "custom",
"default": "Shift+F10",
"passthrough": true
}
}
}
}
38 changes: 38 additions & 0 deletions src/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ if (firstLaunch) {
overwolf.games.onGameLaunched.addListener(gameLaunched);
overwolf.games.onGameInfoUpdated.addListener(gameInfoUpdated);

overwolf.settings.hotkeys.onPressed.addListener((event) => {
if (event && event.name) {
switch (event.name) {
case "toggle_Destiny2_Overlay":
toggleOverlay();
break;
}
}
});

window.eventEmitter.addEventListener("game-launched", function (gameInfo) {
log("EVENT:GAME-LAUNCHED", gameInfo);

Expand Down Expand Up @@ -155,6 +165,23 @@ if (firstLaunch) {
overwolf.windows.close(loadingWindowId, function () {});
}

function toggleOverlay() {
if (overlayWindowId) {
overwolf.windows.getWindowState(overlayWindowId, (result) => {
switch (result.window_state_ex) {
case "normal":
overwolf.windows.hide(overlayWindowId, function () {});
break;
default:
overwolf.windows.restore(overlayWindowId, function () {});
break;
}
});
} else {
openOverlay();
}
}

function openOverlay() {
if (overlayWindowId == null) {
overwolf.windows.obtainDeclaredWindow("overlayWindow", async (result) => {
Expand Down Expand Up @@ -342,6 +369,17 @@ if (firstLaunch) {
}
});

setInterval(async function () {
if (destinyApiClient.profile) {
let lastPlayed = await destinyApiClient.getLastPlayedCharacter();

await destinyApiClient.loadCharacterHistory(
lastPlayed.characterInfo.membershipId,
lastPlayed.characterInfo.characterId
);
}
}, 300 * 1000);

setInterval(function () {
checkExtensionUpdate();
}, 3600000); // Once every hour
Expand Down
23 changes: 21 additions & 2 deletions src/scripts/react/Overlay/Titlebar.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import React, { useEffect } from "react";
import React, { useEffect, useState } from "react";
import { DraggableWindow } from "../../draggable-window";

export function Titlebar() {
const [hotKey, setHotKey] = useState("");

const getHotKeyInfo = () => {
overwolf.settings.hotkeys.get((hotkeys) => {
if (hotkeys.success && hotkeys.games["21812"]) {
setHotKey(hotkeys.games["21812"][0].binding);
}
});
};

useEffect(() => {
overwolf.windows.getCurrentWindow(async function (window) {
new DraggableWindow(window.window, document.getElementById("titleBar"));
});

overwolf.settings.hotkeys.onChanged.addListener(getHotKeyInfo);

getHotKeyInfo();

return () => {
overwolf.settings.hotkeys.onChanged.removeListener(getHotKeyInfo);
};
}, []);

return (
<nav className="navbar bg-dark navbar-dark" id="titleBar">
<span className="navbar-brand text-white text-bold" id="titleBarName">
Destiny 2 - Goal Tracker
Goal Tracker <small>(Toggle: {hotKey})</small>
</span>
</nav>
);
Expand Down

0 comments on commit 73722f8

Please sign in to comment.