Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[desktop] Don't show what's new on fresh installs

Manav Rathi6e9dd8d4c8bf
diff --git a/web/apps/photos/src/pages/gallery/index.tsx b/web/apps/photos/src/pages/gallery/index.tsx
index d419146379..bc5994ada1 100644
--- a/web/apps/photos/src/pages/gallery/index.tsx
+++ b/web/apps/photos/src/pages/gallery/index.tsx
@@ -390,7 +390,7 @@ export default function Gallery() {
}, SYNC_INTERVAL_IN_MICROSECONDS);
if (electron) {
electron.onMainWindowFocus(() => syncWithRemote(false, true));
- if (await shouldShowWhatsNew()) setOpenWhatsNew(true);
+ if (await shouldShowWhatsNew(electron)) setOpenWhatsNew(true);
}
};
main();
diff --git a/web/packages/new/photos/components/WhatsNew.tsx b/web/packages/new/photos/components/WhatsNew.tsx
index f6b02b1f3a..06d8ec7d67 100644
--- a/web/packages/new/photos/components/WhatsNew.tsx
+++ b/web/packages/new/photos/components/WhatsNew.tsx
@@ -1,3 +1,4 @@
+import { ensureElectron } from "@/next/electron";
import { ut } from "@/next/i18n";
import ArrowForward from "@mui/icons-material/ArrowForward";
import {
@@ -30,7 +31,7 @@ export const WhatsNew: React.FC<WhatsNewProps> = ({ open, onClose }) => {
const fullScreen = useMediaQuery("(max-width: 428px)");
useEffect(() => {
- if (open) void didShowWhatsNew();
+ if (open) void didShowWhatsNew(ensureElectron());
}, [open]);
return (
diff --git a/web/packages/new/photos/services/changelog.ts b/web/packages/new/photos/services/changelog.ts
index 9fa1ed942a..8382c13513 100644
--- a/web/packages/new/photos/services/changelog.ts
+++ b/web/packages/new/photos/services/changelog.ts
@@ -1,4 +1,4 @@
-import { ensureElectron } from "@/next/electron";
+import type { Electron } from "@/next/types/ipc";
/**
* The current changelog version.
@@ -9,31 +9,45 @@ import { ensureElectron } from "@/next/electron";
* integer, we increment it whenever we want to show this dialog again. Usually
* we'd do this for each app update, but not necessarily.
*
- * The "What's new" dialog is shown when either we do not have a previously
- * saved changelog version, or if the saved changelog version is less than the
- * current {@link changelogVersion}.
+ * The "What's new" dialog is shown when the saved changelog version is less
+ * than the current {@link changelogVersion}.
*
- * The shown changelog version is persisted on the Node.js layer since there we
- * can store it in the user preferences store, which is not cleared on logout.
+ * The shown changelog version is saved on the Node.js layer since there we can
+ * store it in the user preferences store, which is not cleared on logout.
*
- * On app start, the Node.js layer waits for the {@link onShowWhatsNew} callback
- * to get attached. When a callback is attached, it checks the above conditions
- * and if they are satisfied, it invokes the callback. The callback should
- * return the current {@link changelogVersion} to allow the Node.js layer to
- * update the persisted state.
+ * On app start, we read the last saved version:
+ *
+ * - If it is not present, we set it to the current version _without_ showing
+ * the what's new dialog. This is to handle fresh installs.
+ *
+ * - If it is present and less than the current version, we show the what's
+ * new dialog. Otherwise do nothing.
+ *
+ * The what's new dialog sets the saved version to the current one whenever it
+ * is shown.
*/
const changelogVersion = 1;
/**
* Return true if we should show the {@link WhatsNew} dialog.
+ *
+ * It has the side affect of updating the persisted version (whilst returning
+ * false) if there was no previous persisted changelog version version present.
*/
-export const shouldShowWhatsNew = async () => {
- const electron = globalThis.electron;
- if (!electron) return false;
- const lastShownVersion = (await electron.lastShownChangelogVersion()) ?? 0;
+export const shouldShowWhatsNew = async (electron: Electron) => {
+ const lastShownVersion = await electron.lastShownChangelogVersion();
+ if (!lastShownVersion) {
+ // On a fresh install, save the current version but don't show the
+ // what's new dialog.
+ await electron.setLastShownChangelogVersion(changelogVersion);
+ return false;
+ }
+ // Show what's new if the saved version is older than the current one.
return lastShownVersion < changelogVersion;
};
-export const didShowWhatsNew = async () =>
- // We should only have been called if we're in electron.
- ensureElectron().setLastShownChangelogVersion(changelogVersion);
+/**
+ * Set the saved changelog version to the current changelog version.
+ */
+export const didShowWhatsNew = async (electron: Electron) =>
+ electron.setLastShownChangelogVersion(changelogVersion);