feat: request and get current position api for macOS #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
Added a custom
GeolocationSystemPermissionManagerthat wraps the existing one in electron to make geolocation requests.Serves as an alternative API to navigator.geolocation that many users are facing issues with to make location requests on macOS. The implementation includes macOS geolocation permission handling as well.
Fixes: electron#45290
This fork is a working solution for some of the common geolocation needs of apps. It covers requesting and getting current position (latitude, longitude).
Electron v37.0.0
Use the following APIs:
Note
Request Permission prompt will open only the first time a geolocation request is made. Subsequent calls will open System Settings (Location Services tab).
Once your app has permission, you can retrieve the current position with:
Note
Calling this without geolocation permission will return {latitude : 0, longitude : 0}
You may build it yourself and give it a try! If you run into issues, report them in the issues tab of the fork 🚀
Implementation:
The new
GeolocationSystemPermissionManageressentially uses a wrapped version of theSystemGeolocationSourceAppleclass, the sameGeolocationSystemPermissionManagerhanded over to device service during startup. This change was essential because only a single instance of CLLocationManager can exist (as previously used inSystemGeolocationSourceApple), and multiple instances would lead to a crash.Summary:
Extended
SystemGeolocationSourceAppletoSystemGeolocationSourceAppleCustomand initialized the CLLocationManager inside it before passing it to the device service.Added utility functions to request permission and retrieve the current geolocation under the extended
SystemGeolocationSourceAppleCustomProvided an API to call these functions from main and rendered process
Checklist
npm testpassesRelease Notes
Notes: Added a custom geolocation manager for electron. Provides a way to request for geolocation access