Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(editor): two gaps a packaged build found that a dev build could not

yhh7f5a9a3cd47d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d6d867016..8ff66e933 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,7 +41,15 @@ published separately; it ships inside the editor.
- **One release, announced once.** The startup check and the menu item both raise the same
notification, so clicking Check for Updates in the first seconds after launch answered
- with two identical lines.
+ with two identical lines. Announcing once does not mean announcing only once ever: a
+ download that failed can be offered again, which running the real thing turned out to be
+ the case that mattered.
+
+- **A toast action no longer throws away the line it just wrote.** Pressing a toast's button
+ always dismissed the toast, which is right for an action that leaves (open a page, restart)
+ and wrong for one that keeps reporting on that same line: pressing Download blanked the
+ screen for the second before the first byte report, right where the "did my click do
+ anything" doubt lives.
### Added
diff --git a/desktop/src/components/Toaster.tsx b/desktop/src/components/Toaster.tsx
index 84c226a39..7d4768f63 100644
--- a/desktop/src/components/Toaster.tsx
+++ b/desktop/src/components/Toaster.tsx
@@ -20,7 +20,7 @@ export function Toaster() {
className="toast__action"
onClick={() => {
toast.action?.run();
- Toasts.dismiss(toast.id);
+ if (!toast.action?.keepOpen) Toasts.dismiss(toast.id);
}}
>
{toast.action.label}
diff --git a/desktop/src/store/Toasts.ts b/desktop/src/store/Toasts.ts
index 84faa5b36..29544f8fe 100644
--- a/desktop/src/store/Toasts.ts
+++ b/desktop/src/store/Toasts.ts
@@ -13,6 +13,14 @@ export type ToastKind = 'info' | 'success' | 'warn' | 'error';
export interface ToastAction {
label: string;
run: () => void;
+ /**
+ * Keep the toast when this action is pressed. The default is to dismiss, which
+ * is right for an action that LEAVES (open a page, restart) and wrong for one
+ * that starts work reported on this same line — dismissing would throw away the
+ * state the handler just wrote, leaving nothing on screen until the work's first
+ * report.
+ */
+ keepOpen?: boolean;
}
export interface Toast {
diff --git a/desktop/src/update/updateToast.ts b/desktop/src/update/updateToast.ts
index 7b0f5a309..ae41f0d8c 100644
--- a/desktop/src/update/updateToast.ts
+++ b/desktop/src/update/updateToast.ts
@@ -97,14 +97,23 @@ export function checkForUpdatesInteractive(): Promise<void> {
}
/**
- * The version a toast is already about, so the two surfaces that raise this — the
- * startup check and the menu — announce one release once. Clicking Check for
- * Updates a few seconds after launch used to answer with two identical lines.
+ * The version a live toast is already the current news about, so the two surfaces
+ * that raise this — the startup check and the menu — announce one release once.
+ * Clicking Check for Updates a few seconds after launch used to answer with two
+ * identical lines.
+ *
+ * It is dropped the moment that line stops being the news: pressing Download turns
+ * it into progress, and a download that FAILED must be re-offerable, or checking
+ * again is a click that produces nothing — which is the bug this whole file is
+ * about, reintroduced in a corner where it is harder to see.
*/
let announced: { version: string; id: number } | null = null;
+/** A download in flight; its own line is on screen, so do not add a second. */
+let downloading: string | null = null;
/** Post the "there is a newer Estella" toast, wired to whatever this build can do. */
export function notifyUpdate(release: AvailableUpdate): void {
+ if (downloading === release.version) return;
if (announced?.version === release.version && Toasts.has(announced.id)) return;
const openInBrowser = { label: t('ui.download'), run: () => window.open(release.url) };
@@ -119,6 +128,10 @@ export function notifyUpdate(release: AvailableUpdate): void {
let id = 0;
id = Toasts.push(t('toast.updateAvailable', { version: release.version }), 'info', 0, {
label: t('ui.download'),
+ // This line becomes the download's line; dismissing it here would blank the
+ // screen until the first byte report — a second of "nothing happened" right
+ // after a click, which is the thing being fixed.
+ keepOpen: true,
run: () => void download(id, release),
});
announced = { version: release.version, id };
@@ -128,6 +141,11 @@ async function download(id: number, release: AvailableUpdate): Promise<void> {
const bridge = window.estella?.app;
if (!bridge?.downloadUpdate) return;
+ // From here the line is a download, not an offer — so it no longer suppresses a
+ // fresh announcement, and `downloading` takes over that job for as long as it runs.
+ announced = null;
+ downloading = release.version;
+
// The download outlives its toast if the user closes it — and then there is no
// way back to "Restart", so the line re-posts itself rather than disappearing.
let live = id;
@@ -176,6 +194,9 @@ async function download(id: number, release: AvailableUpdate): Promise<void> {
pinned: false,
action: { label: t('ui.restart'), run: () => void bridge.installUpdate?.() },
});
+ // Downloaded and waiting for a restart IS the current news about this version:
+ // checking again should not offer a download that already happened.
+ announced = { version: release.version, id: live };
} catch (err) {
console.error('[update] download failed', err);
// The link still works when the download did not — a failed update should cost
@@ -189,5 +210,6 @@ async function download(id: number, release: AvailableUpdate): Promise<void> {
});
} finally {
stop?.();
+ downloading = null;
}
}
diff --git a/desktop/tests/update-toast.test.ts b/desktop/tests/update-toast.test.ts
index ef7305a3c..6ec0072f5 100644
--- a/desktop/tests/update-toast.test.ts
+++ b/desktop/tests/update-toast.test.ts
@@ -165,9 +165,20 @@ describe('the download', () => {
};
}
+ // A version per test: the "announce once" guard is module state keyed by version,
+ // and a download left in flight by one test would suppress the next one's offer.
+ let seq = 0;
+ let version = '';
+ /** Press a toast's button exactly as Toaster does — including the dismiss. */
+ const press = (toast: Toast): void => {
+ toast.action?.run();
+ if (!toast.action?.keepOpen) Toasts.dismiss(toast.id);
+ };
+
const startDownload = async (): Promise<void> => {
- notifyUpdate({ version: '9.9.9', url: 'https://example.test', selfInstall: true });
- only().action?.run();
+ version = `9.9.${++seq}`;
+ notifyUpdate({ version, url: 'https://example.test', selfInstall: true });
+ press(only());
await settle();
};
@@ -176,7 +187,7 @@ describe('the download', () => {
await startDownload();
const toast = only();
- expect(toast.message).toBe('Starting the Estella 9.9.9 download…');
+ expect(toast.message).toBe(`Starting the Estella ${version} download…`);
expect(toast.progress).toBe('indeterminate');
expect(toast.pinned).toBe(true);
});
@@ -188,7 +199,7 @@ describe('the download', () => {
dl.report(37.4);
const toast = only();
expect(toast.progress).toBe(37);
- expect(toast.message).toBe('Downloading Estella 9.9.9… 37% of 204.1 MB');
+ expect(toast.message).toBe(`Downloading Estella ${version}… 37% of 204.1 MB`);
});
it('comes back if the user closes it, so Restart stays reachable', async () => {
@@ -204,13 +215,43 @@ describe('the download', () => {
await dl.finish();
const ready = only();
- expect(ready.message).toBe('Estella 9.9.9 is ready — restart to install');
+ expect(ready.message).toBe(`Estella ${version} is ready — restart to install`);
expect(ready.kind).toBe('success');
expect(ready.progress).toBeUndefined();
expect(ready.pinned).toBe(false);
- ready.action?.run();
+ press(ready);
expect(dl.installed()).toBe(true);
+ expect(toasts()).toHaveLength(0); // Restart leaves; its line goes with it
+ });
+
+ it('can be offered again after a download failed', async () => {
+ // Found by driving a real packaged build: the failed line kept the id the
+ // "announce once" guard was holding, so checking again dismissed its own
+ // progress toast and posted nothing — a click that does nothing, which is the
+ // exact complaint this file exists to fix.
+ const dl = downloadBridge();
+ await startDownload();
+ await dl.fail();
+ expect(only().kind).toBe('error');
+
+ notifyUpdate({ version, url: 'https://example.test', selfInstall: true });
+ expect(toasts()).toHaveLength(2);
+ expect(toasts()[1].message).toBe(`Estella ${version} is available`);
+ });
+
+ it('does not offer a second time while it is downloading, or once it is ready', async () => {
+ const dl = downloadBridge();
+ await startDownload();
+ dl.report(30);
+
+ notifyUpdate({ version, url: 'https://example.test', selfInstall: true });
+ expect(toasts()).toHaveLength(1); // the progress line is the news
+
+ await dl.finish();
+ notifyUpdate({ version, url: 'https://example.test', selfInstall: true });
+ expect(toasts()).toHaveLength(1); // and so is "restart to install"
+ expect(only().message).toBe(`Estella ${version} is ready — restart to install`);
});
it('falls back to the link when the download itself fails', async () => {