Skip to content

Commit

Permalink
app: add cooldown to runelite update-checking
Browse files Browse the repository at this point in the history
RuneLite hosts versions on their Github releases page which is
rate-limiting some IPs, so a two-minute cooldown was added. RuneLite
will also now launch even if the update check fails. #55
  • Loading branch information
Adamcake committed Oct 14, 2024
1 parent 800d9b7 commit 44520b7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
6 changes: 0 additions & 6 deletions app/dist/assets/index-CDqugPW9.js

This file was deleted.

6 changes: 6 additions & 0 deletions app/dist/assets/index-CjtNDX7o.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bolt Launcher</title>
<script type="module" crossorigin src="/assets/index-CDqugPW9.js"></script>
<script type="module" crossorigin src="/assets/index-CjtNDX7o.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-BhNxtWTe.css">
</head>
<body>
Expand Down
16 changes: 14 additions & 2 deletions app/src/lib/Util/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { bolt } from '$lib/State/Bolt';
import { GlobalState } from '$lib/State/GlobalState';
import { type Direct6Token } from '$lib/Util/interfaces';
import { logger } from '$lib/Util/Logger';
import { runeliteLastUpdateCheck } from '$lib/Util/store';
import { get } from 'svelte/store';

// asynchronously download and launch RS3's official .deb client using the given env variables
Expand Down Expand Up @@ -130,6 +131,15 @@ export function launchRuneLite(
return;
}

const cooldownMillis = 2 * 60 * 1000;
if (bolt.runeLiteInstalledId !== null) {
const timeLast = get(runeliteLastUpdateCheck);
if (timeLast !== null && timeLast + cooldownMillis > Date.now()) {
launch();
return;
}
}

const xml = new XMLHttpRequest();
const url = 'https://api.github.com/repos/runelite/launcher/releases';
xml.open('GET', url, true);
Expand All @@ -148,6 +158,7 @@ export function launchRuneLite(
xmlRl.onreadystatechange = () => {
if (xmlRl.readyState == 4) {
if (xmlRl.status == 200) {
runeliteLastUpdateCheck.set(Date.now());
launch(runelite.id, xmlRl.response);
} else {
logger.error(
Expand All @@ -164,11 +175,12 @@ export function launchRuneLite(
};
xmlRl.send();
} else {
logger.info('Latest JAR is already installed');
runeliteLastUpdateCheck.set(Date.now());
launch();
}
} else {
logger.error(`Error from ${url}: ${xml.status}: ${xml.responseText}`);
logger.error(`Failed to check for RuneLite updates: ${xml.status}: ${xml.responseText}`);
launch();
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions app/src/lib/Util/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ import { writable, type Writable } from 'svelte/store';

// TODO: remove clientList
export const clientList: Writable<GameClient[]> = writable([]);

// used by launchRunelite, should be moved to wherever that function goes if we get rid of functions.ts
export const runeliteLastUpdateCheck: Writable<number | null> = writable(null);

0 comments on commit 44520b7

Please sign in to comment.