Add isTest to settings and ability to redirect to test env. Add rome/imex specific builds.
This commit is contained in:
2
src/env.d.ts
vendored
2
src/env.d.ts
vendored
@@ -3,6 +3,8 @@
|
||||
export interface ImportMetaEnv {
|
||||
readonly VITE_FIREBASE_CONFIG: string;
|
||||
readonly VITE_GRAPHQL_ENDPOINT: string;
|
||||
readonly VITE_FIREBASE_CONFIG_TEST: string;
|
||||
readonly VITE_GRAPHQL_ENDPOINT_TEST: string;
|
||||
}
|
||||
|
||||
export interface ImportMeta {
|
||||
|
||||
@@ -3,6 +3,7 @@ import log from "electron-log/main";
|
||||
import { GraphQLClient, RequestMiddleware } from "graphql-request";
|
||||
import errorTypeCheck from "../../util/errorTypeCheck.js";
|
||||
import ipcTypes from "../../util/ipcTypes.json";
|
||||
import store from "../store/store.js";
|
||||
|
||||
const requestMiddleware: RequestMiddleware = async (request) => {
|
||||
const token = await getTokenFromRenderer();
|
||||
@@ -20,7 +21,9 @@ const requestMiddleware: RequestMiddleware = async (request) => {
|
||||
};
|
||||
|
||||
const client: GraphQLClient = new GraphQLClient(
|
||||
import.meta.env.VITE_GRAPHQL_ENDPOINT,
|
||||
store.get("app.isTest") || false
|
||||
? import.meta.env.VITE_GRAPHQL_ENDPOINT_TEST
|
||||
: import.meta.env.VITE_GRAPHQL_ENDPOINT,
|
||||
{
|
||||
requestMiddleware,
|
||||
},
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import { electronApp, is, optimizer } from "@electron-toolkit/utils";
|
||||
import Sentry from "@sentry/electron/main";
|
||||
import { app, BrowserWindow, Menu, nativeImage, shell, Tray } from "electron";
|
||||
import {
|
||||
app,
|
||||
BrowserWindow,
|
||||
globalShortcut,
|
||||
Menu,
|
||||
nativeImage,
|
||||
shell,
|
||||
Tray,
|
||||
} from "electron";
|
||||
import log from "electron-log/main";
|
||||
import { autoUpdater } from "electron-updater";
|
||||
import path, { join } from "path";
|
||||
@@ -138,6 +146,20 @@ function createWindow(): void {
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Connect to Test",
|
||||
checked: store.get("app.isTest") as boolean,
|
||||
visible: false,
|
||||
type: "checkbox",
|
||||
id: "toggleTest",
|
||||
click: (): void => {
|
||||
const currentSetting = store.get("app.isTest") as boolean;
|
||||
store.set("app.isTest", !currentSetting);
|
||||
log.info("Setting isTest to: ", !currentSetting);
|
||||
app.relaunch(); // Relaunch the app
|
||||
app.exit(0); // Exit the current instance
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// { role: 'windowMenu' }
|
||||
@@ -219,6 +241,23 @@ function createWindow(): void {
|
||||
const menu: Electron.Menu = Menu.buildFromTemplate(template);
|
||||
Menu.setApplicationMenu(menu);
|
||||
|
||||
// Register a global shortcut to show the hidden item
|
||||
globalShortcut.register("CommandOrControl+Shift+T", () => {
|
||||
console.log("Shortcut pressed! Revealing hidden item.");
|
||||
|
||||
// Update the menu to make the hidden item visible
|
||||
// Find the menu item dynamically by its id
|
||||
const fileMenu = template.find((item) => item.label === "Application");
|
||||
const hiddenItem = fileMenu?.submenu?.find(
|
||||
(item) => item.id === "toggleTest",
|
||||
);
|
||||
if (hiddenItem) {
|
||||
hiddenItem.visible = true; // Update the visibility dynamically
|
||||
const menu: Electron.Menu = Menu.buildFromTemplate(template);
|
||||
Menu.setApplicationMenu(menu);
|
||||
}
|
||||
});
|
||||
|
||||
// Store window properties for later
|
||||
const storeWindowState = (): void => {
|
||||
const [width, height] = mainWindow.getSize();
|
||||
@@ -388,7 +427,7 @@ app.on("before-quit", () => {
|
||||
openAtLogin: !currentSetting,
|
||||
});
|
||||
}
|
||||
|
||||
globalShortcut.unregisterAll();
|
||||
isAppQuitting = true;
|
||||
});
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ const store = new Store({
|
||||
y: undefined,
|
||||
},
|
||||
user: null,
|
||||
isTest: false,
|
||||
bodyshop: {},
|
||||
masterdata: {
|
||||
opcodes: null,
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { contextBridge } from "electron";
|
||||
import { electronAPI } from "@electron-toolkit/preload";
|
||||
import "electron-log/preload";
|
||||
import store from "../main/store/store";
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {};
|
||||
interface Api {
|
||||
isTest: () => boolean;
|
||||
}
|
||||
|
||||
const api: Api = {
|
||||
isTest: (): boolean => store.get("app.isTest") || false,
|
||||
};
|
||||
|
||||
// Use `contextBridge` APIs to expose Electron APIs to
|
||||
// renderer only if context isolation is enabled, otherwise
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { is } from "@electron-toolkit/utils";
|
||||
import { auth } from "@renderer/util/firebase";
|
||||
import { Layout, Menu } from "antd";
|
||||
import { Badge, Layout, Menu } from "antd";
|
||||
import { MenuItemType } from "antd/es/menu/interface";
|
||||
import { signOut } from "firebase/auth";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -18,25 +19,22 @@ const NavigationHeader: React.FC = () => {
|
||||
},
|
||||
},
|
||||
];
|
||||
const isTest = window.api.isTest();
|
||||
return (
|
||||
// <Badge.Ribbon
|
||||
// text={
|
||||
// isWatcherStarted
|
||||
// ? t("settings.labels.started")
|
||||
// : t("settings.labels.stopped")
|
||||
// }
|
||||
// color={isWatcherStarted ? "green" : "red"}
|
||||
// >
|
||||
<Layout.Header style={{ display: "flex", alignItems: "center" }}>
|
||||
<Menu
|
||||
theme="dark"
|
||||
mode="horizontal"
|
||||
defaultSelectedKeys={["2"]}
|
||||
items={menuItems}
|
||||
style={{ flex: 1, minWidth: 0 }}
|
||||
/>
|
||||
</Layout.Header>
|
||||
// </Badge.Ribbon>
|
||||
<Badge.Ribbon
|
||||
text={isTest && "Connected to Test Environment"}
|
||||
color={isTest && "red"}
|
||||
>
|
||||
<Layout.Header style={{ display: "flex", alignItems: "center" }}>
|
||||
<Menu
|
||||
theme="dark"
|
||||
mode="horizontal"
|
||||
defaultSelectedKeys={["2"]}
|
||||
items={menuItems}
|
||||
style={{ flex: 1, minWidth: 0 }}
|
||||
/>
|
||||
</Layout.Header>
|
||||
</Badge.Ribbon>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import SettingsWatcher from "./Settings.Watcher";
|
||||
import Welcome from "../Welcome/Welcome";
|
||||
|
||||
const Settings: React.FC = () => {
|
||||
console.log("is test?", window.api.isTest());
|
||||
return (
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={24}>
|
||||
|
||||
@@ -2,7 +2,11 @@ import { initializeApp } from "firebase/app";
|
||||
import { getAuth } from "firebase/auth";
|
||||
|
||||
// TODO: Replace the following with your app's Firebase project configuration
|
||||
const firebaseConfig = JSON.parse(import.meta.env.VITE_FIREBASE_CONFIG);
|
||||
const firebaseConfig = JSON.parse(
|
||||
window.api.isTest()
|
||||
? import.meta.env.VITE_FIREBASE_CONFIG_TEST
|
||||
: import.meta.env.VITE_FIREBASE_CONFIG,
|
||||
);
|
||||
|
||||
const app = initializeApp(firebaseConfig);
|
||||
export const auth = getAuth();
|
||||
|
||||
Reference in New Issue
Block a user