Skip to content

Open source CapCut alternative.

TypeScript

feat(site): turn cloud mode on for every account

David Le53d9265b7394
diff --git a/site/src/app/api/account/feature-flags/route.ts b/site/src/app/api/account/feature-flags/route.ts
index c5114128..bc8894b9 100644
--- a/site/src/app/api/account/feature-flags/route.ts
+++ b/site/src/app/api/account/feature-flags/route.ts
@@ -8,7 +8,8 @@ import { ACCOUNT_FEATURE_FLAGS, isKnownFeatureFlag } from "@/lib/feature-flags";
import { prisma } from "@/lib/prisma";
// The signed-in account's feature flags: the full registry with each flag's
-// enabled state. Rows exist only for flags the user has touched.
+// enabled state. Rows exist only for flags the user has touched; everyone else
+// gets the flag's registry default.
export const GET = withDonkeyAuth(async (request: DonkeyAuthenticatedRequest) => {
const rows = await prisma.userFeatureFlag.findMany({
where: { userId: request.donkey.userId },
@@ -17,7 +18,7 @@ export const GET = withDonkeyAuth(async (request: DonkeyAuthenticatedRequest) =>
return NextResponse.json({
flags: ACCOUNT_FEATURE_FLAGS.map((f) => ({
...f,
- enabled: enabled.get(f.id) ?? false,
+ enabled: enabled.get(f.id) ?? f.defaultEnabled,
})),
});
});
diff --git a/site/src/cut/lib/flags.ts b/site/src/cut/lib/flags.ts
index 7d47b5fe..d8fed8e0 100644
--- a/site/src/cut/lib/flags.ts
+++ b/site/src/cut/lib/flags.ts
@@ -1,26 +1,32 @@
-// Cut's web-mode flag is an ACCOUNT feature flag ("cut-web-mode"), enabled per
-// user in the account settings' Feature flags section. localStorage only
-// mirrors the server value so reads stay synchronous; RequireSession refreshes
-// the mirror from the account on every app load, and the settings page updates
-// it when the user flips the switch. Reads go through useSyncExternalStore so
-// every component — and every other tab, via the storage event — reacts to a
-// change immediately.
+// Cut's web-mode flag is an ACCOUNT feature flag ("cut-web-mode"), set per user
+// in the account settings' Feature flags section. It ships on for everyone, so
+// the switch is an opt-out. localStorage only mirrors the server value so reads
+// stay synchronous; RequireSession refreshes the mirror from the account on
+// every app load, and the settings page updates it when the user flips the
+// switch. Reads go through useSyncExternalStore so every component — and every
+// other tab, via the storage event — reacts to a change immediately.
+import { featureFlagDefault } from "@/lib/feature-flags";
import { useSyncExternalStore } from "react";
const WEB_MODE_KEY = "cut-web-mode";
const FLAG_EVENT = "cut-flags-changed";
+const WEB_MODE_DEFAULT = featureFlagDefault(WEB_MODE_KEY);
+
+/** The mirror is three-valued: "1" on, "0" off, absent means the account has
+ * never been read here, which is the flag's registry default. */
export function webModeEnabled(): boolean {
- if (typeof window === "undefined") return false;
- return localStorage.getItem(WEB_MODE_KEY) === "1";
+ if (typeof window === "undefined") return WEB_MODE_DEFAULT;
+ const mirror = localStorage.getItem(WEB_MODE_KEY);
+ if (mirror === null) return WEB_MODE_DEFAULT;
+ return mirror === "1";
}
/** Update the local mirror (this tab reacts immediately, other tabs via the
* storage event). The account value is written by the settings page's PUT;
* this never calls the server. */
export function applyWebModeLocal(on: boolean) {
- if (on) localStorage.setItem(WEB_MODE_KEY, "1");
- else localStorage.removeItem(WEB_MODE_KEY);
+ localStorage.setItem(WEB_MODE_KEY, on ? "1" : "0");
window.dispatchEvent(new Event(FLAG_EVENT));
}
@@ -46,7 +52,7 @@ export async function syncAccountFlags() {
if (!res.ok) return;
const body = (await res.json()) as { flags?: { id: string; enabled: boolean }[] };
const webMode = body.flags?.find((f) => f.id === WEB_MODE_KEY);
- if (webMode && webMode.enabled !== webModeEnabled()) applyWebModeLocal(webMode.enabled);
+ if (webMode) applyWebModeLocal(webMode.enabled);
} catch {
// Offline or hosted API unreachable; the mirror stands.
}
@@ -62,5 +68,5 @@ function subscribe(onChange: () => void) {
}
export function useWebMode(): boolean {
- return useSyncExternalStore(subscribe, webModeEnabled, () => false);
+ return useSyncExternalStore(subscribe, webModeEnabled, () => WEB_MODE_DEFAULT);
}
diff --git a/site/src/lib/feature-flags.ts b/site/src/lib/feature-flags.ts
index f962277d..ba1ddc7f 100644
--- a/site/src/lib/feature-flags.ts
+++ b/site/src/lib/feature-flags.ts
@@ -5,6 +5,9 @@ export type AccountFeatureFlag = {
id: string;
title: string;
description: string;
+ /** The state an account with no row of its own gets. A flag that has shipped
+ * to everyone defaults on and the switch becomes an opt-out. */
+ defaultEnabled: boolean;
};
export const ACCOUNT_FEATURE_FLAGS: AccountFeatureFlag[] = [
@@ -13,8 +16,12 @@ export const ACCOUNT_FEATURE_FLAGS: AccountFeatureFlag[] = [
title: "Cloud mode (beta)",
description:
"Edit in any browser on any OS with no install: projects stored in the cloud, exports rendered by a cloud worker. The Mac app keeps running everything locally.",
+ defaultEnabled: true,
},
];
+export const featureFlagDefault = (id: string) =>
+ ACCOUNT_FEATURE_FLAGS.find((f) => f.id === id)?.defaultEnabled ?? false;
+
export const isKnownFeatureFlag = (id: string) =>
ACCOUNT_FEATURE_FLAGS.some((f) => f.id === id);