macOS/QuickLook: support rich thumbnail #107072
|
@ -38,8 +38,9 @@ if(WIN32)
|
|||
|
||||
target_link_libraries(BlendThumb bf_blenlib dbghelp.lib Version.lib)
|
||||
set_target_properties(BlendThumb PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB:msvcrt")
|
||||
endif()
|
||||
|
||||
else()
|
||||
if(UNIX AND NOT APPLE)
|
||||
# -----------------------------------------------------------------------------
|
||||
# Build `blender-thumbnailer` executable
|
||||
|
||||
|
@ -54,3 +55,32 @@ else()
|
|||
target_link_libraries(blender-thumbnailer ${PTHREADS_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
set(SRC
|
||||
src/ThumbnailProvider.mm
|
||||
src/ThumbnailProvider.h
|
||||
src/Info.plist
|
||||
)
|
||||
|
||||
add_executable(blender-thumbnailer MACOSX_BUNDLE ${SRC})
|
||||
set_target_properties(blender-thumbnailer PROPERTIES
|
||||
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/src/Info.plist
|
||||
MACOSX_FRAMEWORK_IDENTIFIER org.blenderfoundation.blender.thumbnailer
|
||||
)
|
||||
set_target_properties(blender-thumbnailer PROPERTIES
|
||||
BUNDLE_EXTENSION appex
|
||||
BL_CODESIGN_ENTITLEMENTS_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/src/ThumbnailExtensionMacOS.entitlements.Debug
|
||||
BL_CODESIGN_ENTITLEMENTS_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/src/ThumbnailExtensionMacOS.entitlements.Release
|
||||
)
|
||||
setup_platform_linker_flags(blender-thumbnailer)
|
||||
target_link_libraries(blender-thumbnailer
|
||||
bf_blenlib
|
||||
# For main function
|
||||
"-e _NSExtensionMain"
|
||||
"-framework QuickLookThumbnailing"
|
||||
)
|
||||
if(DEFINED PTHREADS_LIBRARIES)
|
||||
target_link_libraries(blender-thumbnailer ${PTHREADS_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>blender_thumbnailer</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>blender-thumbnailer</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.blenderfoundation.blender.thumbnailer</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>blender-thumbnailer</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<!-- TODO automate -->
|
||||
<string>3.6.0</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<!-- TODO automate -->
|
||||
<string>3.6.0 2023-04-18</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<!-- TODO automate -->
|
||||
<string>10.15</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionAttributes</key>
|
||||
<dict>
|
||||
<key>QLSupportedContentTypes</key>
|
||||
<array>
|
||||
<string>org.blenderfoundation.blender.file</string>
|
||||
</array>
|
||||
<key>QLThumbnailMinimumDimension</key>
|
||||
<integer>10</integer>
|
||||
</dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.quicklook.thumbnail</string>
|
||||
<key>NSExtensionPrincipalClass</key>
|
||||
<string>ThumbnailProvider</string>
|
||||
<key>com.apple.showsInExtensionsManager</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-only</key>
|
||||
<true/>
|
||||
<key>com.apple.security.get-task-allow</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-only</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#import <QuickLookThumbnailing/QuickLookThumbnailing.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface ThumbnailProvider : QLThumbnailProvider
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,82 @@
|
|||
|
||||
#include "ThumbnailProvider.h"
|
||||
|
||||
/**
|
||||
* This section intends to list the important steps for creating a thumbnail extension.
|
||||
* qlgenerator has been deprecated. App extensions are the way forward.
|
||||
* Process goes something like this:
|
||||
* 1. If an app is launched, or is registered with lsregister, its plugins also get registered.
|
||||
* 2. When a file thumbnail in Finder or QuickLook is requested, the system looks for a plugin
|
||||
* that supports the file type UTI.
|
||||
* 3. The plugin is launched in a sandboxed environment and should call the handler with a reply.
|
||||
*
|
||||
* # Plugin Info.plist
|
||||
* The Info.plist file should contain the following keys:
|
||||
* <dict>
|
||||
* <key>NSExtensionAttributes</key>
|
||||
* <dict>
|
||||
* <key>QLSupportedContentTypes</key>
|
||||
* <array>
|
||||
* <!-- Exactly the file UTIs to be supported. Not inherited from parent bundle. -->
|
||||
* <string>org.blenderfoundation.blender.file</string>
|
||||
* </array>
|
||||
* <key>QLThumbnailMinimumDimension</key>
|
||||
* <!-- To be explored the impact of. -->
|
||||
* <integer>10</integer>
|
||||
* </dict>
|
||||
* <key>NSExtensionPointIdentifier</key>
|
||||
* <!--com.apple.quicklook.thumbnail for preview extensions -->
|
||||
* <string>com.apple.quicklook.thumbnail</string>
|
||||
* <key>NSExtensionPrincipalClass</key>
|
||||
* <!-- Must be the same as in the code. -->
|
||||
* <string>ThumbnailProvider</string>
|
||||
* <!-- Shows checkbox in System Preferences. -->
|
||||
* <key>com.apple.showsInExtensionsManager</key>
|
||||
* <true/>
|
||||
* </dict>
|
||||
*
|
||||
* # Codesigning
|
||||
* - The plugin should be codesigned with entitlements at least for sandbox and read-only/
|
||||
* read-write (for access to the given file).
|
||||
* - com.apple.security.get-task-allow is required for debugging.
|
||||
*
|
||||
* # Registering the plugin
|
||||
* The plugin should be registered with lsregister. Either by calling lsregister or by launching
|
||||
* the parent app.
|
||||
*
|
||||
* # Debugging
|
||||
* Since read-only entitlement is there, creating files to log is not possible. So NSLOG and
|
||||
* viewing it in Console.app (after triggering a thumbnail) is the
|
||||
* way to go. Interesting processes are: qlmanage, quicklookd, kernel,
|
||||
* blender-thumbnailer, secinitd, com.apple.quicklook.ThumbnailsAgent
|
||||
*
|
||||
* LLDB/ Xcode, Other debugging tools can be used to debug the plugin. /usr/bin/qlmanage
|
||||
* is the target. Other args follow.
|
||||
*
|
||||
* # Troubleshooting
|
||||
* - Sometimes blender-thumbnailer running in background can be killed.
|
||||
* - qlmanage -r && killall Finder
|
||||
*
|
||||
* # Triggering a thumbnail
|
||||
* - qlmanage -t /path/to/file.blend
|
||||
* - qlmanage -t -s 512 -o /tmp/ /path/to/file.blend
|
||||
*
|
||||
*/
|
||||
|
||||
@implementation ThumbnailProvider
|
||||
|
||||
- (void)provideThumbnailForFileRequest:(QLFileThumbnailRequest *)request
|
||||
completionHandler:(void (^)(QLThumbnailReply *_Nullable reply,
|
||||
NSError *_Nullable error))handler
|
||||
{
|
||||
|
||||
NSLog(@"hello world from blender");
|
||||
NSURL *foo = [[NSURL alloc] initFileURLWithFileSystemRepresentation:""
|
||||
isDirectory:NO
|
||||
relativeToURL:nil];
|
||||
QLThumbnailReply *reply = [QLThumbnailReply replyWithImageFileURL:foo];
|
||||
|
||||
handler(reply, nil);
|
||||
}
|
||||
|
||||
@end
|
|
@ -1352,7 +1352,16 @@ elseif(APPLE)
|
|||
if(WITH_BLENDER_THUMBNAILER)
|
||||
install(
|
||||
TARGETS blender-thumbnailer
|
||||
DESTINATION Blender.app/Contents/MacOS/
|
||||
DESTINATION Blender.app/Contents/Plugins
|
||||
)
|
||||
get_target_property(BL_CODESIGN_ENTITLEMENTS_DEBUG blender-thumbnailer BL_CODESIGN_ENTITLEMENTS_DEBUG)
|
||||
get_target_property(BL_CODESIGN_ENTITLEMENTS_RELEASE blender-thumbnailer BL_CODESIGN_ENTITLEMENTS_RELEASE)
|
||||
set(BL_CODESIGN_ENTITLEMENTS "$<IF:$<CONFIG:Debug>,${BL_CODESIGN_ENTITLEMENTS_DEBUG},${BL_CODESIGN_ENTITLEMENTS_RELEASE}>")
|
||||
install(CODE
|
||||
"execute_process(COMMAND codesign
|
||||
--deep --force --sign - --entitlements \"${BL_CODESIGN_ENTITLEMENTS}\" --timestamp=none
|
||||
\"${EXECUTABLE_OUTPUT_PATH}/Blender.app/Contents/Plugins/blender-thumbnailer.appex\"
|
||||
)"
|
||||
)
|
||||
endif()
|
||||
|
||||
|
@ -1686,6 +1695,16 @@ execute_process(\
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
# Register with lsregister
|
||||
install(
|
||||
CODE "
|
||||
execute_process(COMMAND /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister
|
||||
-f -R -trusted
|
||||
\"${EXECUTABLE_OUTPUT_PATH}/Blender.app\"
|
||||
)"
|
||||
)
|
||||
endif()
|
||||
# -----------------------------------------------------------------------------
|
||||
# Post-install script
|
||||
|
||||
|
|
Loading…
Reference in New Issue