Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion app/auto-updater-linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ class AutoUpdater extends EventEmitter implements Electron.AutoUpdater {
}
this.emit('checking-for-update');

fetch(this.updateURL)
// Use a short timeout so a blocked network or proxy won't hang the app
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 10000);

fetch(this.updateURL, {signal: controller.signal})
.then((res) => {
clearTimeout(timeout);
if (res.status === 204) {
this.emit('update-not-available');
return;
Expand Down
22 changes: 22 additions & 0 deletions app/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fetch from 'electron-fetch';

/**
* Quick online check with a short timeout.
* Returns true if we can reach a URL within the timeout, false otherwise.
*/
export async function isOnline(timeoutMs = 3000): Promise<boolean> {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), timeoutMs);

try {
// Use a small, lightweight endpoint which returns 204 when reachable.
const res = await fetch('https://www.google.com/generate_204', {signal: controller.signal});
clearTimeout(timeout);
return res && res.status >= 200 && res.status < 300;
} catch (_err) {
// Any error (including abort) counts as offline for our purposes.
return false;
}
}

export default isOnline;
Loading