Skip to content

Commit 5c5f3e5

Browse files
committed
Added new version welcome
1 parent f91c7a0 commit 5c5f3e5

3 files changed

Lines changed: 28 additions & 13 deletions

File tree

src/control.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import { StatsView } from './views/statsView';
1515
import { constants, Contexts, GlobalState, PIcon, VSBuiltInCommands } from './util/constants';
1616
import { Commands } from './util/commands';
1717
import { LocalStorageService } from './util/localStorageService';
18-
import { Version } from './util/version';
18+
import { IVersion, Version } from './util/version';
19+
import { Messages } from './util/messages';
1920

2021
export class Control {
2122
private static _config: Config | undefined;
@@ -100,6 +101,9 @@ export class Control {
100101
undefined,
101102
Commands.GCSUPPORT,
102103
);
104+
105+
// Check Version
106+
void this.checkVersion();
103107
}
104108

105109
static terminate() {
@@ -114,22 +118,34 @@ export class Control {
114118
return secs * 1000 + nanosecs / 1000000;
115119
}
116120

117-
static checkVersion() {
118-
const localVer = new Version(constants.extension.version);
121+
private static async checkVersion() {
122+
const gcodeVersion = new Version(constants.extension.version);
119123

120-
const prevVer = this._storageManager.getValue<Version>(GlobalState.PreviousVersion, 'global') ?? localVer;
124+
const prevVer = new Version(
125+
this._storageManager.getValue<IVersion>(GlobalState.PreviousVersion, 'global') ?? '0.0.0',
126+
);
121127

122-
const newVer = localVer.compareWith(prevVer.getVersion()) === 1 ? true : false;
128+
const newVer = gcodeVersion.compareWith(prevVer.getVersion()) === 1 ? true : false;
123129

124130
if (newVer) {
125131
// Extension has been updated
132+
Logger.log(`G-Code upgraded from ${prevVer.getVersionAsString()} to ${gcodeVersion.getVersionAsString()}`);
133+
await this.showWhatsNew(gcodeVersion);
134+
135+
// Update globalState version
136+
void this._storageManager.setValue<IVersion>(
137+
GlobalState.PreviousVersion,
138+
gcodeVersion.getVersion(),
139+
'global',
140+
);
126141
} else {
127142
return;
128143
}
129144
}
130145

131-
static showWhatsNew() {
146+
private static async showWhatsNew(ver: Version) {
132147
// Show Whats New Message
148+
await Messages.showWhatsNewMessage(ver);
133149
}
134150

135151
static setContext(key: Contexts | string, value: any) {

src/util/messages.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'use strict';
77

88
import { env, MessageItem, Uri, window } from 'vscode';
9+
import { Version } from './version';
910

1011
export class Messages {
1112
static async showSupportGCodeMessage() {
@@ -38,23 +39,21 @@ export class Messages {
3839
}
3940
}
4041

41-
static async showWhatsNewMessage(version: string) {
42-
const actions: MessageItem[] = [{ title: "What's New" }, { title: 'Release Notes' }, { title: '❤' }];
42+
static async showWhatsNewMessage(ver: Version) {
43+
const actions: MessageItem[] = [{ title: "What's New" }, { title: '❤' }];
4344

4445
const result = await Messages.showMessage(
4546
'info',
46-
`G-Code Syntax has been updated to v${version} - Check out what's new!`,
47+
`G-Code Syntax has been updated to v${ver.getVersionAsString()} - Check out what's new!`,
4748
...actions,
4849
);
4950

5051
if (result != null) {
5152
if (result === actions[0]) {
52-
await env.openExternal(Uri.parse(''));
53-
} else if (result === actions[1]) {
5453
await env.openExternal(
5554
Uri.parse('https://github.com/appliedengdesign/vscode-gcode-syntax/blob/master/CHANGELOG.md'),
5655
);
57-
} else if (result === actions[2]) {
56+
} else if (result === actions[1]) {
5857
await env.openExternal(Uri.parse('https://github.com/sponsors/appliedengdesign'));
5958
}
6059
}

src/util/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class Version {
3232
};
3333
}
3434

35-
getVersion(): IVersion {
35+
public getVersion(): IVersion {
3636
return this._version;
3737
}
3838

0 commit comments

Comments
 (0)