mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-07-12 21:02:17 +02:00
minor refactor
This commit is contained in:
parent
beef74ed17
commit
88b4a2f987
4 changed files with 24 additions and 24 deletions
|
|
@ -48,7 +48,12 @@ async function loadState(): Promise<NotificationState> {
|
|||
}
|
||||
|
||||
async function saveState(state: NotificationState): Promise<void> {
|
||||
await fs.writeFile(STATE_FILE, JSON.stringify(state, null, 2), "utf-8");
|
||||
// Write to a sibling tmp file then rename so a mid-write crash can't leave
|
||||
// the JSON corrupt — a corrupt state file would make every event in the
|
||||
// 90s notify window re-fire on next start.
|
||||
const tmp = `${STATE_FILE}.tmp`;
|
||||
await fs.writeFile(tmp, JSON.stringify(state, null, 2), "utf-8");
|
||||
await fs.rename(tmp, STATE_FILE);
|
||||
}
|
||||
|
||||
function gcState(state: NotificationState): NotificationState {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue