refactor: move startup logic to app-support, improve welcome screen UI

This commit is contained in:
Mohamed Boudra
2026-03-15 12:52:29 +07:00
parent 57db31c662
commit 5701543746
6 changed files with 108 additions and 56 deletions
+3 -1
View File
@@ -61,6 +61,7 @@ import {
import { buildNotificationRoute } from "@/utils/notification-routing"; import { buildNotificationRoute } from "@/utils/notification-routing";
import { import {
buildHostRootRoute, buildHostRootRoute,
parseServerIdFromPathname,
parseHostAgentRouteFromPathname, parseHostAgentRouteFromPathname,
parseWorkspaceOpenIntent, parseWorkspaceOpenIntent,
} from "@/utils/host-routes"; } from "@/utils/host-routes";
@@ -469,7 +470,8 @@ function AppWithSidebar({ children }: { children: ReactNode }) {
const pathname = usePathname(); const pathname = usePathname();
const params = useGlobalSearchParams<{ open?: string | string[] }>(); const params = useGlobalSearchParams<{ open?: string | string[] }>();
useFaviconStatus(); useFaviconStatus();
const shouldShowAppChrome = pathname !== "/" && pathname !== ""; const activeServerId = useMemo(() => parseServerIdFromPathname(pathname), [pathname]);
const shouldShowAppChrome = activeServerId !== null;
// Parse selectedAgentKey directly from pathname // Parse selectedAgentKey directly from pathname
// useLocalSearchParams doesn't update when navigating between same-pattern routes // useLocalSearchParams doesn't update when navigating between same-pattern routes
+1 -1
View File
@@ -10,7 +10,7 @@ import {
shouldRedirectToWelcome, shouldRedirectToWelcome,
shouldWaitOnStartupRace, shouldWaitOnStartupRace,
WELCOME_ROUTE, WELCOME_ROUTE,
} from './index-startup' } from '@/app-support/index-startup'
const STARTUP_TIMEOUT_MS = 30_000 const STARTUP_TIMEOUT_MS = 30_000
function useAnyHostOnline(serverIds: string[]): string | null { function useAnyHostOnline(serverIds: string[]): string | null {
+85 -41
View File
@@ -1,8 +1,9 @@
import { useCallback, useState } from "react"; import { useCallback, useState } from "react";
import { Image, Pressable, Text, View, Platform, ScrollView } from "react-native"; import { Pressable, Text, View, Platform, ScrollView } from "react-native";
import { useRouter } from "expo-router"; import { useRouter } from "expo-router";
import { StyleSheet, useUnistyles } from "react-native-unistyles"; import { StyleSheet, useUnistyles } from "react-native-unistyles";
import { QrCode, Link2, ClipboardPaste } from "lucide-react-native"; import { QrCode, Link2, ClipboardPaste } from "lucide-react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import type { HostProfile } from "@/types/host-connection"; import type { HostProfile } from "@/types/host-connection";
import { useHostMutations } from "@/runtime/host-runtime"; import { useHostMutations } from "@/runtime/host-runtime";
import { useSessionStore } from "@/stores/session-store"; import { useSessionStore } from "@/stores/session-store";
@@ -12,12 +13,23 @@ import { NameHostModal } from "./name-host-modal";
import { resolveAppVersion } from "@/utils/app-version"; import { resolveAppVersion } from "@/utils/app-version";
import { formatVersionWithPrefix } from "@/desktop/updates/desktop-updates"; import { formatVersionWithPrefix } from "@/desktop/updates/desktop-updates";
import { buildHostRootRoute } from "@/utils/host-routes"; import { buildHostRootRoute } from "@/utils/host-routes";
import { PaseoLogo } from "@/components/icons/paseo-logo";
type WelcomeAction = {
key: "scan-qr" | "direct-connection" | "paste-pairing-link";
label: string;
testID: string;
primary: boolean;
icon: typeof QrCode;
onPress: () => void;
};
const styles = StyleSheet.create((theme) => ({ const styles = StyleSheet.create((theme) => ({
container: { container: {
flexGrow: 1, flexGrow: 1,
backgroundColor: theme.colors.surface0, backgroundColor: theme.colors.surface0,
padding: theme.spacing[6], padding: theme.spacing[6],
paddingBottom: 0,
alignItems: "center", alignItems: "center",
}, },
content: { content: {
@@ -26,11 +38,6 @@ const styles = StyleSheet.create((theme) => ({
justifyContent: "center", justifyContent: "center",
alignItems: "center", alignItems: "center",
}, },
logo: {
width: 96,
height: 96,
marginBottom: theme.spacing[6],
},
title: { title: {
color: theme.colors.foreground, color: theme.colors.foreground,
fontSize: theme.fontSize.xl, fontSize: theme.fontSize.xl,
@@ -61,8 +68,8 @@ const styles = StyleSheet.create((theme) => ({
borderColor: theme.colors.border, borderColor: theme.colors.border,
}, },
actionButtonPrimary: { actionButtonPrimary: {
backgroundColor: theme.colors.palette.blue[500], backgroundColor: theme.colors.accent,
borderColor: theme.colors.palette.blue[500], borderColor: theme.colors.accent,
}, },
actionText: { actionText: {
color: theme.colors.foreground, color: theme.colors.foreground,
@@ -70,7 +77,7 @@ const styles = StyleSheet.create((theme) => ({
fontWeight: theme.fontWeight.medium, fontWeight: theme.fontWeight.medium,
}, },
actionTextPrimary: { actionTextPrimary: {
color: theme.colors.palette.white, color: theme.colors.accentForeground,
}, },
versionLabel: { versionLabel: {
color: theme.colors.foregroundMuted, color: theme.colors.foregroundMuted,
@@ -86,6 +93,7 @@ export interface WelcomeScreenProps {
export function WelcomeScreen({ onHostAdded }: WelcomeScreenProps) { export function WelcomeScreen({ onHostAdded }: WelcomeScreenProps) {
const { theme } = useUnistyles(); const { theme } = useUnistyles();
const insets = useSafeAreaInsets();
const router = useRouter(); const router = useRouter();
const { renameHost } = useHostMutations(); const { renameHost } = useHostMutations();
const appVersion = resolveAppVersion(); const appVersion = resolveAppVersion();
@@ -111,51 +119,87 @@ export function WelcomeScreen({ onHostAdded }: WelcomeScreenProps) {
[router] [router]
); );
const actions: WelcomeAction[] = Platform.OS === "web"
? [
{
key: "direct-connection",
label: "Direct connection",
testID: "welcome-direct-connection",
primary: true,
icon: Link2,
onPress: () => setIsDirectOpen(true),
},
{
key: "paste-pairing-link",
label: "Paste pairing link",
testID: "welcome-paste-pairing-link",
primary: false,
icon: ClipboardPaste,
onPress: () => setIsPasteLinkOpen(true),
},
]
: [
{
key: "scan-qr",
label: "Scan QR code",
testID: "welcome-scan-qr",
primary: true,
icon: QrCode,
onPress: () => router.push("/pair-scan?source=onboarding"),
},
{
key: "direct-connection",
label: "Direct connection",
testID: "welcome-direct-connection",
primary: false,
icon: Link2,
onPress: () => setIsDirectOpen(true),
},
{
key: "paste-pairing-link",
label: "Paste pairing link",
testID: "welcome-paste-pairing-link",
primary: false,
icon: ClipboardPaste,
onPress: () => setIsPasteLinkOpen(true),
},
];
return ( return (
<ScrollView <ScrollView
style={{ flex: 1, backgroundColor: theme.colors.surface0 }} style={{ flex: 1, backgroundColor: theme.colors.surface0 }}
contentContainerStyle={styles.container} contentContainerStyle={[
styles.container,
{ paddingBottom: theme.spacing[6] + insets.bottom },
]}
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
testID="welcome-screen" testID="welcome-screen"
> >
<View style={styles.content}> <View style={styles.content}>
<Image <PaseoLogo size={96} color={theme.colors.foreground} />
source={require("../../assets/images/icon.png")}
style={styles.logo}
resizeMode="contain"
/>
<Text style={styles.title}>Welcome to Paseo</Text> <Text style={styles.title}>Welcome to Paseo</Text>
<Text style={styles.subtitle}>Add a host to start.</Text> <Text style={styles.subtitle}>Connect to your host to start</Text>
<View style={styles.actions}> <View style={styles.actions}>
<Pressable {actions.map((action) => {
style={[styles.actionButton, styles.actionButtonPrimary]} const Icon = action.icon;
onPress={() => setIsDirectOpen(true)} return (
testID="welcome-direct-connection"
>
<Link2 size={18} color={theme.colors.palette.white} />
<Text style={[styles.actionText, styles.actionTextPrimary]}>Direct connection</Text>
</Pressable>
<Pressable
style={styles.actionButton}
onPress={() => setIsPasteLinkOpen(true)}
testID="welcome-paste-pairing-link"
>
<ClipboardPaste size={18} color={theme.colors.foreground} />
<Text style={styles.actionText}>Paste pairing link</Text>
</Pressable>
{Platform.OS !== "web" ? (
<Pressable <Pressable
style={styles.actionButton} key={action.key}
onPress={() => router.push("/pair-scan?source=onboarding")} style={[styles.actionButton, action.primary ? styles.actionButtonPrimary : null]}
testID="welcome-scan-qr" onPress={action.onPress}
testID={action.testID}
> >
<QrCode size={18} color={theme.colors.foreground} /> <Icon
<Text style={styles.actionText}>Scan QR code</Text> size={18}
color={action.primary ? theme.colors.accentForeground : theme.colors.foreground}
/>
<Text style={[styles.actionText, action.primary ? styles.actionTextPrimary : null]}>
{action.label}
</Text>
</Pressable> </Pressable>
) : null} );
})}
</View> </View>
</View> </View>
<Text style={styles.versionLabel}>{appVersionText}</Text> <Text style={styles.versionLabel}>{appVersionText}</Text>
@@ -554,7 +554,7 @@ function PairingOfferDialogContent(input: {
void QRCode.toDataURL(pairingOffer.url, { void QRCode.toDataURL(pairingOffer.url, {
errorCorrectionLevel: 'M', errorCorrectionLevel: 'M',
margin: 1, margin: 1,
width: 320, width: 480,
}) })
.then((dataUrl) => { .then((dataUrl) => {
if (cancelled) { if (cancelled) {
@@ -606,17 +606,19 @@ function PairingOfferDialogContent(input: {
</Text> </Text>
<View style={styles.qrCard}> <View style={styles.qrCard}>
{qrDataUrl ? ( {qrDataUrl ? (
<Image source={{ uri: qrDataUrl }} style={styles.qrImage} /> <Image source={{ uri: qrDataUrl }} style={styles.qrImage} resizeMode="contain" />
) : qrError ? ( ) : qrError ? (
<Text style={styles.hintText}>QR unavailable: {qrError}</Text> <Text style={styles.hintText}>QR unavailable: {qrError}</Text>
) : ( ) : (
<ActivityIndicator size="small" /> <ActivityIndicator size="small" />
)} )}
</View> </View>
<Text style={styles.linkLabel}>Pairing link</Text> <View style={styles.linkSection}>
<Text style={styles.linkText} selectable> <Text style={styles.linkLabel}>Pairing link</Text>
{pairingOffer.url} <Text style={styles.linkText} selectable>
</Text> {pairingOffer.url}
</Text>
</View>
<View style={styles.modalActions}> <View style={styles.modalActions}>
<Button variant="outline" size="sm" onPress={onCopyLink}> <Button variant="outline" size="sm" onPress={onCopyLink}>
Copy link Copy link
@@ -717,18 +719,21 @@ const styles = StyleSheet.create((theme) => ({
qrCard: { qrCard: {
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
alignSelf: 'center', width: '100%',
minHeight: 220, aspectRatio: 1,
minWidth: 220, alignSelf: 'stretch',
padding: theme.spacing[4], padding: theme.spacing[3],
borderRadius: theme.borderRadius.lg, borderRadius: theme.borderRadius.lg,
borderWidth: 1, borderWidth: 1,
borderColor: theme.colors.border, borderColor: theme.colors.border,
backgroundColor: theme.colors.surface0, backgroundColor: theme.colors.surface0,
}, },
qrImage: { qrImage: {
width: 220, width: '100%',
height: 220, height: '100%',
},
linkSection: {
gap: theme.spacing[2],
}, },
linkLabel: { linkLabel: {
color: theme.colors.foreground, color: theme.colors.foreground,
@@ -7,6 +7,7 @@ import { projectDisplayNameFromProjectId } from '@/utils/project-display-name'
const EMPTY_ORDER: string[] = [] const EMPTY_ORDER: string[] = []
const EMPTY_PROJECTS: SidebarProjectEntry[] = [] const EMPTY_PROJECTS: SidebarProjectEntry[] = []
const EMPTY_WORKSPACE_ORDER_SCOPE: Record<string, string[]> = {}
export type SidebarStateBucket = WorkspaceDescriptor['status'] export type SidebarStateBucket = WorkspaceDescriptor['status']
@@ -271,7 +272,7 @@ export function useSidebarWorkspacesList(options?: {
serverId ? (state.projectOrderByServerId[serverId] ?? EMPTY_ORDER) : EMPTY_ORDER serverId ? (state.projectOrderByServerId[serverId] ?? EMPTY_ORDER) : EMPTY_ORDER
) )
const persistedWorkspaceOrderByScope = useSidebarOrderStore((state) => const persistedWorkspaceOrderByScope = useSidebarOrderStore((state) =>
serverId ? state.workspaceOrderByServerAndProject : {} serverId ? state.workspaceOrderByServerAndProject : EMPTY_WORKSPACE_ORDER_SCOPE
) )
const isActive = Boolean(serverId) const isActive = Boolean(serverId)