Files
pybricks-code/src/sagas/app.ts
T
David Lechner e59bfd4474 add UI to manually check for update
This adds a button to call the ServiceWorkerRegistration.update()
function. This button will be hidden if there is already an update
pending.

This also adds a button to restart the app to apply the update. This
is nice in case users accidentally close the notification that asks
to restart.

The about button is moved to the new app group in the setting menu.
2021-01-28 15:37:40 -06:00

27 lines
812 B
TypeScript

// SPDX-License-Identifier: MIT
// Copyright (c) 2021 The Pybricks Authors
import { call, put, takeEvery } from 'typed-redux-saga/macro';
import {
AppActionType,
AppCheckForUpdatesAction,
AppReloadAction,
didCheckForUpdate,
} from '../actions/app';
function* reload(action: AppReloadAction): Generator {
yield* call(() => action.registration.unregister());
location.reload();
}
function* checkForUpdate(action: AppCheckForUpdatesAction): Generator {
yield* call(() => action.registration.update());
const updateFound = action.registration.installing !== null;
yield* put(didCheckForUpdate(updateFound));
}
export default function* app(): Generator {
yield* takeEvery(AppActionType.Reload, reload);
yield* takeEvery(AppActionType.CheckForUpdate, checkForUpdate);
}