From 152115dea57bcdccfd31d50500a148ca4e0faf8b Mon Sep 17 00:00:00 2001 From: Dax Date: Fri, 13 Nov 2026 08:03:27 -0500 Subject: [PATCH] feat(app): wait an hour after first launch before the first tip (#63760) --- packages/app/src/tips/model.ts | 9 ++++++++- packages/app/src/tips/queue.test.ts | 13 +++++++++++-- packages/app/src/tips/queue.ts | 5 +++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/app/src/tips/model.ts b/packages/app/src/tips/model.ts index 284c9be99f5..e13f055b7ca 100644 --- a/packages/app/src/tips/model.ts +++ b/packages/app/src/tips/model.ts @@ -7,7 +7,7 @@ import { Persist, persisted } from "@/runtime/persistence/storage" import { usePlatform } from "@/runtime/platform/platform" import { ServerConnection, useServers } from "@/runtime/server/registry" import { useGlobal } from "@/runtime/server/runtime" -import { selectTip, TIP_INTERVAL_MS, type Tip } from "./queue" +import { FIRST_TIP_DELAY_MS, selectTip, TIP_INTERVAL_MS, type Tip } from "./queue" const STARTUP_DELAY = 2 * 60 * 1000 @@ -16,6 +16,7 @@ const History = Persistence.struct({ shownAt: Schema.Finite, dismissed: Persistence.array(Schema.String), dismissedAt: Schema.Finite, + firstSeen: Persistence.fallback(Schema.Finite, () => 0), }) export function createTipToasts() { @@ -79,6 +80,11 @@ export function createTipToasts() { shownAt: 0, dismissed: [], dismissedAt: 0, + firstSeen: 0, + }) + + createEffect(() => { + if (loaded() && !history.firstSeen) setHistory("firstSeen", Date.now()) }) const [tick, setTick] = createSignal(0) @@ -90,6 +96,7 @@ export function createTipToasts() { const times = [ Math.max(history.shownAt, history.dismissedAt) + TIP_INTERVAL_MS, + history.firstSeen + FIRST_TIP_DELAY_MS, ...tips.flatMap((tip) => [tip.start ?? 0, tip.end ?? 0]), ] diff --git a/packages/app/src/tips/queue.test.ts b/packages/app/src/tips/queue.test.ts index e4ecf1e5278..ae170ce9a43 100644 --- a/packages/app/src/tips/queue.test.ts +++ b/packages/app/src/tips/queue.test.ts @@ -1,7 +1,10 @@ import { expect, test } from "bun:test" import { selectTip, type Tip } from "./queue" -const fresh = { current: "", shownAt: 0, dismissed: [], dismissedAt: 0 } +const hours = 60 * 60 * 1000 + +// Installed an hour before time 0, so the first-tip delay has already passed. +const fresh = { current: "", shownAt: 0, dismissed: [], dismissedAt: 0, firstSeen: -hours } const first: Tip = { id: "first", title: "tips.browse.title", description: "tips.browse.description" } @@ -9,7 +12,13 @@ const second: Tip = { ...first, id: "second" } const tips = [first, second] -const hours = 60 * 60 * 1000 +test("the first tip waits an hour after the app first ran", () => { + const installed = { ...fresh, firstSeen: 10 * hours } + expect(selectTip(tips, installed, 11 * hours - 1)).toBeUndefined() + expect(selectTip(tips, installed, 11 * hours)).toBe(first) + expect(selectTip(tips, { ...fresh, firstSeen: 0 }, 5 * hours)).toBeUndefined() + expect(selectTip(tips, { ...installed, dismissed: [first.id], dismissedAt: 1 }, 25 * hours)).toBe(second) +}) test("first eligible tip wins until it is handled or stops being eligible", () => { expect(selectTip(tips, fresh, 1)).toBe(first) diff --git a/packages/app/src/tips/queue.ts b/packages/app/src/tips/queue.ts index 85b781f0c55..4cefb7fd04f 100644 --- a/packages/app/src/tips/queue.ts +++ b/packages/app/src/tips/queue.ts @@ -2,6 +2,8 @@ import type { useLanguage } from "@/runtime/i18n/language" export const TIP_INTERVAL_MS = 24 * 60 * 60 * 1000 +export const FIRST_TIP_DELAY_MS = 60 * 60 * 1000 + type Text = Parameters["t"]>[0] export type Tip = { @@ -19,6 +21,7 @@ export type TipHistory = { shownAt: number dismissed: readonly string[] dismissedAt: number + firstSeen: number } /** Array order is priority. Dates are epoch milliseconds; the end is exclusive. */ @@ -37,5 +40,7 @@ export function selectTip(tips: readonly Tip[], history: TipHistory, now: number if (last && now < last + TIP_INTERVAL_MS) return + if (!last && now < (history.firstSeen || now) + FIRST_TIP_DELAY_MS) return + return tips.find(eligible) }