This repository was archived by the owner on Oct 18, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathindex.ts
60 lines (52 loc) · 1.56 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { contextBridge, ipcRenderer } from 'electron'
import * as remote from '@electron/remote'
// @ts-ignore
window.remote = remote;
ipcRenderer.on('log', (event, {level, message, context}) => {
if (level === 'error') {
console.error(`[${level}] ${message}`, context)
} else if (level === 'warn') {
console.warn(`[${level}] ${message}`, context)
} else {
console.log(`[${level}] ${message}`, context)
}
});
// Add Livewire event listeners
ipcRenderer.on('native-event', (event, data) => {
// add support for livewire 3
// @ts-ignore
if (window.Livewire) {
// @ts-ignore
window.Livewire.dispatch('native:' + data.event, data.payload);
}
// add support for livewire 2
// @ts-ignore
if (window.livewire) {
// @ts-ignore
window.livewire.components.components().forEach(component => {
if (Array.isArray(component.listeners)) {
component.listeners.forEach(event => {
if (event.startsWith('native')) {
let event_parts = event.split(/(native:|native-)|:|,/)
if (event_parts[1] == 'native:') {
event_parts.splice(2, 0, 'private', undefined, 'nativephp', undefined)
}
let [
s1,
signature,
channel_type,
s2,
channel,
s3,
event_name,
] = event_parts
if (data.event === event_name) {
// @ts-ignore
window.livewire.emit(event, data.payload)
}
}
})
}
})
}
})