Line data Source code
1 : import { getPreservedQueryParam } from '@/platform/navigation/preservedQueryManager'
2 : import { PRESERVED_QUERY_NAMESPACES } from '@/platform/navigation/preservedQueryNamespaces'
3 : import { WORKSPACE_STORAGE_KEYS } from '@/platform/workspace/workspaceConstants'
4 :
5 2356 : const COMFY_CLOUD = 'cloud'
6 :
7 : /** Where this browser's next boot in a workspace runs, per its hint. */
8 : export type DeploymentHint = 'deployment' | 'cloud' | 'unconfirmed' | 'unknown'
9 :
10 0 : function hintKey(workspaceId: string): string {
11 0 : return `${WORKSPACE_STORAGE_KEYS.DEPLOYMENT_HINT_PREFIX}${workspaceId}`
12 : }
13 :
14 0 : function unconfirmedCloudKey(workspaceId: string): string {
15 0 : return `${WORKSPACE_STORAGE_KEYS.UNCONFIRMED_CLOUD_HINT_PREFIX}${workspaceId}`
16 : }
17 :
18 : /** Reads this browser's deployment hint for the workspace; `unknown` when none is recorded or storage is unreadable. */
19 0 : export function readDeploymentHint(workspaceId: string | null): DeploymentHint {
20 0 : if (workspaceId === null) return 'unknown'
21 0 : try {
22 0 : const hint = localStorage.getItem(hintKey(workspaceId))
23 0 : if (hint !== null) return hint === COMFY_CLOUD ? 'cloud' : 'deployment'
24 0 : return localStorage.getItem(unconfirmedCloudKey(workspaceId)) === null
25 : ? 'unknown'
26 : : 'unconfirmed'
27 : } catch {
28 0 : return 'unknown'
29 : }
30 : }
31 :
32 : /** Records the workspace's next boot target (null for Comfy Cloud), clearing any unconfirmed hint. */
33 0 : export function setDeploymentHint(
34 : workspaceId: string,
35 : deploymentId: string | null
36 : ): void {
37 0 : try {
38 0 : localStorage.setItem(hintKey(workspaceId), deploymentId ?? COMFY_CLOUD)
39 0 : localStorage.removeItem(unconfirmedCloudKey(workspaceId))
40 : } catch {
41 0 : console.warn('Failed to persist the deployment hint')
42 : }
43 : }
44 :
45 : /** Records Comfy Cloud as the workspace's next boot target until a listing says otherwise. */
46 0 : export function setUnconfirmedCloudHint(workspaceId: string): void {
47 0 : try {
48 0 : localStorage.setItem(unconfirmedCloudKey(workspaceId), '1')
49 : } catch {
50 0 : console.warn('Failed to persist the deployment hint')
51 : }
52 : }
53 :
54 : /** True when the page was opened from a deployment link, in its URL or stashed across sign-in. */
55 0 : export function hasDeploymentLink(): boolean {
56 0 : return (
57 : new URLSearchParams(window.location.search).has('deployment') ||
58 : getPreservedQueryParam(
59 : PRESERVED_QUERY_NAMESPACES.DEPLOYMENT,
60 : 'deployment'
61 : ) !== undefined
62 : )
63 : }
|