anthonygelibert / QLColorCode

QuickLook plugin for source code with syntax highlighting.
GNU General Public License v3.0
672 stars 49 forks source link

Doesn't work on 10.15 #51

Closed CarlosAMendoza closed 4 years ago

CarlosAMendoza commented 5 years ago

Needs to be signed so macOS can use it.

rileytwo commented 5 years ago

Is this what you're seeing @CarlosAMendoza?

Screen Shot 2019-09-29 at 8 50 46 AM

However, if I run qlmanage -p .hyper.js, I get a full preview:

Screen Shot 2019-09-29 at 8 55 58 AM

adityasrini commented 5 years ago

No it does not work. GA Catalina. This is the error message I get:

Testing Quick Look preview with files:
    index.js
2019-10-07 20:03:28.975 qlmanage[30011:113479] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x6633, name = 'com.apple.tsm.portname'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2019-10-07 20:03:33.461 qlmanage[30011:113479] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x6e07, name = 'com.apple.coredrag'
See /usr/include/servers/bootstrap_defs.h for the error codes.

EDIT: Command was qlmanage -p index.js. I also tried sudo qlmanage -p index.js. The only difference was that with sudo I didn't get the warnings that this plugin was untrusted and should be moved to the Trash can.

adityasrini commented 5 years ago

I tried the steps from this issue in a related plugin and this time, I get a "this preview cannot be safely displayed in quick look" warning.

kallewesterling commented 5 years ago

Same here. When I try to preview a file, here's what I see:

image
rileytwo commented 5 years ago

While notarizing the app would get rid of that notification, I don't think it would solve the overall issue. You can disable that by running sudo spctl --master-disable (I'm not recommending doing so, I'm just stating this in case you want to try previewing the file without that notification popping up).

I'm able to preview the icon, but still no file preview when pressing space. I'm still getting the same file preview as above

rileytwo commented 5 years ago

After looking around in the logs, I'm able to get this (this is for the .hyper.js file above):

Preview failed due to security risk: web page's main frame was asked to load a url that is not a file URL, and does not conform to html or xml.

sbarex commented 5 years ago

After looking around in the logs, I'm able to get this (this is for the .hyper.js file above):

Preview failed due to security risk: web page's main frame was asked to load a url that is not a file URL, and does not conform to html or xml.

On GeneratePreviewForUrl.m, at line 61 you must add the mime type definition to the properies variable. So the patched code is:

CFDictionaryRef properties = (CFDictionaryRef)@{
        (__bridge NSString *)kQLPreviewPropertyTextEncodingNameKey : textEncoding,
        (__bridge NSString *)kQLPreviewPropertyMIMETypeKey : @"text/html",
    };
sbarex commented 5 years ago

after numerous attempts I have notarized the plugin. After the change I suggested above for adding the mime attribute now works on catalina!

the steps are:

Build the plugin then create a zip: $ /usr/bin/ditto -c -k --keepParent "*folder containing qlcolorcode.qlgenerator*" QLColorCode.zip Then send the zip for notarization whit your appleid user id ad a application password for login: xcrun altool --notarize-app --primary-bundle-id "org.n8gray.qlcolorcode" -u "*appleid user name*" -p "*app password appleid*" --file QLColorCode.zip After the notarization is complete staple the result: $ xcrun stapler staple QLColorCode.qlgenerator

I use an Apple Developer Subscription account. I did not understand if it is possible to notarize with a free account.

I have found more info for notarization on https://stackoverflow.com/a/56799591/1409904

Anyway Apple has deprecated all quicklook api like QLPreviewRequestSetDataRepresentation and suggests to use QLPreviewingController in a Preview Extension (see http://codeworkshop.net/objc-diff/sdkdiffs/macos/10.15/QuickLook.html). But I don't have found any info for use QLPreviewingController on macos.

rileytwo commented 5 years ago

@sbarex the links are taking me to an issue search on this repo

I'm enrolled in the dev program also, but I don't think it's possible to notarize without a paid developer account. There isn't really an official (or clear) statement from apple about it, but everything I've found on the internet points to needing a paid developer account to notarize. Are you not getting any errors in Console.app after adding in those lines?

sbarex commented 5 years ago

@sbarex the links are taking me to an issue search on this repo

I'm enrolled in the dev program also, but I don't think it's possible to notarize without a paid developer account. There isn't really an official (or clear) statement from apple about it, but everything I've found on the internet points to needing a paid developer account to notarize. Are you not getting any errors in Console.app after adding in those lines?

On Console.app, searching for com.apple.quicklook as suggested from qlmanage with -d arguments (that it is also deprecated...) don't show any errors when open a preview of a source file.

But there are some errors when generating thumbnail on Finder with icon view (in detail view the associated application icons are shows for the file and not the preview):

The resulting icon are all black (i use the zenburn theme). With qlmanage -t the icon is generated correctly.

rileytwo commented 5 years ago

I was able to get it working with your instructions @sbarex!

jonluca commented 5 years ago

Thanks for the help @sbarex - @anthonygelibert is there any chance that a notarized version of the binary will be published/released?

Additionally, shouldn't disabling notarization sudo spctl --master-disable make it work? It's still not working after disabling SIP and notarization.

CarlosAMendoza commented 5 years ago

A signed binary would be great for those who don’t have their own developer account. Also thank you for fixing the issue.

alexclst commented 5 years ago

Honestly, even though I have a developer account I would rather that the person responsible for past releases make a notarized binary available than building and notarizing this plugin myself, because then the notarization for the plugin is entirely within its actual developer’s account with Apple. I just don’t think that many people should notarize what is the same version of the same plugin, but maybe that is me just figuring it may come back to bite us at some point.

Plus, the issue is with virtually all but one of the QuickLook plugins I had pre-Catalina. We can option-click apps to bypass the security settings stopping us from using them (or at least we could pre-Catalina, haven’t actually run into a need to do that yet on Catalina), but cannot for QuickLook plugins. So another fix would just be an update to Catalina allowing us to option-click plugins to bypass security checks. Unfortunately that doesn’t seem likely to ever happen.

rileytwo commented 5 years ago

@alexclst I get what you're saying. I don't think @sbarex was suggesting everyone notarize it themselves (nor was I), but instead was showing how the issue can be resolved. I'm glad that they listed out the steps to "fix" the problem because there's not many other resources to help with a Quick Look problem like this one.

Since Quick Look plugins are deprecated and will not working in future releases of macOS, it may not be worth @anthonygelibert's time and money to sign up for a developer account just to notarize QLColorCode, if he doesn't already have a developer account.

sbarex commented 5 years ago

Unfortunately I don't have a personal developer account to use to share the compiled version of the plugin and I can't use my company account for this. I really hope Apple doesn't want to delete quicklook because it was a very useful and unique macos feature. From the little that I understood, however, I think that more developers can notarize the same executable. When executing the program, I suppose macos only checks the presence in Apple's database of a softare that corresponds to a certain hash signed by a certain author and not searching for a specific executable...

alexclst commented 5 years ago

Apple isn’t deleting Quick Look, but just requiring that what used to be separate plugins be App Extensions instead. At least, that is my take on seeing Quick Look as a part of the Extensions preferences in System Preferences:

Screenshot 2019-10-14 at 10 34 07 AM

adityasrini commented 5 years ago

If the maintainer doesn't have the bandwidth to notarize this, perhaps someone from the community can request to become the maintainer or fork and notarize this themselves?

adityasrini commented 5 years ago

I have very limited Objective C knowledge to be able to discern and code review PRs and issue fixes to bugs so I'm not so sure about doing this myself.

sbarex commented 5 years ago

Apple isn’t deleting Quick Look, but just requiring that what used to be separate plugins be App Extensions instead. At least, that is my take on seeing Quick Look as a part of the Extensions preferences in System Preferences:

Screenshot 2019-10-14 at 10 34 07 AM

oh good! do you have found any source example?

rileytwo commented 5 years ago

@sbarex does qlcolorcode still work for you between reboots? Even if I'm able to get it working through building, signing, and notarizing the bundle, it doesn't work the next time I boot my mac up

alexclst commented 5 years ago

oh good! do you have found any source example?

Apple’s sample code for Building an App Based on the Document Browser View Controller talks about previewing custom document formats. This is talking about iOS, but both iOS and macOS now seem to share the same Quick Look Preview Extension target type for building these new App Extension based Quick Look plugins that this sample code includes. I know nothing about the old .qlgenerator plugins at the source level, so would have no way of telling you how different or not this new API is from that which is now deprecated.

sbarex commented 5 years ago

@sbarex does qlcolorcode still work for you between reboots? Even if I'm able to get it working through building, signing, and notarizing the bundle, it doesn't work the next time I boot my mac up

I'm using catalina on vmware fusion for testing before upgrading my mac. For now after the full reboot of the virtual machine the plugin works correctly.

sbarex commented 5 years ago

Apple’s sample code for Building an App Based on the Document Browser View Controller talks about previewing custom document formats. This is talking about iOS, but both iOS and macOS now seem to share the same Quick Look Preview Extension target type for building these new App Extension based Quick Look plugins that this sample code includes. I know nothing about the old .qlgenerator plugins at the source level, so would have no way of telling you how different or not this new API is from that which is now deprecated.

Ok, I saw. I will try to migrate the code on the new system, apparently it does not seem a very complex operation. Is the new quicklook extension system only valid for catalina? The test plugin I made works on catalina and is seen in the list of extensions while on mojave it does nothing and does not appear in the extensions.

Nef10 commented 5 years ago

I had a look at migrating the code over, should not be too complex. I experimented with migrating the https://github.com/whomwah/qlstephen plugin and it was fairly easy. But with the plugins running in a sandbox you cannot just call the highlight tool as the path of the homebrew installation is not allowed to be called. I tried adding the binary to my project but it failed because it calls a dsym. Apparently compiling it so that is does not require the dsym is not easy. The easier solution would probably be to do a link to highlight in one of the allowed path from the sandbox, but this needs to be done manually by the user.

sbarex commented 5 years ago

I'm converted all objective-c code to swift and I have also implemented a switch for light/dark theme.

To works the extension must be sandboxed. But a sandboxed code cannot execute shell process, not event call which highlight! After many test I have found a solution using a XPC service dedicated to obtain the formatted code. The XPC may not be sanboxed, so it's can run shell command. I didn't check if a signed sandbox app require a paid developer account, but for now it seems that the extension does not require notarization.

The advanced of extension is that it's embedded inside an app. So in this app is possible to create an interface to customize the extension (choose the theme for example).

Now I need to make more test before relasing the code.

sbarex commented 5 years ago

I had a look at migrating the code over, should not be too complex. I experimented with migrating the https://github.com/whomwah/qlstephen plugin and it was fairly easy. But with the plugins running in a sandbox you cannot just call the highlight tool as the path of the homebrew installation is not allowed to be called. I tried adding the binary to my project but it failed because it calls a dsym. Apparently compiling it so that is does not require the dsym is not easy. The easier solution would probably be to do a link to highlight in one of the allowed path from the sandbox, but this needs to be done manually by the user.

The solution to embed higlight binary inside the extension is not praticable. colorize.sh call some other command to preprocess some type of files (decompile applescript and java, convert binary plist, …). And the embedded higligligh should be compiled statically, embedding all required libraries (lua, bootstrap, others?) and I don't know how make a fat binary valid for many macos version.

Nef10 commented 5 years ago

I am by no means an expert - I just spend a couple of hours experimenting. At the end I also found XPC mentioned but did not have any time investigating more, maybe I should have mentioned this. I just wanted to share my insights in case in would help anybody, but seem you have already made more progress than I did :)

