mirror of
https://github.com/ente-io/ente.git
synced 2025-08-10 00:12:04 +00:00
Inline more into preload
This commit is contained in:
parent
81ba5379c9
commit
d3093809d6
@ -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 { initWatcher } from "./services/chokidar";
|
||||||
import { addAllowOriginHeader } from "./utils/cors";
|
import { addAllowOriginHeader } from "./utils/cors";
|
||||||
import { createWindow } from "./utils/createWindow";
|
import { createWindow } from "./utils/createWindow";
|
||||||
import { setupAppEventEmitter } from "./utils/events";
|
|
||||||
import setupIpcComs from "./utils/ipcComms";
|
import setupIpcComs from "./utils/ipcComms";
|
||||||
import {
|
import {
|
||||||
handleDockIconHideOnAutoLaunch,
|
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 = () => {
|
const main = () => {
|
||||||
setupLogging(isDev);
|
setupLogging(isDev);
|
||||||
|
|
||||||
|
@ -7,7 +7,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ipcMain } from "electron/main";
|
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 { checkExistsAndCreateDir, fsExists } from "./fs";
|
||||||
import { openDirectory, openLogDirectory } from "./general";
|
import { openDirectory, openLogDirectory } from "./general";
|
||||||
import { logToDisk } from "./log";
|
import { logToDisk } from "./log";
|
||||||
@ -45,4 +51,19 @@ export const attachIPCHandlers = () => {
|
|||||||
ipcMain.handle("checkExistsAndCreateDir", (_, dirPath) =>
|
ipcMain.handle("checkExistsAndCreateDir", (_, dirPath) =>
|
||||||
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 { getDirFiles } from "./api/fs";
|
||||||
import { convertToJPEG, generateImageThumbnail } from "./api/imageProcessor";
|
import { convertToJPEG, generateImageThumbnail } from "./api/imageProcessor";
|
||||||
import { getEncryptionKey, setEncryptionKey } from "./api/safeStorage";
|
import { getEncryptionKey, setEncryptionKey } from "./api/safeStorage";
|
||||||
import {
|
|
||||||
registerForegroundEventListener,
|
|
||||||
registerUpdateEventListener,
|
|
||||||
} from "./api/system";
|
|
||||||
import {
|
import {
|
||||||
getElectronFilesFromGoogleZip,
|
getElectronFilesFromGoogleZip,
|
||||||
getPendingUploads,
|
getPendingUploads,
|
||||||
@ -100,6 +96,47 @@ const fsExists = (path: string): Promise<boolean> =>
|
|||||||
const checkExistsAndCreateDir = (dirPath: string): Promise<void> =>
|
const checkExistsAndCreateDir = (dirPath: string): Promise<void> =>
|
||||||
ipcRenderer.invoke("checkExistsAndCreateDir", dirPath);
|
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
|
// - FIXME below this
|
||||||
|
|
||||||
/* preload: duplicated logError */
|
/* 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
|
// These objects exposed here will become available to the JS code in our
|
||||||
@ -426,6 +445,8 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
|
|||||||
// General
|
// General
|
||||||
appVersion,
|
appVersion,
|
||||||
openDirectory,
|
openDirectory,
|
||||||
|
registerForegroundEventListener,
|
||||||
|
clearElectronStore,
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
openLogDirectory,
|
openLogDirectory,
|
||||||
@ -435,6 +456,7 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
|
|||||||
updateAndRestart,
|
updateAndRestart,
|
||||||
skipAppUpdate,
|
skipAppUpdate,
|
||||||
muteUpdateNotification,
|
muteUpdateNotification,
|
||||||
|
registerUpdateEventListener,
|
||||||
|
|
||||||
// - FS
|
// - FS
|
||||||
fs: {
|
fs: {
|
||||||
@ -450,7 +472,6 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
|
|||||||
saveFileToDisk,
|
saveFileToDisk,
|
||||||
|
|
||||||
selectDirectory,
|
selectDirectory,
|
||||||
clearElectronStore,
|
|
||||||
readTextFile,
|
readTextFile,
|
||||||
showUploadFilesDialog,
|
showUploadFilesDialog,
|
||||||
showUploadDirsDialog,
|
showUploadDirsDialog,
|
||||||
@ -470,11 +491,9 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
|
|||||||
updateWatchMappingSyncedFiles,
|
updateWatchMappingSyncedFiles,
|
||||||
updateWatchMappingIgnoredFiles,
|
updateWatchMappingIgnoredFiles,
|
||||||
convertToJPEG,
|
convertToJPEG,
|
||||||
registerUpdateEventListener,
|
|
||||||
|
|
||||||
runFFmpegCmd,
|
runFFmpegCmd,
|
||||||
generateImageThumbnail,
|
generateImageThumbnail,
|
||||||
registerForegroundEventListener,
|
|
||||||
moveFile,
|
moveFile,
|
||||||
deleteFolder,
|
deleteFolder,
|
||||||
rename,
|
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,
|
Tray,
|
||||||
} from "electron";
|
} from "electron";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { clearElectronStore } from "../api/electronStore";
|
|
||||||
import { attachIPCHandlers } from "../main/ipc";
|
import { attachIPCHandlers } from "../main/ipc";
|
||||||
import {
|
import {
|
||||||
muteUpdateNotification,
|
muteUpdateNotification,
|
||||||
@ -88,43 +87,10 @@ export default function setupIpcComs(
|
|||||||
return safeStorage.decryptString(message);
|
return safeStorage.decryptString(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on("clear-electron-store", () => {
|
|
||||||
clearElectronStore();
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.handle("convert-to-jpeg", (_, fileData, filename) => {
|
ipcMain.handle("convert-to-jpeg", (_, fileData, filename) => {
|
||||||
return convertToJPEG(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(
|
ipcMain.handle(
|
||||||
"run-ffmpeg-cmd",
|
"run-ffmpeg-cmd",
|
||||||
(_, cmd, inputFilePath, outputFileName, dontTimeout) => {
|
(_, cmd, inputFilePath, outputFileName, dontTimeout) => {
|
||||||
|
@ -79,8 +79,22 @@ export interface ElectronAPIsType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** TODO: AUDIT below this */
|
/** TODO: AUDIT below this */
|
||||||
|
// - General
|
||||||
|
registerForegroundEventListener: (onForeground: () => void) => void;
|
||||||
|
clearElectronStore: () => void;
|
||||||
|
|
||||||
|
// - FS legacy
|
||||||
checkExistsAndCreateDir: (dirPath: string) => Promise<void>;
|
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 */
|
/** TODO: FIXME or migrate below this */
|
||||||
saveStreamToDisk: (
|
saveStreamToDisk: (
|
||||||
path: string,
|
path: string,
|
||||||
@ -127,31 +141,24 @@ export interface ElectronAPIsType {
|
|||||||
removeFolder: (folderPath: string) => Promise<void>,
|
removeFolder: (folderPath: string) => Promise<void>,
|
||||||
) => void;
|
) => void;
|
||||||
isFolder: (dirPath: string) => Promise<boolean>;
|
isFolder: (dirPath: string) => Promise<boolean>;
|
||||||
clearElectronStore: () => void;
|
|
||||||
setEncryptionKey: (encryptionKey: string) => Promise<void>;
|
setEncryptionKey: (encryptionKey: string) => Promise<void>;
|
||||||
getEncryptionKey: () => Promise<string>;
|
getEncryptionKey: () => Promise<string>;
|
||||||
convertToJPEG: (
|
convertToJPEG: (
|
||||||
fileData: Uint8Array,
|
fileData: Uint8Array,
|
||||||
filename: string,
|
filename: string,
|
||||||
) => Promise<Uint8Array>;
|
) => Promise<Uint8Array>;
|
||||||
registerUpdateEventListener: (
|
|
||||||
showUpdateDialog: (updateInfo: AppUpdateInfo) => void,
|
|
||||||
) => void;
|
|
||||||
updateAndRestart: () => void;
|
|
||||||
skipAppUpdate: (version: string) => void;
|
|
||||||
runFFmpegCmd: (
|
runFFmpegCmd: (
|
||||||
cmd: string[],
|
cmd: string[],
|
||||||
inputFile: File | ElectronFile,
|
inputFile: File | ElectronFile,
|
||||||
outputFileName: string,
|
outputFileName: string,
|
||||||
dontTimeout?: boolean,
|
dontTimeout?: boolean,
|
||||||
) => Promise<File>;
|
) => Promise<File>;
|
||||||
muteUpdateNotification: (version: string) => void;
|
|
||||||
generateImageThumbnail: (
|
generateImageThumbnail: (
|
||||||
inputFile: File | ElectronFile,
|
inputFile: File | ElectronFile,
|
||||||
maxDimension: number,
|
maxDimension: number,
|
||||||
maxSize: number,
|
maxSize: number,
|
||||||
) => Promise<Uint8Array>;
|
) => Promise<Uint8Array>;
|
||||||
registerForegroundEventListener: (onForeground: () => void) => void;
|
|
||||||
moveFile: (oldPath: string, newPath: string) => Promise<void>;
|
moveFile: (oldPath: string, newPath: string) => Promise<void>;
|
||||||
deleteFolder: (path: string) => Promise<void>;
|
deleteFolder: (path: string) => Promise<void>;
|
||||||
deleteFile: (path: string) => Promise<void>;
|
deleteFile: (path: string) => Promise<void>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user