-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Refactor IPC dispatching #39
Conversation
I found two ipc calls for your review. They look like they might be unused: electron-plugin/src/server/api/window.ts Line 192 in 7bae295
electron-plugin/src/server/api/window.ts Line 200 in 7bae295
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor
Agreed, i'm not sure what these are for. @mpociot can you recall why you added these? |
@simonhamp Yeah, the idea is to have these events available so we could use them in combination with TailwindCSS. For example: in my <script>
const electron = require('electron');
const ipcRenderer = electron.ipcRenderer;
ipcRenderer.on('window:blur', () => {
document.documentElement.classList.remove('focused');
document.documentElement.classList.add('blurred');
});
ipcRenderer.on('window:focus', () => {
document.documentElement.classList.remove('blurred');
document.documentElement.classList.add('focused');
});
</script> Then I can add plugin(function({ addVariant, e }) {
addVariant('blurred', ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.blurred .${e(`blurred${separator}${className}`)}`
})
})
}),
plugin(function({ addVariant, e }) {
addVariant('focused', ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.focused .${e(`blurred${separator}${className}`)}`
})
})
}) And then use them in my layout like: |
@mpociot Right. So I think you could achieve this with the slightly more generic @gwleuverink let's leave these shortcuts in for now tho - we can clean this up before v1 |
Right, but all of these events ha e a slight overhead as they get passed through PHP and then broadcast again, if I'm not mistaken. |
Thanks for your feedback! I'm just getting familiar with NativePHP's inner workings so I appreciate you taking the time a lot! From what I could gather by reading the code, all events passed through the So I get that there is a bit extra overhead as marcel mentioned. But leaving those extra IPC calls there as is they are effectively dispatched twice, under a different event name. Couldn't we maybe consolidate this by not awaiting the http call to the backend? The call to php is made regardless, but I don't think there is a need to wait for it if I understand correctly |
Hm wouldn't it be sufficient if we move the if condition / IPC dispatching before the axios call? But we could also get rid of the await I think, as we don't really need to wait for it to finish anyway |
Agreed, either approach here seems fine. I have to say I prefer to |
As briefly discussed in NativePHP/laravel#367
When starting on this PR I only added the clause that dispatched an ipc event to the menubar window in diff
However a repeating pattern became apparent. I was seeing this in 3 spots:
This seems like a crucial & easy to miss implementation detail. It might be good to extract that so dispatching events to the menubar isn't missed in the future.
This is only a small refactor. Please feel free to disregard or point me to any changes I can make to make this work for you.
If you prefer I can cherry-pick d11ba10 and resubmit the PR 👍🏻