Skip to content

Commit

Permalink
Merge branch 'main' into feature/build-with-obfuscated-bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp authored Dec 18, 2024
2 parents 8b0e43d + 2156a83 commit aeee3fe
Show file tree
Hide file tree
Showing 42 changed files with 733 additions and 812 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@

All notable changes to `nativephp-laravel` will be documented in this file.

## 0.8.7 - 2024-11-17

### What's Changed

* Fix/forward native env variables to Child Processes by @gwleuverink in https://github.com/NativePHP/electron/pull/129
* Fix some MenuBar quirks by @simonhamp in https://github.com/NativePHP/electron/pull/133
* Pass MenuBar clicked event parameters correctly by @simonhamp in https://github.com/NativePHP/electron/pull/134
* Delete the `native:queue` command by @JustinLawrenceMS in https://github.com/NativePHP/electron/pull/130

### New Contributors

* @JustinLawrenceMS made their first contribution in https://github.com/NativePHP/electron/pull/130

**Full Changelog**: https://github.com/NativePHP/electron/compare/0.8.6...0.8.7

## 0.8.6 - 2024-11-14

### What's Changed

* MenuBar improvements by @simonhamp in https://github.com/NativePHP/electron/pull/131

**Full Changelog**: https://github.com/NativePHP/electron/compare/0.8.5...0.8.6

## 0.8.5 - 2024-11-13

### What's Changed

* Tidy / remove commented out child process env merge by @gwleuverink in https://github.com/NativePHP/electron/pull/126
* Create build-plugin.yml by @simonhamp in https://github.com/NativePHP/electron/pull/127
* Make the queue worker work by @simonhamp in https://github.com/NativePHP/electron/pull/128

### New Contributors

* @gwleuverink made their first contribution in https://github.com/NativePHP/electron/pull/126

**Full Changelog**: https://github.com/NativePHP/electron/compare/0.8.4...0.8.5

## 0.8.4 - 2024-11-11

### What's Changed
Expand Down
44 changes: 0 additions & 44 deletions resources/js/README.md

This file was deleted.

