-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Listener crashes the renderer process in Electron sometimes #14
Comments
Oh that's fun - i'll try to dig into it. This may in fact be a bug with Napi itself 🤔 |
@KishanBagaria what listener-related code is being invoked there? knowing whether this is happening during setup, teardown, etc will help me narrow this down a bit. Looks like |
I have something like this running in my renderer process: import nmc from 'node-mac-contacts'
import { throttle } from 'lodash'
if (!nmc.listener.isListening()) nmc.listener.setup()
nmc.listener.on('contact-changed', throttle(() => {
console.log(new Date(), 'refetching contacts')
processAllContacts()
}, 5000, { trailing: true })) And say when I add a contact using the |
Another recent crash log if it's helpful:
|
For posterity, here's the workaround I used for this. I wrote some Swift code that prints "changed" when the contacts are changed and compiled it into an executable binary. Then in the renderer process I run this binary as a child process. setbuf(__stdoutp, nil) // disables buffering
class Observer: NSObject {
@objc func contactStoreDidChange() {
print("changed")
}
override init() {
super.init()
NotificationCenter.default.addObserver(
self,
selector: #selector(self.contactStoreDidChange),
name: .CNContactStoreDidChange,
object: nil
)
print("listening")
}
} setupListener = () => {
if (this.isListening) return
const cp = childProcess.spawn(swiftContactsBinPath)
cp.stdout.on('data', (chunk: Buffer) => {
const data = chunk.toString().split('\n')
if (data.includes('changed')) this.onContactChanged()
})
cp.stderr.on('data', chunk => {
console.error('error', chunk)
})
this.isListening = true
} |
So I can't repro this consistently but it happens when a contact is mutated:
process.versions
:The text was updated successfully, but these errors were encountered: