Skip to content

Commit 38d5342

Browse files
committed
fix(desktop): auto-setup workspace and skip onboarding for shared identity worktrees
SPROUT_SHARE_IDENTITY=1 shares the Nostr private key across worktrees but each worktree gets a unique Tauri identifier, isolating localStorage. This left two gaps: no workspace config (forcing WelcomeSetup on every new worktree) and no onboarding completion marker (forcing re-onboarding despite the user already having a profile on the relay). Add an is_shared_identity Tauri command that exposes the env var to the frontend. When true, useWorkspaceInit auto-creates a workspace from the default relay URL (mirroring WelcomeSetup.handleConnect) and the onboarding gate writes the completion marker immediately after the identity query succeeds, bypassing the fragile relay profile check.
1 parent 962dd7d commit 38d5342

6 files changed

Lines changed: 75 additions & 5 deletions

File tree

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ doc/
5353
# Local identity files
5454
identity.key
5555
**/identity.key
56+
57+
# Claude Code worktrees
58+
.claude/worktrees/

‎desktop/src-tauri/src/commands/identity.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ pub fn get_default_relay_url() -> String {
3737
relay::relay_ws_url()
3838
}
3939

40+
#[tauri::command]
41+
pub fn is_shared_identity() -> bool {
42+
std::env::var("SPROUT_SHARE_IDENTITY")
43+
.map(|v| v == "1")
44+
.unwrap_or(false)
45+
}
46+
4047
#[tauri::command]
4148
pub fn get_relay_ws_url(state: State<'_, AppState>) -> String {
4249
relay_ws_url_with_override(&state)

‎desktop/src-tauri/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ pub fn run() {
461461
get_presence,
462462
set_presence,
463463
get_default_relay_url,
464+
is_shared_identity,
464465
get_relay_ws_url,
465466
get_relay_http_url,
466467
get_media_proxy_port,

‎desktop/src/features/onboarding/hooks.ts‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useQueryClient, type QueryStatus } from "@tanstack/react-query";
44
import { channelsQueryKey } from "@/features/channels/hooks";
55
import { useProfileQuery } from "@/features/profile/hooks";
66
import { useIdentityQuery } from "@/shared/api/hooks";
7-
import { getChannels, joinChannel } from "@/shared/api/tauri";
7+
import { getChannels, isSharedIdentity, joinChannel } from "@/shared/api/tauri";
88

99
const DEFAULT_AUTO_JOIN_CHANNEL_NAME = "general";
1010

@@ -36,6 +36,7 @@ type UseFirstRunOnboardingGateOptions = {
3636
hasExistingProfile: boolean;
3737
identityIsFetching: boolean;
3838
identityStatus: QueryStatus;
39+
isSharedIdentity: boolean;
3940
profileStatus: QueryStatus;
4041
};
4142

@@ -129,6 +130,7 @@ export function useFirstRunOnboardingGate({
129130
hasExistingProfile,
130131
identityIsFetching,
131132
identityStatus,
133+
isSharedIdentity: isSharedIdentityProp,
132134
profileStatus,
133135
}: UseFirstRunOnboardingGateOptions) {
134136
const [gateState, setGateState] = React.useState<OnboardingGateState>(() =>
@@ -146,7 +148,7 @@ export function useFirstRunOnboardingGate({
146148
}, [currentPubkey]);
147149

148150
React.useEffect(() => {
149-
if (hasSettledCurrentPubkey || !currentPubkey) {
151+
if ((hasSettledCurrentPubkey && !isSharedIdentityProp) || !currentPubkey) {
150152
return;
151153
}
152154

@@ -164,6 +166,26 @@ export function useFirstRunOnboardingGate({
164166
return;
165167
}
166168

169+
// Shared identity worktrees have already onboarded in the main checkout.
170+
// Skip unconditionally without waiting for the relay profile query.
171+
if (isSharedIdentityProp) {
172+
if (typeof window !== "undefined" && currentPubkey) {
173+
window.localStorage.setItem(
174+
onboardingCompletionStorageKey(currentPubkey),
175+
"true",
176+
);
177+
}
178+
setGateState((current) =>
179+
updateActiveGateState(current, currentPubkey, (activeGateState) => ({
180+
...activeGateState,
181+
hasCompletedCurrentPubkey: true,
182+
hasSettledCurrentPubkey: true,
183+
isOpen: false,
184+
})),
185+
);
186+
return;
187+
}
188+
167189
if (!isSettledQueryStatus(profileStatus)) {
168190
return;
169191
}
@@ -197,6 +219,7 @@ export function useFirstRunOnboardingGate({
197219
hasExistingProfile,
198220
hasSettledCurrentPubkey,
199221
identityStatus,
222+
isSharedIdentityProp,
200223
profileStatus,
201224
]);
202225

@@ -252,11 +275,16 @@ export function useAppOnboardingState() {
252275
const identity = identityQuery.data;
253276
const currentPubkey = identity?.pubkey ?? null;
254277
const profileQuery = useProfileQuery();
278+
const [sharedIdentity, setSharedIdentity] = React.useState(false);
279+
React.useEffect(() => {
280+
isSharedIdentity().then(setSharedIdentity).catch(() => {});
281+
}, []);
255282
const onboardingGate = useFirstRunOnboardingGate({
256283
currentPubkey,
257284
hasExistingProfile: hasRealDisplayName(profileQuery.data?.displayName),
258285
identityIsFetching: identityQuery.fetchStatus === "fetching",
259286
identityStatus: identityQuery.status,
287+
isSharedIdentity: sharedIdentity,
260288
profileStatus: profileQuery.status,
261289
});
262290
const gateComplete = onboardingGate.complete;

‎desktop/src/features/workspaces/useWorkspaceInit.ts‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { useEffect, useRef, useState } from "react";
22

33
import { relayClient } from "@/shared/api/relayClient";
4-
import { applyWorkspace, getDefaultRelayUrl } from "@/shared/api/tauri";
4+
import { applyWorkspace, getDefaultRelayUrl, getIdentity, isSharedIdentity } from "@/shared/api/tauri";
55
import { resetMediaCaches } from "@/shared/lib/mediaUrl";
66
import { clearSearchHitEventCache } from "@/app/navigation/searchHitEventCache";
77
import { clearAllDrafts } from "@/features/messages/lib/useDrafts";
88
import { resetAgentObserverStore } from "@/features/agents/observerRelayStore";
99

10+
import {
11+
deriveWorkspaceName,
12+
normalizeRelayUrl,
13+
saveActiveWorkspaceId,
14+
saveWorkspaces,
15+
} from "./workspaceStorage";
1016
import type { Workspace } from "./types";
1117

1218
/**
@@ -60,9 +66,30 @@ export function useWorkspaceInit(
6066

6167
async function init() {
6268
if (!activeWorkspace) {
63-
// No workspace — need setup
6469
try {
65-
const defaultRelayUrl = await getDefaultRelayUrl();
70+
const [defaultRelayUrl, sharedIdentity] = await Promise.all([
71+
getDefaultRelayUrl(),
72+
isSharedIdentity(),
73+
]);
74+
75+
if (sharedIdentity) {
76+
// Shared identity worktree: auto-create workspace from the
77+
// default relay URL so the user skips WelcomeSetup entirely.
78+
const identity = await getIdentity();
79+
const normalizedUrl = normalizeRelayUrl(defaultRelayUrl);
80+
const workspace: Workspace = {
81+
id: crypto.randomUUID(),
82+
name: deriveWorkspaceName(normalizedUrl),
83+
relayUrl: normalizedUrl,
84+
pubkey: identity.pubkey,
85+
addedAt: new Date().toISOString(),
86+
};
87+
saveWorkspaces([workspace]);
88+
saveActiveWorkspaceId(workspace.id);
89+
window.location.reload();
90+
return;
91+
}
92+
6693
if (!cancelled) {
6794
setResult({
6895
isReady: false,

‎desktop/src/shared/api/tauri.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ export function getDefaultRelayUrl(): Promise<string> {
519519
return invokeTauri<string>("get_default_relay_url");
520520
}
521521

522+
export function isSharedIdentity(): Promise<boolean> {
523+
return invokeTauri<boolean>("is_shared_identity");
524+
}
525+
522526
export function getRelayWsUrl(): Promise<string> {
523527
return invokeTauri<string>("get_relay_ws_url");
524528
}

0 commit comments

Comments
 (0)