From a47849000238ceb4e656de0ebf3aec718d39b25f Mon Sep 17 00:00:00 2001 From: Gero Posmyk-Leinemann Date: Wed, 29 Jan 2025 13:10:10 +0000 Subject: [PATCH 1/2] [signing] Sigin: Offer manual fallback in case the extension can't open a browser Tool: gitpod/catfood.gitpod.cloud --- src/authentication/gitpodServer.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/authentication/gitpodServer.ts b/src/authentication/gitpodServer.ts index f43357c4..6da26684 100644 --- a/src/authentication/gitpodServer.ts +++ b/src/authentication/gitpodServer.ts @@ -29,6 +29,9 @@ async function getUserInfo(token: string, serviceUrl: string, logger: ILogServic }; } +const ACTION_COPY = "Copy to clipboard"; +const ACTION_CANCEL = "Cancel"; + export default class GitpodServer extends Disposable { public static AUTH_COMPLETE_PATH = '/complete-gitpod-auth'; @@ -76,8 +79,16 @@ export default class GitpodServer extends Disposable { location: vscode.ProgressLocation.Window, title: `Signing in to ${this._serviceUrl}...`, }, async () => { - await vscode.env.openExternal(uri as any); - // this._logger.trace(">> URL ", uri); + const success = await vscode.env.openExternal(uri as any); + if (!success) { + // Handle the case where the extension can't open a browser window + const action = await vscode.window.showWarningMessage("There was a problem opening the login URL in your browser. Please copy it into your browser manually.", ACTION_COPY, ACTION_CANCEL); + if (action === ACTION_COPY) { + await vscode.env.clipboard.writeText(uri); + } else if (action === ACTION_CANCEL) { + throw new Error("Signin cancelled by user"); + } + } // Register a single listener for the URI callback, in case the user starts the login process multiple times // before completing it. From 2eac2c67ea7a0e660d7a03fdaa71e3793185ea39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Wed, 29 Jan 2025 14:39:33 +0100 Subject: [PATCH 2/2] Fix TSLint issues --- src/authentication/gitpodServer.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/authentication/gitpodServer.ts b/src/authentication/gitpodServer.ts index 6da26684..fea74859 100644 --- a/src/authentication/gitpodServer.ts +++ b/src/authentication/gitpodServer.ts @@ -29,8 +29,8 @@ async function getUserInfo(token: string, serviceUrl: string, logger: ILogServic }; } -const ACTION_COPY = "Copy to clipboard"; -const ACTION_CANCEL = "Cancel"; +const ACTION_COPY = 'Copy to clipboard'; +const ACTION_CANCEL = 'Cancel'; export default class GitpodServer extends Disposable { @@ -82,11 +82,11 @@ export default class GitpodServer extends Disposable { const success = await vscode.env.openExternal(uri as any); if (!success) { // Handle the case where the extension can't open a browser window - const action = await vscode.window.showWarningMessage("There was a problem opening the login URL in your browser. Please copy it into your browser manually.", ACTION_COPY, ACTION_CANCEL); + const action = await vscode.window.showWarningMessage('There was a problem opening the login URL in your browser. Please copy it into your browser manually.', ACTION_COPY, ACTION_CANCEL); if (action === ACTION_COPY) { await vscode.env.clipboard.writeText(uri); } else if (action === ACTION_CANCEL) { - throw new Error("Signin cancelled by user"); + throw new Error('Signin cancelled by user'); } }