Spruce types
This commit is contained in:
parent
9e093493eb
commit
532824b3d5
7 changed files with 31 additions and 46 deletions
|
@ -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();
|
||||
|
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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<Blob>;
|
||||
arrayBuffer: () => Promise<Uint8Array>;
|
||||
}
|
||||
|
||||
export enum FILE_PATH_TYPE {
|
||||
/* eslint-disable no-unused-vars */
|
||||
FILES = "files",
|
||||
ZIPS = "zips",
|
||||
}
|
||||
|
||||
export interface AppUpdateInfo {
|
||||
autoUpdatable: boolean;
|
||||
version: string;
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
};
|
||||
|
|
@ -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: <ArrowForward />,
|
||||
|
@ -170,7 +170,7 @@ export default function App({ Component, pageProps }: AppProps) {
|
|||
message: t("UPDATE_AVAILABLE"),
|
||||
onClick: () =>
|
||||
setDialogMessage(
|
||||
getUpdateAvailableForDownloadMessage(updateInfo),
|
||||
getUpdateAvailableForDownloadMessage(update),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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: <AutoAwesomeOutlinedIcon />,
|
||||
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: <AutoAwesomeOutlinedIcon />,
|
||||
title: t("UPDATE_AVAILABLE"),
|
||||
content: t("UPDATE_AVAILABLE_MESSAGE"),
|
||||
|
|
|
@ -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<ElectronFile[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue