Open History to see the last commit
1const NIGHTLY_SERVER_VERSION_PATTERN = /-nightly\.\d{8}\.\d+$/;
2
3export function formatAppDisplayName(input: {
4 readonly baseName: string;
5 readonly stageLabel: string;
6}): string {
7 if (input.stageLabel.trim().toLowerCase() === "latest") {
8 return input.baseName;
9 }
10
11 return `${input.baseName} (${input.stageLabel})`;
12}
13
14/**
15 * Whether the sidebar v2 beta is on by default for a build stage.
16 *
17 * Nightly and local dev opt in; Alpha and Latest stay on v1. This is resolved
18 * from the client's own stage label rather than the connected server's version:
19 * v2 only exists in the client, so a stable client on a nightly server has
20 * nothing to turn on.
21 */
22export function resolveSidebarV2Default(stageLabel: string): boolean {
23 const stage = stageLabel.trim().toLowerCase();
24 return stage === "nightly" || stage === "dev";
25}
26
27/**
28 * Resolved sidebar v2 state: an explicit choice if the user has made one,
29 * otherwise the default for this build stage.
30 *
31 * A stored `enabled: true` counts as an explicit choice even without the
32 * companion flag. `true` was never the schema default, so it can only have come
33 * from the Settings → Beta toggle — settings written before that flag existed
34 * would otherwise lose the opt-in and drop such users back to v1 on production.
35 * Mirrors how `normalizeDesktopSettingsDocument` treats a legacy stored
36 * `updateChannel: "nightly"` as user-configured.
37 *
38 * `settingsHydrated` guards the startup window: client settings load
39 * asynchronously and the pre-hydration snapshot is just the schema defaults, so
40 * resolving against it would mount one sidebar and swap it out a tick later,
41 * remounting the tree. While hydrating, hold v1 — where both paths already
42 * start.
43 */
44export function resolveSidebarV2Enabled(input: {
45 readonly enabled: boolean;
46 readonly configuredByUser: boolean;
47 readonly settingsHydrated: boolean;
48 readonly stageLabel: string;
49}): boolean {
50 if (!input.settingsHydrated) {
51 return false;
52 }
53
54 return input.configuredByUser || input.enabled
55 ? input.enabled
56 : resolveSidebarV2Default(input.stageLabel);
57}
58
59export function resolveServerBackedAppStageLabel(input: {
60 readonly primaryServerVersion: string | null | undefined;
61 readonly fallbackStageLabel: string;
62}): string {
63 return input.primaryServerVersion &&
64 NIGHTLY_SERVER_VERSION_PATTERN.test(input.primaryServerVersion)
65 ? "Nightly"
66 : input.fallbackStageLabel;
67}
68
69export function resolveServerBackedAppDisplayName(input: {
70 readonly baseName: string;
71 readonly fallbackDisplayName: string;
72 readonly fallbackStageLabel: string;
73 readonly primaryServerVersion: string | null | undefined;
74}): string {
75 const stageLabel = resolveServerBackedAppStageLabel({
76 primaryServerVersion: input.primaryServerVersion,
77 fallbackStageLabel: input.fallbackStageLabel,
78 });
79
80 return stageLabel === input.fallbackStageLabel
81 ? input.fallbackDisplayName
82 : formatAppDisplayName({ baseName: input.baseName, stageLabel });
83}