Skip to content

Commit

Permalink
Simplify update checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdoming committed Oct 30, 2024
1 parent a5ed425 commit cf28241
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions packages/desktop-client/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function AppInner() {
const { showBoundary: showErrorBoundary } = useErrorBoundary();
const dispatch = useDispatch();

const maybeUpdate = async <T,>(cb: () => T): Promise<T> => {
const maybeUpdate = async <T,>(cb?: () => T): Promise<T> => {
if (global.Actual.isUpdateReadyForDownload()) {
dispatch(
setAppState({
Expand All @@ -60,36 +60,36 @@ function AppInner() {
);
await global.Actual.applyAppUpdate();
}
return cb();
return cb?.();
};

async function init() {
const socketName = await global.Actual.getServerSocket();
const socketName = await maybeUpdate(() => global.Actual.getServerSocket());

dispatch(
setAppState({
loadingText: t('Initializing the connection to the local database...'),
}),
);
await maybeUpdate(() => initConnection(socketName));
await initConnection(socketName);

// Load any global prefs
dispatch(
setAppState({
loadingText: t('Loading global preferences...'),
}),
);
await maybeUpdate(() => dispatch(loadGlobalPrefs()));
await dispatch(loadGlobalPrefs());

// Open the last opened budget, if any
dispatch(
setAppState({
loadingText: t('Opening last budget...'),
}),
);
const budgetId = await maybeUpdate(() => send('get-last-opened-backup'));
const budgetId = await send('get-last-opened-backup');
if (budgetId) {
await maybeUpdate(() => dispatch(loadBudget(budgetId)));
await dispatch(loadBudget(budgetId));

// Check to see if this file has been remotely deleted (but
// don't block on this in case they are offline or something)
Expand All @@ -98,16 +98,16 @@ function AppInner() {
loadingText: t('Retrieving remote files...'),
}),
);
await maybeUpdate(() =>
send('get-remote-files').then(files => {
if (files) {
const remoteFile = files.find(f => f.fileId === cloudFileId);
if (remoteFile && remoteFile.deleted) {
dispatch(closeBudget());
}
await send('get-remote-files').then(files => {
if (files) {
const remoteFile = files.find(f => f.fileId === cloudFileId);
if (remoteFile && remoteFile.deleted) {
dispatch(closeBudget());
}
}),
);
}
});

await maybeUpdate();
}
}

Expand Down

0 comments on commit cf28241

Please sign in to comment.