π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
logout
Manav Rathi79e048b4b738
diff --git a/desktop/src/main/services/logout.ts b/desktop/src/main/services/logout.tsindex 805eb6d109..14968ff24e 100644--- a/desktop/src/main/services/logout.ts+++ b/desktop/src/main/services/logout.ts@@ -3,6 +3,7 @@ import log from "../log";import { clearPendingVideoResults } from "../stream";import { clearStores } from "./store";import { watchReset } from "./watch";+import { terminateUtilityProcesses } from "./workers";import { clearOpenZipCache } from "./zip";/**@@ -36,4 +37,9 @@ export const logout = (watcher: FSWatcher) => {} catch (e) {ignoreError("zip cache", e);}+ try {+ terminateUtilityProcesses();+ } catch (e) {+ ignoreError("utility processes", e);+ }};diff --git a/desktop/src/main/services/workers.ts b/desktop/src/main/services/workers.tsindex ee6c5961ea..916292ceb6 100644--- a/desktop/src/main/services/workers.ts+++ b/desktop/src/main/services/workers.ts@@ -15,9 +15,22 @@ import type { UtilityProcessType } from "../../types/ipc";import log, { processUtilityProcessLogMessage } from "../log";import { messagePortMainEndpoint } from "../utils/comlink";+/**+ * Terminate any existing utility processes if they're running.+ *+ * This function is called during the logout sequence.+ */+export const terminateUtilityProcesses = () => {+ terminateMLProcessIfRunning();+ terminateFFmpegProcessIfRunning();+};+/** The active ML utility process, if any. */let _utilityProcessML: UtilityProcess | undefined;+/** The active FFmpeg utility process, if any. */+let _utilityProcessFFmpeg: UtilityProcess | undefined;+/*** A promise to a comlink {@link Endpoint} that can be used to communicate with* the active ffmpeg utility process (if any).@@ -92,12 +105,16 @@ export const triggerCreateUtilityProcess = (window: BrowserWindow,) => triggerCreateMLUtilityProcess(window);-export const triggerCreateMLUtilityProcess = (window: BrowserWindow) => {+const terminateMLProcessIfRunning = () => {if (_utilityProcessML) {- log.debug(() => "Terminating previous ML utility process");+ log.debug(() => "Terminating running ML utility process");_utilityProcessML.kill();_utilityProcessML = undefined;}+};++export const triggerCreateMLUtilityProcess = (window: BrowserWindow) => {+ terminateMLProcessIfRunning();const { port1, port2 } = new MessageChannelMain();@@ -173,7 +190,20 @@ const handleMessagesFromMLUtilityProcess = (child: UtilityProcess) => {export const ffmpegUtilityProcessEndpoint = () =>(_utilityProcessFFmpegEndpoint ??= createFFmpegUtilityProcessEndpoint());+const terminateFFmpegProcessIfRunning = () => {+ if (_utilityProcessFFmpeg) {+ log.debug(() => "Terminating running FFmpeg utility process");+ _utilityProcessFFmpeg.kill();+ _utilityProcessFFmpeg = undefined;+ _utilityProcessFFmpegEndpoint = undefined;+ }+};+const createFFmpegUtilityProcessEndpoint = () => {+ if (_utilityProcessFFmpeg) {+ throw new Error("FFmpeg utility process is already running");+ }+// Promise.withResolvers is currently in the node available to us.let resolve: ((endpoint: Endpoint) => void) | undefined;const promise = new Promise<Endpoint>((r) => (resolve = r));@@ -203,6 +233,8 @@ const createFFmpegUtilityProcessEndpoint = () => {log.info("Ignoring unknown message from ffmpeg utility process", m);});+ _utilityProcessFFmpeg = child;+// Resolve with the other end of the message channel (once we get an "ack"// from the utility process).return promise;