fix: retry the initial history load when the first fetch fails

This commit is contained in:
Eduard Tolosa 2026-06-25 18:17:42 -05:00
parent 189a52798b
commit 306cedfd68

View file

@ -97,8 +97,9 @@ export class StrataPanel {
if (this._initialLoaded) return; if (this._initialLoaded) return;
if (!this._proxy.g_name_owner) return; if (!this._proxy.g_name_owner) return;
this._initialLoaded = true; this._initialLoaded = true;
this._loadHistory(0, this._pageSize).catch(e => this._loadHistory(0, this._pageSize).then(ok => {
logError('initial _loadHistory failed', e)); if (!ok) this._initialLoaded = false;
});
} }
@ -393,14 +394,14 @@ export class StrataPanel {
async _loadHistory(offset, limit) { async _loadHistory(offset, limit) {
if (!this._overlay) return 0; if (!this._overlay) return false;
try { try {
const [json] = await this._proxy.GetHistoryAsync(offset, limit); const [json] = await this._proxy.GetHistoryAsync(offset, limit);
if (!this._overlay) return 0; if (!this._overlay) return false;
const items = JSON.parse(json); const items = JSON.parse(json);
const BATCH = 20; const BATCH = 20;
for (let i = 0; i < items.length; i += BATCH) { for (let i = 0; i < items.length; i += BATCH) {
if (!this._overlay) return items.length; if (!this._overlay) return false;
await new Promise(resolve => await new Promise(resolve =>
GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => { GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
const end = Math.min(i + BATCH, items.length); const end = Math.min(i + BATCH, items.length);
@ -416,10 +417,10 @@ export class StrataPanel {
const firstWidget = this._widgets.get(items[0].id); const firstWidget = this._widgets.get(items[0].id);
if (firstWidget) this._setActiveWidget(firstWidget); if (firstWidget) this._setActiveWidget(firstWidget);
} }
return items.length; return true;
} catch (e) { } catch (e) {
logError('GetHistory failed', e); logError('GetHistory failed', e);
return 0; return false;
} }
} }