Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Updater #581

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 30 additions & 15 deletions src/renderer/managers/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,25 @@ export async function checkUpdate(id: string, verbose = true): Promise<void> {
}

const newVersion = res.manifest.version;
const versions = [newVersion.split("."), version.split(".")];

if (newVersion === version) {
if (
newVersion !== version &&
(versions[0][0] > versions[1][0] ||
(versions[0][0] === versions[1][0] && versions[0][1] > versions[1][1]) ||
(versions[0][0] === versions[1][0] &&
versions[0][1] === versions[1][1] &&
versions[0][2] > versions[1][2]))
) {
logger.log(`Entity ${id} has an update available`);
updaterState.set(id, {
available: true,
url: res.url,
webUrl: res.webUrl,
lastChecked: Date.now(),
version: newVersion,
});
} else {
if (verbose) logger.log(`Entity ${id} is up to date`);
updaterState.set(id, {
available: false,
Expand All @@ -144,17 +161,7 @@ export async function checkUpdate(id: string, verbose = true): Promise<void> {
webUrl: res.webUrl,
version: newVersion,
});
return;
}

logger.log(`Entity ${id} has an update available`);
updaterState.set(id, {
available: true,
url: res.url,
webUrl: res.webUrl,
lastChecked: Date.now(),
version: newVersion,
});
}

export async function installUpdate(id: string, force = false, verbose = true): Promise<boolean> {
Expand Down Expand Up @@ -219,10 +226,18 @@ export async function checkAllUpdates(autoCheck = false, verbose = false): Promi

logger.log("Checking for updates");

await Promise.all([
checkUpdate(REPLUGGED_ID, verbose),
...addons.map((addon) => checkUpdate(addon.manifest.id, verbose)),
]);
const delay = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));

async function checkUpdatesWithRateLimit(): Promise<void> {
await checkUpdate(REPLUGGED_ID, verbose);

for (const addon of addons) {
await checkUpdate(addon.manifest.id, verbose);
await delay(1000 / 15); // Delay for 1 second divided by 15 (15 requests per second)
}
}

await checkUpdatesWithRateLimit();

logger.log("All updates checked");
updaterSettings.set("lastChecked", Date.now());
Expand Down
Loading