Following this tutorial https://github.com/laravelarticle/laravel-electron, I converted my laravel project into electron desktop app. However, the app works fine when I run it with "npm start", but when the app is packaged, the resulted .exe application shows a blank page.
I also noticed that when I run "php artisan serve" command from laravel project, the .exe application works !
this is main.js
const { ipcMain } = require('electron');
const { autoUpdater } = require('electron-updater');
const electron = require('electron');
const path = require('path')
const BrowserWindow = electron.BrowserWindow
const app = electron.app
let mainWindow;
var phpServer = require(`node-php-server`);
const serverUrl = `http://127.0.0.1:8000`;
function createWindow () {
// Create a PHP Server
phpServer.createServer({
port: 8000,
hostname: '127.0.0.1',
base: `${__dirname}/www/public`,
keepalive: false,
open: false,
bin: `${__dirname}/php/php.exe`,
router: __dirname + '/www/server.php'
});
const {
width,
height
} = electron.screen.getPrimaryDisplay().workAreaSize
mainWindow = new BrowserWindow({
width: width,
height: height,
webPreferences: {
nodeIntegration: true,
},
});
mainWindow.loadURL(serverUrl);
/*mainWindow.webContents.once('dom-ready', function () {
mainWindow.show()
mainWindow.maximize();
// mainWindow.webContents.openDevTools()
});*/
// Emitted when the window is closed.
mainWindow.on('closed', function () {
phpServer.close();
mainWindow = null;
});
mainWindow.once('ready-to-show', () => {
autoUpdater.checkForUpdatesAndNotify();
});
}
app.on('ready', () => {
createWindow();
});
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
// PHP SERVER QUIT
phpServer.close();
app.quit();
}
});
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
});
ipcMain.on('app_version', (event) => {
event.sender.send('app_version', { version: app.getVersion() });
});
autoUpdater.on('update-available', () => {
mainWindow.webContents.send('update_available');
});
autoUpdater.on('update-downloaded', () => {
mainWindow.webContents.send('update_downloaded');
});
ipcMain.on('restart_app', () => {
autoUpdater.quitAndInstall();
});
And here is package.json
{
"name": "POS-Cube-Master",
"version": "1.0.0",
"description": "",
"main": "main.js",
"dependencies": {
"child_process": "^1.0.2",
"electron-updater": "^4.3.4",
"node-php-server": "^0.1.2",
"npm": "^6.14.7",
"which": "^2.0.2",
"yarn": "^1.22.4"
},
"devDependencies": {
"electron": "^9.1.1",
"electron-builder": "^22.8.0",
"electron-packager": "^15.0.0"
},
"scripts": {
"start": "electron .",
"build": "electron-builder build --win --publish never",
"deploy": "electron-builder build --win --publish always"
},
"repository": {
"type": "git",
"url": "https://github.com/Lama-3O/POS_CubeMaster.git"
},
"author": "CubeMaster",
"license": "ISC",
"bugs": {
"url": "https://github.com/Lama-3O/POS_CubeMaster/issues"
},
"homepage": "https://github.com/Lama-3O/POS_CubeMaster#readme"
}
I really tried a lot of solutions. What could be the problem ?