Skip to content

Commit

Permalink
Improve reliability of state saving
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Feb 9, 2024
1 parent 8bb5b8e commit c6438ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/main/StateTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default class StateTracker {
private satelliteUUIDs: { [id: number]: string } = {};

constructor() {
let lastState: ApplicationState | null = null;
if (fs.existsSync(STATE_FILENAME)) {
lastState = jsonfile.readFileSync(STATE_FILENAME);
}
setInterval(() => {
let state: ApplicationState = { hubs: [], satellites: [] };
Object.keys(this.rendererStates).forEach((windowId) => {
Expand Down Expand Up @@ -43,7 +47,10 @@ export default class StateTracker {
});
}
});
jsonfile.writeFileSync(STATE_FILENAME, state);
if (state.hubs.length > 0 && JSON.stringify(state) !== JSON.stringify(lastState)) {
jsonfile.writeFileSync(STATE_FILENAME, state);
lastState = state;
}
}, this.SAVE_PERIOD_MS);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2449,7 +2449,7 @@ app.whenReady().then(() => {
setupMenu();
let applicationState = stateTracker.getSavedApplicationState();
let targetWindow: BrowserWindow | null = null;
if (applicationState === null) {
if (applicationState === null || applicationState.hubs.length === 0) {
targetWindow = createHubWindow();
} else {
applicationState.hubs.forEach((hubState, index) => {
Expand Down

0 comments on commit c6438ff

Please sign in to comment.