Skip to content

Commit cff1dfd

Browse files
committed
Refactor state control into controller
1 parent 42f754a commit cff1dfd

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

src/control.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { StatusBarControl } from './util/statusBar';
1212
import { NavTreeView } from './views/navTreeView';
1313
import { GCodeUnitsController } from './gcodeUnits';
1414
import { StatsView } from './views/statsView';
15-
import { constants, Contexts, GlobalState, PIcon, VSBuiltInCommands } from './util/constants';
15+
import { constants, Contexts, PIcon, VSBuiltInCommands } from './util/constants';
1616
import { Commands } from './util/commands';
17-
import { LocalStorageService } from './util/localStorageService';
18-
import { IVersion, Version } from './util/version';
17+
import { Version } from './util/version';
1918
import { Messages } from './util/messages';
19+
import { StateControl } from './util/stateControl';
2020

2121
export class Control {
2222
private static _config: Config | undefined;
@@ -26,7 +26,7 @@ export class Control {
2626
// Controllers
2727
private static _statusBarControl: StatusBarControl;
2828
private static _unitsController: GCodeUnitsController | undefined;
29-
private static _storageManager: LocalStorageService;
29+
private static _stateController: StateControl;
3030

3131
// Views
3232
private static _statsView: StatsView | undefined;
@@ -36,8 +36,8 @@ export class Control {
3636
this._context = context;
3737
this._config = config;
3838

39-
// Load GlobalState Storage Manager
40-
this._storageManager = new LocalStorageService(context);
39+
// Load State Controller
40+
this._stateController = new StateControl(context);
4141

4242
// Load StatusBars
4343
context.subscriptions.push((this._statusBarControl = new StatusBarControl(this._context)));
@@ -121,23 +121,19 @@ export class Control {
121121
private static async checkVersion() {
122122
const gcodeVersion = new Version(constants.extension.version);
123123

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

128126
const newVer = gcodeVersion.compareWith(prevVer.getVersion()) === 1 ? true : false;
129127

130128
if (newVer) {
131129
// Extension has been updated
132-
Logger.log(`G-Code upgraded from ${prevVer.getVersionAsString()} to ${gcodeVersion.getVersionAsString()}`);
133-
await this.showWhatsNew(gcodeVersion);
134130

135131
// Update globalState version
136-
void this._storageManager.setValue<IVersion>(
137-
GlobalState.PreviousVersion,
138-
gcodeVersion.getVersion(),
139-
'global',
140-
);
132+
Logger.log('Updating...');
133+
void this._stateController.updateVer(gcodeVersion);
134+
135+
Logger.log(`G-Code upgraded from ${prevVer.getVersionAsString()} to ${gcodeVersion.getVersionAsString()}`);
136+
await this.showWhatsNew(gcodeVersion);
141137
} else {
142138
return;
143139
}
@@ -183,4 +179,8 @@ export class Control {
183179
static get gcodeUnitsController() {
184180
return this._unitsController;
185181
}
182+
183+
static get stateController() {
184+
return this._stateController;
185+
}
186186
}

src/util/constants.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface IConstants {
3131
readonly urls: {
3232
readonly changeLog: string;
3333
readonly readme: string;
34+
readonly vsmpReviews: string;
3435
};
3536
}
3637

@@ -50,6 +51,9 @@ export const constants: IConstants = {
5051
urls: {
5152
changeLog: 'https://github.com/appliedengdesign/vscode-gcode-syntax/blob/master/CHANGELOG.md',
5253
readme: 'https://github.com/appliedengdesign/vscode-gcode-syntax/blob/master/README.md',
54+
vsmpReviews:
55+
'https://marketplace.visualstudio.com/items?' +
56+
'itemName=appliedengdesign.vscode-gcode-syntax&ssr=false#review-details',
5357
},
5458
};
5559

@@ -67,8 +71,3 @@ export const enum VSBuiltInCommands {
6771
export const enum Contexts {
6872
NavTreeViewEnabled = 'gcode:navTree:enabled',
6973
}
70-
71-
export const enum GlobalState {
72-
PreviousVersion = 'gcode:previousVersion',
73-
Version = 'gcode:version',
74-
}

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-
public getVersion(): IVersion {
35+
getVersion(): IVersion {
3636
return this._version;
3737
}
3838

0 commit comments

Comments
 (0)