Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteregrets committed Oct 29, 2023
1 parent f2c460d commit fceeb2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/binaryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ async function getConfiguredMirrordBinary(): Promise<string | null> {
* Criteria for auto-update:
* - Auto-update is enabled by default
* - if mirrord binary path is mentioned in workspace settings, then that is used
* - if a version is specified, that version is downloaded
* - if auto-update is enabled, then latest supported version is downloaded
* - if auto-update is disabled, and a version is specified, then that version is downloaded
* - if auto-update is disabled, and no version is specified, then local mirrord binary is used
* - if auto-update is disabled, and no version is specified, and no local mirrord binary is found, then latest supported version is downloaded
* - if auto-update is disabled, any local mirrord binary is used
* @returns Path to mirrord binary
*/
export async function getMirrordBinary(): Promise<string> {
Expand All @@ -117,7 +116,9 @@ export async function getMirrordBinary(): Promise<string> {
}
const latestVersion = await getLatestSupportedVersion(10000);

const autoUpdateConfigured = vscode.workspace.getConfiguration().get("mirrord.autoUpdate", true);
const autoUpdateConfigured = vscode.workspace.getConfiguration().get("mirrord.autoUpdate");

const extensionPath = getExtensionMirrordPath().fsPath;


if (typeof autoUpdateConfigured === 'string') {
Expand All @@ -127,19 +128,29 @@ export async function getMirrordBinary(): Promise<string> {
return localMirrordBinary;
}
await downloadMirrordBinary(getExtensionMirrordPath(), autoUpdateConfigured);
return getExtensionMirrordPath().fsPath;
return extensionPath;
} else {
vscode.window.showErrorMessage(`Invalid version format ${autoUpdateConfigured}: must follow semver format`);
}
}

if (typeof autoUpdateConfigured === 'boolean') {
if (!autoUpdateConfigured) {
const localMirrordBinary = await getLocalMirrordBinary();
if (localMirrordBinary) {
return localMirrordBinary;
}
return extensionPath;
}
}

// Auto-update is enabled or no specific version specified.
const localMirrordBinary = await getLocalMirrordBinary();
const localMirrordBinary = await getLocalMirrordBinary(latestVersion);
if (localMirrordBinary) {
return localMirrordBinary;
}
await downloadMirrordBinary(getExtensionMirrordPath(), latestVersion);
return getExtensionMirrordPath().fsPath;
return extensionPath;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode';
import { ConfigurationProvider } from './debugger';
import { MirrordStatus } from './status';
import { getMirrordBinary } from './binaryManager';

export let globalContext: vscode.ExtensionContext;

Expand All @@ -12,6 +13,10 @@ export async function activate(context: vscode.ExtensionContext) {
context.workspaceState.update('enabled', false);
vscode.debug.registerDebugConfigurationProvider('*', new ConfigurationProvider(), 2);


// start mirrord binary updates
await getMirrordBinary();

new MirrordStatus(vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0))
.register()
.draw();
Expand Down

0 comments on commit fceeb2a

Please sign in to comment.