diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b496590..315a7d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +### Added + +- Default URL setting that takes precedence over CODER_URL. +- Autologin setting that automatically initiates login when the extension + activates using either the default URL or CODER_URL. + ## [v1.3.5](https://github.com/coder/vscode-coder/releases/tag/v1.3.5) (2024-10-16) ### Fixed diff --git a/package.json b/package.json index 51994d82..2a78c176 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,16 @@ "markdownDescription": "If not set, will inherit from the `no_proxy` or `NO_PROXY` environment variables. `http.proxySupport` must be set to `on` or `off`, otherwise VS Code will override the proxy agent set by the plugin.", "type": "string", "default": "" + }, + "coder.defaultUrl": { + "markdownDescription": "This will be shown in the URL prompt, along with CODER_URL if set, for the user to select when logging in. If autologin is enabled, this URL will be automatically logged into when the extension is activated.", + "type": "string", + "default": "" + }, + "coder.autologin": { + "markdownDescription": "Automatically log into the default URL or CODER_URL when the extension is activated. Has no effect if neither is set.", + "type": "boolean", + "default": false } } }, diff --git a/src/commands.ts b/src/commands.ts index cf5850ad..516c90b3 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -78,13 +78,14 @@ export class Commands { * CODER_URL or enter a new one. Undefined means the user aborted. */ private async askURL(selection?: string): Promise { + const defaultURL = vscode.workspace.getConfiguration().get("coder.defaultUrl") ?? "" const quickPick = vscode.window.createQuickPick() - quickPick.value = selection || process.env.CODER_URL || "" + quickPick.value = selection || defaultURL || process.env.CODER_URL || "" quickPick.placeholder = "https://example.coder.com" quickPick.title = "Enter the URL of your Coder deployment." // Initial items. - quickPick.items = this.storage.withUrlHistory(process.env.CODER_URL).map((url) => ({ + quickPick.items = this.storage.withUrlHistory(defaultURL, process.env.CODER_URL).map((url) => ({ alwaysShow: true, label: url, })) @@ -93,7 +94,7 @@ export class Commands { // an option in case the user wants to connect to something that is not in // the list. quickPick.onDidChangeValue((value) => { - quickPick.items = this.storage.withUrlHistory(process.env.CODER_URL, value).map((url) => ({ + quickPick.items = this.storage.withUrlHistory(defaultURL, process.env.CODER_URL, value).map((url) => ({ alwaysShow: true, label: url, })) @@ -111,8 +112,8 @@ export class Commands { /** * Ask the user for the URL if it was not provided, letting them choose from a - * list of recent URLs or CODER_URL or enter a new one, and normalizes the - * returned URL. Undefined means the user aborted. + * list of recent URLs or the default URL or CODER_URL or enter a new one, and + * normalizes the returned URL. Undefined means the user aborted. */ public async maybeAskUrl(providedUrl: string | undefined | null, lastUsedUrl?: string): Promise { let url = providedUrl || (await this.askURL(lastUsedUrl)) @@ -134,7 +135,8 @@ export class Commands { /** * Log into the provided deployment. If the deployment URL is not specified, - * ask for it first with a menu showing recent URLs and CODER_URL, if set. + * ask for it first with a menu showing recent URLs along with the default URL + * and CODER_URL, if those are set. */ public async login(...args: string[]): Promise { // Destructure would be nice but VS Code can pass undefined which errors. diff --git a/src/extension.ts b/src/extension.ts index 2235683c..92f7296b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -215,5 +215,14 @@ export async function activate(ctx: vscode.ExtensionContext): Promise { } else { storage.writeToCoderOutputChannel("Not currently logged in") vscode.commands.executeCommand("setContext", "coder.loaded", true) + + // Handle autologin, if not already logged in. + const cfg = vscode.workspace.getConfiguration() + if (cfg.get("coder.autologin") === true) { + const defaultUrl = cfg.get("coder.defaultUrl") || process.env.CODER_URL + if (defaultUrl) { + vscode.commands.executeCommand("coder.login", defaultUrl) + } + } } }