Skip to content

Commit

Permalink
feat: Added support to detect if the app is offline, and then exit it.
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Mar 30, 2022
1 parent f310106 commit 7eebfc3
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/scripts/react/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@ function LoadingWindow() {
useEffect(() => {
const backgroundWindow = overwolf.windows.getMainWindow();

const destinyApiClient = (backgroundWindow as any)
.destinyApiClient as DestinyApiClient;

const eventEmitter = (backgroundWindow as any).eventEmitter as EventEmitter;

eventEmitter.addEventListener("loading-text", (data) => {
const loadingActivity = document.querySelector("#loading-activity");
loadingActivity.textContent = data;
});

const loadingActivity = document.querySelector("#loading-activity");
loadingActivity.textContent = "Checking manifest";
// check if browser is online
if (!navigator.onLine) {
eventEmitter.emit("loading-text", "No internet connection, exiting...");
setTimeout(function () {
eventEmitter.emit("shutdown", "No internet connection available.");
}, 5000);
} else {
const destinyApiClient = (backgroundWindow as any).destinyApiClient as DestinyApiClient;

const loadingActivity = document.querySelector("#loading-activity");
loadingActivity.textContent = "Checking manifest";

destinyApiClient.checkManifestVersion().then(async () => {
destinyApiClient
.checkStoredDefinitions(false)
.then(async (missingDefinitions) => {
destinyApiClient.checkManifestVersion().then(async () => {
destinyApiClient.checkStoredDefinitions(false).then(async (missingDefinitions) => {
const loadingActivity = document.querySelector("#loading-activity");
if (missingDefinitions.length > 0) {
loadingActivity.textContent = "Downloading definitions...";
Expand All @@ -47,7 +51,8 @@ function LoadingWindow() {
}, 1000);
});
});
});
});
}
}, []);

return (
Expand All @@ -58,9 +63,7 @@ function LoadingWindow() {
<div className="row">
<div className="col-12">
<h1>Loading</h1>
<h3 id="loading-activity">
Please wait while we load the application
</h3>
<h3 id="loading-activity">Please wait while we load the application</h3>
</div>
</div>
</div>
Expand Down

0 comments on commit 7eebfc3

Please sign in to comment.