Skip to content

Commit 608a454

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/extras
2 parents 4f6fb0e + 80b499f commit 608a454

File tree

10 files changed

+63
-32
lines changed

10 files changed

+63
-32
lines changed

resources/js/electron-plugin/dist/server/api/system.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,17 @@ router.get('/printers', (req, res) => __awaiter(void 0, void 0, void 0, function
6262
});
6363
}));
6464
router.post('/print', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
65-
const { printer, html } = req.body;
65+
const { printer, html, settings } = req.body;
6666
let printWindow = new BrowserWindow({
6767
show: false,
6868
});
69+
const defaultSettings = {
70+
silent: true,
71+
deviceName: printer,
72+
};
73+
const mergedSettings = Object.assign(Object.assign({}, defaultSettings), (settings && typeof settings === 'object' ? settings : {}));
6974
printWindow.webContents.on('did-finish-load', () => {
70-
printWindow.webContents.print({
71-
silent: true,
72-
deviceName: printer,
73-
}, (success, errorType) => {
75+
printWindow.webContents.print(mergedSettings, (success, errorType) => {
7476
if (success) {
7577
console.log('Print job completed successfully.');
7678
res.sendStatus(200);
@@ -88,12 +90,12 @@ router.post('/print', (req, res) => __awaiter(void 0, void 0, void 0, function*
8890
yield printWindow.loadURL(`data:text/html;charset=UTF-8,${html}`);
8991
}));
9092
router.post('/print-to-pdf', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
91-
const { html } = req.body;
93+
const { html, settings } = req.body;
9294
let printWindow = new BrowserWindow({
9395
show: false,
9496
});
9597
printWindow.webContents.on('did-finish-load', () => {
96-
printWindow.webContents.printToPDF({}).then(data => {
98+
printWindow.webContents.printToPDF(settings !== null && settings !== void 0 ? settings : {}).then(data => {
9799
printWindow.close();
98100
res.json({
99101
result: data.toString('base64'),

resources/js/electron-plugin/dist/server/state.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import Store from "electron-store";
22
import { notifyLaravel } from "./utils.js";
33
const settingsStore = new Store();
44
settingsStore.onDidAnyChange((newValue, oldValue) => {
5-
const changedKey = Object.keys(newValue).find((key) => newValue[key] !== oldValue[key]);
6-
if (changedKey) {
5+
const changedKeys = Object.keys(newValue).filter((key) => newValue[key] !== oldValue[key]);
6+
changedKeys.forEach((key) => {
77
notifyLaravel("events", {
88
event: "Native\\Laravel\\Events\\Settings\\SettingChanged",
99
payload: {
10-
key: changedKey,
11-
value: newValue[changedKey] || null,
10+
key,
11+
value: newValue[key] || null,
1212
},
1313
});
14-
}
14+
});
1515
});
1616
function generateRandomString(length) {
1717
let result = "";

resources/js/electron-plugin/src/server/api/system.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,24 @@ router.get('/printers', async (req, res) => {
6060
});
6161

6262
router.post('/print', async (req, res) => {
63-
const {printer, html} = req.body;
63+
const {printer, html, settings} = req.body;
6464

6565
let printWindow = new BrowserWindow({
6666
show: false,
6767
});
6868

69+
const defaultSettings = {
70+
silent: true,
71+
deviceName: printer,
72+
};
73+
74+
const mergedSettings = {
75+
...defaultSettings,
76+
...(settings && typeof settings === 'object' ? settings : {}),
77+
};
78+
6979
printWindow.webContents.on('did-finish-load', () => {
70-
printWindow.webContents.print({
71-
silent: true,
72-
deviceName: printer,
73-
}, (success, errorType) => {
80+
printWindow.webContents.print(mergedSettings, (success, errorType) => {
7481
if (success) {
7582
console.log('Print job completed successfully.');
7683
res.sendStatus(200);
@@ -89,14 +96,14 @@ router.post('/print', async (req, res) => {
8996
});
9097

9198
router.post('/print-to-pdf', async (req, res) => {
92-
const {html} = req.body;
99+
const {html, settings} = req.body;
93100

94101
let printWindow = new BrowserWindow({
95102
show: false,
96103
});
97104

98105
printWindow.webContents.on('did-finish-load', () => {
99-
printWindow.webContents.printToPDF({}).then(data => {
106+
printWindow.webContents.printToPDF(settings ?? {}).then(data => {
100107
printWindow.close();
101108
res.json({
102109
result: data.toString('base64'),

resources/js/electron-plugin/src/server/state.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ import { notifyLaravel } from "./utils.js";
55
const settingsStore = new Store();
66
settingsStore.onDidAnyChange((newValue, oldValue) => {
77
// Only notify of the changed key/value pair
8-
const changedKey = Object.keys(newValue).find(
9-
(key) => newValue[key] !== oldValue[key]
10-
);
8+
const changedKeys = Object.keys(newValue).filter((key) => newValue[key] !== oldValue[key]);
119

12-
if (changedKey) {
10+
changedKeys.forEach((key) => {
1311
notifyLaravel("events", {
1412
event: "Native\\Laravel\\Events\\Settings\\SettingChanged",
1513
payload: {
16-
key: changedKey,
17-
value: newValue[changedKey] || null,
14+
key,
15+
value: newValue[key] || null,
1816
},
1917
});
20-
}
18+
});
2119
});
2220

2321
interface State {

src/Commands/BuildCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515
use Native\Electron\Traits\OsAndArch;
1616
use Native\Electron\Traits\PatchesPackagesJson;
1717
use Native\Electron\Traits\PrunesVendorDirectory;
18+
use Symfony\Component\Console\Attribute\AsCommand;
1819
use Symfony\Component\Process\Process as SymfonyProcess;
1920

2021
use function Laravel\Prompts\intro;
2122

23+
#[AsCommand(
24+
name: 'native:build',
25+
description: 'Build the NativePHP application for the specified operating system and architecture.',
26+
)]
2227
class BuildCommand extends Command
2328
{
2429
use CleansEnvFile;

src/Commands/BundleCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
use Native\Electron\Traits\LocatesPhpBinary;
1818
use Native\Electron\Traits\PatchesPackagesJson;
1919
use Native\Electron\Traits\PrunesVendorDirectory;
20+
use Symfony\Component\Console\Attribute\AsCommand;
2021
use Symfony\Component\Finder\Finder;
2122
use ZipArchive;
2223

2324
use function Laravel\Prompts\intro;
2425

26+
#[AsCommand(
27+
name: 'native:bundle',
28+
description: 'Bundle your application for distribution.',
29+
)]
2530
class BundleCommand extends Command
2631
{
2732
use CleansEnvFile;
@@ -35,8 +40,6 @@ class BundleCommand extends Command
3540

3641
protected $signature = 'native:bundle {--fetch} {--clear} {--without-cleanup}';
3742

38-
protected $description = 'Bundle your application for distribution.';
39-
4043
private ?string $key;
4144

4245
private string $zipPath;

src/Commands/DevelopCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
use Native\Electron\Traits\Installer;
99
use Native\Electron\Traits\InstallsAppIcon;
1010
use Native\Electron\Traits\PatchesPackagesJson;
11+
use Symfony\Component\Console\Attribute\AsCommand;
1112

1213
use function Laravel\Prompts\intro;
1314
use function Laravel\Prompts\note;
1415

16+
#[AsCommand(
17+
name: 'native:serve',
18+
description: 'Start the NativePHP development server with the Electron app',
19+
)]
1520
class DevelopCommand extends Command
1621
{
1722
use CopiesCertificateAuthority;

src/Commands/InstallCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
use Illuminate\Console\Command;
66
use Native\Electron\Traits\Installer;
77
use RuntimeException;
8+
use Symfony\Component\Console\Attribute\AsCommand;
89

910
use function Laravel\Prompts\confirm;
1011
use function Laravel\Prompts\info;
1112
use function Laravel\Prompts\intro;
1213
use function Laravel\Prompts\note;
1314
use function Laravel\Prompts\outro;
1415

16+
#[AsCommand(
17+
name: 'native:install',
18+
description: 'Install all of the NativePHP resources',
19+
)]
1520
class InstallCommand extends Command
1621
{
1722
use Installer;
@@ -20,8 +25,6 @@ class InstallCommand extends Command
2025
{--force : Overwrite existing files by default}
2126
{--installer=npm : The package installer to use: npm, yarn or pnpm}';
2227

23-
protected $description = 'Install all of the NativePHP resources';
24-
2528
public function handle(): void
2629
{
2730
intro('Publishing NativePHP Service Provider...');

src/Commands/PublishCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
use Illuminate\Support\Facades\Artisan;
77
use Native\Electron\Traits\LocatesPhpBinary;
88
use Native\Electron\Traits\OsAndArch;
9+
use Symfony\Component\Console\Attribute\AsCommand;
910

11+
#[AsCommand(
12+
name: 'native:publish',
13+
description: 'Build and publish the NativePHP app for the specified operating system and architecture',
14+
)]
1015
class PublishCommand extends Command
1116
{
1217
use LocatesPhpBinary;

src/Commands/ResetCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44

55
use Illuminate\Console\Command;
66
use Native\Electron\Traits\PatchesPackagesJson;
7+
use Symfony\Component\Console\Attribute\AsCommand;
78
use Symfony\Component\Filesystem\Filesystem;
89

910
use function Laravel\Prompts\intro;
1011

12+
#[AsCommand(
13+
name: 'native:reset',
14+
description: 'Clear all build and dist files',
15+
)]
1116
class ResetCommand extends Command
1217
{
1318
use PatchesPackagesJson;
1419

1520
protected $signature = 'native:reset {--with-app-data : Clear the app data as well}';
1621

17-
protected $description = 'Clear all build and dist files';
18-
1922
public function handle(): int
2023
{
2124
intro('Clearing build and dist directories...');

0 commit comments

Comments
 (0)