:electron: Fix early server-started signification message (#5303)

* fix issue where server was telling parent process it was ready but was not finished listening

* release notes
This commit is contained in:
Michael Clark
2025-07-08 08:39:42 +00:00
committed by GitHub
parent 405c8b986f
commit 3a09d91399
3 changed files with 31 additions and 16 deletions

View File

@@ -56,6 +56,10 @@ export function ElectronServerConfig({
const [startingSyncServer, setStartingSyncServer] = useState(false);
const onConfigureSyncServer = async () => {
if (startingSyncServer) {
return; // Prevent multiple clicks
}
if (
isNaN(electronServerPort) ||
electronServerPort <= 0 ||
@@ -221,23 +225,23 @@ export function ElectronServerConfig({
>
<Label title={t('')} style={{ textAlign: 'left', width: '7ch' }} />
{!electronSyncServerRunning ? (
<Button
<ButtonWithLoading
variant="primary"
style={{ padding: 10, width: '8ch' }}
onPress={onConfigureSyncServer}
isPending={startingSyncServer}
isLoading={startingSyncServer}
>
<Trans>Start</Trans>
</Button>
</ButtonWithLoading>
) : (
<Button
<ButtonWithLoading
variant="primary"
style={{ padding: 10, width: '8ch' }}
onPress={onConfigureSyncServer}
isPending={startingSyncServer}
isLoading={startingSyncServer}
>
<Trans>Save</Trans>
</Button>
</ButtonWithLoading>
)}
</View>
</View>

View File

@@ -156,6 +156,15 @@ function parseHTTPSConfig(value: string) {
return fs.readFileSync(value);
}
function sendServerStartedMessage() {
// Signify to any parent process that the server has started. Used in electron desktop app
// @ts-ignore-error electron types
process.parentPort?.postMessage({ type: 'server-started' });
console.log(
'Listening on ' + config.get('hostname') + ':' + config.get('port') + '...',
);
}
export async function run() {
const portVal = config.get('port');
const port = typeof portVal === 'string' ? parseInt(portVal) : portVal;
@@ -186,16 +195,12 @@ export async function run() {
key: parseHTTPSConfig(config.get('https.key')),
cert: parseHTTPSConfig(config.get('https.cert')),
};
https.createServer(httpsOptions, app).listen(port, hostname);
https.createServer(httpsOptions, app).listen(port, hostname, () => {
sendServerStartedMessage();
});
} else {
app.listen(port, hostname);
app.listen(port, hostname, () => {
sendServerStartedMessage();
});
}
// Signify to any parent process that the server has started. Used in electron desktop app
// @ts-ignore-error electron types
process.parentPort?.postMessage({ type: 'server-started' });
console.log(
'Listening on ' + config.get('hostname') + ':' + config.get('port') + '...',
);
}

View File

@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MikesGlitch]
---
Fix server-started message invoking too early, causing desktop app server configuration flakiness.