Add translations and testing framework.
This commit is contained in:
21
src/main/index.test.ts
Normal file
21
src/main/index.test.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { _electron as electron } from "playwright";
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
test("example test", async () => {
|
||||
const electronApp = await electron.launch({ args: ["."] });
|
||||
const isPackaged = await electronApp.evaluate(async ({ app }) => {
|
||||
// This runs in Electron's main process, parameter here is always
|
||||
// the result of the require('electron') in the main app script.
|
||||
return app.isPackaged;
|
||||
});
|
||||
|
||||
expect(isPackaged).toBe(false);
|
||||
|
||||
// Wait for the first BrowserWindow to open
|
||||
// and return its Page object
|
||||
const window = await electronApp.firstWindow();
|
||||
await window.screenshot({ path: "intro.png" });
|
||||
|
||||
// close app
|
||||
await electronApp.close();
|
||||
});
|
||||
@@ -4,7 +4,8 @@ import log from "electron-log/main";
|
||||
import { join } from "path";
|
||||
import icon from "../../resources/icon.png?asset";
|
||||
import ErrorTypeCheck from "../util/errorTypeCheck";
|
||||
|
||||
import "./store/store";
|
||||
log.initialize();
|
||||
function createWindow(): void {
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
|
||||
@@ -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 };
|
||||
@@ -8,6 +8,7 @@ const store = new Store({
|
||||
enabled: false,
|
||||
pollingInterval: 30000,
|
||||
},
|
||||
user: null,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user