From 56599bfdb3e7da401acf9f33720937122dbf4a36 Mon Sep 17 00:00:00 2001 From: Modo Date: Thu, 26 Oct 2023 21:57:21 +0530 Subject: [PATCH] Setup childprocess --- backend/rest_api.py | 3 +++ backend/rest_api.spec | 37 ++++++++++++++++++++++++++++++++++++ frontend/main.js | 30 +++++++++++++++++++++++++++-- frontend/scripts/register.js | 4 ++-- 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 backend/rest_api.spec diff --git a/backend/rest_api.py b/backend/rest_api.py index 165b2c9..3218f1a 100644 --- a/backend/rest_api.py +++ b/backend/rest_api.py @@ -9,6 +9,9 @@ from data_handler import DataHandler app: Flask = Flask(__name__) +if __name__ == "__main__": + app.run(debug=True) + def handle_first_launched(): """ diff --git a/backend/rest_api.spec b/backend/rest_api.spec new file mode 100644 index 0000000..126d766 --- /dev/null +++ b/backend/rest_api.spec @@ -0,0 +1,37 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['rest_api.py', 'encryption_handler.py', 'data_handler.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name='rest_api', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) diff --git a/frontend/main.js b/frontend/main.js index 0784341..a7a2fa1 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -1,5 +1,7 @@ const { app, BrowserWindow, shell } = require('electron') const path = require('path') +const { spawn } = require('node:child_process'); +const rest_api = spawn('python', ['./backend/rest_api.py']); function createWindow () { @@ -21,9 +23,10 @@ function createWindow () { return { action: 'deny' }; }); - + win.webContents.openDevTools(); } + app.whenReady().then(() => { createWindow() @@ -32,7 +35,23 @@ app.whenReady().then(() => { createWindow() } }) + + rest_api.stdout.on('data', (data) => { + console.log(data.toString()); + }); + + rest_api.stderr.on('data', (data) => { + console.error(data.toString()); + }); + + rest_api.on('exit', (code) => { + console.log(`Child exited with code ${code}`); + }); +}); + +app.on('before-quit', () => { + rest_api.kill(); }) app.on('window-all-closed', () => { @@ -46,6 +65,13 @@ app.on('web-contents-created', (event, contents) => { event.preventDefault(); require('electron').shell.openExternal(navigationUrl); }); - }); +}); + + + + + + + diff --git a/frontend/scripts/register.js b/frontend/scripts/register.js index ab1985a..7198d3e 100644 --- a/frontend/scripts/register.js +++ b/frontend/scripts/register.js @@ -1,4 +1,4 @@ - +const PORT = 5000 const errlabel = document.getElementById('errlabel') function validateRegister() { @@ -40,7 +40,7 @@ async function createUser(username,password) { const errorMessage = await response.text(); errlabel.textContentL = errorMessage; setTimeout(()=> { - errorlabel.textContent = ""; + errlabel.textContent = ""; },3000) throw new Error(errorMessage); }