2022-04-15 14:56:13 +02:00
|
|
|
import * as antares from 'common/interfaces/antares';
|
2021-01-10 18:30:56 +01:00
|
|
|
import { ipcMain } from 'electron';
|
|
|
|
|
2023-09-13 19:21:08 +02:00
|
|
|
import { validateSender } from '../libs/misc/validateSender';
|
|
|
|
|
2024-01-19 18:03:20 +01:00
|
|
|
export default (connections: Record<string, antares.Client>) => {
|
2021-01-10 18:30:56 +01:00
|
|
|
ipcMain.handle('get-function-informations', async (event, params) => {
|
2023-09-13 19:21:08 +02:00
|
|
|
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };
|
|
|
|
|
2021-01-10 18:30:56 +01:00
|
|
|
try {
|
|
|
|
const result = await connections[params.uid].getFunctionInformations(params);
|
|
|
|
return { status: 'success', response: result };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.handle('drop-function', async (event, params) => {
|
2023-09-13 19:21:08 +02:00
|
|
|
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };
|
|
|
|
|
2021-01-10 18:30:56 +01:00
|
|
|
try {
|
|
|
|
await connections[params.uid].dropFunction(params);
|
|
|
|
return { status: 'success' };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.handle('alter-function', async (event, params) => {
|
2023-09-13 19:21:08 +02:00
|
|
|
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };
|
|
|
|
|
2021-01-10 18:30:56 +01:00
|
|
|
try {
|
|
|
|
await connections[params.uid].alterFunction(params);
|
|
|
|
return { status: 'success' };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-03 11:29:14 +02:00
|
|
|
ipcMain.handle('alter-trigger-function', async (event, params) => {
|
2023-09-13 19:21:08 +02:00
|
|
|
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };
|
|
|
|
|
2021-07-03 11:29:14 +02:00
|
|
|
try {
|
|
|
|
await connections[params.uid].alterTriggerFunction(params);
|
|
|
|
return { status: 'success' };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-10 18:30:56 +01:00
|
|
|
ipcMain.handle('create-function', async (event, params) => {
|
2023-09-13 19:21:08 +02:00
|
|
|
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };
|
|
|
|
|
2021-01-10 18:30:56 +01:00
|
|
|
try {
|
|
|
|
await connections[params.uid].createFunction(params);
|
|
|
|
return { status: 'success' };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
2021-07-03 11:29:14 +02:00
|
|
|
|
|
|
|
ipcMain.handle('create-trigger-function', async (event, params) => {
|
2023-09-13 19:21:08 +02:00
|
|
|
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };
|
|
|
|
|
2021-07-03 11:29:14 +02:00
|
|
|
try {
|
|
|
|
await connections[params.uid].createTriggerFunction(params);
|
|
|
|
return { status: 'success' };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
2021-01-10 18:30:56 +01:00
|
|
|
};
|