Skip to content

Commit

Permalink
Notify users if there's a pre-release version available. (#11569)
Browse files Browse the repository at this point in the history
* Notify users if there's a pre-release version available
  • Loading branch information
spebl authored Oct 24, 2023
1 parent fecfc08 commit 8fbc56a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as path from 'path';
import * as vscode from 'vscode';
import { Range } from 'vscode-languageclient';
import * as nls from 'vscode-nls';
import { TargetPopulation } from 'vscode-tas-client';
import { logAndReturn } from '../Utility/Async/returns';
import * as util from '../common';
import { PlatformInformation } from '../platform';
Expand Down Expand Up @@ -1162,3 +1163,36 @@ export function UpdateInsidersAccess(): void {
void vscode.commands.executeCommand("workbench.extensions.installExtension", "ms-vscode.cpptools", { installPreReleaseVersion: true }).then(undefined, logAndReturn.undefined);
}
}

export async function preReleaseCheck(): Promise<void> {
const displayedPreReleasePrompt: PersistentState<boolean> = new PersistentState<boolean>("CPP.displayedPreReleasePrompt", false);

// First we need to make sure the user isn't already on a pre-release version and hasn't dismissed this prompt before.
if (!displayedPreReleasePrompt.Value && util.getCppToolsTargetPopulation() === TargetPopulation.Public) {
// Get the info on the latest version from the marketplace to check if there is a pre-release version available.
const response = await fetch('https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery', {
method: 'POST',
headers: {
Accept : 'application/json; api-version=3.0-preview',
'Content-Type' : 'application/json'
},
body: '{"filters": [{"criteria": [{"filterType": 7, "value": "ms-vscode.cpptools"}]}], "flags": 529}'
});

const data = await response.json();
const preReleaseAvailable = data.results[0].extensions[0].versions[0].properties.some((e: object) => Object.values(e).includes("Microsoft.VisualStudio.Code.PreRelease"));

// If the user isn't on the pre-release version, but one is available, prompt them to install it.
if (preReleaseAvailable) {
displayedPreReleasePrompt.Value = true;
const message: string = localize("prerelease.message", "A pre-release version of the C/C++ extension is available. Would you like to switch to it?");
const yes: string = localize("yes.button", "Yes");
const no: string = localize("no.button", "No");
void vscode.window.showInformationMessage(message, yes, no).then((selection) => {
if (selection === yes) {
void vscode.commands.executeCommand("workbench.extensions.installExtension", "ms-vscode.cpptools", { installPreReleaseVersion: true }).then(undefined, logAndReturn.undefined);
}
});
}
}
}
1 change: 1 addition & 0 deletions Extension/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CppToo
util.checkDistro(info);
await checkVsixCompatibility();
LanguageServer.UpdateInsidersAccess();
await LanguageServer.preReleaseCheck();

const settings: CppSettings = new CppSettings((vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) ? vscode.workspace.workspaceFolders[0]?.uri : undefined);
let isOldMacOs: boolean = false;
Expand Down

0 comments on commit 8fbc56a

Please sign in to comment.