Skip to content

Commit 91a64bc

Browse files
committed
fix: update changelog for version 1.10.2 and improve update notification logic
1 parent b43108b commit 91a64bc

File tree

3 files changed

+56
-21
lines changed

3 files changed

+56
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to the "magento-log-viewer" extension will be documented in
44

55
## [1.10.2] - 2025-05-28
66
- update: `readme.md` update
7+
- fix: update notification for better performance
78
- fix: update configuration keys for Magento project selection to correctly save "Is this a Magento project" response
89

910
## Latest Release

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento-log-viewer",
33
"displayName": "Magento Log Viewer",
44
"description": "A Visual Studio Code extension to view and manage Magento log files.",
5-
"version": "1.10.1",
5+
"version": "1.10.2",
66
"publisher": "MathiasElle",
77
"icon": "resources/logo.png",
88
"repository": {

src/updateNotifier.ts

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,66 @@
11
import * as vscode from 'vscode';
22

3-
export async function showUpdateNotification(context: vscode.ExtensionContext) {
4-
const extension = vscode.extensions.getExtension('MathiasElle.magento-log-viewer');
5-
if (!extension) {
6-
return;
7-
}
3+
const EXTENSION_ID = 'MathiasElle.magento-log-viewer';
4+
const STORAGE_KEY = 'lastVersion';
5+
const URLS = {
6+
GITHUB: 'https://github.com/OpenForgeProject/vscode-ext-magento-log-viewer',
7+
SPONSOR: 'https://github.com/sponsors/dermatz'
8+
};
9+
const ACTIONS = {
10+
SUPPORT: '❤️ Support this Project',
11+
CHANGELOG: 'Changelog',
12+
GITHUB: 'GitHub'
13+
};
14+
15+
/**
16+
* Shows a notification when the extension is updated.
17+
* @param context Extension context
18+
*/
19+
export async function showUpdateNotification(context: vscode.ExtensionContext): Promise<void> {
20+
try {
21+
const lastVersion = context.globalState.get<string>(STORAGE_KEY);
22+
23+
const extension = vscode.extensions.getExtension(EXTENSION_ID);
24+
if (!extension) {
25+
console.warn(`Extension ${EXTENSION_ID} could not be found.`);
26+
return;
27+
}
28+
29+
const currentVersion = extension.packageJSON.version;
830

9-
const currentVersion = extension.packageJSON.version;
10-
const lastVersion = context.globalState.get<string>('lastVersion');
31+
// check if the extension has been updated
32+
if (lastVersion === currentVersion) {
33+
return;
34+
}
1135

12-
if (lastVersion !== currentVersion) {
1336
const action = await vscode.window.showInformationMessage(
1437
`Magento Log Viewer was updated to Version ${currentVersion} ✨!`,
15-
'❤️ Support this Project',
16-
'Changelog',
17-
'GitHub'
38+
ACTIONS.SUPPORT,
39+
ACTIONS.CHANGELOG,
40+
ACTIONS.GITHUB
1841
);
1942

20-
if (action === 'GitHub') {
21-
vscode.env.openExternal(vscode.Uri.parse('https://github.com/OpenForgeProject/vscode-ext-magento-log-viewer'));
22-
} else if (action === 'Changelog') {
23-
const changelogPath = vscode.Uri.joinPath(extension.extensionUri, 'CHANGELOG.md');
24-
const doc = await vscode.workspace.openTextDocument(changelogPath);
25-
await vscode.window.showTextDocument(doc);
26-
} else if (action === '❤️ Support this Project') {
27-
vscode.env.openExternal(vscode.Uri.parse('https://github.com/sponsors/dermatz'));
43+
switch (action) {
44+
case ACTIONS.GITHUB:
45+
await vscode.env.openExternal(vscode.Uri.parse(URLS.GITHUB));
46+
break;
47+
case ACTIONS.CHANGELOG:
48+
try {
49+
const changelogPath = vscode.Uri.joinPath(extension.extensionUri, 'CHANGELOG.md');
50+
const doc = await vscode.workspace.openTextDocument(changelogPath);
51+
await vscode.window.showTextDocument(doc);
52+
} catch (error) {
53+
console.error('Error opening changelog:', error);
54+
}
55+
break;
56+
case ACTIONS.SUPPORT:
57+
await vscode.env.openExternal(vscode.Uri.parse(URLS.SPONSOR));
58+
break;
2859
}
2960

30-
await context.globalState.update('lastVersion', currentVersion);
61+
// Update the last version in global state
62+
await context.globalState.update(STORAGE_KEY, currentVersion);
63+
} catch (error) {
64+
console.error('Fehler in showUpdateNotification:', error);
3165
}
3266
}

0 commit comments

Comments
 (0)