MCPcopy
hub / github.com/AutoMaker-Org/automaker / handleAppReady

Function handleAppReady

apps/ui/src/main.ts:62–221  ·  view source on GitHub ↗

* Handle app.whenReady()

()

Source from the content-addressed store, hash-verified

60 * Handle app.whenReady()
61 */
62async function handleAppReady(): Promise<void> {
63 // In production, use Automaker dir in appData for app isolation
64 // In development, use project root for shared data between Electron and web mode
65 let userDataPathToUse: string;
66
67 if (app.isPackaged) {
68 // Production: Ensure userData path is consistent so files land in Automaker dir
69 try {
70 const desiredUserDataPath = path.join(app.getPath('appData'), 'Automaker');
71
72 if (app.getPath('userData') !== desiredUserDataPath) {
73 app.setPath('userData', desiredUserDataPath);
74 logger.info('[PRODUCTION] userData path set to:', desiredUserDataPath);
75 }
76
77 userDataPathToUse = desiredUserDataPath;
78 } catch (error) {
79 logger.warn('[PRODUCTION] Failed to set userData path:', (error as Error).message);
80 userDataPathToUse = app.getPath('userData');
81 }
82 } else {
83 // Development: Explicitly set userData to project root for shared data between Electron and web
84 // This OVERRIDES Electron's default userData path (~/.config/Automaker)
85 // __dirname is apps/ui/dist-electron, so go up to get project root
86 const projectRoot = path.join(__dirname, '../../..');
87 userDataPathToUse = path.join(projectRoot, 'data');
88
89 try {
90 app.setPath('userData', userDataPathToUse);
91 logger.info('[DEVELOPMENT] userData path explicitly set to:', userDataPathToUse);
92 } catch (error) {
93 logger.warn(
94 '[DEVELOPMENT] Failed to set userData path, using fallback:',
95 (error as Error).message
96 );
97 userDataPathToUse = path.join(projectRoot, 'data');
98 }
99 }
100
101 // Initialize centralized path helpers for Electron
102 // This must be done before any file operations
103 setElectronUserDataPath(userDataPathToUse);
104
105 // In development mode, allow access to the entire project root (for source files, node_modules, etc.)
106 // In production, only allow access to the built app directory and resources
107 if (isDev) {
108 // __dirname is apps/ui/dist-electron, so go up 3 levels to get project root
109 const projectRoot = path.join(__dirname, '../../..');
110 setElectronAppPaths([__dirname, projectRoot]);
111 } else {
112 setElectronAppPaths(__dirname, process.resourcesPath);
113 }
114
115 logger.info('Initialized path security helpers');
116
117 // Initialize security settings for path validation
118 // Set DATA_DIR before initializing so it's available for security checks
119 // Use the project's shared data directory in development, userData in production

Callers

nothing calls this directly

Calls 11

setElectronUserDataPathFunction · 0.90
setElectronAppPathsFunction · 0.90
initAllowedPathsFunction · 0.90
getIconPathFunction · 0.90
waitForServerFunction · 0.90
ensureApiKeyFunction · 0.90
findAvailablePortFunction · 0.90
startStaticServerFunction · 0.90
startServerFunction · 0.90
createWindowFunction · 0.90
getPathMethod · 0.80

Tested by

no test coverage detected