fixed electron build + implemented dynamic settings + custom user data folder
This commit is contained in:
1 parent
8958ead210
commit
b872cd0733
14 files changed
+286
-81
No files matched your search
@@ -3,42 +3,17 @@ const { app, BrowserWindow } = require('electron');
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
|
||||
let expressProcess;
|
||||
let win;
|
||||
|
||||
function createWindow() {
|
||||
win = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 720,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
win.loadURL(
|
||||
url.format({
|
||||
pathname: path.join(__dirname, 'dist\\show-z\\browser\\index.html'),
|
||||
protocol: 'file:',
|
||||
slashes: true
|
||||
})
|
||||
);
|
||||
|
||||
win.on('closed', () => {
|
||||
win = null;
|
||||
});
|
||||
}
|
||||
|
||||
// app.on('ready', createWindow);
|
||||
|
||||
app.on('ready', () => {
|
||||
// Start the Express server
|
||||
const expressProcess = spawn('node', ['backend/server.js']);
|
||||
expressProcess.stdout.on('data', (data) => {
|
||||
console.log(`Express stdout: ${data}`);
|
||||
});
|
||||
expressProcess.stderr.on('data', (data) => {
|
||||
console.error(`Express stderr: ${data}`);
|
||||
});
|
||||
// ! Start the Express server loop
|
||||
startExpressServer();
|
||||
createMediaFolders();
|
||||
|
||||
// Start the Electron app
|
||||
createWindow();
|
||||
@@ -55,3 +30,60 @@ app.on('activate', () => {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
const { dialog, ipcMain } = require('electron');
|
||||
const { createMediaFolders } = require('./backend/services/mediaService');
|
||||
|
||||
ipcMain.on('select-dirs', async (event, arg) => {
|
||||
const result = await dialog.showOpenDialog(mainWindow, {
|
||||
properties: ['openDirectory']
|
||||
})
|
||||
console.log('directories selected', result.filePaths)
|
||||
})
|
||||
|
||||
function startExpressServer() {
|
||||
let parrentProcess = {
|
||||
"electron_path": app.getPath('userData')
|
||||
}
|
||||
// Start the Express server
|
||||
expressProcess = spawn('node', ['backend/server.js'], { env: { PARENT_PROCESS: JSON.stringify(parrentProcess) } });
|
||||
expressProcess.stdout.on('data', (data) => {
|
||||
console.log(`Express stdout: ${data}`);
|
||||
});
|
||||
expressProcess.stderr.on('data', (data) => {
|
||||
console.error(`Express stderr: ${data}`);
|
||||
});
|
||||
|
||||
// Restart the server if it crashes
|
||||
expressProcess.on('exit', (code, signal) => {
|
||||
console.log(`Express process exited with code ${code} and signal ${signal}. Restarting...`);
|
||||
startExpressServer();
|
||||
});
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
win = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 720,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js'),
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: false,
|
||||
contextIsolation: true,
|
||||
sandbox: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
win.loadURL(
|
||||
url.format({
|
||||
pathname: path.join(__dirname, 'dist', 'showy', 'browser', 'index.html'),
|
||||
protocol: 'file:',
|
||||
slashes: true
|
||||
})
|
||||
);
|
||||
|
||||
win.on('closed', () => {
|
||||
win = null;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user