Add translations and testing framework.
This commit is contained in:
@@ -1,6 +1,38 @@
|
||||
import { ipcMain } from "electron";
|
||||
import ipcTypes from "../../util/ipcTypes.json";
|
||||
import log from "electron-log/main";
|
||||
import { ipcMainHandleAuthStateChanged } from "./ipcMainHandler.user";
|
||||
// Log all IPC messages and their payloads
|
||||
|
||||
const logIpcMessages = () => {
|
||||
// Get all message types from ipcTypes.toMain
|
||||
Object.keys(ipcTypes.toMain).forEach((key) => {
|
||||
const messageType = ipcTypes.toMain[key];
|
||||
|
||||
// Wrap the original handler with our logging
|
||||
const originalHandler = ipcMain.listeners(messageType)[0];
|
||||
if (originalHandler) {
|
||||
ipcMain.removeAllListeners(messageType);
|
||||
}
|
||||
ipcMain.on(messageType, (event, payload) => {
|
||||
log.info(
|
||||
`%c[IPC Main]%c${messageType}`,
|
||||
"color: red",
|
||||
"color: green",
|
||||
payload
|
||||
);
|
||||
// Call original handler if it existed
|
||||
if (originalHandler) {
|
||||
originalHandler(event, payload);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
ipcMain.on(ipcTypes.toMain.test, (payload: any) =>
|
||||
console.log("** Verify that ipcMain is loaded and working.", payload)
|
||||
);
|
||||
|
||||
ipcMain.on(ipcTypes.toMain.authStateChanged, ipcMainHandleAuthStateChanged);
|
||||
|
||||
logIpcMessages();
|
||||
|
||||
14
src/main/ipc/ipcMainHandler.user.ts
Normal file
14
src/main/ipc/ipcMainHandler.user.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { IpcMainEvent } from "electron";
|
||||
import Store from "../store/store";
|
||||
import { User } from "firebase/auth";
|
||||
import log from "electron-log/main";
|
||||
|
||||
const ipcMainHandleAuthStateChanged = async (
|
||||
event: IpcMainEvent,
|
||||
user: User | null
|
||||
) => {
|
||||
Store.set("user", user);
|
||||
log.log(Store.get("user"));
|
||||
};
|
||||
|
||||
export { ipcMainHandleAuthStateChanged };
|
||||
Reference in New Issue
Block a user