Feel free to just put the code up, I can and would like to help testing or whatever else is needed

NylonDiamond commented 5 years ago

We're all counting on you guys! You can do it!

sbarex commented 5 years ago

Ok, I tried to migrate the qlgenerator to the extension system: sbarex/SourceCodeSyntaxHighlight. It's a programming exercise, I don't think we can consider it a real application. I'm not an application developer so the program may have numerous bugs or naivety.

NylonDiamond commented 5 years ago

Awesome, thanks for the hard work! Can you give a quick tutorial on how to use this? That would be awesome. I cloned the project but am not so experienced in Xcode and Swift programming. How do I launch the gui/service? Thanks

rileytwo commented 5 years ago

@NylonDiamond (this is just my experience)

After cloning the repo, open QLExt.xcodeproj in Xcode. Build the project (cmd+b, or pressing the arrow in the top left of the toolbar). After it builds, go to your Xcode derived data folder, which is at ~/Library/Developer/Xcode/DerivedData/, and find the QLExt build.

In my case, it was called QLExt-aevsjvkhlsnolcgkutvwtnucbwag (don't mind the extra letters). In that folder, go to Build/Products/Debug/ and you'll find QLExt.app. Copy this to your application folder, open the application, and then press cmd+, to go to preferences, where you can set up what theme and font you want to use.

edit: this worked for me

NylonDiamond commented 5 years ago

Awesome, that build process that worked for me as well. I'm able to preview CSS, HTML and PHP at the moment. No javascript, shell scripts or XML. @sbarex did say there would possible be some bugs so it's all good. Just letting people know. Thanks again @sbarex !

alexclst commented 5 years ago

Thanks @sbarex for doing this! After first thinking it wasn’t working I see it was just file format issues. I recommend that any of us who have questions or issues regarding this app submit issues over at its repo. This is a very great start, and I’m happy to have it back, even if it has a ways still to go to be on par with QLColorCode.

sbarex commented 5 years ago

QLColorCode will always remain the number one for me. If his developer want to migrate it to the Catalian extensions I would be happy! I have added support for some missing format but there are still bug in my code!

NylonDiamond commented 5 years ago

Woo, javascript and .sh works for me now. Those were a couple of the main ones I was needing. Thanks again. Your rock man! Hopefully, there will be support for JSON and othe types in the future.

DaveyJake commented 5 years ago

Just wanted to let everyone know that QuickLookJSON is fixed for Catalina.

When looking at the package contents, I noticed one major difference: the presence of a folder named _CodeSignature which contains a single file named CodeResources (no file extension). It's a .plist XML file that documents every file contained within the package and (when necessary) assigns each an internal hash value. Not sure if that's what needs to be done across all of the QL plugins not currently working but just wanted to share. Hopefully all will be fixed soon?

NylonDiamond commented 5 years ago

Nice! It does seem to be working. Thanks for the update @DaveyJake .

sbarex commented 5 years ago

The _CodeSignature/_CodeSignature contain the signature of the files inside the package. The quicklook generator was notarized by the author. This is why it works.

setanarut commented 5 years ago

@sbarex You seem like someone who can fix it. https://github.com/Nyx0uf/qlImageSize/issues/45#issuecomment-540099534

lucky13820 commented 5 years ago

Ok, I tried to migrate the qlgenerator to the extension system: sbarex/SourceCodeSyntaxHighlight. It's a programming exercise, I don't think we can consider it a real application. I'm not an application developer so the program may have numerous bugs or naivety.

Thanks, your app is working fine.

Caf commented 5 years ago

Any chance to have this working from the HomeBrew casks when updated? Thanks for the hard work guys!

sbarex commented 5 years ago

Has anyone tried to see if it works on 10.15.1? I updated my virtual machine and it seems that now the various qlgenerators works but I'm not sure if I did something strange in the settings or if it's a problem solved in the last update.

darkbrow commented 5 years ago

It works on my Mac running macOS 10.15.1

sbarex commented 5 years ago

Works also for xml and plist format?

darkbrow commented 5 years ago

No. It does not work for xml and plist format.

vpicouet commented 5 years ago

Hello, thanks a lot for this work, unfortunately I did not manage to build the app (image). I am new to Xcode, do you now what's the issue here? Thanks!

Capture d’écran, le 2019-11-13 à 14 49 55

sbarex commented 5 years ago

Hello, thanks a lot for this work, unfortunately I did not manage to build the app (image). I am new to Xcode, do you now what's the issue here? Thanks!

Capture d’écran, le 2019-11-13 à 14 49 55

Have you cloned the project or only download the source code? You must select the "Syntax Highlight" target on the active scheme popup, Lua libs will be automatically compiled.

The correrct way to download the source is:

git clone https://github.com/sbarex/SourceCodeSyntaxHighlight.git
cd SourceCodeSyntaxHighlight
git submodule init  
git submodule update

Then open the SourceCodeSyntaxHighlight.xcodeproj and select Syntax hightlight from active scheme popup.

In my repository there is also the precompiled version of the app so is not required to download and compile manually the source code.

In the future plese notifify any bug inside my repository, thanks.

neslob commented 4 years ago

Removing the quarantine attribute from all files is another solution, to get Quicklook working. No need to change any code.

List attributes xattr -r ~/Library/QuickLook/QLColorCode.qlgenerator

Delete attribute com.apple.quarantine xattr -d -r com.apple.quarantine ~/Library/QuickLook/QLColorCode.qlgenerator

gbstan commented 4 years ago

I find QLColorCode very useful and use it daily. It would be very useful if we could get it to work on macOS 10.15, but for the moment this doesn't seem to be the case. After installing highlight and QLColorCode from homebrew (brew cask install qlcolorcode highlight)I have tried:

xattr -d -r com.apple.quarantine ~/Library/QuickLook/QLColorCode.qlgenerator

on macOS 10.15.2 but it doesn't work (even after relaunching finder or rebooting)