Reapply "Deflake project settings override on desktop (#4370)" (#4450)

This reverts commit b11040c23c.
This commit is contained in:
49lf
2024-11-11 13:23:51 -05:00
parent 0c2ca726d0
commit a4b7dd5182
8 changed files with 49 additions and 34 deletions

View File

@ -121,20 +121,28 @@ export default class CodeManager {
// Only write our buffer contents to file once per second. Any faster
// and file-system watchers which read, will receive empty data during
// writes.
clearTimeout(this.timeoutWriter)
this.writeCausedByAppCheckedInFileTreeFileSystemWatcher = true
this.timeoutWriter = setTimeout(() => {
// Wait one event loop to give a chance for params to be set
// Save the file to disk
this._currentFilePath &&
return new Promise((resolve, reject) => {
this.timeoutWriter = setTimeout(() => {
if (!this._currentFilePath)
return reject(new Error('currentFilePath not set'))
// Wait one event loop to give a chance for params to be set
// Save the file to disk
window.electron
.writeFile(this._currentFilePath, this.code ?? '')
.then(resolve)
.catch((err: Error) => {
// TODO: add tracing per GH issue #254 (https://github.com/KittyCAD/modeling-app/issues/254)
console.error('error saving file', err)
toast.error('Error saving file, please check file permissions')
reject(err)
})
}, 1000)
}, 1000)
})
} else {
safeLSSetItem(PERSIST_CODE_KEY, this.code)
}