diff --git a/app/renderer/js/pages/preference/new-server-form.ts b/app/renderer/js/pages/preference/new-server-form.ts index 2d7fe4db7..1b7fec31c 100644 --- a/app/renderer/js/pages/preference/new-server-form.ts +++ b/app/renderer/js/pages/preference/new-server-form.ts @@ -60,7 +60,9 @@ export function initNewServerForm({$root, onChange}: NewServerFormProps): void { $saveServerButton.textContent = "Connecting..."; let serverConf; try { - serverConf = await DomainUtil.checkDomain($newServerUrl.value.trim()); + serverConf = await DomainUtil.checkDomain( + await autoComplete($newServerUrl.value.trim()), + ); } catch (error: unknown) { $saveServerButton.textContent = "Connect"; await dialog.showMessageBox({ @@ -78,6 +80,17 @@ export function initNewServerForm({$root, onChange}: NewServerFormProps): void { onChange(); } + async function autoComplete(url: string): Promise { + const pattern = /^[a-zA-Z\d-]*$/; + let serverUrl = url.trim(); + + if (pattern.test(serverUrl)) { + serverUrl = "https://" + serverUrl + ".zulipchat.com"; + } + + return serverUrl; + } + $saveServerButton.addEventListener("click", async () => { await submitFormHandler(); });