2020-05-23 04:56:25 +08:00
|
|
|
/*
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { _t } from "../languageHandler";
|
|
|
|
import Notifier from "../Notifier";
|
|
|
|
import GenericToast from "../components/views/toasts/GenericToast";
|
|
|
|
import ToastStore from "../stores/ToastStore";
|
|
|
|
|
|
|
|
const onAccept = () => {
|
|
|
|
Notifier.setEnabled(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const onReject = () => {
|
2020-09-15 20:58:29 +08:00
|
|
|
Notifier.setPromptHidden(true);
|
2020-05-23 04:56:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const TOAST_KEY = "desktopnotifications";
|
|
|
|
|
2020-11-03 01:25:56 +08:00
|
|
|
export const showToast = (fromMessageSend: boolean) => {
|
2020-05-23 04:56:25 +08:00
|
|
|
ToastStore.sharedInstance().addOrReplaceToast({
|
|
|
|
key: TOAST_KEY,
|
2020-11-03 01:25:56 +08:00
|
|
|
title: fromMessageSend ? _t("Don't miss a reply") : _t("Notifications"),
|
2020-05-23 04:56:25 +08:00
|
|
|
props: {
|
2020-11-03 01:25:56 +08:00
|
|
|
description: _t("Enable desktop notifications"),
|
|
|
|
acceptLabel: _t("Enable"),
|
2020-05-23 04:56:25 +08:00
|
|
|
onAccept,
|
2020-11-03 01:25:56 +08:00
|
|
|
rejectLabel: _t("Dismiss"),
|
2020-05-23 04:56:25 +08:00
|
|
|
onReject,
|
|
|
|
},
|
|
|
|
component: GenericToast,
|
2020-05-29 00:30:43 +08:00
|
|
|
priority: 30,
|
2020-05-23 04:56:25 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const hideToast = () => {
|
|
|
|
ToastStore.sharedInstance().dismissToast(TOAST_KEY);
|
|
|
|
};
|