Minor bug fixes and CI change.
This commit is contained in:
@@ -41,6 +41,8 @@ function createWindow(): void {
|
||||
x,
|
||||
y,
|
||||
show: false,
|
||||
minWidth: 600,
|
||||
minHeight: 400,
|
||||
//autoHideMenuBar: true,
|
||||
...(process.platform === "linux" ? { icon } : {}),
|
||||
webPreferences: {
|
||||
|
||||
@@ -13,7 +13,10 @@ import {
|
||||
SettingsWatcherPollingGet,
|
||||
SettingsWatcherPollingSet,
|
||||
} from "./ipcMainHandler.settings";
|
||||
import { ipcMainHandleAuthStateChanged } from "./ipcMainHandler.user";
|
||||
import {
|
||||
ipcMainHandleAuthStateChanged,
|
||||
ipMainHandleResetPassword,
|
||||
} from "./ipcMainHandler.user";
|
||||
|
||||
// Log all IPC messages and their payloads
|
||||
const logIpcMessages = (): void => {
|
||||
@@ -47,6 +50,7 @@ ipcMain.on(ipcTypes.toMain.test, () =>
|
||||
|
||||
//Auth handler
|
||||
ipcMain.on(ipcTypes.toMain.authStateChanged, ipcMainHandleAuthStateChanged);
|
||||
ipcMain.on(ipcTypes.toMain.user.resetPassword, ipMainHandleResetPassword);
|
||||
|
||||
//Add debug handlers if in development
|
||||
if (import.meta.env.DEV) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IpcMainEvent } from "electron";
|
||||
import { IpcMainEvent, shell } from "electron";
|
||||
import log from "electron-log/main";
|
||||
import { autoUpdater } from "electron-updater";
|
||||
import { User } from "firebase/auth";
|
||||
@@ -10,39 +10,59 @@ import {
|
||||
QUERY_MASTERDATA_TYPED,
|
||||
} from "../graphql/queries";
|
||||
import Store from "../store/store";
|
||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||
import { sendIpcToRenderer } from "../util/toRenderer";
|
||||
import ipcTypes from "../../util/ipcTypes.json";
|
||||
|
||||
const ipcMainHandleAuthStateChanged = async (
|
||||
event: IpcMainEvent,
|
||||
_event: IpcMainEvent,
|
||||
user: User | null,
|
||||
): Promise<void> => {
|
||||
Store.set("user", user);
|
||||
try {
|
||||
//Need to query the currently active shop, and store the metadata as well.
|
||||
//Also need to query the OP Codes for decoding reference.
|
||||
const activeBodyshop: ActiveBodyshopQueryResult = await client.request(
|
||||
QUERY_ACTIVE_BODYSHOP_TYPED,
|
||||
);
|
||||
|
||||
//Need to query the currently active shop, and store the metadata as well.
|
||||
//Also need to query the OP Codes for decoding reference.
|
||||
const activeBodyshop: ActiveBodyshopQueryResult = await client.request(
|
||||
QUERY_ACTIVE_BODYSHOP_TYPED,
|
||||
);
|
||||
Store.set("app.bodyshop", activeBodyshop.bodyshops[0]);
|
||||
|
||||
Store.set("app.bodyshop", activeBodyshop.bodyshops[0]);
|
||||
const OpCodes: MasterdataQueryResult = await client.request(
|
||||
QUERY_MASTERDATA_TYPED,
|
||||
{
|
||||
key: `${activeBodyshop.bodyshops[0].region_config}_ciecaopcodes`,
|
||||
},
|
||||
);
|
||||
Store.set(
|
||||
"app.masterdata.opcodes",
|
||||
JSON.parse(OpCodes.masterdata[0]?.value),
|
||||
);
|
||||
log.debug("Received authentication state change from Renderer.", user);
|
||||
log.debug("Requery shop information & master data.");
|
||||
|
||||
const OpCodes: MasterdataQueryResult = await client.request(
|
||||
QUERY_MASTERDATA_TYPED,
|
||||
{
|
||||
key: `${activeBodyshop.bodyshops[0].region_config}_ciecaopcodes`,
|
||||
},
|
||||
);
|
||||
Store.set("app.masterdata.opcodes", JSON.parse(OpCodes.masterdata[0]?.value));
|
||||
log.debug("Received authentication state change from Renderer.", user);
|
||||
log.debug("Requery shop information & master data.");
|
||||
|
||||
//Check for updates
|
||||
const convCo = activeBodyshop.bodyshops[0].convenient_company;
|
||||
if (convCo === "alpha") {
|
||||
autoUpdater.channel = "alpha";
|
||||
} else if (convCo === "beta") {
|
||||
autoUpdater.channel = "beta";
|
||||
//Check for updates
|
||||
const convCo = activeBodyshop.bodyshops[0].convenient_company;
|
||||
if (convCo === "alpha") {
|
||||
autoUpdater.channel = "alpha";
|
||||
} else if (convCo === "beta") {
|
||||
autoUpdater.channel = "beta";
|
||||
}
|
||||
} catch (error) {
|
||||
log.error(
|
||||
"Error while querying active bodyshop or masterdata",
|
||||
errorTypeCheck(error),
|
||||
);
|
||||
sendIpcToRenderer(
|
||||
ipcTypes.toRenderer.general.showErrorMessage,
|
||||
"Error connecting to ImEX Online servers to get shop data. Please try again.",
|
||||
);
|
||||
}
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
};
|
||||
|
||||
export { ipcMainHandleAuthStateChanged };
|
||||
const ipMainHandleResetPassword = async (): Promise<void> => {
|
||||
shell.openExternal("https://imex.online/resetpassword");
|
||||
};
|
||||
|
||||
export { ipcMainHandleAuthStateChanged, ipMainHandleResetPassword };
|
||||
|
||||
21
src/main/util/toRenderer.ts
Normal file
21
src/main/util/toRenderer.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { BrowserWindow } from "electron";
|
||||
import log from "electron-log/main";
|
||||
|
||||
const getMainWindow = (): Electron.BrowserWindow => {
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0];
|
||||
return mainWindow;
|
||||
};
|
||||
|
||||
const sendIpcToRenderer = (ipcMessage: string, ...args: any[]): void => {
|
||||
const window = getMainWindow();
|
||||
if (window) {
|
||||
window.webContents.send(ipcMessage, ...args);
|
||||
} else {
|
||||
log.error(
|
||||
"Unable to find main window. Cannot send IPC message.",
|
||||
ipcMessage,
|
||||
args,
|
||||
);
|
||||
}
|
||||
};
|
||||
export { getMainWindow, sendIpcToRenderer };
|
||||
Reference in New Issue
Block a user