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

issue 887: fixed auto reloading and enable background reloading #1394

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
25 changes: 21 additions & 4 deletions app/renderer/js/utils/reconnect-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ export default class ReconnectUtil {
url: string;
alreadyReloaded: boolean;
fibonacciBackoff: backoff.Backoff;
webview: WebView;

constructor(webview: WebView) {
this.url = webview.properties.url;
this.alreadyReloaded = false;
this.webview = webview;

// Improve backoff settings with jitter
this.fibonacciBackoff = backoff.fibonacci({
initialDelay: 5000,
maxDelay: 300_000,
randomisationFactor: 0.3, // Add jitter
});
}

Expand All @@ -38,28 +43,40 @@ export default class ReconnectUtil {
});
}

async _checkAndReload(): Promise<boolean> {
private async _checkAndReload(): Promise<boolean> {
if (this.alreadyReloaded) {
return true;
}

if (await this.isOnline()) {
ipcRenderer.send("forward-message", "reload-viewer");
// Reload the webview without forcing navigation
await this._reloadWebviewInBackground();
logger.log("You're back online.");
return true;
}

logger.log(
"There is no internet connection, try checking network cables, modem and router.",
);
this._updateErrorMessage();
return false;
}

private async _reloadWebviewInBackground(): Promise<void> {
try {
this.webview.reload();
} catch (error) {
logger.error("Failed to reload webview:", error);
}
}

private _updateErrorMessage(): void {
const errorMessageHolder = document.querySelector("#description");
if (errorMessageHolder) {
errorMessageHolder.innerHTML = html`
<div>Your internet connection doesn't seem to work properly!</div>
<div>Verify that it works and then click try again.</div>
`.html;
}

return false;
}
}
Binary file added libgconf-2-4_3.2.6-7ubuntu2_amd64.deb
Binary file not shown.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"node-json-db": "^1.3.0",
"playwright-core": "^1.41.0-alpha-jan-9-2024",
"pre-commit": "^1.2.2",
"prettier": "^3.0.3",
"prettier": "^3.3.3",
"semver": "^7.3.5",
"stylelint": "^16.1.0",
"stylelint-config-standard": "^36.0.0",
Expand Down