Skip to content

Commit 1b45d5a

Browse files
committed
fix: compare content failed before save project
1 parent 5592408 commit 1b45d5a

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/EIDETypeDefine.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,31 @@ export abstract class Configuration<ConfigType = any, EventType = any> {
244244
this._event.emit('dataChanged');
245245
}
246246

247+
private _json_equal(str1: string, str2: string): boolean {
248+
249+
try {
250+
const s1 = JSON.stringify(jsonc.parse(str1));
251+
const s2 = JSON.stringify(jsonc.parse(str2));
252+
return s1 == s2;
253+
} catch (error) {
254+
// nothing todo
255+
}
256+
257+
return str1 == str2;
258+
}
259+
247260
Save(force?: boolean): void {
248261

249262
let oldContent: string | undefined;
250-
let newContent: string | undefined = this.ToJson();
263+
let newContent: string = this.ToJson();
251264

252265
try {
253-
if (this.cfgFile.IsExist()) {
254-
oldContent = this.cfgFile.Read();
255-
}
266+
if (this.cfgFile.IsExist()) oldContent = this.cfgFile.Read();
256267
} catch (error) {
257268
GlobalEvent.emit('globalLog', ExceptionToMessage(error, 'Warning'));
258269
}
259270

260-
if (oldContent != newContent) {
271+
if (oldContent == undefined || !this._json_equal(oldContent, newContent)) {
261272
this.cfgFile.Write(newContent);
262273
}
263274
}

0 commit comments

Comments
 (0)