Skip to content
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

added getCenterOfActiveScreen in Screen class #375

Merged

Conversation

danielpetrica
Copy link
Contributor

Added a function that Returns the center of the screen where the mouse pointer is placed. Useful if you want to initialize a smaller window and place it exactly in the center of screen.

Closes this discussion idea #373

I ran pest and all tests passed. Also ran Phpstan on the specific file. Maybe it could be a good idea to add a test for it but don't know how.

Added function that Returns the center of the screen where the mouse pointer is placed. Useful if you want to initialise a smaller window and place it exactly in the center of screen.
@simonhamp
Copy link
Member

simonhamp commented Oct 18, 2024

I'd like to see part of this exposed via our Electron web service instead of being fully implemented here as Electron already supports some of what you're doing here. For example, you can use:

I'm imagining a Screen::active() method which returns the details of the currently active display.

This would be a useful primitive for other use-cases, not only for finding the center of the "current" screen. It would also be slightly more performant, as it would only need to make one cross-service API call instead of two (you're calling cursorPosition and displays).

Are you up for adapting this PR and creating the Electron side @danielpetrica?

@danielpetrica
Copy link
Contributor Author

@simonhamp Sounds like a better and cleaner idea. At the time I didn't have much confidence on working on electron. I'll try to look into it as this would simplify my work over time too

@simonhamp
Copy link
Member

No worries. I've created the Electron side for you - so you'd just need to use this in your PHP code.

@danielpetrica
Copy link
Contributor Author

Thank you a lot I'll change it this weekend then

@danielpetrica
Copy link
Contributor Author

hi @simonhamp I tried using the newly creatited active method but it returns a null value trigering a type error. while investigating I tried to call $this->client->get('screen/active') directly inside the Screen class, but it returns an error

  {
    "Illuminate\\Http\\Client\\Response": "<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /api/screen/active</pre>
</body></html>"
  }

@danielpetrica
Copy link
Contributor Author

I changed the electron pluign to track dev-main so it's updated and in the vendor I can see the new updates for the active endpoint. I tried running yarn install and also stoping and starting the native:serve command

@danielpetrica
Copy link
Contributor Author

While debbugging I saw that in the server api routes the new routes are missing https://github.com/NativePHP/electron/blob/main/resources/js/electron-plugin/dist/server/api/screen.js
How can I compile it so that it's updated?

@danielpetrica
Copy link
Contributor Author

I've managed to build the electron plugin by running npm run plugin:build inside of vendor/nativephp/electron/resources/js/electron-plugin.
I can confirm that in my project this code works now, and is much cleaner.

@simonhamp
Copy link
Member

Glad you found this! I was going to reply earlier with exactly those instructions

Well done 👍🏼

src/Facades/Screen.php Show resolved Hide resolved
src/Screen.php Outdated Show resolved Hide resolved
src/Screen.php Outdated Show resolved Hide resolved
src/Screen.php Outdated Show resolved Hide resolved
@danielpetrica
Copy link
Contributor Author

made the changes required. thanks for pointing the issues out for me

Copy link
Member

@simonhamp simonhamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final thing... please can we return to single-quoted strings where we're not explicitly using interpolation?

Basically this is everywhere you have double-quotes now

@danielpetrica
Copy link
Contributor Author

Yes I'll fix this

@danielpetrica
Copy link
Contributor Author

pushed the update. I'm sorry for all the formatting issues. My IDE applied my default to the project. I'll be more careful next time

@simonhamp
Copy link
Member

No apology needed. Thanks for putting in the work 🙏🏼

@simonhamp simonhamp merged commit b5982c5 into NativePHP:main Oct 20, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants