Inline more into preload
This commit is contained in:
parent
81ba5379c9
commit
d3093809d6
7 changed files with 89 additions and 95 deletions
|
@ -1,18 +0,0 @@
|
|||
import { ipcRenderer } from "electron";
|
||||
import { AppUpdateInfo } from "../types";
|
||||
|
||||
export const registerUpdateEventListener = (
|
||||
showUpdateDialog: (updateInfo: AppUpdateInfo) => void,
|
||||
) => {
|
||||
ipcRenderer.removeAllListeners("show-update-dialog");
|
||||
ipcRenderer.on("show-update-dialog", (_, updateInfo: AppUpdateInfo) => {
|
||||
showUpdateDialog(updateInfo);
|
||||
});
|
||||
};
|
||||
|
||||
export const registerForegroundEventListener = (onForeground: () => void) => {
|
||||
ipcRenderer.removeAllListeners("app-in-foreground");
|
||||
ipcRenderer.on("app-in-foreground", () => {
|
||||
onForeground();
|
||||
});
|
||||
};
|
|
@ -19,7 +19,7 @@ import { logErrorSentry, setupLogging } from "./main/log";
|
|||
import { initWatcher } from "./services/chokidar";
|
||||
import { addAllowOriginHeader } from "./utils/cors";
|
||||
import { createWindow } from "./utils/createWindow";
|
||||
import { setupAppEventEmitter } from "./utils/events";
|
||||
|
||||
import setupIpcComs from "./utils/ipcComms";
|
||||
import {
|
||||
handleDockIconHideOnAutoLaunch,
|
||||
|
@ -127,6 +127,13 @@ const deleteLegacyDiskCacheDirIfExists = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
function setupAppEventEmitter(mainWindow: BrowserWindow) {
|
||||
// fire event when mainWindow is in foreground
|
||||
mainWindow.on("focus", () => {
|
||||
mainWindow.webContents.send("app-in-foreground");
|
||||
});
|
||||
}
|
||||
|
||||
const main = () => {
|
||||
setupLogging(isDev);
|
||||
|
||||
|
|
|
@ -7,7 +7,13 @@
|
|||
*/
|
||||
|
||||
import { ipcMain } from "electron/main";
|
||||
import { appVersion } from "../services/appUpdater";
|
||||
import { clearElectronStore } from "../api/electronStore";
|
||||
import {
|
||||
appVersion,
|
||||
muteUpdateNotification,
|
||||
skipAppUpdate,
|
||||
updateAndRestart,
|
||||
} from "../services/appUpdater";
|
||||
import { checkExistsAndCreateDir, fsExists } from "./fs";
|
||||
import { openDirectory, openLogDirectory } from "./general";
|
||||
import { logToDisk } from "./log";
|
||||
|
@ -45,4 +51,19 @@ export const attachIPCHandlers = () => {
|
|||
ipcMain.handle("checkExistsAndCreateDir", (_, dirPath) =>
|
||||
checkExistsAndCreateDir(dirPath),
|
||||
);
|
||||
|
||||
ipcMain.on("clear-electron-store", (_) => {
|
||||
clearElectronStore();
|
||||
});
|
||||
|
||||
ipcMain.on("update-and-restart", (_) => {
|
||||
updateAndRestart();
|
||||
});
|
||||
ipcMain.on("skip-app-update", (_, version) => {
|
||||
skipAppUpdate(version);
|
||||
});
|
||||
|
||||
ipcMain.on("mute-update-notification", (_, version) => {
|
||||
muteUpdateNotification(version);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -35,10 +35,6 @@ import { runFFmpegCmd } from "./api/ffmpeg";
|
|||
import { getDirFiles } from "./api/fs";
|
||||
import { convertToJPEG, generateImageThumbnail } from "./api/imageProcessor";
|
||||
import { getEncryptionKey, setEncryptionKey } from "./api/safeStorage";
|
||||
import {
|
||||
registerForegroundEventListener,
|
||||
registerUpdateEventListener,
|
||||
} from "./api/system";
|
||||
import {
|
||||
getElectronFilesFromGoogleZip,
|
||||
getPendingUploads,
|
||||
|
@ -100,6 +96,47 @@ const fsExists = (path: string): Promise<boolean> =>
|
|||
const checkExistsAndCreateDir = (dirPath: string): Promise<void> =>
|
||||
ipcRenderer.invoke("checkExistsAndCreateDir", dirPath);
|
||||
|
||||
/* preload: duplicated */
|
||||
interface AppUpdateInfo {
|
||||
autoUpdatable: boolean;
|
||||
version: string;
|
||||
}
|
||||
|
||||
const registerUpdateEventListener = (
|
||||
showUpdateDialog: (updateInfo: AppUpdateInfo) => void,
|
||||
) => {
|
||||
ipcRenderer.removeAllListeners("show-update-dialog");
|
||||
ipcRenderer.on("show-update-dialog", (_, updateInfo: AppUpdateInfo) => {
|
||||
showUpdateDialog(updateInfo);
|
||||
});
|
||||
};
|
||||
|
||||
const registerForegroundEventListener = (onForeground: () => void) => {
|
||||
ipcRenderer.removeAllListeners("app-in-foreground");
|
||||
ipcRenderer.on("app-in-foreground", () => {
|
||||
onForeground();
|
||||
});
|
||||
};
|
||||
|
||||
const clearElectronStore = () => {
|
||||
ipcRenderer.send("clear-electron-store");
|
||||
};
|
||||
|
||||
// - App update
|
||||
|
||||
const updateAndRestart = () => {
|
||||
ipcRenderer.send("update-and-restart");
|
||||
};
|
||||
|
||||
const skipAppUpdate = (version: string) => {
|
||||
ipcRenderer.send("skip-app-update", version);
|
||||
};
|
||||
|
||||
const muteUpdateNotification = (version: string) => {
|
||||
ipcRenderer.send("mute-update-notification", version);
|
||||
};
|
||||
|
||||
|
||||
// - FIXME below this
|
||||
|
||||
/* preload: duplicated logError */
|
||||
|
@ -370,24 +407,6 @@ const selectDirectory = async (): Promise<string> => {
|
|||
}
|
||||
};
|
||||
|
||||
const clearElectronStore = () => {
|
||||
ipcRenderer.send("clear-electron-store");
|
||||
};
|
||||
|
||||
// - App update
|
||||
|
||||
const updateAndRestart = () => {
|
||||
ipcRenderer.send("update-and-restart");
|
||||
};
|
||||
|
||||
const skipAppUpdate = (version: string) => {
|
||||
ipcRenderer.send("skip-app-update", version);
|
||||
};
|
||||
|
||||
const muteUpdateNotification = (version: string) => {
|
||||
ipcRenderer.send("mute-update-notification", version);
|
||||
};
|
||||
|
||||
// -
|
||||
|
||||
// These objects exposed here will become available to the JS code in our
|
||||
|
@ -426,6 +445,8 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
|
|||
// General
|
||||
appVersion,
|
||||
openDirectory,
|
||||
registerForegroundEventListener,
|
||||
clearElectronStore,
|
||||
|
||||
// Logging
|
||||
openLogDirectory,
|
||||
|
@ -435,6 +456,7 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
|
|||
updateAndRestart,
|
||||
skipAppUpdate,
|
||||
muteUpdateNotification,
|
||||
registerUpdateEventListener,
|
||||
|
||||
// - FS
|
||||
fs: {
|
||||
|
@ -450,7 +472,6 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
|
|||
saveFileToDisk,
|
||||
|
||||
selectDirectory,
|
||||
clearElectronStore,
|
||||
readTextFile,
|
||||
showUploadFilesDialog,
|
||||
showUploadDirsDialog,
|
||||
|
@ -470,11 +491,9 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
|
|||
updateWatchMappingSyncedFiles,
|
||||
updateWatchMappingIgnoredFiles,
|
||||
convertToJPEG,
|
||||
registerUpdateEventListener,
|
||||
|
||||
runFFmpegCmd,
|
||||
generateImageThumbnail,
|
||||
registerForegroundEventListener,
|
||||
moveFile,
|
||||
deleteFolder,
|
||||
rename,
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
import { BrowserWindow } from "electron";
|
||||
|
||||
export function setupAppEventEmitter(mainWindow: BrowserWindow) {
|
||||
// fire event when mainWindow is in foreground
|
||||
mainWindow.on("focus", () => {
|
||||
mainWindow.webContents.send("app-in-foreground");
|
||||
});
|
||||
}
|
|
@ -9,7 +9,6 @@ import {
|
|||
Tray,
|
||||
} from "electron";
|
||||
import path from "path";
|
||||
import { clearElectronStore } from "../api/electronStore";
|
||||
import { attachIPCHandlers } from "../main/ipc";
|
||||
import {
|
||||
muteUpdateNotification,
|
||||
|
@ -88,43 +87,10 @@ export default function setupIpcComs(
|
|||
return safeStorage.decryptString(message);
|
||||
});
|
||||
|
||||
ipcMain.on("clear-electron-store", () => {
|
||||
clearElectronStore();
|
||||
});
|
||||
|
||||
ipcMain.handle("convert-to-jpeg", (_, fileData, filename) => {
|
||||
return convertToJPEG(fileData, filename);
|
||||
});
|
||||
|
||||
ipcMain.handle("open-log-dir", () => {
|
||||
// [Note: Electron app paths]
|
||||
//
|
||||
// By default, these paths are at the following locations:
|
||||
//
|
||||
// * macOS: `~/Library/Application Support/ente`
|
||||
// * Linux: `~/.config/ente`
|
||||
// * Windows: `%APPDATA%`, e.g. `C:\Users\<username>\AppData\Local\ente`
|
||||
// * Windows: C:\Users\<you>\AppData\Local\<Your App Name>
|
||||
//
|
||||
// https://www.electronjs.org/docs/latest/api/app
|
||||
shell.openPath(app.getPath("logs"));
|
||||
});
|
||||
|
||||
ipcMain.handle("open-dir", (_, dirPath) => {
|
||||
shell.openPath(path.normalize(dirPath));
|
||||
});
|
||||
|
||||
ipcMain.on("update-and-restart", () => {
|
||||
updateAndRestart();
|
||||
});
|
||||
ipcMain.on("skip-app-update", (_, version) => {
|
||||
skipAppUpdate(version);
|
||||
});
|
||||
|
||||
ipcMain.on("mute-update-notification", (_, version) => {
|
||||
muteUpdateNotification(version);
|
||||
});
|
||||
|
||||
ipcMain.handle(
|
||||
"run-ffmpeg-cmd",
|
||||
(_, cmd, inputFilePath, outputFileName, dontTimeout) => {
|
||||
|
|
|
@ -79,8 +79,22 @@ export interface ElectronAPIsType {
|
|||
};
|
||||
|
||||
/** TODO: AUDIT below this */
|
||||
// - General
|
||||
registerForegroundEventListener: (onForeground: () => void) => void;
|
||||
clearElectronStore: () => void;
|
||||
|
||||
// - FS legacy
|
||||
checkExistsAndCreateDir: (dirPath: string) => Promise<void>;
|
||||
|
||||
// - App update
|
||||
updateAndRestart: () => void;
|
||||
skipAppUpdate: (version: string) => void;
|
||||
muteUpdateNotification: (version: string) => void;
|
||||
|
||||
registerUpdateEventListener: (
|
||||
showUpdateDialog: (updateInfo: AppUpdateInfo) => void,
|
||||
) => void;
|
||||
|
||||
/** TODO: FIXME or migrate below this */
|
||||
saveStreamToDisk: (
|
||||
path: string,
|
||||
|
@ -127,31 +141,24 @@ export interface ElectronAPIsType {
|
|||
removeFolder: (folderPath: string) => Promise<void>,
|
||||
) => void;
|
||||
isFolder: (dirPath: string) => Promise<boolean>;
|
||||
clearElectronStore: () => void;
|
||||
setEncryptionKey: (encryptionKey: string) => Promise<void>;
|
||||
getEncryptionKey: () => Promise<string>;
|
||||
convertToJPEG: (
|
||||
fileData: Uint8Array,
|
||||
filename: string,
|
||||
) => Promise<Uint8Array>;
|
||||
registerUpdateEventListener: (
|
||||
showUpdateDialog: (updateInfo: AppUpdateInfo) => void,
|
||||
) => void;
|
||||
updateAndRestart: () => void;
|
||||
skipAppUpdate: (version: string) => void;
|
||||
runFFmpegCmd: (
|
||||
cmd: string[],
|
||||
inputFile: File | ElectronFile,
|
||||
outputFileName: string,
|
||||
dontTimeout?: boolean,
|
||||
) => Promise<File>;
|
||||
muteUpdateNotification: (version: string) => void;
|
||||
|
||||
generateImageThumbnail: (
|
||||
inputFile: File | ElectronFile,
|
||||
maxDimension: number,
|
||||
maxSize: number,
|
||||
) => Promise<Uint8Array>;
|
||||
registerForegroundEventListener: (onForeground: () => void) => void;
|
||||
moveFile: (oldPath: string, newPath: string) => Promise<void>;
|
||||
deleteFolder: (path: string) => Promise<void>;
|
||||
deleteFile: (path: string) => Promise<void>;
|
||||
|
|
Loading…
Add table
Reference in a new issue