25 changes: 15 additions & 10 deletions resources/js/electron-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ try {

if (isBuilding) {

console.log('=====================');
console.log('Building for ' + targetOs);
console.log('=====================');
console.log('updater config', updaterConfig);
console.log('=====================');
console.log();
console.log('===================================================================');
console.log(' Building for ' + targetOs);
console.log('===================================================================');
console.log();
console.log('Updater config', updaterConfig);
console.log();

try {
const appPath = join(__dirname, 'resources', 'app');
Expand Down Expand Up @@ -116,15 +118,18 @@ if (isBuilding) {
removeSync(tmpDir);
}

console.log('=====================');
console.log();
console.log('Copied app to resources');
console.log(join(process.env.APP_PATH, 'dist'));
console.log('=====================');
console.log();
console.log('===================================================================');
console.log(' Starting build...');
console.log();
} catch (e) {
console.error('=====================');
console.error('Error copying app to resources');
console.error();
console.error('Error copying app into build environment');
console.error(e);
console.error('=====================');
console.error();
}

}
Expand Down
4 changes: 4 additions & 0 deletions resources/js/electron-plugin/dist/preload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const Native = {
return callback(data.payload, event);
}
});
},
contextMenu: (template) => {
let menu = remote.Menu.buildFromTemplate(template);
menu.popup({ window: remote.getCurrentWindow() });
}
};
window.Native = Native;
Expand Down
18 changes: 16 additions & 2 deletions resources/js/electron-plugin/dist/server/api/childProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { utilityProcess } from 'electron';
import state from '../state';
import { notifyLaravel } from "../utils";
import { join } from 'path';
import { getDefaultEnvironmentVariables, getDefaultPhpIniSettings } from "../php";
const router = express.Router();
const killSync = require('kill-sync');
function startProcess(settings) {
Expand All @@ -21,8 +22,8 @@ function startProcess(settings) {
}
const proc = utilityProcess.fork(join(__dirname, '../../electron-plugin/dist/server/childProcess.js'), cmd, {
cwd,
serviceName: alias,
stdio: 'pipe',
serviceName: alias,
env: Object.assign(Object.assign({}, process.env), env)
});
proc.stdout.on('data', (data) => {
Expand Down Expand Up @@ -68,7 +69,7 @@ function startProcess(settings) {
const settings = Object.assign({}, getSettings(alias));
delete state.processes[alias];
if (settings.persistent) {
console.log('Process [' + alias + '] wathchdog restarting...');
console.log('Process [' + alias + '] watchdog restarting...');
startProcess(settings);
}
});
Expand All @@ -78,6 +79,15 @@ function startProcess(settings) {
settings
};
}
function startPhpProcess(settings) {
const defaultEnv = getDefaultEnvironmentVariables(state.randomSecret, state.electronApiPort);
const iniSettings = Object.assign(Object.assign({}, getDefaultPhpIniSettings()), state.phpIni);
const iniArgs = Object.keys(iniSettings).map(key => {
return ['-d', `${key}=${iniSettings[key]}`];
}).flat();
settings = Object.assign(Object.assign({}, settings), { cmd: [state.php, ...iniArgs, ...settings.cmd], env: Object.assign(Object.assign({}, settings.env), defaultEnv) });
return startProcess(settings);
}
function stopProcess(alias) {
const proc = getProcess(alias);
if (proc === undefined) {
Expand Down Expand Up @@ -105,6 +115,10 @@ router.post('/start', (req, res) => {
const proc = startProcess(req.body);
res.json(proc);
});
router.post('/start-php', (req, res) => {
const proc = startPhpProcess(req.body);
res.json(proc);
});
router.post('/stop', (req, res) => {
const { alias } = req.body;
stopProcess(alias);
Expand Down
6 changes: 3 additions & 3 deletions resources/js/electron-plugin/dist/server/api/contextMenu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from 'express';
import { mapMenu } from "./helper";
import { compileMenu } from "./helper";
import contextMenu from "electron-context-menu";
const router = express.Router();
let contextMenuDisposable = null;
Expand All @@ -21,8 +21,8 @@ router.post('/', (req, res) => {
showSearchWithGoogle: false,
showInspectElement: false,
prepend: (defaultActions, parameters, browserWindow) => {
return req.body.entries.map(mapMenu);
}
return req.body.entries.map(compileMenu);
},
});
});
export default router;
35 changes: 33 additions & 2 deletions resources/js/electron-plugin/dist/server/api/dock.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
import express from 'express';
import { app, Menu } from 'electron';
import { mapMenu } from "./helper";
import { compileMenu } from './helper';
import state from '../state';
const router = express.Router();
router.post('/', (req, res) => {
const menuEntries = req.body.items.map(mapMenu);
const menuEntries = req.body.items.map(compileMenu);
const menu = Menu.buildFromTemplate(menuEntries);
app.dock.setMenu(menu);
res.sendStatus(200);
});
router.post('/show', (req, res) => {
app.dock.show();
res.sendStatus(200);
});
router.post('/hide', (req, res) => {
app.dock.hide();
res.sendStatus(200);
});
router.post('/icon', (req, res) => {
app.dock.setIcon(req.body.path);
res.sendStatus(200);
});
router.post('/bounce', (req, res) => {
const { type } = req.body;
state.dockBounce = app.dock.bounce(type);
res.sendStatus(200);
});
router.post('/cancel-bounce', (req, res) => {
app.dock.cancelBounce(state.dockBounce);
res.sendStatus(200);
});
router.get('/badge', (req, res) => {
res.json({
label: app.dock.getBadge(),
});
});
router.post('/badge', (req, res) => {
app.dock.setBadge(req.body.label);
res.sendStatus(200);
});
export default router;
92 changes: 49 additions & 43 deletions resources/js/electron-plugin/dist/server/api/helper/index.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,66 @@
import { shell } from "electron";
import { notifyLaravel } from "../../utils";
function triggerMenuItemEvent(menuItem) {
import { shell } from 'electron';
import { notifyLaravel, goToUrl } from '../../utils';
import state from '../../state';
function triggerMenuItemEvent(menuItem, combo) {
notifyLaravel('events', {
event: '\\Native\\Laravel\\Events\\Menu\\MenuItemClicked',
payload: [
{
event: menuItem.event || '\\Native\\Laravel\\Events\\Menu\\MenuItemClicked',
payload: {
item: {
id: menuItem.id,
label: menuItem.label,
checked: menuItem.checked
}
]
checked: menuItem.checked,
},
combo,
},
});
}
const mapMenu = (menu) => {
if (menu.submenu) {
menu.submenu = menu.submenu.map(mapMenu);
}
if (menu.type === 'link') {
menu.type = 'normal';
menu.click = () => {
triggerMenuItemEvent(menu);
shell.openExternal(menu.url);
};
return menu;
export function compileMenu(item) {
var _a, _b;
if (item.submenu) {
if (Array.isArray(item.submenu)) {
item.submenu = (_a = item.submenu) === null || _a === void 0 ? void 0 : _a.map(compileMenu);
}
else {
item.submenu = (_b = item.submenu.submenu) === null || _b === void 0 ? void 0 : _b.map(compileMenu);
}
}
if (menu.type === 'checkbox') {
menu.click = () => {
menu.checked = !menu.checked;
triggerMenuItemEvent(menu);
if (item.type === 'link') {
item.type = 'normal';
item.click = (menuItem, focusedWindow, combo) => {
triggerMenuItemEvent(item, combo);
if (item.openInBrowser) {
shell.openExternal(item.url);
return;
}
if (!focusedWindow) {
return;
}
const id = Object.keys(state.windows)
.find(key => state.windows[key] === focusedWindow);
goToUrl(item.url, id);
};
return item;
}
if (menu.type === 'event') {
return {
label: menu.label,
accelerator: menu.accelerator,
click() {
notifyLaravel('events', {
event: menu.event
});
}
if (item.type === 'checkbox' || item.type === 'radio') {
item.click = (menuItem, focusedWindow, combo) => {
item.checked = !item.checked;
triggerMenuItemEvent(item, combo);
};
return item;
}
if (menu.type === 'role') {
if (item.type === 'role') {
let menuItem = {
role: menu.role
role: item.role
};
if (menu.label) {
menuItem['label'] = menu.label;
if (item.label) {
menuItem['label'] = item.label;
}
return menuItem;
}
if (!menu.click) {
menu.click = () => {
triggerMenuItemEvent(menu);
if (!item.click) {
item.click = (menuItem, focusedWindow, combo) => {
triggerMenuItemEvent(item, combo);
};
}
return menu;
};
export { mapMenu, };
return item;
}
5 changes: 3 additions & 2 deletions resources/js/electron-plugin/dist/server/api/menu.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import express from 'express';
import { Menu } from 'electron';
import { mapMenu } from "./helper";
import { compileMenu } from './helper';
const router = express.Router();
router.post('/', (req, res) => {
const menuEntries = req.body.items.map(mapMenu);
Menu.setApplicationMenu(null);
const menuEntries = req.body.items.map(compileMenu);
const menu = Menu.buildFromTemplate(menuEntries);
Menu.setApplicationMenu(menu);
res.sendStatus(200);
Expand Down
Loading

0 comments on commit aeee3fe

Please sign in to comment.