-
-
Notifications
You must be signed in to change notification settings - Fork 73
Fix gestures #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix gestures #321
Changes from 3 commits
161bd29
50df3da
3823d2d
9e4e778
b7d2dbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ let serverProcess; | |
| let serverHost = '0.0.0.0'; | ||
| let serverPort = 3000; | ||
|
|
||
| // Load config if exists | ||
| try { | ||
| const configPath = './src/server-config.json'; | ||
| if (fs.existsSync(configPath)) { | ||
|
|
@@ -27,21 +28,44 @@ if (!gotLock) { | |
| process.exit(0); | ||
| } | ||
|
|
||
| // Wait until server is ready | ||
| function waitForServer(url) { | ||
| return new Promise((resolve) => { | ||
| // Wait until server is ready (with retry limit) | ||
| function waitForServer(url, maxRetries = 20, delay = 500) { | ||
| return new Promise((resolve, reject) => { | ||
| let retries = 0; | ||
|
|
||
| const check = () => { | ||
| http | ||
| .get(url, () => resolve()) | ||
| .on('error', () => setTimeout(check, 500)); | ||
| .get(url, (res) => { | ||
| if (res.statusCode === 200) { | ||
| console.log('✅ Server is ready'); | ||
| resolve(); | ||
| } else { | ||
| retry(); | ||
| } | ||
| }) | ||
| .on('error', retry); | ||
| }; | ||
|
Comment on lines
47
to
65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against double settlement when request completes near timeout boundary. If the response arrives just before the timeout fires, Suggested fix const check = () => {
+ let done = false;
const req = http
.get(url, (res) => {
res.resume();
if (res.statusCode === 200) {
console.log('Server is ready');
+ done = true;
resolve();
} else {
retry();
}
})
- .on('error', retry);
+ .on('error', () => {
+ if (!done) retry();
+ });
// Add timeout to prevent hanging
req.setTimeout(delay, () => {
- req.destroy(new Error('Request timeout'));
+ if (!done) req.destroy(new Error('Request timeout'));
});
};🤖 Prompt for AI Agents |
||
|
|
||
| const retry = () => { | ||
| retries++; | ||
| console.log(`Waiting for server... (${retries}/${maxRetries})`); | ||
|
|
||
| if (retries >= maxRetries) { | ||
| return reject( | ||
| new Error(`Server failed to start after ${maxRetries} attempts`) | ||
| ); | ||
| } | ||
|
|
||
| setTimeout(check, delay); | ||
| }; | ||
|
|
||
| check(); | ||
| }); | ||
| } | ||
|
|
||
| // Start Nitro server (production) | ||
| // Start Nitro server | ||
| function startServer() { | ||
| return new Promise((resolve) => { | ||
| return new Promise((resolve, reject) => { | ||
| const serverPath = path.join( | ||
| process.resourcesPath, | ||
| 'app.asar.unpacked', | ||
|
|
@@ -50,19 +74,33 @@ function startServer() { | |
| 'index.mjs' | ||
| ); | ||
|
|
||
| console.log("Starting server from:", serverPath); | ||
| console.log('Starting server from:', serverPath); | ||
|
|
||
| serverProcess = spawn('node', [serverPath], { | ||
| stdio: 'ignore', // no terminal | ||
| windowsHide: true, // hide CMD | ||
| stdio: 'ignore', | ||
| windowsHide: true, | ||
| env: { | ||
| ...process.env, | ||
| HOST: serverHost, | ||
| PORT: serverPort.toString(), | ||
| }, | ||
|
Comment on lines
97
to
104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a derived connect URL instead of hardcoded This startup path binds Nitro to Suggested fix+function getServerUrl() {
+ const connectHost =
+ serverHost === '0.0.0.0'
+ ? '127.0.0.1'
+ : serverHost === '::'
+ ? '[::1]'
+ : serverHost;
+
+ return `http://${connectHost}:${serverPort}`;
+}
+
...
- waitForServer(`http://localhost:${serverPort}`)
+ waitForServer(getServerUrl())Update Also applies to: 130-137 🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| waitForServer(`http://localhost:${serverPort}`).then(resolve); | ||
| // Detect early crash | ||
| let resolved = false; | ||
|
|
||
| serverProcess.once('exit', (code) => { | ||
| if (!resolved) { | ||
| reject(new Error(`Nitro server exited early with code ${code}`)); | ||
| } | ||
| }); | ||
|
|
||
| waitForServer(`http://localhost:${serverPort}`) | ||
| .then(() => { | ||
| resolved = true; | ||
| resolve(); | ||
| }) | ||
| .catch(reject); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
|
|
||
|
|
@@ -78,25 +116,45 @@ function createWindow() { | |
|
|
||
| mainWindow.loadURL(`http://localhost:${serverPort}`); | ||
|
|
||
| // Show when ready | ||
| mainWindow.once('ready-to-show', () => { | ||
| mainWindow.show(); | ||
| }); | ||
|
|
||
| // Debug only if needed | ||
| mainWindow.webContents.on('did-fail-load', (e, code, desc) => { | ||
| console.log("LOAD FAILED:", code, desc); | ||
| console.log('LOAD FAILED:', code, desc); | ||
| }); | ||
| } | ||
|
|
||
| // Graceful shutdown | ||
| function shutdown() { | ||
| console.log('Shutting down...'); | ||
|
|
||
| if (serverProcess) { | ||
| serverProcess.kill('SIGTERM'); | ||
| } | ||
|
|
||
| app.quit(); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| process.on('SIGINT', shutdown); | ||
| process.on('SIGTERM', shutdown); | ||
|
|
||
| // App start | ||
| app.whenReady().then(async () => { | ||
| await startServer(); | ||
| createWindow(); | ||
| try { | ||
| await startServer(); | ||
| createWindow(); | ||
| } catch (err) { | ||
| console.error('❌ Failed to start server:', err.message); | ||
| app.quit(); | ||
| } | ||
| }); | ||
|
|
||
| // Cleanup | ||
| // Cleanup on window close | ||
| app.on('window-all-closed', () => { | ||
| if (serverProcess) serverProcess.kill(); | ||
| if (serverProcess) { | ||
| serverProcess.kill('SIGTERM'); | ||
| } | ||
|
|
||
| if (process.platform !== 'darwin') app.quit(); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.