Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit e55de8e

Browse files
committed
Merge branch 'main' of github.com:NativePHP/electron-plugin
2 parents bfda665 + 872895d commit e55de8e

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# nativephp-electron
1+
# @nativephp/electron-plugin
2+
3+
The Electron back-end for NativePHP.
4+
5+
## Issues
6+
7+
Please raise any issues on the [NativePHP/laravel](/nativephp/laravel/issues/new/choose) repo.

dist/server/api/menuBar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ router.post("/hide", (req, res) => {
2525
});
2626
router.post("/create", (req, res) => {
2727
res.sendStatus(200);
28-
const { width, height, url, label, alwaysOnTop, vibrancy, backgroundColor, transparency, icon, showDockIcon, onlyShowContextWindow, contextMenu } = req.body;
28+
const { width, height, url, label, alwaysOnTop, vibrancy, backgroundColor, transparency, icon, showDockIcon, onlyShowContextWindow, windowPosition, contextMenu } = req.body;
2929
if (onlyShowContextWindow === true) {
3030
const tray = new electron_1.Tray(icon || state_1.default.icon.replace("icon.png", "IconTemplate.png"));
3131
tray.setContextMenu(buildMenu(contextMenu));
@@ -47,6 +47,7 @@ router.post("/create", (req, res) => {
4747
index: url,
4848
showDockIcon,
4949
showOnAllWorkspaces: false,
50+
windowPosition: windowPosition !== null && windowPosition !== void 0 ? windowPosition : "trayCenter",
5051
browserWindow: {
5152
width,
5253
height,

src/server/api/menuBar.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ router.post("/create", (req, res) => {
4343
icon,
4444
showDockIcon,
4545
onlyShowContextWindow,
46+
windowPosition,
4647
contextMenu
4748
} = req.body;
4849

@@ -68,6 +69,7 @@ router.post("/create", (req, res) => {
6869
index: url,
6970
showDockIcon,
7071
showOnAllWorkspaces: false,
72+
windowPosition: windowPosition ?? "trayCenter",
7173
browserWindow: {
7274
width,
7375
height,
@@ -102,6 +104,15 @@ router.post("/create", (req, res) => {
102104
});
103105
});
104106

107+
state.activeMenuBar.tray.on("drop-files", (event, files) => {
108+
notifyLaravel("events", {
109+
event: "\\Native\\Laravel\\Events\\MenuBar\\MenuBarDroppedFiles",
110+
payload: [
111+
files
112+
]
113+
});
114+
});
115+
105116
if (onlyShowContextWindow !== true) {
106117
state.activeMenuBar.tray.on("right-click", () => {
107118
notifyLaravel("events", {

src/server/api/system.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,29 @@ router.post('/print', async (req, res) => {
4747
await printWindow.loadURL(`data:text/html;charset=UTF-8,${html}`);
4848
});
4949

50+
router.post('/print-to-pdf', async (req, res) => {
51+
const {html} = req.body;
52+
53+
let printWindow = new BrowserWindow({
54+
show: false,
55+
});
56+
57+
printWindow.webContents.on('did-finish-load', () => {
58+
printWindow.webContents.printToPDF({'transferMode': 'ReturnAsBase64'}).then(data => {
59+
printWindow.close();
60+
res.json({
61+
result: data.toString('base64'),
62+
});
63+
}).catch(e => {
64+
printWindow.close();
65+
66+
res.status(400).json({
67+
error: e.message,
68+
});
69+
});
70+
});
71+
72+
await printWindow.loadURL(`data:text/html;charset=UTF-8,${html}`);
73+
});
74+
5075
export default router;

0 commit comments

Comments
 (0)