-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Catalyst Release Notes Support #1482
Comments
I haven't tried Catalyst. If it's compatible with Cocoa and can use frameworks, it should be able to use Sparkle. |
Sparkle builds against the normal macOS sdk, so I'm pretty sure you can't use it directly from a Catalyst app. You can probably use it by bridging to macOS via a plugin, and having the plugin link against Sparkle and create the SUUpdater object. I'm not sure how well this will work, but I'm planning to try it. Will let you know... :) |
Update: I think the approach I described above should work, but I've currently hit an issue. My bridging plugin links to Sparkle, embeds the framework, and owns an The various SU keys are in the main application's Checking for updating appears to be working fine. However, currently, when it finds an update, I'm getting a crash in It seems that the system is actually crashing inside WebView, trying to access the alert's window: As yet, I haven't figured out what's going on here. |
I did wonder if this was something to do with
which looks suspiciously like WebView itself isn't there. However, I've tried swapping out WebView for WKWebView, and I'm still getting a crash in a similar place, so I don't think it's that. |
This crash seems to be related to using WebKit from the bridging plugin, and not specifically anything to do with Sparkle. I suspect that it may be caused by WebKit getting confused about whether or not it's running under AppKit or Catalyst. Unfortunately WebKit is used by the default driver (via SUUpdateAlert), so it may be necessary to write an alternative driver. |
Does it help if you hide release notes? |
So, I didn't try the hiding of release notes, but I suspect that it wouldn't help. The WebView would still be in the xib, and just opening a xib-based window containing a WebView from the AppKit side of things is enough to crash. However, I have got it working: https://twitter.com/samdeane/status/1233081407947395074 The approach I took required a bit of effort, but it allows me to present a custom Sparkle UI from the Catalyst side of things (as it happens I'm using SwiftUI for this, though it's not required). To do this I had to create a custom Sparkle user driver (implementing the The details are probably too much to go into here, but I will write it up as a blog post and drop a link here when I'm done. |
I've not yet had time to write that blog post, but I have managed to generalise the code a bit and extract it into an example which you can find here. |
FWIW I updated generalised my code a bit more and made a fairly self-contained solution. You just link to the framework from your Catalyst app, and it deals with embedding Sparkle and loading the plugin. |
@kornelski I've also tested a bit, unfortunately hiding the release notes doesn't help as @samdeane already expected because the nib still contains the class. |
Another idea: I just noticed this marker: |
WKWebView requires macOS 10.10+. I've only very recently raised minimum macOS version for Sparkle to 10.9. |
Got it, what about a
|
I know some apps use release notes to warn that an update is not free, so hiding release notes could be an unpleasant surprise. |
Maybe it would be fine to switch Sparkle 2.x only? |
I could try, can you push the 2.x to cocoapods please (maybe as 2.x-beta)? I've just checked the repo but only the 1.x is available there 🤔 |
I don't use Cocoapods. I could release 2.0-beta if you create a podspec. |
What about the podspec that is in the project already? |
We fallback to legacy WebView in two cases: * On systems prior to macOS 10.11 (it may be possible to support WKWebView in 10.10, but due to an 10.11+ only API I didn't bother putting in the effort) * For apps using the downloader XPC service which are most likely sandboxed apps without an outgoing network entitlement. WKWebView doesn't function in that case (FB6993802 - feedback-assistant/reports#1) Additional notes: * Added an abstraction for using WebView or WKWebView * Web view is created and inserted programmatically rather than from the nib which has previously caused issues (and is not allowed for WKWebView prior to 10.12 due to some NSCoding bug). * We need to rely on WKWebView private API for drawing transparent background (FB7539179 - feedback-assistant/reports#81). Additional notes in the code. * We always inject a custom stylesheet for dark mode colors and default font family/size (for WKWebView). * This should also improve the Catalyst support story (#1482)
We fallback to legacy WebView in two cases: * On systems prior to macOS 10.11 (it may be possible to support WKWebView in 10.10, but due to an 10.11+ only API I didn't bother putting in the effort) * For apps using the downloader XPC service which are most likely sandboxed apps without an outgoing network entitlement. WKWebView doesn't function in that case (FB6993802 - feedback-assistant/reports#1) Additional notes: * Added an abstraction for using WebView or WKWebView * Web view is created and inserted programmatically rather than from the nib which has previously caused issues (and is not allowed for WKWebView prior to 10.12 due to some NSCoding bug). * We need to rely on WKWebView private API for drawing transparent background (FB7539179 - feedback-assistant/reports#81). Additional notes in the code. * We always inject a custom stylesheet for dark mode colors and default font family/size (for WKWebView). * This should also improve the Catalyst support story (#1482)
@zorgiepoo I gave it a try and there are still WKWebView problems. I guess because WKWebView is different between UIKit and AppKit? Trying to hide the release notes didn't seem to help.
|
I did get this working by making one small change shown in #1713. If you make that change, disable showing release notes, and use a bundle to load Sparkle, it works. This wouldn't have been possible without #1704, so many thanks for that change. Showing release notes in a Catalyst app with Sparkle is something I suspect isn't possible. The UIKit WKWebView vs. the AppKit WKWebView are probably too different. At least this gets those of us doing Catalyst apps a way to distribute test builds, since there still isn't TestFlight for the Mac yet. |
Actually I figured out that even without any Sparkle code at all, if run this:
within my AppKit bundle, it crashes with same error. I've created a related bug report at feedbackassistant.apple.com. |
Yeah I guess WKWebView isn't a NSView in this case which sounds quite odd to me.. but I'm not so familiar with Catalyst. Thanks for #1713 which is a good addition and for filing the Feedback report. And kudos for trying the custom user driver / UI approach here. |
I've adopted the changes of @vincode-io for the 1.x version in #1715 |
FYI, I just checked the status of my feedback report, it is set to: |
It then seems like if you want to use a web view to show release notes in a Catalyst app, you need to show the web view on the iOS side of your app, which would entail a custom user driver (2.x). Hiding release notes is probably simpler for majority. |
Catalyst is more documented on https://sparkle-project.org/documentation/programmatic-setup/ now. |
Hello - I have run into this problem, and hiding release notes doesn't seem like a satisfactory solution, nor does reinventing the wheel by replacing the whole window with a custom UI. How feasible would it be to display release notes with something other than a WKWebView? I believe NSAttributedString can be created from HTML, and displayed in an NSTextView? Failing that, can anybody who's already solved this with a custom UI share their code? |
sparkle-cli has a custom UI (or lack of one) that creates an NSAttributedString from the HTML and prints it to the console. So if you create a custom UI, it should be possible. |
If you want Sparkle to automatically use a NSTextView for Catalyst apps then maybe that is possible as well (maybe would involve a new |
Okay, so I think I got it working well enough for my own purposes, with an SUWebView implementation that does this:
Like you said, not good enough to ship, but hopefully this is a helpful start if anybody wants/needs to take it further. |
Nice. How does it look though or what’s lacking? |
Looks basically fine, except it's not changing the text color for dark mode (that might be an easy fix though) But some things it lacks that I don't need personally:
|
The styling from the attributed string will be as much as we can get here.
Yeah this is expected (Sparkle also disables javascript by default generally; most apps don't use it).
I think you can use -[NSProcessInfo macCatalystApp] Link clicking and dark mode should be possible or at least TextEdit can do it. I think this would be nice over no release notes. |
Dark mode should be usesAdaptiveColorMappingForDarkAppearance property. Link clicking might need to override this delegate method https://developer.apple.com/documentation/appkit/nstextviewdelegate/1449527-textview?language=objc - for web views we do have some "safe link" handling and only allow certain url schemes. |
I looked into this more and tried to do a more complete implementation based on @WeirdHat 's snippet however it cannot be shipped. The NSAttributedString HTML reader APIs use WebKit underneath. If you pass any HTML options like I tried to do, a Catalyst app will crash with the stacktrace pointing to WebKit usage. If you don't pass any options, it will "work" (for now) but I consider this brittle and easily breakable in the future. To use NSAttributedString+HTML, I think there needs to be an out-of-process (XPC) implementation. If you want to support a non-HTML path, this could technically be safe and do-able today though (but I consider this somewhat incomplete). |
I added support for a plain text view for release notes in #2315 After thinking about it, I don't like the idea of converting HTML into a NSAttributedString. I don't want it to (potentially) go through WebKit and it also didn't always give the result I'd expect if I recall correctly. I think markdown support in the future would make a better alternative #2319 |
Can I use Sparkle to auto-update apps (distributed outside of the Mac App Store of course) that are built using Catalyst? Is there anything I need to do special to make it all work?
The text was updated successfully, but these errors were encountered: