Skip to content

Commit

Permalink
fix: default project not created on first boot
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Dec 26, 2023
1 parent ad3b5be commit 5769cf8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
window._tauriStorageRestorePromise = window.__TAURI__.fs.readTextFile(
"storageDB/storageDBDump.json", { dir: window.__TAURI__.fs.BaseDirectory.AppLocalData })
.catch(err =>{
window.Phoenix.firstBoot = true;
console.error("First boot detected or Failed to init storage from cache." +
" If first boot, ignore this error", err);
});
Expand Down
10 changes: 10 additions & 0 deletions src/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
return;
}
const EVENT_CHANGED = "change";
const FIRST_BOOT_TIME = "firstBootTime";
let storageNodeConnector;
let _testKey;
let nodeStoragePhoenixApis = {};
Expand Down Expand Up @@ -220,19 +221,28 @@
}
}

function setupFirstBoot() {
const firstBootTime = getItem(FIRST_BOOT_TIME);
if(!firstBootTime){
window.Phoenix.firstBoot = true;
setItem(FIRST_BOOT_TIME, Date.now());
}
}

const storageReadyPromise = new Promise((resolve) => {
if(isBrowser || Phoenix.isTestWindow){
// in browsers its immediately ready as we use localstorage
// in tests, immediately resolve with empty storage.
resolve();
setupFirstBoot();
return;
}
// In tauri, we have to read it from app local data dump(which is usually written at app close time. This
// will help the storage to quick start from a json dump instead of waiting for node to boot up and init lmdb)
window._tauriStorageRestorePromise
.then((jsonData)=>{
cache = JSON.parse(jsonData);
setupFirstBoot();
})
.finally(resolve);
});
Expand Down
1 change: 0 additions & 1 deletion test/SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
window._tauriStorageRestorePromise = window.__TAURI__.fs.readTextFile(
"storageDB/storageDBDump.json", { dir: window.__TAURI__.fs.BaseDirectory.AppLocalData })
.catch(err =>{
window.Phoenix.firstBoot = true;
console.error("First boot detected or Failed to init storage from cache." +
" If first boot, ignore this error", err);
});
Expand Down

0 comments on commit 5769cf8

Please sign in to comment.