Skip to content

Commit 6fc11c9

Browse files
committed
Merge branch 'v2' into add-webPreferences-docs
2 parents 3a8e8ac + dfbb61e commit 6fc11c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+6170
-966
lines changed

composer.lock

Lines changed: 618 additions & 418 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 537 additions & 525 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/filament/filament/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/filament/forms/forms.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/filament/forms/components/date-time-picker.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/filament/forms/components/markdown-editor.js

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/filament/tables/components/table.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/docs/desktop/2/_index.md

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Digging Deeper
3+
order: 3
4+
---
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: Broadcasting
3+
order: 100
4+
---
5+
6+
# Broadcasting
7+
8+
NativePHP facilitates event broadcasting of both [native events](#native-events) (emitted by Electron/Tauri) and
9+
[custom events](#custom-events) dispatched by your Laravel app. You can listen to all of these events in your
10+
Laravel application as you normally would or in the [JavaScript](#listening-with-javascript) on your pages.
11+
12+
## Native events
13+
14+
NativePHP fires various events during its operations, such as `WindowBlurred` & `NotificationClicked`. A full list
15+
of all events fired and broadcast by NativePHP can be found in the
16+
[`src/Events`](https://github.com/nativephp/laravel/tree/main/src/Events) folder.
17+
18+
## Custom events
19+
20+
You can also broadcast your own events. Simply implement the `ShouldBroadcastNow` contract in your event class and
21+
define the `broadcastOn` method, returning `nativephp` as one of the channels it broadcasts to:
22+
23+
```php
24+
use Illuminate\Broadcasting\Channel;
25+
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
26+
27+
class JobFinished implements ShouldBroadcastNow
28+
{
29+
public function broadcastOn(): array
30+
{
31+
return [
32+
new Channel('nativephp'),
33+
];
34+
}
35+
}
36+
```
37+
38+
This is particularly useful for scenarios where you want to offload an intensive task to a background queue and await
39+
its completion without constantly polling your application for its status.
40+
41+
## Listening with JavaScript
42+
43+
You can listen to all native and custom events emitted by your application in real-time using JavaScript.
44+
45+
NativePHP injects a `window.Native` object into every window. The `on()` method allows you to register a callback as
46+
the second parameter that will run when the event specified in the first parameter is fired:
47+
48+
```js
49+
Native.on(
50+
'Native\\Desktop\\Events\\Windows\\WindowBlurred',
51+
(payload, event) => {
52+
//
53+
},
54+
)
55+
```
56+
57+
## Listening with Livewire
58+
59+
To make this process even easier when using [Livewire](https://livewire.laravel.com), you may use the `native:` prefix when
60+
listening to events. This is similar to
61+
[listening to Laravel Echo events using Livewire](https://livewire.laravel.com/docs/events#real-time-events-using-laravel-echo).
62+
63+
You may use a string name:
64+
65+
```php
66+
class AppSettings extends Component
67+
{
68+
public $windowFocused = true;
69+
70+
#[On('native:\\Native\\Desktop\\Events\\Windows\\WindowFocused')]
71+
public function windowFocused()
72+
{
73+
$this->windowFocused = true;
74+
}
75+
76+
#[On('native:\\Native\\Desktop\\Events\\Windows\\WindowBlurred')]
77+
public function windowBlurred()
78+
{
79+
$this->windowFocused = false;
80+
}
81+
}
82+
```
83+
84+
You may find it more convenient to use PHP's class name resolution keyword, `::class`:
85+
86+
```php
87+
use Native\Desktop\Events\Windows\WindowBlurred;
88+
use Native\Desktop\Events\Windows\WindowFocused;
89+
90+
class AppSettings extends Component
91+
{
92+
public $windowFocused = true;
93+
94+
#[On('native:'.WindowFocused::class)]
95+
public function windowFocused()
96+
{
97+
$this->windowFocused = true;
98+
}
99+
100+
#[On('native:'.WindowBlurred::class)]
101+
public function windowBlurred()
102+
{
103+
$this->windowFocused = false;
104+
}
105+
}
106+
```

0 commit comments

Comments
 (0)