Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: show dialog if system time is out of sync

thecodrr31a3451461b7
diff --git a/apps/web/src/app-effects.js b/apps/web/src/app-effects.js
index 266bcf6ff..9c29b445b 100644
--- a/apps/web/src/app-effects.js
+++ b/apps/web/src/app-effects.js
@@ -16,7 +16,10 @@ import { registerKeyMap } from "./common/key-map";
import { isUserPremium } from "./hooks/use-is-user-premium";
import { loadTrackerScript } from "./utils/analytics";
import useAnnouncements from "./utils/use-announcements";
-import { showAnnouncementDialog } from "./common/dialog-controller";
+import {
+ showAnnouncementDialog,
+ showInvalidSystemTimeDialog,
+} from "./common/dialog-controller";
import useSystemTheme from "./utils/use-system-theme";
import { isTesting } from "./utils/platform";
@@ -84,6 +87,13 @@ export default function AppEffects({ setShow }) {
);
useEffect(() => {
+ const systemTimeInvalidEvent = EV.subscribe(
+ EVENTS.systemTimeInvalid,
+ async ({ serverTime, localTime }) => {
+ await showInvalidSystemTimeDialog({ serverTime, localTime });
+ }
+ );
+
const attachmentsLoadingEvent = EV.subscribe(
EVENTS.attachmentsLoading,
({ type, total, current }) => {
@@ -119,6 +129,7 @@ export default function AppEffects({ setShow }) {
return () => {
attachmentsLoadingEvent.unsubscribe();
progressEvent.unsubscribe();
+ systemTimeInvalidEvent.unsubscribe();
};
}, [setProcessingStatus]);
diff --git a/apps/web/src/common/dialogcontroller.js b/apps/web/src/common/dialogcontroller.js
index 56b6f5e6a..751b2509d 100644
--- a/apps/web/src/common/dialogcontroller.js
+++ b/apps/web/src/common/dialogcontroller.js
@@ -15,6 +15,7 @@ import * as Icon from "../components/icons";
import Config from "../utils/config";
import Dialogs from "../components/dialogs";
import { Mutex } from "async-mutex";
+import { formatDate } from "notes-core/utils/date";
const DialogMutex = new Mutex();
function showDialog(dialog) {
@@ -597,3 +598,25 @@ export function showImportDialog() {
<Dialogs.ImportDialog onClose={(res) => perform(res)} />
));
}
+
+export function showInvalidSystemTimeDialog({ serverTime, localTime }) {
+ return showDialog((Dialogs) => (
+ <Dialogs.Confirm
+ title={"Your system clock is out of sync"}
+ subtitle={
+ "Please correct your system date & time and reload the app to avoid syncing issues."
+ }
+ message={
+ <>
+ Server time:{" "}
+ {formatDate(serverTime, { dateStyle: "medium", timeStyle: "medium" })}
+ <br />
+ Local time:{" "}
+ {formatDate(localTime, { dateStyle: "medium", timeStyle: "medium" })}
+ </>
+ }
+ yesText="Reload app"
+ onYes={() => window.location.reload()}
+ />
+ ));
+}
diff --git a/apps/web/src/components/dialogs/confirm.js b/apps/web/src/components/dialogs/confirm.js
index 3f47ccb7b..e8d8ddc72 100644
--- a/apps/web/src/components/dialogs/confirm.js
+++ b/apps/web/src/components/dialogs/confirm.js
@@ -10,16 +10,18 @@ function Confirm(props) {
icon={props.icon}
description={props.subtitle}
onClose={props.onNo}
- positiveButton={{
- text: props.yesText,
- onClick: props.onYes,
- autoFocus: !!props.yesText,
- }}
+ positiveButton={
+ props.yesText && {
+ text: props.yesText,
+ onClick: props.onYes,
+ autoFocus: !!props.yesText,
+ }
+ }
negativeButton={
props.noText && { text: props.noText, onClick: props.onNo }
}
>
- <Box>
+ <Box pb={!props.noText && !props.yesText ? 2 : 0}>
<Text as="span" variant="body">
{props.message}
</Text>