Comments (19)
I'm willing to have another go at this; however, I'm wondering if maybe we can release the current codebase as a new version on crates.io? There have been quite a few changes since the published version was released and I think some of these could be added to notify-rust
while we wait.
from mac-notification-sys.
Alright, I started a usernotifications
branch on my fork. I'm just trying things out at the moment but I seem to be hitting some roadblocks due to the little knowledge I have of the macos/objc build system.
I've been able to link the UserNotifications framework using #[link(name = "UserNotifications", kind = "framework")]
(as well as adding .flag("-mmacosx-version-min=10.14")
to the build.rs
file. With this, I'm able to successfully include the UserNotifications.h
file.
However, my major roadblock and I'm unsure how to handle it is with using it. When I try getting an instance of the UNUserNotificationCenter
object with [UNUserNotificationCenter currentNotificationCenter]
, I get the error Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL
which may have to do with
- The overriding of the bundleIdentifier
- Maybe some kind of build step I'm forgetting that is required for macos binaries?
Info.plist
maybe? - Perhaps this is the step that requires the codesigning (which I haven't tried yet).
Google searches return unanswered questions from a couple of years ago so that doesn't help. Also, it seems most people (and Apple docs) expect you to use Xcode to build your binaries, which limits the number of resources I can find on this.
If anyone knows about the macos build steps, I'd appreciate any insight into what this might be caused by.
from mac-notification-sys.
FWIW, UserNotifications.framework
requires your app be codesigned + (I think, am mobile so can't look up) opted in to the hardened runtime.
I have UserNotifications.framework working in cacao, but there's no demo - but if the app is codesigned with valid entitlements and so on, it should work.
from mac-notification-sys.
Oh yeah sorry I never really got around to finishing this. Major roadblock was (probably still is) codesigning. It's possible but I have little to no knowledge of this and I can't find much documentation on doing it with non-Xcode codebases. So perhaps someone (with more experience) wants to take a stab at it?
from mac-notification-sys.
For what it's worth, the codesigning requirement does get a bit odd for people just looking to release a cross-platform tool. There's realistically an argument to just keep using the older API until it well and truly stops working.
If you wanted to upgrade mac-notification-sys
to use the newer API, there's a few things I can think of off the top of my head that are worth noting:
- Definitely feel free to borrow and/or extend the code I used in cacao. I'd be happy to be a second pair of eyes or a sanity check if it's helpful.
- For an app that's going to be a complete
.app
bundle, the codesigning requirement isn't too thorny.cargo-bundle
coupled with acodesign
script has worked fine for me in the past. - For an binary that's not a
.app
bundle, you could likely make use of the API by embedding theInfo.plist
. You'd need to pass something like-sectcreate __TEXT __info_plist /path/to/Info.plist
as a linker flag, and then runcodesign
on the resulting binary with an appropriate entitlements file. - I would maybe keep both APIs (old and new) around, so users in development mode could build and test without needing to go the full codesign route from the start.
from mac-notification-sys.
@h4llow3En I think we never made this release, if you want you can make me co-owner on crates.io and I can take that off your hands
from mac-notification-sys.
@hoodie I send an invite to be coowner
from mac-notification-sys.
As a heads up on why this might be a PITA...
UserNotifications.framework
requires that the application be code-signed. NSUserNotification
does not have this requirement last I checked.
from mac-notification-sys.
Since macOS 11.0 the NSNotification Framework is now marked ad deprecated.
Fortunately https://docs.rs/tugger-apple-codesign/0.2.0/tugger_apple_codesign/ tries to provide a codesigning.
Maybe this is the missing step to finally switch to the UN API
from mac-notification-sys.
@Pandawan FYI If you still have the time 🙂
from mac-notification-sys.
Haven’t looked too much into it, but IIRC this only handles code signing and not notarization, which is required to run apps on Big Sur... Would have to check if that doesn’t prevent us from using the framework
from mac-notification-sys.
Nice, yeah something to try out. I see you implemented it in rust using the objc
crate instead of using objective-c code directly like mac-notification-sys currently does, perhaps this is also something we could do? Any pros/cons you observed?
from mac-notification-sys.
Pros are that it just feels more in-line with it being a Rust project. Cons... none so far, but for all I know there could be some.
from mac-notification-sys.
just checking in @Pandawan @h4llow3En are the roadblocks mentioned above still valid? are we stuck here or is there something we could pick up?
from mac-notification-sys.
Unfortunately it's the same with me. I found https://github.com/indygreg/PyOxidizer/tree/main/tugger-apple-codesign which could be interesting, but I had no time to dive into it
from mac-notification-sys.
[Question]
Hello, I really like this repo and notify-rust! Awesome! While I'm working on my pomodoro cli app, I faced this issue also. At first I tried to solve this problem but failed.. And I wonder how other libraries in different languages handle this issue. So I investigated a bit.
- golang: beeep utilizes osca script
- nodejs: node-notifier has executable binary and calls this for notifying. And the binary is terminal-notifier
- php: JoliNotif, I don't know php but it seems utilizes both osascript and terminal-notifier binary
It seems many libraries uses executable directly. So I wonder is there some reason to use raw objective-c in mac-notification-sys
?
from mac-notification-sys.
For osascript/Apple Script, the capabilities are much more limited (only title, subtitle, and sound are available).
As for terminal-notifier, it doesn’t support actions and instead recommends using alerter instead for alerts (sticky notifications or notifications with actions). This would require having two binaries instead of one to support every kind of notification, which (imo) doesn’t feel very optimal when a simple objective-c file can handle both.
In general, having Rust interface directly with the API is much more powerful than this kind of indirection.
Perhaps we can integrate mac-notification-sys to use cacao (as mentioned above) since it already supports UserNotifications—or maybe take inspiration from how it does things?
The other option, which is what I was trying to do a while ago, is to upgrade mac-notification-sys and figure out how to sign it.
from mac-notification-sys.
- For an binary that's not a
.app
bundle, you could likely make use of the API by embedding theInfo.plist
. You'd need to pass something like-sectcreate __TEXT __info_plist /path/to/Info.plist
as a linker flag, and then runcodesign
on the resulting binary with an appropriate entitlements file.
If you'd rather avoid linker flags, I made embed_plist
which handles this with a declarative macro.
from mac-notification-sys.
I've been trying to get this going again for the past few days with a quick objc-only project and simply cannot get past this issue:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL
I've even tried with a Console project on Xcode directly and I get the same error. (To be fair, Xcode shows a lot of different options for linking, bundle, etc. so I'm not sure if I set things up properly on there).
I thought that perhaps if I were to codesign, add the appropriate entitlements and Info.plist things would start working.
So I added a quick Info.plist file which is compiled and embedded with build.sh; after this, I codesigned with the Entitlements.plist using the sign.sh script.
However, this seems to get rejected by the OS (killed immediately on start) with the error (in the Console, not from the program directly):
com.migueltenant.foo: Unsatisfied entitlements: com.apple.developer.aps-environment
implying that my push notifications entitlements are not complete but I cannot find any documentation on what the requirements for notification entitlements are. (Note: Adding/Removing sandbox does not change anything)
Note that I've been codesigning with a self-signed certificate as I do not have a paid Apple Developer license. I've tried signing with one of the Xcode auto-generated ones (for development) in my Keychain Access but this does not seem to change anything.
So any thoughts on how to get this working would be appreciated.
from mac-notification-sys.
Related Issues (20)
- set_application appears not to be thread safe
- Hangs on macOS Catalina HOT 1
- Add responses to Notification HOT 1
- Create Github Actions
- Notification timeout or dismiss event
- NSDictionary uses only NSStrings
- Replace send_notification() with show() HOT 1
- Using rust bindgen HOT 2
- Replace dependency on dirs with dirs-next
- Mac OS X 11.0.1 build fails HOT 4
- build fail in macos x 10.15.7 HOT 18
- set_application doesn't seem to take effect (and can't be set twice) HOT 4
- Displaying alerts with actions? HOT 1
- macOS 11.5 does not seem to send notifications HOT 1
- Notifications do not display HOT 20
- MacOS 13 failure
- v0.5.3 crashes HOT 9
- Possible version mismatch in CoreFoundation.framework HOT 2
- Action buttons HOT 2
- crash when label is clicked in the dropdown options HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mac-notification-sys.