implemented first version of the modular IPC system

This commit is contained in:
2025-11-17 18:00:04 +01:00
parent 4b72568ad3
commit 4dc53b9d5f
5 changed files with 149 additions and 18 deletions
+29 -1
View File
@@ -5,11 +5,39 @@ try {
onFileDrop: (file) => webUtils.getPathForFile(file) onFileDrop: (file) => webUtils.getPathForFile(file)
}) })
contextBridge.exposeInMainWorld("extractor", { contextBridge.exposeInMainWorld("extractor", {
extract: (file) => ipcRenderer.send("extract", file) extract: (file) => {
let q = // TODO get rid of this example code and have the actual json object be sent
{
video: {
module: "extraction-video-to-audio", // The name of the module, idk if we ever implement other extraction modules, the default one is extraction-video-to-audio
inputVideoPath: file.inputVideoPath, // See script.js on line 27 for an example of what this should look like
outputType: file.outputType // The file format to be used for the audio output file, such as wav, mp3, flac and so on
},
transcription:{
module: "String" // The module name of the transcription model you want to use
},
document:{
module: "String", // The module name of the AI model you want to use to create the document
styles: [ // An array of all the document styles/prompts you want to have the document be processed with
{
prompt: "String",
}
]
}
}
// ipcRenderer.send("file_submit", {module:"extraction-video-to-audio", parameter:file})
ipcRenderer.send("file_submit", q)
}
}) })
contextBridge.exposeInMainWorld("electronAPI", { contextBridge.exposeInMainWorld("electronAPI", {
getFilePath: (file) => {return webUtils.getPathForFile(file)} getFilePath: (file) => {return webUtils.getPathForFile(file)}
}) })
ipcRenderer.on("progress", (event, resp) => {
alert(`Finished step ${resp.curstep} of ${resp.totalsteps}`)
})
ipcRenderer.on("error", (event, err) => {alert(err)})
} catch (error) { } catch (error) {
console.log("Error in preload.js"); console.log("Error in preload.js");
} }
+87 -3
View File
@@ -60,7 +60,7 @@ let mainWindow;
function createWindow() { function createWindow() {
mainWindow = new electron.BrowserWindow({ mainWindow = new electron.BrowserWindow({
width: 800, width: 800,
height: 600, height: 800,
webPreferences: { webPreferences: {
nodeIntegration: false, nodeIntegration: false,
contextIsolation: true, contextIsolation: true,
@@ -74,6 +74,90 @@ function createWindow() {
electron.app.whenReady().then(createWindow); electron.app.whenReady().then(createWindow);
electron.ipcMain.on("extract", (event, args) => { // electron.ipcMain.on("extract", (event, args) => {
mapFunctions.get("extraction-video-to-audio").function(args) // mapFunctions.get("extraction-video-to-audio").function(args)
// })
// setTimeout(() => {
// mainWindow.webContents.send("fuck", "worked uwu")
// }, 5000);
electron.ipcMain.on("file_submit", async (event, args) => {
try {
let curstep = 0
let totalsteps = 2 + args.document.styles.length
if(args.document.styles.length == 0)
throw new Error("At least one Document Style needed");
console.log(args);
let audiopath = ""
let transcriptpath = ""
// This code handles the Video to Audio extraction module call
await mapFunctions.get("module-handler").function(args.video.module, {inputVideoPath: args.video.inputVideoPath, outputType: args.video.outputType}).then(resp => {
// console.log(resp);
audiopath = resp
curstep++
mainWindow.webContents.send("progress", {curstep:curstep, totalsteps:totalsteps})
}).catch(err => {
mainWindow.webContents.send("error", err)
return
})
// TODO implement transcription module
// // This code handles the Audio to Text transcription module call
// await mapFunctions.get("module-handler").function(args.transcription.module, audiopath).then(resp => {
// console.log(resp);
// transcriptpath = resp
// curstep++
// mainWindow.webContents.send("progress", {curstep:curstep, totalsteps:totalsteps})
// }).catch(err => {
// mainWindow.webContents.send("error", err)
// return
// })
// TODO implement documentation module
// // This code handles the Text to Document processing module call
// for (let i = 0; i < args.document.styles.length; i++) {
// await mapFunctions.get("module-handler").function(args.document.module, {prompt: args.document.styles[i].prompt, transcript: transcriptpath}).then(resp => {
// console.log(resp);
// transcriptpath = resp
// curstep++
// mainWindow.webContents.send("progress", {curstep:curstep, totalsteps:totalsteps})
// }).catch(err => {
// mainWindow.webContents.send("error", err)
// return
// })
// }
} catch (error) {
console.log(error);
}
}) })
let q =
{
video: {
module: "String", // The name of the module, idk if we ever implement other extraction modules, the default one is extraction-video-to-audio
inputVideoPath: "String", // See script.js on line 27 for an example of what this should look like
outputType: "String" // The file format to be used for the audio output file, such as wav, mp3, flac and so on
},
transcription:{
module: "String" // The module name of the transcription model you want to use
},
document:{
module: "String", // The module name of the AI model you want to use to create the document
styles: [ // An array of all the document styles/prompts you want to have the document be processed with
{
prompt: "String",
}
]
}
}
@@ -32,11 +32,11 @@ module.exports = {
hideCursor: true hideCursor: true
}); });
try { try {
// if (meta.url === `file://${process.argv[1]}`) { return new Promise((resolve, reject) => {
this.extractAudioFromVideo(parameter.inputVideoPath, progressBar, parameter.outputType) this.extractAudioFromVideo(parameter.inputVideoPath, progressBar, parameter.outputType)
.then(() => console.log('Audio extraction successful.')) .then((resp) => resolve(resp))
.catch((err) => console.error(err)); .catch((err) => console.error(err));
// } })
} catch (error) { } catch (error) {
console.log(parameter.outputType); console.log(parameter.outputType);
@@ -75,7 +75,7 @@ module.exports = {
progressBar.update(100, { timemark: 'done' }); progressBar.update(100, { timemark: 'done' });
progressBar.stop(); progressBar.stop();
console.log(`Extraction completed: ${outputAudioPath}`); console.log(`Extraction completed: ${outputAudioPath}`);
resolve(); resolve(outputAudioPath);
}) })
.on('error', (err) => { .on('error', (err) => {
progressBar.stop(); progressBar.stop();
+3
View File
@@ -9,5 +9,8 @@ module.exports = {
// mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./a.mp4", outputType:"wav"}) // mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./a.mp4", outputType:"wav"})
// mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./b.mp4", outputType:"wav"}) // mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./b.mp4", outputType:"wav"})
// mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./b.mp4", outputType:"flac"}) // mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./b.mp4", outputType:"flac"})
// mapFunctions.get("ipc-handler").function("extraction-video-to-audio", {inputVideoPath:"./a.mp4", outputType:"flac"})
} }
} }
@@ -0,0 +1,16 @@
module.exports = {
name:"module-handler", // Unique name for our function that will later be used to get the function from the map via "mapFunctions.get("example").function()"
async function(module,parameter){
return new Promise(async (resolve, reject) => {
if(mapFunctions.get(module) == undefined){
reject("requested modules not found")
return
}
mapFunctions.get(module).function(parameter).then((result) => {
resolve(result)
}).catch((err) => {
reject(err)
});
})
}
}