Handle logout
This commit is contained in:
parent
11811053fa
commit
b82507f74c
5 changed files with 52 additions and 2 deletions
|
@ -69,6 +69,7 @@ import {
|
|||
watchUpdateIgnoredFiles,
|
||||
watchUpdateSyncedFiles,
|
||||
} from "./services/watch";
|
||||
import { clearConvertToMP4Results } from "./stream";
|
||||
|
||||
/**
|
||||
* Listen for IPC events sent/invoked by the renderer process, and route them to
|
||||
|
@ -108,6 +109,8 @@ export const attachIPCHandlers = () => {
|
|||
|
||||
ipcMain.on("clearStores", () => clearStores());
|
||||
|
||||
ipcMain.on("clearConvertToMP4Results", () => clearConvertToMP4Results());
|
||||
|
||||
ipcMain.handle("saveEncryptionKey", (_, encryptionKey: string) =>
|
||||
saveEncryptionKey(encryptionKey),
|
||||
);
|
||||
|
|
|
@ -42,13 +42,19 @@ export const registerStreamProtocol = () => {
|
|||
switch (host) {
|
||||
case "read":
|
||||
return handleRead(ensure(searchParams.get("path")));
|
||||
|
||||
case "read-zip":
|
||||
return handleReadZip(
|
||||
ensure(searchParams.get("zipPath")),
|
||||
ensure(searchParams.get("entryName")),
|
||||
);
|
||||
|
||||
case "write":
|
||||
return handleWrite(ensure(searchParams.get("path")), request);
|
||||
|
||||
case "convert-to-mp4":
|
||||
return handleConvertToMP4(searchParams.get("token"), request);
|
||||
|
||||
default:
|
||||
return new Response("", { status: 404 });
|
||||
}
|
||||
|
@ -209,4 +215,29 @@ const writeNodeStream = async (filePath: string, fileStream: Readable) => {
|
|||
*
|
||||
* See also: [Note: IPC streams]
|
||||
*/
|
||||
const convertToMP4 = (token?: string) => {};
|
||||
const handleConvertToMP4 = (token: string | undefined, request: Request) => {
|
||||
// try {
|
||||
// if (token) {
|
||||
// } else {
|
||||
// await writeStream(path, ensure(request.body));
|
||||
// return new Response("", { status: 200 });
|
||||
// }
|
||||
// } catch (e) {
|
||||
// log.error("Failed to handle convert-to-mp4 stream", e);
|
||||
// return new Response(`Failed to write stream: ${String(e)}`, {
|
||||
// status: 500,
|
||||
// });
|
||||
// }
|
||||
};
|
||||
|
||||
/**
|
||||
* A map from token to file paths for convert-to-mp4 requests that we have
|
||||
* received.
|
||||
*/
|
||||
const convertToMP4Results = new Map<string, string>();
|
||||
|
||||
/**
|
||||
* Clear any in-memory state for in-flight convert-to-mp4 requests. Meant to be
|
||||
* called during logout.
|
||||
*/
|
||||
export const clearConvertToMP4Results = () => convertToMP4Results.clear();
|
||||
|
|
|
@ -65,6 +65,9 @@ const selectDirectory = () => ipcRenderer.invoke("selectDirectory");
|
|||
|
||||
const clearStores = () => ipcRenderer.send("clearStores");
|
||||
|
||||
const clearConvertToMP4Results = () =>
|
||||
ipcRenderer.send("clearConvertToMP4Results");
|
||||
|
||||
const encryptionKey = () => ipcRenderer.invoke("encryptionKey");
|
||||
|
||||
const saveEncryptionKey = (encryptionKey: string) =>
|
||||
|
@ -308,6 +311,7 @@ contextBridge.exposeInMainWorld("electron", {
|
|||
openLogDirectory,
|
||||
selectDirectory,
|
||||
clearStores,
|
||||
clearConvertToMP4Results,
|
||||
encryptionKey,
|
||||
saveEncryptionKey,
|
||||
onMainWindowFocus,
|
||||
|
|
|
@ -47,6 +47,11 @@ export const logoutUser = async () => {
|
|||
} catch (e) {
|
||||
log.error("Ignoring error when resetting native folder watches", e);
|
||||
}
|
||||
try {
|
||||
await electron.clearConvertToMP4Results();
|
||||
} catch (e) {
|
||||
log.error("Ignoring error when clearing convert-to-mp4 results", e);
|
||||
}
|
||||
try {
|
||||
await electron.clearStores();
|
||||
} catch (e) {
|
||||
|
|
|
@ -67,10 +67,17 @@ export interface Electron {
|
|||
* Clear any stored data.
|
||||
*
|
||||
* This is a coarse single shot cleanup, meant for use in clearing any
|
||||
* Electron side state during logout.
|
||||
* persisted Electron side state during logout.
|
||||
*/
|
||||
clearStores: () => void;
|
||||
|
||||
/**
|
||||
* Clear an state corresponding to in-flight convert-to-mp4 requests.
|
||||
*
|
||||
* This is meant for use during logout.
|
||||
*/
|
||||
clearConvertToMP4Results: () => void;
|
||||
|
||||
/**
|
||||
* Return the previously saved encryption key from persistent safe storage.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue