diff --git a/src/scripts/mainWindow.js b/src/scripts/mainWindow.js index dda5185..e4c179b 100644 --- a/src/scripts/mainWindow.js +++ b/src/scripts/mainWindow.js @@ -9,6 +9,9 @@ const backgroundWindow = overwolf.windows.getMainWindow(); /** @type EventEmitter */ const eventEmitter = backgroundWindow.eventEmitter; + +const db = backgroundWindow.db; + var overwolfAdvertiseObject = null; var overwolfAdvertiseInitialized = false; @@ -29,12 +32,39 @@ eventEmitter.addEventListener("refresh-window", function (window) { } }); +function setLastPlayedCharacter(lastPlayed) { + let lastPlayedClass = document.querySelector("#lastPlayedClass"); + let lastPlayedTotalTime = document.querySelector("#lastPlayedTotalTime"); + + lastPlayedClass.innerText = `${lastPlayed.genderName} ${lastPlayed.raceName} ${lastPlayed.className}`; + lastPlayedTotalTime.innerText = `Played ${formatTimespan( + new Date(), + new Date(Date.now() + lastPlayed.minutesPlayedTotal * 60 * 1000) + )}`; +} + +eventEmitter.addEventListener("destiny-data-loaded", async function () { + await destinyApiClient.getNamedDataObject(true); +}); + +eventEmitter.addEventListener("destiny-not-authed", function () { + document.querySelector("#authenticateWithBungie").style.display = ""; +}); + +eventEmitter.addEventListener( + "destiny2-api-update", + function (namedDataObject) { + let lastPlayedCharacter = namedDataObject.characterInfo; + + setLastPlayedCharacter(lastPlayedCharacter); + } +); + eventEmitter.addEventListener("game-exited", function () {}); -/* function onOwAdReady() { - if (!OwAd) { - // TODO: Handle fallback if the OwAd-API doesn't load + if (typeof OwAd === "undefined") { + document.getElementById("adContainer").style.display = "none"; return; } @@ -42,7 +72,7 @@ function onOwAdReady() { overwolfAdvertiseObject.addEventListener("ow_internal_rendered", () => { overwolfAdvertiseInitialized = true; }); -}*/ +} function loadSettings() {} @@ -110,7 +140,7 @@ function bindExitButtonEvent(window) { } (function () { - overwolf.windows.getCurrentWindow(function (window) { + overwolf.windows.getCurrentWindow(async function (window) { new DraggableWindow(window.window, document.getElementById("titleBar")); bindExitButtonEvent(window); @@ -119,6 +149,31 @@ function bindExitButtonEvent(window) { document.getElementById("titleBarName").innerHTML = windowTitle; }); + document.getElementById("visibleItems").value = await db.getItem( + "d2-visible-items" + ); + + document.getElementById("trackMilestones").checked = JSON.parse( + (await db.getItem("d2-track-milestones")) || "true" + ) + ? "checked" + : ""; + document.getElementById("trackBounties").checked = JSON.parse( + (await db.getItem("d2-track-bounties")) || "true" + ) + ? "checked" + : ""; + document.getElementById("trackQuests").checked = JSON.parse( + (await db.getItem("d2-track-quests")) || "true" + ) + ? "checked" + : ""; + document.getElementById("trackRecords").checked = JSON.parse( + (await db.getItem("d2-track-records")) || "true" + ) + ? "checked" + : ""; + document .getElementById("send-logs") .removeEventListener("click", sendLogsToDeveloper); @@ -134,6 +189,64 @@ function bindExitButtonEvent(window) { document .getElementById("authenticateWithBungie") .addEventListener("click", authenticateWithBungie); + + document + .getElementById("visibleItems") + .addEventListener("change", async (event) => { + await db.setItem("d2-visible-items", event.target.value); + eventEmitter.emit( + "visible-items-changed", + parseInt(event.target.value) + ); + }); + + document + .getElementById("trackMilestones") + .addEventListener("change", async function (event) { + let checked = event.target.checked; + console.log("milestones", checked); + await db.setItem("d2-track-milestones", checked); + + eventEmitter.emit("tracked-items-changed"); + }); + + document + .getElementById("trackBounties") + .addEventListener("change", async function (event) { + let checked = event.target.checked; + + console.log("bounties", checked); + await db.setItem("d2-track-bounties", checked); + + eventEmitter.emit("tracked-items-changed"); + }); + + document + .getElementById("trackQuests") + .addEventListener("change", async function (event) { + let checked = event.target.checked; + + console.log("quests", checked); + await db.setItem("d2-track-quests", checked); + + eventEmitter.emit("tracked-items-changed"); + }); + + document + .getElementById("trackRecords") + .addEventListener("change", async function (event) { + let checked = event.target.checked; + + console.log("records", checked); + await db.setItem("d2-track-records", checked); + + eventEmitter.emit("tracked-items-changed"); + }); + + let hasAuthed = await destinyApiClient.isAuthenticated(); + if (hasAuthed) { + document.querySelector("#authenticateWithBungie").style.display = "none"; + } }); localStorage.setItem("mainWindow_opened", true); diff --git a/src/scss/main-window.scss b/src/scss/main-window.scss index 65496e6..22e5b25 100644 --- a/src/scss/main-window.scss +++ b/src/scss/main-window.scss @@ -1,6 +1,6 @@ #main-win-container { overflow-y: scroll; - max-height: 682px; + max-height: 739px; } .desktop { @@ -28,51 +28,26 @@ padding: 5px; } -#weekSummaryGraph { - background-color: #272b30; -} - -#sessionStats td { - padding-top: 4px; - padding-bottom: 4px; -} - -.ct-label { - color: white; -} - -.ct-grid { - stroke: rgba(255, 255, 255, 0.2); -} - -.ct-bar { - stroke-width: 50px; - stroke: var(--default-backgroundcolor) !important; -} - .fade { transition: opacity 0.08s; } -.chartist-tooltip { - background: #272b30; - border: 1px solid #515960; - color: #fff; -} - -.chartist-tooltip:before { - border-top-color: #272b30; -} - #changelog { h1 { margin-top: 0; } } -#last10Sessions table td { - max-width: 0; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; +#main-card { + min-height: 649px; + max-height: 649px; +} + +#adContainer .card-body { + background-color: black; + background-image: url(../../images/ads_placeholder_bg.png); + width: 400px; + height: 300px; + padding: 0; + margin-left: 10px; } diff --git a/src/windows/main-window.html b/src/windows/main-window.html index dc8d168..a4e23ea 100644 --- a/src/windows/main-window.html +++ b/src/windows/main-window.html @@ -3,38 +3,18 @@