@@ -44,6 +44,8 @@ export interface IDeviceContext {
44
44
*/
45
45
configuration : string ;
46
46
47
+ onDidChange : vscode . Event < void > ;
48
+
47
49
initialize ( ) : void ;
48
50
}
49
51
@@ -55,6 +57,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
55
57
56
58
private static _deviceContext : DeviceContext = new DeviceContext ( ) ;
57
59
60
+ private _onDidChange = new vscode . EventEmitter < void > ( ) ;
61
+
58
62
private _port : string ;
59
63
60
64
private _board : string ;
@@ -69,22 +73,31 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
69
73
70
74
private _watcher : vscode . FileSystemWatcher ;
71
75
76
+ private _vscodeWatcher : vscode . FileSystemWatcher ;
77
+
72
78
/**
73
79
* @constructor
74
80
*/
75
81
private constructor ( ) {
76
82
if ( vscode . workspace && vscode . workspace . rootPath ) {
77
83
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
+
78
87
this . _watcher . onDidCreate ( ( ) => this . loadContext ( ) ) ;
79
88
this . _watcher . onDidChange ( ( ) => this . loadContext ( ) ) ;
80
89
this . _watcher . onDidDelete ( ( ) => this . loadContext ( ) ) ;
90
+ this . _vscodeWatcher . onDidDelete ( ( ) => this . loadContext ( ) ) ;
81
91
}
82
92
}
83
93
84
94
public dispose ( ) {
85
95
if ( this . _watcher ) {
86
96
this . _watcher . dispose ( ) ;
87
97
}
98
+ if ( this . _vscodeWatcher ) {
99
+ this . _vscodeWatcher . dispose ( ) ;
100
+ }
88
101
}
89
102
90
103
public get arduinoApp ( ) : ArduinoApp {
@@ -116,13 +129,20 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
116
129
const configFile = files [ 0 ] ;
117
130
deviceConfigJson = util . tryParseJSON ( fs . readFileSync ( configFile . fsPath , "utf8" ) ) ;
118
131
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 ( ) ;
123
137
} else {
124
138
Logger . notifyUserError ( "arduinoFileError" , new Error ( constants . messages . ARDUINO_FILE_ERROR ) ) ;
125
139
}
140
+ } else {
141
+ this . _port = null ;
142
+ this . _board = null ;
143
+ this . _sketch = null ;
144
+ this . _configuration = null ;
145
+ this . _onDidChange . fire ( ) ;
126
146
}
127
147
return this ;
128
148
} ) ;
@@ -150,6 +170,10 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
150
170
fs . writeFileSync ( deviceConfigFile , JSON . stringify ( deviceConfigJson , null , 4 ) ) ;
151
171
}
152
172
173
+ public get onDidChange ( ) : vscode . Event < void > {
174
+ return this . _onDidChange . event ;
175
+ }
176
+
153
177
public get port ( ) {
154
178
return this . _port ;
155
179
}
0 commit comments