Deflake project settings override on desktop (#4370)

This commit is contained in:
49fl
2024-10-31 21:42:52 -04:00
committed by 49lf
parent 6ccd5e22b8
commit 765e587f6b
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)
}