Skip to content

Commit

Permalink
Add default URL and autologin settings
Browse files Browse the repository at this point in the history
  • Loading branch information
code-asher committed Oct 29, 2024
1 parent 733fbbf commit 14a6aeb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
},
Expand Down
14 changes: 8 additions & 6 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | undefined> {
const defaultURL = vscode.workspace.getConfiguration().get<string>("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,
}))
Expand All @@ -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,
}))
Expand All @@ -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<string | undefined> {
let url = providedUrl || (await this.askURL(lastUsedUrl))
Expand All @@ -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<void> {
// Destructure would be nice but VS Code can pass undefined which errors.
Expand Down
9 changes: 9 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,14 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
} 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)
}
}
}
}

0 comments on commit 14a6aeb

Please sign in to comment.