|
1 | 1 | /** |
2 | 2 | * @license |
3 | | - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. |
| 3 | + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. |
4 | 4 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
5 | 5 | * @ignore |
6 | 6 | */ |
@@ -107,30 +107,36 @@ const AutoPrefs = (() => { |
107 | 107 | const filepath = AutoPrefs.getPath(userDataPath); |
108 | 108 | if (fs.existsSync(filepath)) { |
109 | 109 | try { |
110 | | - const props = JSON.parse(fs.readFileSync(filepath)); |
111 | | - // Update all the other _fields with values from the |
112 | | - // file just read. |
113 | | - AutoPrefs.set(props); |
114 | | - // See if auto-prefs.json contained a projects field |
115 | | - if (typeof props.projects !== 'undefined') { |
116 | | - // It did, so use it to do a UserProjects.putAll() |
117 | | - UserProjects.putAll(props.projects); |
118 | | - // Use UserProjects.write() to write out the |
119 | | - // in-memory projects. |
120 | | - UserProjects.write(userDataPath); |
121 | | - } |
122 | | - // See if auto-prefs.json contained a preferences field |
123 | | - if (typeof props.preferences !== 'undefined') { |
124 | | - // It did, so use it to do a UserPrefs.putAll() |
125 | | - UserPrefs.putAll(props.preferences); |
126 | | - // Use UserPrefs.write() to write out the |
127 | | - // in-memory preferences. |
128 | | - UserPrefs.write(userDataPath); |
| 110 | + const fileContents = fs.readFileSync(filepath); |
| 111 | + |
| 112 | + if (fileContents !== this.previousContents) { |
| 113 | + const props = JSON.parse(fileContents); |
| 114 | + // Update all the other _fields with values from the |
| 115 | + // file just read. |
| 116 | + AutoPrefs.set(props); |
| 117 | + // See if auto-prefs.json contained a projects field |
| 118 | + if (typeof props.projects !== 'undefined') { |
| 119 | + // It did, so use it to do a UserProjects.putAll() |
| 120 | + UserProjects.putAll(props.projects); |
| 121 | + // Use UserProjects.write() to write out the |
| 122 | + // in-memory projects. |
| 123 | + UserProjects.write(userDataPath); |
| 124 | + } |
| 125 | + // See if auto-prefs.json contained a preferences field |
| 126 | + if (typeof props.preferences !== 'undefined') { |
| 127 | + // It did, so use it to do a UserPrefs.putAll() |
| 128 | + UserPrefs.putAll(props.preferences); |
| 129 | + // Use UserPrefs.write() to write out the |
| 130 | + // in-memory preferences. |
| 131 | + UserPrefs.write(userDataPath); |
| 132 | + } |
| 133 | + // The auto-prefs.json field could have contained a |
| 134 | + // projects or preferences field, which will not be |
| 135 | + // in the _fields. Write out the updated _fields. |
| 136 | + AutoPrefs.write(userDataPath); |
| 137 | + |
| 138 | + this.previousContents = fileContents; |
129 | 139 | } |
130 | | - // The auto-prefs.json field could have contained a |
131 | | - // projects or preferences field, which will not be |
132 | | - // in the _fields. Write out the updated _fields. |
133 | | - AutoPrefs.write(userDataPath); |
134 | 140 | } |
135 | 141 | catch(err) { |
136 | 142 | log('error', err); |
|
0 commit comments