Skip to content

Commit b069817

Browse files
author
Calvinn Ng
committed
add pop up about new extension version available
1 parent 5be9c21 commit b069817

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

extensions/vscode/src/activation/activate.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,50 @@ import { getExtensionVersion } from "../util/util";
99
import { getExtensionUri } from "../util/vscode";
1010
import { VsCodeContinueApi } from "./api";
1111
import { setupInlineTips } from "./inlineTips";
12+
import axios from 'axios';
13+
14+
const EXTENSION_ID = 'ahrefs.ahrefs-continue';
15+
const CURRENT_VERSION = vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON.version;
16+
17+
async function checkForExtensionUpdate() {
18+
try {
19+
const response = await axios.get(`https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery`, {
20+
headers: {
21+
'Content-Type': 'application/json',
22+
'Accept': 'application/json;api-version=3.0-preview.1'
23+
},
24+
data: {
25+
filters: [{
26+
criteria: [{ filterType: 7, value: EXTENSION_ID }]
27+
}],
28+
flags: 131
29+
}
30+
});
31+
32+
const latestVersion = response.data.results[0].extensions[0].versions[0].version;
33+
34+
if (latestVersion !== CURRENT_VERSION) {
35+
notifyUpdateAvailable(latestVersion);
36+
}
37+
} catch (error) {
38+
console.error('Failed to check for updates:', error);
39+
}
40+
}
41+
42+
function notifyUpdateAvailable(latestVersion: string) {
43+
const message = `A new version (${latestVersion}) of Ahrefs-Continue is available!`;
44+
const updateAction = 'Update Now';
45+
46+
vscode.window.showInformationMessage(message, updateAction).then(selection => {
47+
if (selection === updateAction) {
48+
vscode.commands.executeCommand('extension.open', EXTENSION_ID);
49+
}
50+
});
51+
}
1252

1353
export async function activateExtension(context: vscode.ExtensionContext) {
1454
// Add necessary files
55+
checkForExtensionUpdate();
1556
getTsConfigPath();
1657
getContinueRcPath();
1758

0 commit comments

Comments
 (0)