|
@@ -26,7 +26,7 @@ import { createWatcher } from "./main/services/watch";
|
|
|
import { userPreferences } from "./main/stores/user-preferences";
|
|
|
import { migrateLegacyWatchStoreIfNeeded } from "./main/stores/watch";
|
|
|
import { registerStreamProtocol } from "./main/stream";
|
|
|
-import { isDev } from "./main/utils-electron";
|
|
|
+import { isDev } from "./main/utils/electron";
|
|
|
|
|
|
/**
|
|
|
* The URL where the renderer HTML is being served from.
|
|
@@ -127,54 +127,22 @@ const registerPrivilegedSchemes = () => {
|
|
|
{
|
|
|
scheme: "stream",
|
|
|
privileges: {
|
|
|
- // TODO(MR): Remove the commented bits if we don't end up
|
|
|
- // needing them by the time the IPC refactoring is done.
|
|
|
-
|
|
|
- // Prevent the insecure origin issues when fetching this
|
|
|
- // secure: true,
|
|
|
- // Allow the web fetch API in the renderer to use this scheme.
|
|
|
supportFetchAPI: true,
|
|
|
- // Allow it to be used with video tags.
|
|
|
- // stream: true,
|
|
|
},
|
|
|
},
|
|
|
]);
|
|
|
};
|
|
|
|
|
|
-/**
|
|
|
- * [Note: Increased disk cache for the desktop app]
|
|
|
- *
|
|
|
- * Set the "disk-cache-size" command line flag to ask the Chromium process to
|
|
|
- * use a larger size for the caches that it keeps on disk. This allows us to use
|
|
|
- * the web based caching mechanisms on both the web and the desktop app, just
|
|
|
- * ask the embedded Chromium to be a bit more generous in disk usage when
|
|
|
- * running as the desktop app.
|
|
|
- *
|
|
|
- * The size we provide is in bytes.
|
|
|
- * https://www.electronjs.org/docs/latest/api/command-line-switches#--disk-cache-sizesize
|
|
|
- *
|
|
|
- * Note that increasing the disk cache size does not guarantee that Chromium
|
|
|
- * will respect in verbatim, it uses its own heuristics atop this hint.
|
|
|
- * https://superuser.com/questions/378991/what-is-chrome-default-cache-size-limit/1577693#1577693
|
|
|
- *
|
|
|
- * See also: [Note: Caching files].
|
|
|
- */
|
|
|
-const increaseDiskCache = () =>
|
|
|
- app.commandLine.appendSwitch(
|
|
|
- "disk-cache-size",
|
|
|
- `${5 * 1024 * 1024 * 1024}`, // 5 GB
|
|
|
- );
|
|
|
-
|
|
|
/**
|
|
|
* Create an return the {@link BrowserWindow} that will form our app's UI.
|
|
|
*
|
|
|
* This window will show the HTML served from {@link rendererURL}.
|
|
|
*/
|
|
|
-const createMainWindow = async () => {
|
|
|
+const createMainWindow = () => {
|
|
|
// Create the main window. This'll show our web content.
|
|
|
const window = new BrowserWindow({
|
|
|
webPreferences: {
|
|
|
- preload: path.join(app.getAppPath(), "preload.js"),
|
|
|
+ preload: path.join(__dirname, "preload.js"),
|
|
|
sandbox: true,
|
|
|
},
|
|
|
// The color to show in the window until the web content gets loaded.
|
|
@@ -184,7 +152,7 @@ const createMainWindow = async () => {
|
|
|
show: false,
|
|
|
});
|
|
|
|
|
|
- const wasAutoLaunched = await autoLauncher.wasAutoLaunched();
|
|
|
+ const wasAutoLaunched = autoLauncher.wasAutoLaunched();
|
|
|
if (wasAutoLaunched) {
|
|
|
// Don't automatically show the app's window if we were auto-launched.
|
|
|
// On macOS, also hide the dock icon on macOS.
|
|
@@ -198,7 +166,7 @@ const createMainWindow = async () => {
|
|
|
if (isDev) window.webContents.openDevTools();
|
|
|
|
|
|
window.webContents.on("render-process-gone", (_, details) => {
|
|
|
- log.error(`render-process-gone: ${details}`);
|
|
|
+ log.error(`render-process-gone: ${details.reason}`);
|
|
|
window.webContents.reload();
|
|
|
});
|
|
|
|
|
@@ -227,7 +195,7 @@ const createMainWindow = async () => {
|
|
|
});
|
|
|
|
|
|
window.on("show", () => {
|
|
|
- if (process.platform == "darwin") app.dock.show();
|
|
|
+ if (process.platform == "darwin") void app.dock.show();
|
|
|
});
|
|
|
|
|
|
// Let ipcRenderer know when mainWindow is in the foreground so that it can
|
|
@@ -281,7 +249,7 @@ export const allowExternalLinks = (webContents: WebContents) => {
|
|
|
// Returning `action` "deny" accomplishes this.
|
|
|
webContents.setWindowOpenHandler(({ url }) => {
|
|
|
if (!url.startsWith(rendererURL)) {
|
|
|
- shell.openExternal(url);
|
|
|
+ void shell.openExternal(url);
|
|
|
return { action: "deny" };
|
|
|
} else {
|
|
|
return { action: "allow" };
|
|
@@ -319,30 +287,46 @@ const setupTrayItem = (mainWindow: BrowserWindow) => {
|
|
|
|
|
|
/**
|
|
|
* Older versions of our app used to maintain a cache dir using the main
|
|
|
- * process. This has been deprecated in favor of using a normal web cache.
|
|
|
+ * process. This has been removed in favor of cache on the web layer.
|
|
|
+ *
|
|
|
+ * Delete the old cache dir if it exists.
|
|
|
+ *
|
|
|
+ * This will happen in two phases. The cache had three subdirectories:
|
|
|
+ *
|
|
|
+ * - Two of them, "thumbs" and "files", will be removed now (v1.7.0, May 2024).
|
|
|
*
|
|
|
- * See [Note: Increased disk cache for the desktop app]
|
|
|
+ * - The third one, "face-crops" will be removed once we finish the face search
|
|
|
+ * changes. See: [Note: Legacy face crops].
|
|
|
*
|
|
|
- * Delete the old cache dir if it exists. This code was added March 2024, and
|
|
|
- * can be removed after some time once most people have upgraded to newer
|
|
|
- * versions.
|
|
|
+ * This migration code can be removed after some time once most people have
|
|
|
+ * upgraded to newer versions.
|
|
|
*/
|
|
|
const deleteLegacyDiskCacheDirIfExists = async () => {
|
|
|
- // The existing code was passing "cache" as a parameter to getPath. This is
|
|
|
- // incorrect if we go by the types - "cache" is not a valid value for the
|
|
|
- // parameter to `app.getPath`.
|
|
|
+ const removeIfExists = async (dirPath: string) => {
|
|
|
+ if (existsSync(dirPath)) {
|
|
|
+ log.info(`Removing legacy disk cache from ${dirPath}`);
|
|
|
+ await fs.rm(dirPath, { recursive: true });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // [Note: Getting the cache path]
|
|
|
+ //
|
|
|
+ // The existing code was passing "cache" as a parameter to getPath.
|
|
|
//
|
|
|
- // It might be an issue in the types, since at runtime it seems to work. For
|
|
|
- // example, on macOS I get `~/Library/Caches`.
|
|
|
+ // However, "cache" is not a valid parameter to getPath. It works! (for
|
|
|
+ // example, on macOS I get `~/Library/Caches`), but it is intentionally not
|
|
|
+ // documented as part of the public API:
|
|
|
+ //
|
|
|
+ // - docs: remove "cache" from app.getPath
|
|
|
+ // https://github.com/electron/electron/pull/33509
|
|
|
//
|
|
|
// Irrespective, we replicate the original behaviour so that we get back the
|
|
|
- // same path that the old got was getting.
|
|
|
+ // same path that the old code was getting.
|
|
|
//
|
|
|
- // @ts-expect-error
|
|
|
+ // @ts-expect-error "cache" works but is not part of the public API.
|
|
|
const cacheDir = path.join(app.getPath("cache"), "ente");
|
|
|
if (existsSync(cacheDir)) {
|
|
|
- log.info(`Removing legacy disk cache from ${cacheDir}`);
|
|
|
- await fs.rm(cacheDir, { recursive: true });
|
|
|
+ await removeIfExists(path.join(cacheDir, "thumbs"));
|
|
|
+ await removeIfExists(path.join(cacheDir, "files"));
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -375,7 +359,6 @@ const main = () => {
|
|
|
// The order of the next two calls is important
|
|
|
setupRendererServer();
|
|
|
registerPrivilegedSchemes();
|
|
|
- increaseDiskCache();
|
|
|
migrateLegacyWatchStoreIfNeeded();
|
|
|
|
|
|
app.on("second-instance", () => {
|
|
@@ -390,39 +373,35 @@ const main = () => {
|
|
|
// Emitted once, when Electron has finished initializing.
|
|
|
//
|
|
|
// Note that some Electron APIs can only be used after this event occurs.
|
|
|
- app.on("ready", async () => {
|
|
|
- // Create window and prepare for the renderer.
|
|
|
- mainWindow = await createMainWindow();
|
|
|
- attachIPCHandlers();
|
|
|
- attachFSWatchIPCHandlers(createWatcher(mainWindow));
|
|
|
- registerStreamProtocol();
|
|
|
-
|
|
|
- // Configure the renderer's environment.
|
|
|
- setDownloadPath(mainWindow.webContents);
|
|
|
- allowExternalLinks(mainWindow.webContents);
|
|
|
-
|
|
|
- // TODO(MR): Remove or resurrect
|
|
|
- // The commit that introduced this header override had the message
|
|
|
- // "fix cors issue for uploads". Not sure what that means, so disabling
|
|
|
- // it for now to see why exactly this is required.
|
|
|
- // addAllowOriginHeader(mainWindow);
|
|
|
-
|
|
|
- // Start loading the renderer.
|
|
|
- mainWindow.loadURL(rendererURL);
|
|
|
-
|
|
|
- // Continue on with the rest of the startup sequence.
|
|
|
- Menu.setApplicationMenu(await createApplicationMenu(mainWindow));
|
|
|
- setupTrayItem(mainWindow);
|
|
|
- if (!isDev) setupAutoUpdater(mainWindow);
|
|
|
-
|
|
|
- try {
|
|
|
- deleteLegacyDiskCacheDirIfExists();
|
|
|
- deleteLegacyKeysStoreIfExists();
|
|
|
- } catch (e) {
|
|
|
- // Log but otherwise ignore errors during non-critical startup
|
|
|
- // actions.
|
|
|
- log.error("Ignoring startup error", e);
|
|
|
- }
|
|
|
+ void app.whenReady().then(() => {
|
|
|
+ void (async () => {
|
|
|
+ // Create window and prepare for the renderer.
|
|
|
+ mainWindow = createMainWindow();
|
|
|
+ attachIPCHandlers();
|
|
|
+ attachFSWatchIPCHandlers(createWatcher(mainWindow));
|
|
|
+ registerStreamProtocol();
|
|
|
+
|
|
|
+ // Configure the renderer's environment.
|
|
|
+ setDownloadPath(mainWindow.webContents);
|
|
|
+ allowExternalLinks(mainWindow.webContents);
|
|
|
+
|
|
|
+ // Start loading the renderer.
|
|
|
+ void mainWindow.loadURL(rendererURL);
|
|
|
+
|
|
|
+ // Continue on with the rest of the startup sequence.
|
|
|
+ Menu.setApplicationMenu(await createApplicationMenu(mainWindow));
|
|
|
+ setupTrayItem(mainWindow);
|
|
|
+ setupAutoUpdater(mainWindow);
|
|
|
+
|
|
|
+ try {
|
|
|
+ await deleteLegacyDiskCacheDirIfExists();
|
|
|
+ await deleteLegacyKeysStoreIfExists();
|
|
|
+ } catch (e) {
|
|
|
+ // Log but otherwise ignore errors during non-critical startup
|
|
|
+ // actions.
|
|
|
+ log.error("Ignoring startup error", e);
|
|
|
+ }
|
|
|
+ })();
|
|
|
});
|
|
|
|
|
|
// This is a macOS only event. Show our window when the user activates the
|