From 532824b3d5945c0779eb5e978de66560e5b96624 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Thu, 18 Apr 2024 12:49:39 +0530 Subject: [PATCH] Spruce types --- desktop/src/main/services/app-update.ts | 6 +++--- desktop/src/preload.ts | 8 ++++---- desktop/src/types/ipc.ts | 18 +++++------------- desktop/src/types/main.ts | 12 ------------ web/apps/photos/src/pages/_app.tsx | 10 +++++----- web/apps/photos/src/utils/ui/index.tsx | 6 +++--- web/packages/next/types/ipc.ts | 17 +++++++++++------ 7 files changed, 31 insertions(+), 46 deletions(-) delete mode 100644 desktop/src/types/main.ts diff --git a/desktop/src/main/services/app-update.ts b/desktop/src/main/services/app-update.ts index b47448501..aa1dd3aeb 100644 --- a/desktop/src/main/services/app-update.ts +++ b/desktop/src/main/services/app-update.ts @@ -3,7 +3,7 @@ import { app, BrowserWindow } from "electron"; import { default as electronLog } from "electron-log"; import { autoUpdater } from "electron-updater"; import { allowWindowClose } from "../../main"; -import { AppUpdateInfo } from "../../types/ipc"; +import { AppUpdate } from "../../types/ipc"; import log from "../log"; import { userPreferences } from "../stores/user-preferences"; @@ -52,8 +52,8 @@ const checkForUpdatesAndNotify = async (mainWindow: BrowserWindow) => { return; } - const showUpdateDialog = (updateInfo: AppUpdateInfo) => - mainWindow.webContents.send("appUpdateAvailable", updateInfo); + const showUpdateDialog = (update: AppUpdate) => + mainWindow.webContents.send("appUpdateAvailable", update); log.debug(() => "Attempting auto update"); autoUpdater.downloadUpdate(); diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts index 39d01a66d..cf5ded6d8 100644 --- a/desktop/src/preload.ts +++ b/desktop/src/preload.ts @@ -42,7 +42,7 @@ import { contextBridge, ipcRenderer } from "electron/renderer"; // While we can't import other code, we can import types since they're just // needed when compiling and will not be needed / looked around for at runtime. import type { - AppUpdateInfo, + AppUpdate, ElectronFile, FolderWatch, PendingUploads, @@ -77,12 +77,12 @@ const onMainWindowFocus = (cb?: () => void) => { // - App update const onAppUpdateAvailable = ( - cb?: ((updateInfo: AppUpdateInfo) => void) | undefined, + cb?: ((update: AppUpdate) => void) | undefined, ) => { ipcRenderer.removeAllListeners("appUpdateAvailable"); if (cb) { - ipcRenderer.on("appUpdateAvailable", (_, updateInfo: AppUpdateInfo) => - cb(updateInfo), + ipcRenderer.on("appUpdateAvailable", (_, update: AppUpdate) => + cb(update), ); } }; diff --git a/desktop/src/types/ipc.ts b/desktop/src/types/ipc.ts index 864c6ab11..1d330dc6f 100644 --- a/desktop/src/types/ipc.ts +++ b/desktop/src/types/ipc.ts @@ -5,6 +5,11 @@ * See [Note: types.ts <-> preload.ts <-> ipc.ts] */ +export interface AppUpdate { + autoUpdatable: boolean; + version: string; +} + export interface FolderWatch { rootFolderName: string; uploadStrategy: number; @@ -20,9 +25,7 @@ export interface FolderWatchSyncedFile { } export interface PendingUploads { - /** The collection to which we're uploading */ collectionName: string; - /* The upload can be either of a Google Takeout zip, or regular files */ type: "files" | "zips"; files: ElectronFile[]; } @@ -73,14 +76,3 @@ export interface ElectronFile { blob: () => Promise; arrayBuffer: () => Promise; } - -export enum FILE_PATH_TYPE { - /* eslint-disable no-unused-vars */ - FILES = "files", - ZIPS = "zips", -} - -export interface AppUpdateInfo { - autoUpdatable: boolean; - version: string; -} diff --git a/desktop/src/types/main.ts b/desktop/src/types/main.ts deleted file mode 100644 index 501a552f1..000000000 --- a/desktop/src/types/main.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { FILE_PATH_TYPE } from "./ipc"; - - - -/* eslint-disable no-unused-vars */ -export const FILE_PATH_KEYS: { - [k in FILE_PATH_TYPE]: keyof UploadStoreType; -} = { - [FILE_PATH_TYPE.ZIPS]: "zipPaths", - [FILE_PATH_TYPE.FILES]: "filePaths", -}; - diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx index c31256f13..fb5c2ebbd 100644 --- a/web/apps/photos/src/pages/_app.tsx +++ b/web/apps/photos/src/pages/_app.tsx @@ -5,7 +5,7 @@ import { logStartupBanner, logUnhandledErrorsAndRejections, } from "@/next/log-web"; -import { AppUpdateInfo } from "@/next/types/ipc"; +import { AppUpdate } from "@/next/types/ipc"; import { APPS, APP_TITLES, @@ -160,9 +160,9 @@ export default function App({ Component, pageProps }: AppProps) { const electron = globalThis.electron; if (!electron) return; - const showUpdateDialog = (updateInfo: AppUpdateInfo) => { - if (updateInfo.autoUpdatable) { - setDialogMessage(getUpdateReadyToInstallMessage(updateInfo)); + const showUpdateDialog = (update: AppUpdate) => { + if (update.autoUpdatable) { + setDialogMessage(getUpdateReadyToInstallMessage(update)); } else { setNotificationAttributes({ endIcon: , @@ -170,7 +170,7 @@ export default function App({ Component, pageProps }: AppProps) { message: t("UPDATE_AVAILABLE"), onClick: () => setDialogMessage( - getUpdateAvailableForDownloadMessage(updateInfo), + getUpdateAvailableForDownloadMessage(update), ), }); } diff --git a/web/apps/photos/src/utils/ui/index.tsx b/web/apps/photos/src/utils/ui/index.tsx index 1b01116d3..8f4895ead 100644 --- a/web/apps/photos/src/utils/ui/index.tsx +++ b/web/apps/photos/src/utils/ui/index.tsx @@ -1,5 +1,5 @@ import { ensureElectron } from "@/next/electron"; -import { AppUpdateInfo } from "@/next/types/ipc"; +import { AppUpdate } from "@/next/types/ipc"; import { logoutUser } from "@ente/accounts/services/user"; import { DialogBoxAttributes } from "@ente/shared/components/DialogBox/types"; import AutoAwesomeOutlinedIcon from "@mui/icons-material/AutoAwesomeOutlined"; @@ -55,7 +55,7 @@ export const getTrashFileMessage = (deleteFileHelper): DialogBoxAttributes => ({ export const getUpdateReadyToInstallMessage = ({ version, -}: AppUpdateInfo): DialogBoxAttributes => ({ +}: AppUpdate): DialogBoxAttributes => ({ icon: , title: t("UPDATE_AVAILABLE"), content: t("UPDATE_INSTALLABLE_MESSAGE"), @@ -73,7 +73,7 @@ export const getUpdateReadyToInstallMessage = ({ export const getUpdateAvailableForDownloadMessage = ({ version, -}: AppUpdateInfo): DialogBoxAttributes => ({ +}: AppUpdate): DialogBoxAttributes => ({ icon: , title: t("UPDATE_AVAILABLE"), content: t("UPDATE_AVAILABLE_MESSAGE"), diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.ts index ccdf4b6d5..db8012b8c 100644 --- a/web/packages/next/types/ipc.ts +++ b/web/packages/next/types/ipc.ts @@ -5,11 +5,6 @@ import type { ElectronFile } from "./file"; -export interface AppUpdateInfo { - autoUpdatable: boolean; - version: string; -} - /** * Extra APIs provided by our Node.js layer when our code is running inside our * desktop (Electron) app. @@ -100,7 +95,7 @@ export interface Electron { * Note: Setting a callback clears any previous callbacks. */ onAppUpdateAvailable: ( - cb?: ((updateInfo: AppUpdateInfo) => void) | undefined, + cb?: ((update: AppUpdate) => void) | undefined, ) => void; /** @@ -378,6 +373,16 @@ export interface Electron { getDirFiles: (dirPath: string) => Promise; } +/** + * Data passed across the IPC bridge when an app update is available. + */ +export interface AppUpdate { + /** `true` if the user automatically update to this (new) version */ + autoUpdatable: boolean; + /** The new version that is available */ + version: string; +} + /** * A top level folder that was selected by the user for watching. *