Spruce types
This commit is contained in:
parent
9e093493eb
commit
532824b3d5
|
@ -3,7 +3,7 @@ import { app, BrowserWindow } from "electron";
|
||||||
import { default as electronLog } from "electron-log";
|
import { default as electronLog } from "electron-log";
|
||||||
import { autoUpdater } from "electron-updater";
|
import { autoUpdater } from "electron-updater";
|
||||||
import { allowWindowClose } from "../../main";
|
import { allowWindowClose } from "../../main";
|
||||||
import { AppUpdateInfo } from "../../types/ipc";
|
import { AppUpdate } from "../../types/ipc";
|
||||||
import log from "../log";
|
import log from "../log";
|
||||||
import { userPreferences } from "../stores/user-preferences";
|
import { userPreferences } from "../stores/user-preferences";
|
||||||
|
|
||||||
|
@ -52,8 +52,8 @@ const checkForUpdatesAndNotify = async (mainWindow: BrowserWindow) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const showUpdateDialog = (updateInfo: AppUpdateInfo) =>
|
const showUpdateDialog = (update: AppUpdate) =>
|
||||||
mainWindow.webContents.send("appUpdateAvailable", updateInfo);
|
mainWindow.webContents.send("appUpdateAvailable", update);
|
||||||
|
|
||||||
log.debug(() => "Attempting auto update");
|
log.debug(() => "Attempting auto update");
|
||||||
autoUpdater.downloadUpdate();
|
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
|
// 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.
|
// needed when compiling and will not be needed / looked around for at runtime.
|
||||||
import type {
|
import type {
|
||||||
AppUpdateInfo,
|
AppUpdate,
|
||||||
ElectronFile,
|
ElectronFile,
|
||||||
FolderWatch,
|
FolderWatch,
|
||||||
PendingUploads,
|
PendingUploads,
|
||||||
|
@ -77,12 +77,12 @@ const onMainWindowFocus = (cb?: () => void) => {
|
||||||
// - App update
|
// - App update
|
||||||
|
|
||||||
const onAppUpdateAvailable = (
|
const onAppUpdateAvailable = (
|
||||||
cb?: ((updateInfo: AppUpdateInfo) => void) | undefined,
|
cb?: ((update: AppUpdate) => void) | undefined,
|
||||||
) => {
|
) => {
|
||||||
ipcRenderer.removeAllListeners("appUpdateAvailable");
|
ipcRenderer.removeAllListeners("appUpdateAvailable");
|
||||||
if (cb) {
|
if (cb) {
|
||||||
ipcRenderer.on("appUpdateAvailable", (_, updateInfo: AppUpdateInfo) =>
|
ipcRenderer.on("appUpdateAvailable", (_, update: AppUpdate) =>
|
||||||
cb(updateInfo),
|
cb(update),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
* See [Note: types.ts <-> preload.ts <-> ipc.ts]
|
* See [Note: types.ts <-> preload.ts <-> ipc.ts]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export interface AppUpdate {
|
||||||
|
autoUpdatable: boolean;
|
||||||
|
version: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface FolderWatch {
|
export interface FolderWatch {
|
||||||
rootFolderName: string;
|
rootFolderName: string;
|
||||||
uploadStrategy: number;
|
uploadStrategy: number;
|
||||||
|
@ -20,9 +25,7 @@ export interface FolderWatchSyncedFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PendingUploads {
|
export interface PendingUploads {
|
||||||
/** The collection to which we're uploading */
|
|
||||||
collectionName: string;
|
collectionName: string;
|
||||||
/* The upload can be either of a Google Takeout zip, or regular files */
|
|
||||||
type: "files" | "zips";
|
type: "files" | "zips";
|
||||||
files: ElectronFile[];
|
files: ElectronFile[];
|
||||||
}
|
}
|
||||||
|
@ -73,14 +76,3 @@ export interface ElectronFile {
|
||||||
blob: () => Promise<Blob>;
|
blob: () => Promise<Blob>;
|
||||||
arrayBuffer: () => Promise<Uint8Array>;
|
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,
|
logStartupBanner,
|
||||||
logUnhandledErrorsAndRejections,
|
logUnhandledErrorsAndRejections,
|
||||||
} from "@/next/log-web";
|
} from "@/next/log-web";
|
||||||
import { AppUpdateInfo } from "@/next/types/ipc";
|
import { AppUpdate } from "@/next/types/ipc";
|
||||||
import {
|
import {
|
||||||
APPS,
|
APPS,
|
||||||
APP_TITLES,
|
APP_TITLES,
|
||||||
|
@ -160,9 +160,9 @@ export default function App({ Component, pageProps }: AppProps) {
|
||||||
const electron = globalThis.electron;
|
const electron = globalThis.electron;
|
||||||
if (!electron) return;
|
if (!electron) return;
|
||||||
|
|
||||||
const showUpdateDialog = (updateInfo: AppUpdateInfo) => {
|
const showUpdateDialog = (update: AppUpdate) => {
|
||||||
if (updateInfo.autoUpdatable) {
|
if (update.autoUpdatable) {
|
||||||
setDialogMessage(getUpdateReadyToInstallMessage(updateInfo));
|
setDialogMessage(getUpdateReadyToInstallMessage(update));
|
||||||
} else {
|
} else {
|
||||||
setNotificationAttributes({
|
setNotificationAttributes({
|
||||||
endIcon: <ArrowForward />,
|
endIcon: <ArrowForward />,
|
||||||
|
@ -170,7 +170,7 @@ export default function App({ Component, pageProps }: AppProps) {
|
||||||
message: t("UPDATE_AVAILABLE"),
|
message: t("UPDATE_AVAILABLE"),
|
||||||
onClick: () =>
|
onClick: () =>
|
||||||
setDialogMessage(
|
setDialogMessage(
|
||||||
getUpdateAvailableForDownloadMessage(updateInfo),
|
getUpdateAvailableForDownloadMessage(update),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { ensureElectron } from "@/next/electron";
|
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 { logoutUser } from "@ente/accounts/services/user";
|
||||||
import { DialogBoxAttributes } from "@ente/shared/components/DialogBox/types";
|
import { DialogBoxAttributes } from "@ente/shared/components/DialogBox/types";
|
||||||
import AutoAwesomeOutlinedIcon from "@mui/icons-material/AutoAwesomeOutlined";
|
import AutoAwesomeOutlinedIcon from "@mui/icons-material/AutoAwesomeOutlined";
|
||||||
|
@ -55,7 +55,7 @@ export const getTrashFileMessage = (deleteFileHelper): DialogBoxAttributes => ({
|
||||||
|
|
||||||
export const getUpdateReadyToInstallMessage = ({
|
export const getUpdateReadyToInstallMessage = ({
|
||||||
version,
|
version,
|
||||||
}: AppUpdateInfo): DialogBoxAttributes => ({
|
}: AppUpdate): DialogBoxAttributes => ({
|
||||||
icon: <AutoAwesomeOutlinedIcon />,
|
icon: <AutoAwesomeOutlinedIcon />,
|
||||||
title: t("UPDATE_AVAILABLE"),
|
title: t("UPDATE_AVAILABLE"),
|
||||||
content: t("UPDATE_INSTALLABLE_MESSAGE"),
|
content: t("UPDATE_INSTALLABLE_MESSAGE"),
|
||||||
|
@ -73,7 +73,7 @@ export const getUpdateReadyToInstallMessage = ({
|
||||||
|
|
||||||
export const getUpdateAvailableForDownloadMessage = ({
|
export const getUpdateAvailableForDownloadMessage = ({
|
||||||
version,
|
version,
|
||||||
}: AppUpdateInfo): DialogBoxAttributes => ({
|
}: AppUpdate): DialogBoxAttributes => ({
|
||||||
icon: <AutoAwesomeOutlinedIcon />,
|
icon: <AutoAwesomeOutlinedIcon />,
|
||||||
title: t("UPDATE_AVAILABLE"),
|
title: t("UPDATE_AVAILABLE"),
|
||||||
content: t("UPDATE_AVAILABLE_MESSAGE"),
|
content: t("UPDATE_AVAILABLE_MESSAGE"),
|
||||||
|
|
|
@ -5,11 +5,6 @@
|
||||||
|
|
||||||
import type { ElectronFile } from "./file";
|
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
|
* Extra APIs provided by our Node.js layer when our code is running inside our
|
||||||
* desktop (Electron) app.
|
* desktop (Electron) app.
|
||||||
|
@ -100,7 +95,7 @@ export interface Electron {
|
||||||
* Note: Setting a callback clears any previous callbacks.
|
* Note: Setting a callback clears any previous callbacks.
|
||||||
*/
|
*/
|
||||||
onAppUpdateAvailable: (
|
onAppUpdateAvailable: (
|
||||||
cb?: ((updateInfo: AppUpdateInfo) => void) | undefined,
|
cb?: ((update: AppUpdate) => void) | undefined,
|
||||||
) => void;
|
) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -378,6 +373,16 @@ export interface Electron {
|
||||||
getDirFiles: (dirPath: string) => Promise<ElectronFile[]>;
|
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.
|
* A top level folder that was selected by the user for watching.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue