Skip to content

Commit

Permalink
feat: Added loading window, which also handles missing manifest files.
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Mar 15, 2022
1 parent 8d6ed92 commit 5fe424f
Show file tree
Hide file tree
Showing 13 changed files with 1,524 additions and 1,356 deletions.
23 changes: 23 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@
"background_optimization": false,
"block_top_window_navigation": true
},
"loadingWindow": {
"file": "resources/compiled/windows/loading-window.html",
"show_in_taskbar": true,
"is_background_page": false,
"grab_focus_on_desktop": true,
"desktop_only": true,
"native_window": true,
"disable_hardware_acceleration": true,
"disable_auto_dpi_sizing": true,
"resizable": false,
"min_size": {
"width": 450,
"height": 400
},
"size": {
"width": 450,
"height": 400
},
"max_size": {
"width": 450,
"height": 400
}
},
"overlayWindow": {
"file": "resources/compiled/windows/overlay-window.html",
"show_in_taskbar": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "overwolf-destiny2-overlay",
"version": "0.1.17",
"version": "1.0.0",
"repository": "https://github.com/itssimple/destiny2-overlay.git",
"author": "Chris Gårdenberg <webmaster@itssimple.se>",
"license": "MIT",
Expand Down
23 changes: 23 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@
"background_optimization": false,
"block_top_window_navigation": true
},
"loadingWindow": {
"file": "resources/compiled/windows/loading-window.html",
"show_in_taskbar": true,
"is_background_page": false,
"grab_focus_on_desktop": true,
"desktop_only": true,
"native_window": true,
"disable_hardware_acceleration": true,
"disable_auto_dpi_sizing": true,
"resizable": false,
"min_size": {
"width": 450,
"height": 400
},
"size": {
"width": 450,
"height": 400
},
"max_size": {
"width": 450,
"height": 400
}
},
"overlayWindow": {
"file": "resources/compiled/windows/overlay-window.html",
"show_in_taskbar": true,
Expand Down
135 changes: 92 additions & 43 deletions src/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var firstLaunch = true;
var mainWindowId = null;
var overlayWindowId = null;
var loadingWindowId = null;

const destiny2ClassId = 21812;

Expand Down Expand Up @@ -145,6 +146,23 @@ if (firstLaunch) {
}, 5000);
});

function openLoadingWindow() {
overwolf.windows.obtainDeclaredWindow("loadingWindow", (result) => {
console.log(result);
if (!result.success) {
return;
}

loadingWindowId = result.window.id;
overwolf.windows.restore(result.window.id);
log("WINDOW", `Opening window. Reason: Missing manifest data`);
});
}

function closeLoadingWindow() {
overwolf.windows.close(loadingWindowId, function () {});
}

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

window.eventEmitter.addEventListener(
'manifests-loaded',
async function () {
closeLoadingWindow();
localStorage.removeItem("mainWindow_opened");
openWindow(null, null);
}
);

function checkExtensionUpdate() {
overwolf.extensions.checkForExtensionUpdate((updateState) => {
if (updateState.success) {
Expand Down Expand Up @@ -380,56 +407,78 @@ if (firstLaunch) {

overwolf.extensions.current.getExtraObject(
"destiny2ApiClient",
(result) => {
async (result) => {
if (result.status == "success") {
window.d2ApiClient = result.object;

window.destinyApiClient = new DestinyApiClient(d2ApiClient);
}
}
);

//openOverlay();

let wasPreviouslyOpened = localStorage.getItem("mainWindow_opened");

let locSearch = location.search;

if (
locSearch.indexOf("-from-desktop") > -1 ||
locSearch.indexOf("source=commandline") > -1 ||
locSearch.indexOf("source=dock") > -1 ||
locSearch.indexOf("source=storeapi") > -1 ||
locSearch.indexOf("source=odk") > -1 ||
locSearch.indexOf("source=after-install") > -1 ||
locSearch.indexOf("source=tray") > -1 ||
(wasPreviouslyOpened != null && wasPreviouslyOpened == "true")
) {
localStorage.removeItem("mainWindow_opened");
openWindow(null, locSearch);
} else if (locSearch.indexOf("source=gamelaunchevent") > -1) {
log("GAME:LAUNCH", "Application was started by game");
overwolf.games.getRunningGameInfo(function (data) {
if (data) {
gameLaunched(data);
await destinyApiClient.checkManifestVersion();

let missingDefinitions = await destinyApiClient.checkStoredDefinitions(false);

let showLoadingWindow = true;

if(missingDefinitions.length > 0) {
log("DATABASE", "Missing definitions, downloading them", missingDefinitions);
showLoadingWindow = true;
}

let wasPreviouslyOpened = localStorage.getItem("mainWindow_opened");

let locSearch = location.search;

if (
locSearch.indexOf("-from-desktop") > -1 ||
locSearch.indexOf("source=commandline") > -1 ||
locSearch.indexOf("source=dock") > -1 ||
locSearch.indexOf("source=storeapi") > -1 ||
locSearch.indexOf("source=odk") > -1 ||
locSearch.indexOf("source=after-install") > -1 ||
locSearch.indexOf("source=tray") > -1 ||
(wasPreviouslyOpened != null && wasPreviouslyOpened == "true")
) {
if(showLoadingWindow) {
log("DATABASE", "Opening loading window");
openLoadingWindow();
} else {
localStorage.removeItem("mainWindow_opened");
openWindow(null, locSearch);
}
} else if (locSearch.indexOf("source=gamelaunchevent") > -1) {
log("GAME:LAUNCH", "Application was started by game");
overwolf.games.getRunningGameInfo(async function (data) {
if (data) {
if(showLoadingWindow) {
await destinyApiClient.checkStoredDefinitions(true);
}
gameLaunched(data);
}
});
} else if (locSearch.indexOf("source=urlscheme")) {
log("URL-LAUNCH", "Application was started by url", locSearch);
let urlSchemeStart = unescape(
locSearch.replace("?source=urlscheme&", "")
);

if(showLoadingWindow) {
log("DATABASE", "Opening loading window");
openLoadingWindow();
}

handleUrlLaunch(urlSchemeStart);
}

// Removes the source-value from location.search, so we don't trigger multiple times
history.replaceState(
{},
window.title,
location.href.replace(location.search, "")
);
log("DATABASE", "Database initialized");
}
});
} else if (locSearch.indexOf("source=urlscheme")) {
log("URL-LAUNCH", "Application was started by url", locSearch);
let urlSchemeStart = unescape(
locSearch.replace("?source=urlscheme&", "")
);

handleUrlLaunch(urlSchemeStart);
}

// Removes the source-value from location.search, so we don't trigger multiple times
history.replaceState(
{},
window.title,
location.href.replace(location.search, "")
}
);
log("DATABASE", "Database initialized");
});
}
}
58 changes: 30 additions & 28 deletions src/scripts/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,42 @@
*
* @param {Number} timestamp
*/
function NDate(timestamp) {
this.timestamp = timestamp;
this.date = new Date(timestamp);
/**
*
* @param {Number} days Use an integer, will floor it
*/
this.addDay = function (days) {
if (isNaN(days)) {
throw new Error('Parameter "days" is not a number.');
}

this.timestamp = this.timestamp + Math.floor(days) * 86400000;

this.updateDate();
class NDate {
constructor(timestamp) {
this.timestamp = timestamp;
this.date = new Date(timestamp);
/**
*
* @param {Number} days Use an integer, will floor it
*/
this.addDay = function (days) {
if (isNaN(days)) {
throw new Error('Parameter "days" is not a number.');
}

return this;
};
this.timestamp = this.timestamp + Math.floor(days) * 86400000;

this.updateDate = function updateDate() {
this.date = new Date(this.timestamp);
};
this.updateDate();

this.removeTime = function () {
let x = new Date(this.timestamp);
x.setHours(0, 0, 0, 0);
this.timestamp = x.getTime();
return this;
};

this.updateDate();
this.updateDate = function updateDate() {
this.date = new Date(this.timestamp);
};

return this;
};
this.removeTime = function () {
let x = new Date(this.timestamp);
x.setHours(0, 0, 0, 0);
this.timestamp = x.getTime();

this.updateDate();

return this;
return this;
};

return this;
}
}

function GetUTCDate() {
Expand Down
Loading

0 comments on commit 5fe424f

Please sign in to comment.