Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of prompting users when an update is available
* Shows a notification prompting users to restart when an update has been downloaded
* and we're ready to apply it.
export const promptToUpdateEpic: Epic<Action<ReleaseChannel | UpdateStatus>, State> = (
) => {
// Update status is redux state populated by autoUpdater events
const updateStatusChanged = action$.pipe(
map(() => getUpdateStatus(store)),
// We'll want to cancel our timer if the release channel changes
const releaseChannelChanged = action$.pipe(
map(() => getReleaseChannel(store)),
return combineLatest(updateStatusChanged, releaseChannelChanged).pipe(
filter(() => isUpdateSupported(store)),
switchMap(([ updateStatus, channel ]) => {
// Cancel the timer for any changes to the staged update
if (updateStatus !== UpdateStatus.UPDATE_DOWNLOADED) {
return empty<ReleaseChannel>();
// Once downloaded, emit once, then remind at regular intervals
return timer(0, RESTART_REMINDER_INTERVAL).pipe(mapTo(channel));
map((channel) => updatePromptNotificationOptions(channel)),
// Dispatch this to a separate epic that handles notifications
function updatePromptNotificationOptions(
channel: ReleaseChannel
): Electron.NotificationConstructorOptions {
return {
// … you get the idea
title: 'It’s a bird, it’s a tractor, it’s … a new version of Slack?'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment