MCPcopy
hub / github.com/stravu/crystal / checkInitialState

Function checkInitialState

frontend/src/App.tsx:164–254  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

162 }
163
164 const checkInitialState = async () => {
165 if (!window.electron?.invoke) {
166 return;
167 }
168
169 // Get preferences from database
170 const hideWelcomeResult = await window.electron.invoke('preferences:get', 'hide_welcome') as IPCResponse<string>;
171 const welcomeShownResult = await window.electron.invoke('preferences:get', 'welcome_shown') as IPCResponse<string>;
172 const hideDiscordResult = await window.electron.invoke('preferences:get', 'hide_discord') as IPCResponse<string>;
173
174 const hideWelcome = hideWelcomeResult?.data === 'true';
175 const hasSeenWelcome = welcomeShownResult?.data === 'true';
176 const hideDiscord = hideDiscordResult?.data === 'true';
177
178
179 // Track whether we're showing the welcome screen
180 let welcomeScreenShown = false;
181
182 // If user explicitly said "don't show again", respect that preference
183 if (hideWelcome) {
184 welcomeScreenShown = false;
185 } else {
186 try {
187 const projectsResponse = await API.projects.getAll();
188 const hasProjects = projectsResponse.success && projectsResponse.data && projectsResponse.data.length > 0;
189 // Get sessions from the API to avoid stale closure
190 const sessionsResponse = await API.sessions.getAll();
191 const hasSessions = sessionsResponse.success && sessionsResponse.data && sessionsResponse.data.length > 0;
192
193 // Show welcome if:
194 // 1. First time user (no projects and never seen welcome)
195 // 2. Returning user with no active data (no projects and no sessions)
196 const isFirstTimeUser = !hasProjects && !hasSeenWelcome;
197 const isReturningUserWithNoData = !hasProjects && !hasSessions && hasSeenWelcome;
198
199
200 if (isFirstTimeUser || isReturningUserWithNoData) {
201 setIsWelcomeOpen(true);
202 welcomeScreenShown = true;
203 // Mark that welcome has been shown at least once
204 await window.electron.invoke('preferences:set', 'welcome_shown', 'true');
205 } else {
206 welcomeScreenShown = false;
207 }
208 } catch (error) {
209 console.error('Error checking initial state:', error);
210 welcomeScreenShown = false;
211 }
212 }
213
214 // If welcome screen is not shown and Discord hasn't been hidden, check if we should show Discord popup
215 if (!welcomeScreenShown && !hideDiscord) {
216
217 try {
218 // Get the last app open to see if Discord was already shown
219 const result = await window.electron.invoke('app:get-last-open') as IPCResponse<{ discord_shown?: boolean }>;
220
221 if (result?.success && result.data) {

Callers 1

AppFunction · 0.85

Calls 2

getAllMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected