From b2dbd357b8c58d1cccd4eaa28b341562bf3f6745 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 2 Mar 2026 10:31:20 +0100 Subject: [PATCH] fix(developer): address review comments Co-authored-by: Darcy Wong Co-authored-by: Eberhard Beilharz --- developer/src/server/src/config.ts | 4 -- developer/src/server/src/index.ts | 52 +++++++++++-------- .../Keyman.Developer.UI.UfrmServerOptions.pas | 5 +- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/developer/src/server/src/config.ts b/developer/src/server/src/config.ts index 8d6c967855..e60ec6d0a0 100644 --- a/developer/src/server/src/config.ts +++ b/developer/src/server/src/config.ts @@ -8,7 +8,6 @@ export class Configuration { public readonly lockFilename: string; public readonly pidFilename: string; public readonly configFilename: string; - public readonly ngrokBinPath: string; /* Configuration values - set in config.json by TIKE */ @@ -17,7 +16,6 @@ export class Configuration { /* ngrok Configuration */ public readonly useNgrok: boolean; - public readonly ngrokControlPort: number; public readonly ngrokToken: string; public readonly ngrokVisible: boolean; @@ -42,8 +40,6 @@ export class Configuration { // ngrok configuration this.useNgrok = cfg?.useNgrok ?? false; - this.ngrokBinPath = this.appDataPath + 'bin/'; - this.ngrokControlPort = cfg?.ngrokControlPort ?? 8009; this.ngrokToken = cfg?.ngrokToken ?? ''; this.ngrokVisible = cfg?.ngrokVisible ?? false; } diff --git a/developer/src/server/src/index.ts b/developer/src/server/src/index.ts index a91b36d545..36fd8431d8 100644 --- a/developer/src/server/src/index.ts +++ b/developer/src/server/src/index.ts @@ -125,30 +125,36 @@ async function startNGrok() { return false; } - let started = false; - const listener = await ngrok.forward({ - proto: 'http', - addr: configuration.port, - authtoken: configuration.ngrokToken, - onLogEvent: (msg: string) => { - if(options.ngrokLog) { - console.log(chalk.cyan(('\n'+msg).split('\n').join('\n[ngrok] ').trim())); + try { + let started = false; + const listener = await ngrok.forward({ + proto: 'http', + addr: configuration.port, + authtoken: configuration.ngrokToken, + onLogEvent: (msg: string) => { + if(options.ngrokLog) { + console.log(chalk.cyan(('\n'+msg).split('\n').join('\n[ngrok] ').trim())); + } + }, + onStatusChange: (state: string) => { + if(state == 'connected' && started) { + // We only announce reconnection after initial start + configuration.ngrokEndpoint = listener.url() ?? ''; + console.log(chalk.blueBright('ngrok tunnel reconnected at %s'), configuration.ngrokEndpoint); + } else if(state == 'closed') { + configuration.ngrokEndpoint = ''; + console.log(chalk.blueBright('ngrok tunnel closed')); + } } - }, - onStatusChange: (state: string) => { - if(state == 'connected' && started) { - // We only announce reconnection after initial start - configuration.ngrokEndpoint = listener.url(); - console.log(chalk.blueBright('ngrok tunnel reconnected at %s'), configuration.ngrokEndpoint); - } else if(state == 'closed') { - configuration.ngrokEndpoint = ''; - console.log(chalk.blueBright('ngrok tunnel closed')); - } - } - }); - started = true; - configuration.ngrokEndpoint = listener.url(); - console.log(chalk.blueBright('ngrok tunnel established at %s'), configuration.ngrokEndpoint); + }); + started = true; + configuration.ngrokEndpoint = listener.url(); + console.log(chalk.blueBright('ngrok tunnel established at %s'), configuration.ngrokEndpoint); + } catch(e) { + configuration.ngrokEndpoint = ''; + console.error(chalk.red('ngrok tunnel failed to connect with an error: %s'), e); + return false; + } return true; } diff --git a/developer/src/tike/dialogs/Keyman.Developer.UI.UfrmServerOptions.pas b/developer/src/tike/dialogs/Keyman.Developer.UI.UfrmServerOptions.pas index f2dbf9ad41..4a2225e564 100644 --- a/developer/src/tike/dialogs/Keyman.Developer.UI.UfrmServerOptions.pas +++ b/developer/src/tike/dialogs/Keyman.Developer.UI.UfrmServerOptions.pas @@ -82,7 +82,8 @@ const SUrlNgrokSignup = 'https://dashboard.ngrok.com/signup'; // Note, we manually update the version of ngrok as required in subsequent - // releases, rather than trying to handle a potentially moving target + // releases, rather than trying to handle a potentially moving target. This + // should match developer/src/server/package.json version for ngrok. SNgrokVersion = 'v1.7.0'; SUrlNgrokDownload = 'https://github.com/ngrok/ngrok-javascript/releases/download/'+SNgrokVersion+'/ngrok.win32-ia32-msvc.node'; SNgrokNodeModuleFilename = 'ngrok-win32-ia32-msvc.node'; @@ -317,7 +318,7 @@ end; function TfrmServerOptions.RedistInstallerPath: string; begin - Result := TServerDebugAPI.ServerBinPath + SVCRedistExeFilename; + Result := TServerDebugAPI.ServerBinPath + '\' + SVCRedistExeFilename; end; procedure TfrmServerOptions.UpdateVersionLabel;