Allow deferring of Update Toast until the next morning
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/21833/head
parent
f45c584c8a
commit
9431393bda
|
@ -23,6 +23,7 @@ import BaseEventIndexManager from './indexing/BaseEventIndexManager';
|
|||
import {ActionPayload} from "./dispatcher/payloads";
|
||||
import {CheckUpdatesPayload} from "./dispatcher/payloads/CheckUpdatesPayload";
|
||||
import {Action} from "./dispatcher/actions";
|
||||
import {hideToast as hideUpdateToast} from "./toasts/UpdateToast";
|
||||
|
||||
export enum UpdateCheckStatus {
|
||||
Checking = "CHECKING",
|
||||
|
@ -32,6 +33,8 @@ export enum UpdateCheckStatus {
|
|||
Ready = "READY",
|
||||
}
|
||||
|
||||
const UPDATE_DEFER_KEY = "mx_defer_update";
|
||||
|
||||
/**
|
||||
* Base class for classes that provide platform-specific functionality
|
||||
* eg. Setting an application badge or displaying notifications
|
||||
|
@ -74,12 +77,45 @@ export default abstract class BasePlatform {
|
|||
}
|
||||
|
||||
startUpdateCheck() {
|
||||
hideUpdateToast();
|
||||
localStorage.removeItem(UPDATE_DEFER_KEY);
|
||||
dis.dispatch<CheckUpdatesPayload>({
|
||||
action: Action.CheckUpdates,
|
||||
status: UpdateCheckStatus.Checking,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the currently running app to the latest available version
|
||||
* and replace this instance of the app with the new version.
|
||||
*/
|
||||
installUpdate() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the version update has been deferred and that deferment is still in effect
|
||||
* @param newVersion the version string to check
|
||||
*/
|
||||
protected shouldShowUpdate(newVersion: string): boolean {
|
||||
try {
|
||||
const [version, deferUntil] = JSON.parse(localStorage.getItem(UPDATE_DEFER_KEY));
|
||||
return newVersion !== version || Date.now() > deferUntil;
|
||||
} catch (e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore the pending update and don't prompt about this version
|
||||
* until the next morning (8am).
|
||||
*/
|
||||
deferUpdate(newVersion: string) {
|
||||
const date = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
||||
date.setHours(8, 0, 0, 0); // set to next 8am
|
||||
localStorage.setItem(UPDATE_DEFER_KEY, JSON.stringify([newVersion, date.getTime()]));
|
||||
hideUpdateToast();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the platform supports displaying
|
||||
* notifications, otherwise false.
|
||||
|
|
|
@ -18,7 +18,6 @@ import React, {useState} from "react";
|
|||
|
||||
import {UpdateCheckStatus} from "../../../BasePlatform";
|
||||
import PlatformPeg from "../../../PlatformPeg";
|
||||
import {hideToast as hideUpdateToast} from "../../../toasts/UpdateToast";
|
||||
import {useDispatcher} from "../../../hooks/useDispatcher";
|
||||
import dis from "../../../dispatcher/dispatcher";
|
||||
import {Action} from "../../../dispatcher/actions";
|
||||
|
@ -60,7 +59,6 @@ const UpdateCheckButton = () => {
|
|||
const onCheckForUpdateClick = () => {
|
||||
setState(null);
|
||||
PlatformPeg.get().startUpdateCheck();
|
||||
hideUpdateToast();
|
||||
};
|
||||
|
||||
useDispatcher(dis, ({action, ...params}) => {
|
||||
|
|
|
@ -40,6 +40,10 @@ function installUpdate() {
|
|||
}
|
||||
|
||||
export const showToast = (version: string, newVersion: string, releaseNotes?: string) => {
|
||||
function onReject() {
|
||||
PlatformPeg.get().deferUpdate(newVersion);
|
||||
}
|
||||
|
||||
let onAccept;
|
||||
let acceptLabel = _t("What's new?");
|
||||
if (releaseNotes) {
|
||||
|
@ -79,6 +83,8 @@ export const showToast = (version: string, newVersion: string, releaseNotes?: st
|
|||
description: _t("A new version of Riot is available!"),
|
||||
acceptLabel,
|
||||
onAccept,
|
||||
rejectLabel: _t("Later"),
|
||||
onReject,
|
||||
},
|
||||
component: GenericToast,
|
||||
priority: 20,
|
||||
|
|
Loading…
Reference in New Issue