8000 Merge pull request #296 from Microsoft/yaohai_dev · Netoperz/vscode-arduino@eeca889 · GitHub
[go: up one dir, main page]

Skip to content

Commit eeca889

Browse files
authored
Merge pull request microsoft#296 from Microsoft/yaohai_dev
Fix configuration updating issues.
2 parents baaf686 + c99e595 commit eeca889

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

src/arduino/board.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,13 @@ export class Board implements IBoard {
123123
if (!targetConfig) {
124124
return false;
125125
}
126-
targetConfig.selectedOption = optionId;
127-
const dc = DeviceContext.getIntance();
128-
dc.configuration = this.customConfig;
129-
return true;
126+
if (targetConfig.selectedOption !== optionId) {
127+
targetConfig.selectedOption = optionId;
128+
const dc = DeviceContext.getIntance();
129+
dc.configuration = this.customConfig;
130+
return true;
131+
}
132+
return false;
130133
}
131134

132135
private getPackageName() {

src/arduino/boardManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export class BoardManager {
7878
this.loadInstalledBoards();
7979
this.updateStatusBar();
8080
this._boardStatusBar.show();
81+
82+
const dc = DeviceContext.getIntance();
83+
dc.onDidChange(() => {
84+
this.updateStatusBar();
85+
});
8186
}
8287

8388
public async changeBoardType() {

src/deviceContext.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export interface IDeviceContext {
4444
*/
4545
configuration: string;
4646

47+
onDidChange: vscode.Event<void>;
48+
4749
initialize(): void;
4850
}
4951

@@ -55,6 +57,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
5557

5658
private static _deviceContext: DeviceContext = new DeviceContext();
5759

60+
private _onDidChange = new vscode.EventEmitter<void>();
61+
5862
private _port: string;
5963

6064
private _board: string;
@@ -69,22 +73,31 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
6973

7074
private _watcher: vscode.FileSystemWatcher;
7175

76+
private _vscodeWatcher: vscode.FileSystemWatcher;
77+
7278
/**
7379
* @constructor
7480
*/
7581
private constructor() {
7682
if (vscode.workspace && vscode.workspace.rootPath) {
7783
this._watcher = vscode.workspace.createFileSystemWatcher(path.join(vscode.workspace.rootPath, ARDUINO_CONFIG_FILE));
84+
// We only care about the deletion arduino.json in the .vscode folder:
85+
this._vscodeWatcher = vscode.workspace.createFileSystemWatcher(path.join(vscode.workspace.rootPath, ".vscode"), true, true, false);
86+
7887
this._watcher.onDidCreate(() => this.loadContext());
7988
this._watcher.onDidChange(() => this.loadContext());
8089
this._watcher.onDidDelete(() => this.loadContext());
90+
this._vscodeWatcher.onDidDelete(() => this.loadContext());
8191
}
8292
}
8393

8494
public dispose() {
8595
if (this._watcher) {
8696
this._watcher.dispose();
8797
}
98+
if (this._vscodeWatcher) {
99+
this._vscodeWatcher.dispose();
100+
}
88101
}
89102

90103
public get arduinoApp(): ArduinoApp {
@@ -116,13 +129,20 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
116129
const configFile = files[0];
117130
deviceConfigJson = util.tryParseJSON(fs.readFileSync(configFile.fsPath, "utf8"));
118131
if (deviceConfigJson) {
119-
this._port = deviceConfigJson.port || this._port;
120-
this._board = deviceConfigJson.board || this._board;
121-
this._sketch = deviceConfigJson.sketch || this._sketch;
122-
this._configuration = deviceConfigJson.configuration || this._configuration;
132+
this._port = deviceConfigJson.port;
133+
this._board = deviceConfigJson.board;
134+
this._sketch = deviceConfigJson.sketch;
135+
this._configuration = deviceConfigJson.configuration;
136+
this._onDidChange.fire();
123137
} else {
124138
Logger.notifyUserError("arduinoFileError", new Error(constants.messages.ARDUINO_FILE_ERROR));
125139
}
140+
} else {
141+
this._port = null;
142+
this._board = null;
143+
this._sketch = null;
144+
this._configuration = null;
145+
this._onDidChange.fire();
126146
}
127147
return this;
128148
});
@@ -150,6 +170,10 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
150170
fs.writeFileSync(deviceConfigFile, JSON.stringify(deviceConfigJson, null, 4));
151171
}
152172

173+
public get onDidChange(): vscode.Event<void> {
174+
return this._onDidChange.event;
175+
}
176+
153177
public get port() {
154178
return this._port;
155179
}

src/serialmonitor/serialMonitor.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export class SerialMonitor implements vscode.Disposable {
6868
this._baudRateStatusBar.tooltip = "Baud Rate";
6969
this._baudRateStatusBar.text = SerialMonitor.DEFAULT_BAUD_RATE.toString();
7070
this.updatePortListStatus(null);
71+
72+
const dc = DeviceContext.getIntance();
73+
dc.onDidChange(() => {
74+
this.updatePortListStatus(null);
75+
});
7176
}
7277

7378
public async dispose() {
@@ -119,7 +124,7 @@ export class SerialMonitor implements vscode.Disposable {
119124
await this.selectSerialPort(null, null);
120125
}
121126
if (!this._currentPort) {
122-
return ;
127+
return;
123128
}
124129
}
125130

@@ -136,7 +141,7 @@ export class SerialMonitor implements vscode.Disposable {
136141

137142
if (!this._serialPortCtrl.currentPort) {
138143
Logger.traceError("openSerialMonitorError", new Error(`Failed to open serial port ${this._currentPort}`));
139-
return ;
144+
return;
140145
}
141146

142147
try {

0 commit comments

Comments
 (0)
0