Add settings config.
This commit is contained in:
@@ -7,14 +7,10 @@ import ImportJob from "../decoder/decoder";
|
||||
import store from "../store/store";
|
||||
import { StartWatcher, StopWatcher } from "../watcher/watcher";
|
||||
import {
|
||||
getSetting,
|
||||
setSetting,
|
||||
SettingEmsOutFilePathGet,
|
||||
SettingEmsOutFilePathSet,
|
||||
SettingsPaintScaleInputConfigsGet,
|
||||
SettingsPaintScaleInputConfigsSet,
|
||||
SettingsPaintScaleInputPathSet,
|
||||
SettingsPaintScaleOutputConfigsGet,
|
||||
SettingsPaintScaleOutputConfigsSet,
|
||||
SettingsPaintScaleOutputPathSet,
|
||||
SettingsPpcFilePathGet,
|
||||
SettingsPpcFilePathSet,
|
||||
SettingsWatchedFilePathsAdd,
|
||||
@@ -92,6 +88,8 @@ ipcMain.handle(
|
||||
ipcTypes.toMain.settings.filepaths.remove,
|
||||
SettingsWatchedFilePathsRemove,
|
||||
);
|
||||
ipcMain.handle(ipcTypes.toMain.settings.get, getSetting);
|
||||
ipcMain.handle(ipcTypes.toMain.settings.set, setSetting);
|
||||
ipcMain.handle(
|
||||
ipcTypes.toMain.settings.watcher.getpolling,
|
||||
SettingsWatcherPollingGet,
|
||||
@@ -112,34 +110,6 @@ ipcMain.handle(
|
||||
SettingEmsOutFilePathSet,
|
||||
);
|
||||
|
||||
// Paint Scale Input Settings Handlers
|
||||
ipcMain.handle(
|
||||
ipcTypes.toMain.settings.paintScale.getInputConfigs,
|
||||
SettingsPaintScaleInputConfigsGet,
|
||||
);
|
||||
ipcMain.handle(
|
||||
ipcTypes.toMain.settings.paintScale.setInputConfigs,
|
||||
SettingsPaintScaleInputConfigsSet,
|
||||
);
|
||||
ipcMain.handle(
|
||||
ipcTypes.toMain.settings.paintScale.setInputPath,
|
||||
SettingsPaintScaleInputPathSet,
|
||||
);
|
||||
|
||||
// Paint Scale Output Settings Handlers
|
||||
ipcMain.handle(
|
||||
ipcTypes.toMain.settings.paintScale.getOutputConfigs,
|
||||
SettingsPaintScaleOutputConfigsGet,
|
||||
);
|
||||
ipcMain.handle(
|
||||
ipcTypes.toMain.settings.paintScale.setOutputConfigs,
|
||||
SettingsPaintScaleOutputConfigsSet,
|
||||
);
|
||||
ipcMain.handle(
|
||||
ipcTypes.toMain.settings.paintScale.setOutputPath,
|
||||
SettingsPaintScaleOutputPathSet,
|
||||
);
|
||||
|
||||
ipcMain.handle(ipcTypes.toMain.user.getActiveShop, () => {
|
||||
return store.get("app.bodyshop.shopname");
|
||||
});
|
||||
|
||||
@@ -10,7 +10,22 @@ import {
|
||||
StartWatcher,
|
||||
StopWatcher,
|
||||
} from "../watcher/watcher";
|
||||
import { PaintScaleConfig } from "../../util/types/paintScale";
|
||||
|
||||
const getSetting = async (
|
||||
_event: IpcMainInvokeEvent,
|
||||
key: string,
|
||||
): Promise<any> => {
|
||||
return Store.get(`settings.${key}`);
|
||||
};
|
||||
|
||||
const setSetting = async (
|
||||
_event: IpcMainInvokeEvent,
|
||||
key: string,
|
||||
value: any,
|
||||
): Promise<any> => {
|
||||
Store.set(`settings.${key}`, value);
|
||||
return Store.get(`settings.${key}`);
|
||||
};
|
||||
|
||||
// Initialize paint scale input configs in store if not set
|
||||
if (!Store.get("settings.paintScaleInputConfigs")) {
|
||||
@@ -130,35 +145,6 @@ const SettingEmsOutFilePathSet = async (): Promise<string> => {
|
||||
return (Store.get("settings.emsOutFilePath") as string) || "";
|
||||
};
|
||||
|
||||
const SettingsPaintScaleInputConfigsGet = (
|
||||
_event?: IpcMainInvokeEvent,
|
||||
): PaintScaleConfig[] => {
|
||||
try {
|
||||
const configs = Store.get(
|
||||
"settings.paintScaleInputConfigs",
|
||||
) as PaintScaleConfig[];
|
||||
log.debug("Retrieved paint scale input configs:", configs);
|
||||
return configs || [];
|
||||
} catch (error) {
|
||||
log.error("Error getting paint scale input configs:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const SettingsPaintScaleInputConfigsSet = async (
|
||||
_event: IpcMainInvokeEvent,
|
||||
configs: PaintScaleConfig[],
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
Store.set("settings.paintScaleInputConfigs", configs);
|
||||
log.debug("Saved paint scale input configs:", configs);
|
||||
return true;
|
||||
} catch (error) {
|
||||
log.error("Error setting paint scale input configs:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const SettingsPaintScaleInputPathSet = async (
|
||||
_event: IpcMainInvokeEvent,
|
||||
): Promise<string | null> => {
|
||||
@@ -184,35 +170,6 @@ const SettingsPaintScaleInputPathSet = async (
|
||||
}
|
||||
};
|
||||
|
||||
const SettingsPaintScaleOutputConfigsGet = (
|
||||
_event?: IpcMainInvokeEvent,
|
||||
): PaintScaleConfig[] => {
|
||||
try {
|
||||
const configs = Store.get(
|
||||
"settings.paintScaleOutputConfigs",
|
||||
) as PaintScaleConfig[];
|
||||
log.debug("Retrieved paint scale output configs:", configs);
|
||||
return configs || [];
|
||||
} catch (error) {
|
||||
log.error("Error getting paint scale output configs:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const SettingsPaintScaleOutputConfigsSet = async (
|
||||
_event: IpcMainInvokeEvent,
|
||||
configs: PaintScaleConfig[],
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
Store.set("settings.paintScaleOutputConfigs", configs);
|
||||
log.debug("Saved paint scale output configs:", configs);
|
||||
return true;
|
||||
} catch (error) {
|
||||
log.error("Error setting paint scale output configs:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const SettingsPaintScaleOutputPathSet = async (
|
||||
_event: IpcMainInvokeEvent,
|
||||
): Promise<string | null> => {
|
||||
@@ -248,10 +205,8 @@ export {
|
||||
SettingsWatcherPollingSet,
|
||||
SettingEmsOutFilePathGet,
|
||||
SettingEmsOutFilePathSet,
|
||||
SettingsPaintScaleInputConfigsGet,
|
||||
SettingsPaintScaleInputConfigsSet,
|
||||
SettingsPaintScaleInputPathSet,
|
||||
SettingsPaintScaleOutputConfigsGet,
|
||||
SettingsPaintScaleOutputConfigsSet,
|
||||
SettingsPaintScaleOutputPathSet,
|
||||
getSetting,
|
||||
setSetting,
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ const store = new Store({
|
||||
enabled: false,
|
||||
interval: 30000,
|
||||
},
|
||||
esApiKey: "",
|
||||
},
|
||||
app: {
|
||||
windowBounds: {
|
||||
|
||||
77
src/renderer/src/components/Settings/Settings.Config.tsx
Normal file
77
src/renderer/src/components/Settings/Settings.Config.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
import { Card, Form, Input } from "antd";
|
||||
import { FC, useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import ipcTypes from "../../../../util/ipcTypes.json";
|
||||
|
||||
const SettingsConfig: FC = () => {
|
||||
const { t } = useTranslation();
|
||||
const [form] = Form.useForm();
|
||||
|
||||
const settingFields = [
|
||||
{
|
||||
name: "esApiKey",
|
||||
label: t("settings.labels.esApiKey"),
|
||||
component: Input,
|
||||
hasFeedback: true,
|
||||
componentProps: {},
|
||||
},
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
settingFields.forEach((field) => {
|
||||
window.electron.ipcRenderer
|
||||
.invoke(ipcTypes.toMain.settings.get, field.name)
|
||||
.then((value: any) => {
|
||||
form.setFieldsValue({ [field.name]: value });
|
||||
});
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleFieldChange = (changedFields: any): void => {
|
||||
changedFields.forEach((field) => {
|
||||
const fieldName = field.name[0];
|
||||
const { value } = field;
|
||||
|
||||
// Placeholder for validation
|
||||
const isValid = validateField(fieldName, value);
|
||||
if (isValid) {
|
||||
window.electron.ipcRenderer.invoke(
|
||||
ipcTypes.toMain.settings.set,
|
||||
fieldName,
|
||||
value,
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const validateField = (fieldName: string, value: any): boolean => {
|
||||
// Placeholder for actual validation logic
|
||||
console.log(`Validating ${fieldName}:`, value);
|
||||
return true;
|
||||
};
|
||||
|
||||
return (
|
||||
<Card title={t("settings.labels.config")}>
|
||||
<Form form={form} onFieldsChange={handleFieldChange} layout="vertical">
|
||||
{settingFields.map((field) => (
|
||||
<Form.Item
|
||||
key={field.name}
|
||||
label={t(`settings.labels.${field.name}`, field.label)}
|
||||
name={field.name}
|
||||
hasFeedback={field.hasFeedback}
|
||||
validateStatus="validating"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: t(`settings.validation.${field.name}Required`),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<field.component {...field.componentProps} />
|
||||
</Form.Item>
|
||||
))}
|
||||
</Form>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
export default SettingsConfig;
|
||||
@@ -3,10 +3,10 @@ import { Col, Row } from "antd";
|
||||
import { FC } from "react";
|
||||
import SettingsWatchedPaths from "./Settings.WatchedPaths";
|
||||
import SettingsWatcher from "./Settings.Watcher";
|
||||
import SettingsConfig from "./Settings.Config";
|
||||
|
||||
const colSpans = {
|
||||
md: 12, // Two columns on medium screens and above
|
||||
sm: 24, // One column on small screens
|
||||
span: 24,
|
||||
};
|
||||
|
||||
const Settings: FC = () => {
|
||||
@@ -18,6 +18,9 @@ const Settings: FC = () => {
|
||||
<Col {...colSpans}>
|
||||
<SettingsWatcher />
|
||||
</Col>
|
||||
<Col {...colSpans}>
|
||||
<SettingsConfig />
|
||||
</Col>
|
||||
</Row>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -37,7 +37,9 @@
|
||||
"setOutputPath": "toMain_settings_paintScale_setOutputPath",
|
||||
"updateInputCron": "toMain_settings_paintScale_updateInputCron",
|
||||
"updateOutputCron": "toMain_settings_paintScale_updateOutputCron"
|
||||
}
|
||||
},
|
||||
"get": "toMain_settings_get",
|
||||
"set": "toMain_settings_set"
|
||||
},
|
||||
"user": {
|
||||
"getTokenResponse": "toMain_user_getTokenResponse",
|
||||
@@ -68,4 +70,4 @@
|
||||
"showErrorMessage": "toRenderer_general_showErrorMessage"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user