Skip to content

Commit

Permalink
Fix django server runtime with settimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
vimm0 committed Jun 7, 2023
1 parent 98b7b8e commit aa4db36
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 71 deletions.
44 changes: 44 additions & 0 deletions backend/back.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
['manage.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='back',
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,
)
113 changes: 42 additions & 71 deletions webdesk-de/main.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,52 @@
const { app, BrowserWindow } = require('electron')
const path = require('path')
const {spawn} = require('child_process');
const { app, BrowserWindow } = require('electron');
const { spawn } = require('child_process');

let DJANGO_CHILD_PROCESS = null;
const MAIN_WINDOW_WEBPACK_ENTRY = '';
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
let dj;
let mainWindow = null;

const spawnDjango = () =>
{
// if (isDevelopmentEnv()) {
// return spawn(`python\\edtwExampleEnv\\Scripts\\python.exe`,
// ['python\\edtwExample\\manage.py', 'runserver', '--noreload'], {
// shell: true,
// });
// }
return spawn(`cd back && webdeskbackend.exe runserver --noreload`, {
shell: true,
});
}

const startDjangoServer = () =>
{
DJANGO_CHILD_PROCESS = spawnDjango();
}
const startDjango = () => {
// return new Promise((resolve) => {
dj = spawn(`./back/webdeskbackend runserver --noreload`, { shell: true });

const createWindow = () => {
startDjangoServer();
// Create the browser window.
// const mainWindow = new BrowserWindow({
// height: 600,
// width: 800,
// });
dj.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});

// mainWindow.webContents.session.webRequest.onBeforeSendHeaders(
// (details, callback) =>
// {
// const { requestHeaders } = details;
// UpsertKeyValue(requestHeaders, 'Access-Control-Allow-Origin', ['*']);
// callback({ requestHeaders });
// },
// );
dj.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});

// mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) =>
// {
// const { responseHeaders } = details;
// UpsertKeyValue(responseHeaders, 'Access-Control-Allow-Origin', ['*']);
// UpsertKeyValue(responseHeaders, 'Access-Control-Allow-Headers', ['*']);
// callback({
// responseHeaders,
// });
dj.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
// });

// // and load the index.html of the app.
// mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);

// Open the DevTools.
// openDevTools(mainWindow);
const win = new BrowserWindow({
width: 800,
height: 600,
// webPreferences: {
// preload: path.join(__dirname, 'preload.js')
// }
})

// win.loadFile('index.html')
win.loadURL('http://localhost:8000/admin')

}

};

app.whenReady().then(() => {
createWindow()

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
startDjango();

setTimeout(() => {
mainWindow = new BrowserWindow({ width: 800, height: 600 });
mainWindow.loadURL('http://localhost:8000/admin');
mainWindow.on('closed', function () {
mainWindow = null;
dj.kill('SIGINT');
});
}, 1000);
});


// Kill local Django server
app.on('before-quit', function () {
dj.kill('SIGINT')
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()

// Quit when all windows are closed.
app.on('window-all-closed', function () {

// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin')
app.quit()
})

0 comments on commit aa4db36

Please sign in to comment.