Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): track startup with a continuous bar instead of segments

Claude349316977c2f
diff --git a/apps/client/index.html b/apps/client/index.html
index 426f62057b..184bbb3184 100644
--- a/apps/client/index.html
+++ b/apps/client/index.html
@@ -63,31 +63,16 @@
background: #72b755;
animation: splash-slide 1.4s ease-in-out infinite;
}
- /* Segmented state, installed by splash.ts once the startup phases are known: one
- segment per phase, each as wide as that phase is expensive. */
- #splash .splash-bar.is-segmented {
- display: flex;
- gap: 2px;
- background: none;
- overflow: visible;
- }
- #splash .splash-bar.is-segmented .splash-bar-fill {
- display: none;
- }
- #splash .splash-seg {
- flex-basis: 0;
- height: 100%;
- border-radius: 2px;
- background: rgba(128, 128, 128, 0.2);
- transition: background-color 0.3s ease;
+ /* Tracking state, installed by splash.ts once the startup phases are known. The long
+ ease-out carries the fill towards the running phase's end without ever reaching it,
+ so a slow step keeps moving instead of looking stalled. */
+ #splash .splash-bar.is-continuous .splash-bar-fill {
+ width: 0;
+ animation: none;
+ transition: width 12s cubic-bezier(0.16, 0.85, 0.3, 1);
}
- #splash .splash-seg.is-done {
- background: #72b755;
- }
- #splash .splash-seg.is-active {
- background: linear-gradient(90deg, rgba(114, 183, 85, 0.25) 0%, #72b755 50%, rgba(114, 183, 85, 0.25) 100%);
- background-size: 250% 100%;
- animation: splash-seg-sweep 1.2s ease-in-out infinite;
+ #splash .splash-bar.is-continuous.is-finishing .splash-bar-fill {
+ transition: width 0.3s ease;
}
#splash-status {
min-height: 1.5em;
@@ -113,10 +98,6 @@
0%, 100% { opacity: 0.3; }
50% { opacity: 1; }
}
- @keyframes splash-seg-sweep {
- 0% { background-position: 100% 0; }
- 100% { background-position: 0 0; }
- }
@media (prefers-color-scheme: dark) {
#splash { background: #242424; color: #999999; }
#splash .splash-title { color: #cccccc; }
@@ -124,7 +105,7 @@
@media (prefers-reduced-motion: reduce) {
#splash .splash-content { opacity: 1; animation: none; }
#splash .splash-bar-fill { width: 100%; animation: splash-pulse 1.8s ease-in-out infinite; }
- #splash .splash-seg.is-active { background: rgba(114, 183, 85, 0.55); animation: none; }
+ #splash .splash-bar.is-continuous .splash-bar-fill { transition: width 0.2s linear; }
}
@media print {
#splash { display: none; }
diff --git a/apps/client/src/services/splash.spec.ts b/apps/client/src/services/splash.spec.ts
index 37d267c18d..e763c313db 100644
--- a/apps/client/src/services/splash.spec.ts
+++ b/apps/client/src/services/splash.spec.ts
@@ -22,11 +22,8 @@ function renderSplash() {
</div>`;
}
-function segmentClasses() {
- return [ ...document.querySelectorAll(".splash-seg") ].map((seg) => ({
- done: seg.classList.contains("is-done"),
- active: seg.classList.contains("is-active")
- }));
+function fillWidth(): string {
+ return document.querySelector<HTMLElement>(".splash-bar-fill")?.style.width ?? "";
}
beforeEach(() => {
@@ -51,60 +48,62 @@ describe("splash", () => {
expect(document.getElementById("splash-status")?.textContent).toBe("something broke");
});
- it("draws one segment per phase, sized by weight", async () => {
- const { initSplashProgress } = await freshSplash();
+ it("tracks the running phase's share of the total weight", async () => {
+ const { initSplashProgress, reportSplashPhase } = await freshSplash();
initSplashProgress(PHASES);
const bar = document.querySelector(".splash-bar");
- expect(bar?.classList.contains("is-segmented")).toBe(true);
+ expect(bar?.classList.contains("is-continuous")).toBe(true);
- const segments = [ ...document.querySelectorAll<HTMLElement>(".splash-seg") ];
- expect(segments.map((seg) => seg.style.flexGrow)).toEqual([ "1", "3", "2" ]);
+ // Weights 1, 3, 2: the bar eases towards the end of whichever phase is running.
+ reportSplashPhase("first");
+ expect(fillWidth()).toBe("17%");
+ reportSplashPhase("second");
+ expect(fillWidth()).toBe("67%");
+ expect(document.getElementById("splash-status")?.textContent).toBe("Second…");
});
- it("keeps the sequence the first caller installed", async () => {
+ it("stops short of a full bar while the startup is still running", async () => {
const { initSplashProgress, reportSplashPhase } = await freshSplash();
initSplashProgress(PHASES);
- // Standalone claims the bar before the client's own, shorter list is offered.
- initSplashProgress([ { id: "other", weight: 1, status: "Other…" } ]);
- expect(document.querySelectorAll(".splash-seg")).toHaveLength(3);
- reportSplashPhase("other");
- expect(document.getElementById("splash-status")?.textContent).toBe("");
+ // The last phase ends the sequence, but a full bar would read as finished.
+ reportSplashPhase("third");
+ expect(fillWidth()).toBe("95%");
});
- it("marks earlier phases done, the reported one active, and shows its status", async () => {
+ it("keeps the sequence the first caller installed", async () => {
const { initSplashProgress, reportSplashPhase } = await freshSplash();
initSplashProgress(PHASES);
+ // Standalone claims the bar before the client's own, shorter list is offered.
+ initSplashProgress([ { id: "other", weight: 1, status: "Other…" } ]);
- reportSplashPhase("second");
- expect(segmentClasses()).toEqual([
- { done: true, active: false },
- { done: false, active: true },
- { done: false, active: false }
- ]);
- expect(document.getElementById("splash-status")?.textContent).toBe("Second…");
+ reportSplashPhase("other");
+ expect(document.getElementById("splash-status")?.textContent).toBe("");
+ expect(fillWidth()).toBe("");
});
it("never moves backwards, and ignores an unknown phase", async () => {
const { initSplashProgress, reportSplashPhase } = await freshSplash();
initSplashProgress(PHASES);
- reportSplashPhase("third");
+ reportSplashPhase("second");
// A phase reported late — or, in a follower tab, out of order — must not undo progress.
reportSplashPhase("first");
reportSplashPhase("nonexistent");
- expect(document.getElementById("splash-status")?.textContent).toBe("Third…");
- expect(segmentClasses()[2]).toEqual({ done: false, active: true });
+ expect(fillWidth()).toBe("67%");
+ expect(document.getElementById("splash-status")?.textContent).toBe("Second…");
});
- it("fills the bar, then fades the splash out and removes it", async () => {
+ it("runs the bar out to full, then fades the splash out and removes it", async () => {
const { initSplashProgress, reportSplashPhase, hideSplash } = await freshSplash();
initSplashProgress(PHASES);
reportSplashPhase("second");
hideSplash();
- expect(segmentClasses().every((seg) => seg.done && !seg.active)).toBe(true);
+ expect(fillWidth()).toBe("100%");
+ const bar = document.querySelector(".splash-bar");
+ expect(bar?.classList.contains("is-finishing")).toBe(true);
expect(document.getElementById("splash")?.classList.contains("splash-hidden")).toBe(true);
vi.runAllTimers();
diff --git a/apps/client/src/services/splash.ts b/apps/client/src/services/splash.ts
index be25fb4a55..38daebfe5d 100644
--- a/apps/client/src/services/splash.ts
+++ b/apps/client/src/services/splash.ts
@@ -11,11 +11,17 @@
/** Matches the `#splash` opacity transition in index.html. */
const SPLASH_FADE_MS = 400;
-/** One step of the startup sequence, drawn as its own segment of the progress bar. */
+/**
+ * How full the bar can get while the startup is still running. The last phase would otherwise
+ * ease to a full bar and sit there, which reads as finished; {@link hideSplash} closes the gap.
+ */
+const MAX_RUNNING_FILL = 0.95;
+
+/** One step of the startup sequence, which the progress bar advances through. */
export interface SplashPhase {
/** Name {@link reportSplashPhase} uses to announce that the step has started. */
id: string;
- /** Relative cost of the step, which sets how wide its segment is. */
+ /** Relative cost of the step, which sets how much of the bar it covers. */
weight: number;
/** Shown under the bar while the step runs. */
status: string;
@@ -32,33 +38,24 @@ export const CLIENT_STARTUP_PHASES: SplashPhase[] = [
];
let phases: SplashPhase[] = [];
+let totalWeight = 0;
-/** Index of the phase now running. Every earlier phase is drawn as complete. */
+/** Index of the phase now running. */
let currentPhase = -1;
/**
- * Splits the progress bar into one segment per phase, each sized by its weight. The first caller
- * wins, so standalone's longer sequence survives the client's own call later in the same startup.
+ * Hands the progress bar the sequence it is to track, replacing its indeterminate animation. The
+ * first caller wins, so standalone's longer sequence survives the client's own call later in the
+ * same startup.
*/
export function initSplashProgress(startupPhases: SplashPhase[]): void {
- if (phases.length) {
+ if (phases.length || !startupPhases.length) {
return;
}
phases = startupPhases;
+ totalWeight = phases.reduce((sum, phase) => sum + phase.weight, 0);
- const bar = document.querySelector("#splash .splash-bar");
- if (!bar) {
- return;
- }
-
- bar.classList.add("is-segmented");
- for (const phase of phases) {
- const segment = document.createElement("div");
- segment.className = "splash-seg";
- // The one genuinely computed value here: a segment is as wide as its phase is costly.
- segment.style.flexGrow = String(phase.weight);
- bar.append(segment);
- }
+ document.querySelector("#splash .splash-bar")?.classList.add("is-continuous");
}
/**
@@ -73,11 +70,11 @@ export function reportSplashPhase(id: string): void {
}
currentPhase = index;
- const segments = document.querySelectorAll<HTMLElement>("#splash .splash-seg");
- for (const [ segmentIndex, segment ] of segments.entries()) {
- segment.classList.toggle("is-done", segmentIndex < index);
- segment.classList.toggle("is-active", segmentIndex === index);
- }
+ // The bar eases towards the end of the phase now running rather than sitting at its start, so
+ // a step that takes seconds still shows movement; the long ease-out in index.html means it
+ // only approaches that end, and never claims more than the running phase covers.
+ const completed = phases.slice(0, index).reduce((sum, earlier) => sum + earlier.weight, 0);
+ setFillWidth(Math.min((completed + phase.weight) / totalWeight, MAX_RUNNING_FILL));
updateSplashStatus(phase.status);
}
@@ -107,13 +104,18 @@ export function hideSplash(): void {
return;
}
- // Fill the bar before it goes, so the last phase is not left mid-flight behind the fade.
- for (const segment of splashEl.querySelectorAll<HTMLElement>(".splash-seg")) {
- segment.classList.remove("is-active");
- segment.classList.add("is-done");
- }
+ // Run the bar out to full, so the last phase is not left mid-flight behind the fade.
+ splashEl.querySelector(".splash-bar")?.classList.add("is-finishing");
+ setFillWidth(1);
splashEl.classList.add("splash-hidden");
setTimeout(() => splashEl.remove(), SPLASH_FADE_MS);
}
+function setFillWidth(fraction: number): void {
+ const fill = document.querySelector<HTMLElement>("#splash .splash-bar-fill");
+ if (fill) {
+ // The one genuinely computed value here: how far through the startup the bar has got.
+ fill.style.width = `${Math.min(100, Math.round(fraction * 100))}%`;
+ }
+}
diff --git a/apps/standalone/src/index.html b/apps/standalone/src/index.html
index 0de1cbe0bb..f2611a9088 100644
--- a/apps/standalone/src/index.html
+++ b/apps/standalone/src/index.html
@@ -63,31 +63,16 @@
background: #72b755;
animation: splash-slide 1.4s ease-in-out infinite;
}
- /* Segmented state, installed by splash.ts once the startup phases are known: one
- segment per phase, each as wide as that phase is expensive. */
- #splash .splash-bar.is-segmented {
- display: flex;
- gap: 2px;
- background: none;
- overflow: visible;
- }
- #splash .splash-bar.is-segmented .splash-bar-fill {
- display: none;
- }
- #splash .splash-seg {
- flex-basis: 0;
- height: 100%;
- border-radius: 2px;
- background: rgba(128, 128, 128, 0.2);
- transition: background-color 0.3s ease;
+ /* Tracking state, installed by splash.ts once the startup phases are known. The long
+ ease-out carries the fill towards the running phase's end without ever reaching it,
+ so a slow step keeps moving instead of looking stalled. */
+ #splash .splash-bar.is-continuous .splash-bar-fill {
+ width: 0;
+ animation: none;
+ transition: width 12s cubic-bezier(0.16, 0.85, 0.3, 1);
}
- #splash .splash-seg.is-done {
- background: #72b755;
- }
- #splash .splash-seg.is-active {
- background: linear-gradient(90deg, rgba(114, 183, 85, 0.25) 0%, #72b755 50%, rgba(114, 183, 85, 0.25) 100%);
- background-size: 250% 100%;
- animation: splash-seg-sweep 1.2s ease-in-out infinite;
+ #splash .splash-bar.is-continuous.is-finishing .splash-bar-fill {
+ transition: width 0.3s ease;
}
#splash-status {
min-height: 1.5em;
@@ -113,10 +98,6 @@
0%, 100% { opacity: 0.3; }
50% { opacity: 1; }
}
- @keyframes splash-seg-sweep {
- 0% { background-position: 100% 0; }
- 100% { background-position: 0 0; }
- }
@media (prefers-color-scheme: dark) {
#splash { background: #242424; color: #999999; }
#splash .splash-title { color: #cccccc; }
@@ -124,7 +105,7 @@
@media (prefers-reduced-motion: reduce) {
#splash .splash-content { opacity: 1; animation: none; }
#splash .splash-bar-fill { width: 100%; animation: splash-pulse 1.8s ease-in-out infinite; }
- #splash .splash-seg.is-active { background: rgba(114, 183, 85, 0.55); animation: none; }
+ #splash .splash-bar.is-continuous .splash-bar-fill { transition: width 0.2s linear; }
}
@media print {
#splash { display: none; }
diff --git a/apps/standalone/src/local-bridge.spec.ts b/apps/standalone/src/local-bridge.spec.ts
index 0f2d778f3e..a6e2b99944 100644
--- a/apps/standalone/src/local-bridge.spec.ts
+++ b/apps/standalone/src/local-bridge.spec.ts
@@ -65,23 +65,22 @@ describe("startup progress", () => {
it("advances the splash as the worker reports its startup phases", async () => {
document.body.innerHTML = `
<div id="splash">
- <div class="splash-bar"></div>
+ <div class="splash-bar"><div class="splash-bar-fill"></div></div>
<div id="splash-status"></div>
</div>`;
const bridge = await freshBridge();
const { initSplashProgress } = await import("../../client/src/services/splash.js");
initSplashProgress([
{ id: "sqlite", weight: 1, status: "Loading the database engine…" },
- { id: "core", weight: 1, status: "Loading Trilium…" }
+ { id: "core", weight: 1, status: "Loading Trilium…" },
+ { id: "application", weight: 2, status: "Loading the application…" }
]);
bridge.startLocalServerWorker();
lastWorker().onmessage?.({ data: { type: "STARTUP_PROGRESS", phase: "core" } });
expect(document.getElementById("splash-status")?.textContent).toBe("Loading Trilium…");
- const segments = [ ...document.querySelectorAll(".splash-seg") ];
- expect(segments[0]?.classList.contains("is-done")).toBe(true);
- expect(segments[1]?.classList.contains("is-active")).toBe(true);
+ expect(document.querySelector<HTMLElement>(".splash-bar-fill")?.style.width).toBe("50%");
document.body.innerHTML = "";
});
diff --git a/apps/standalone/src/main.spec.ts b/apps/standalone/src/main.spec.ts
index 19a444d0ad..e06ca01876 100644
--- a/apps/standalone/src/main.spec.ts
+++ b/apps/standalone/src/main.spec.ts
@@ -120,7 +120,7 @@ describe("bootstrap", () => {
it("reports progress on the splash while the SW installs", async () => {
document.body.innerHTML = `
<div id="splash">
- <div class="splash-bar"></div>
+ <div class="splash-bar"><div class="splash-bar-fill"></div></div>
<div id="splash-status"></div>
</div>`;
const sw: ServiceWorkerLike = {
@@ -132,10 +132,9 @@ describe("bootstrap", () => {
await vi.waitFor(() => expect(sw.register).toHaveBeenCalled());
expect(document.getElementById("splash-status")?.textContent)
.toBe("Setting up offline support…");
- // One segment per startup phase, the first of them active.
- const segments = [ ...document.querySelectorAll(".splash-seg") ];
- expect(segments).toHaveLength(8);
- expect(segments[0]?.classList.contains("is-active")).toBe(true);
+ // Eight weighted phases, the first of which covers 1/18 of the bar.
+ const fill = document.querySelector<HTMLElement>(".splash-bar-fill");
+ expect(fill?.style.width).toBe("6%");
});
it("reloads the page when the SW installs but does not take control", async () => {