Skip to content

Commit

Permalink
feat: Added settings for number of items and type of items to track
Browse files Browse the repository at this point in the history
- Also added an ad-placeholder
- Added so you can see your last played class and how much time you've spent with it.
- Refactored the mainwindow scss
  • Loading branch information
itssimple committed Aug 17, 2021
1 parent 0f72236 commit ffe2045
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 99 deletions.
123 changes: 118 additions & 5 deletions src/scripts/mainWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,20 +32,47 @@ 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;
}

overwolfAdvertiseObject = new OwAd(document.getElementById("ow_ad"));
overwolfAdvertiseObject.addEventListener("ow_internal_rendered", () => {
overwolfAdvertiseInitialized = true;
});
}*/
}

function loadSettings() {}

Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand Down
51 changes: 13 additions & 38 deletions src/scss/main-window.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#main-win-container {
overflow-y: scroll;
max-height: 682px;
max-height: 739px;
}

.desktop {
Expand Down Expand Up @@ -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;
}
Loading

0 comments on commit ffe2045

Please sign in to comment.