From ddf41d0c4ee3f661bd6c74300960ece547bb6f6d Mon Sep 17 00:00:00 2001 From: Ankit Meel Date: Mon, 17 Apr 2023 02:03:10 +0530 Subject: [PATCH 1/7] WIP: macOS: support QuickLook preview Can't get the appex to be picked up the OS :( --- source/blender/blendthumb/CMakeLists.txt | 50 +++++++- .../src/Base.lproj/PreviewViewController.xib | 21 ++++ source/blender/blendthumb/src/Info.plist | 46 +++++++ .../blendthumb/src/ThumbnailProvider.h | 10 ++ .../blendthumb/src/ThumbnailProvider.mm | 119 ++++++++++++++++++ source/creator/CMakeLists.txt | 8 +- tests/gtests/runner/CMakeLists.txt | 1 - 7 files changed, 249 insertions(+), 6 deletions(-) create mode 100644 source/blender/blendthumb/src/Base.lproj/PreviewViewController.xib create mode 100644 source/blender/blendthumb/src/Info.plist create mode 100644 source/blender/blendthumb/src/ThumbnailProvider.h create mode 100644 source/blender/blendthumb/src/ThumbnailProvider.mm diff --git a/source/blender/blendthumb/CMakeLists.txt b/source/blender/blendthumb/CMakeLists.txt index feec85d9056..08f8e15a143 100644 --- a/source/blender/blendthumb/CMakeLists.txt +++ b/source/blender/blendthumb/CMakeLists.txt @@ -21,6 +21,10 @@ set(SRC src/blendthumb_png.cc ) +set(LIB + bf_blenlib +) + if(WIN32) # ----------------------------------------------------------------------------- # Build `BlendThumb.dll` @@ -36,10 +40,14 @@ if(WIN32) add_library(BlendThumb SHARED ${SRC} ${SRC_WIN32}) - target_link_libraries(BlendThumb bf_blenlib dbghelp.lib Version.lib) + list(APPEND LIB + dbghelp.lib + Version.lib + ) + target_link_libraries(BlendThumb ${LIB}) set_target_properties(BlendThumb PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB:msvcrt") - -else() +endif() +if(UNIX AND NOT APPLE) # ----------------------------------------------------------------------------- # Build `blender-thumbnailer` executable @@ -49,7 +57,41 @@ else() add_executable(blender-thumbnailer ${SRC} ${SRC_CMD}) setup_platform_linker_flags(blender-thumbnailer) - target_link_libraries(blender-thumbnailer bf_blenlib) + target_link_libraries(blender-thumbnailer ${LIB}) + if(DEFINED PTHREADS_LIBRARIES) + target_link_libraries(blender-thumbnailer ${PTHREADS_LIBRARIES}) + endif() +endif() +if(APPLE) + # ----------------------------------------------------------------------------- + # Build `blender-thumbnailer` appex + + set(SRC_CMD + src/ThumbnailProvider.mm + src/ThumbnailProvider.h + src/Info.plist + ) + + add_executable(blender-thumbnailer MACOSX_BUNDLE ${SRC} ${SRC_CMD}) + 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 + XIB_RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/Base.lproj") + # Doesn't affect other generators. So need to specify extension for others. + set_target_properties(blender-thumbnailer PROPERTIES + XCODE_PRODUCT_TYPE com.apple.product-type.app-extension) + set_target_properties(blender-thumbnailer PROPERTIES + BUNDLE_EXTENSION appex) + setup_platform_linker_flags(blender-thumbnailer) + set_target_properties(blender-thumbnailer PROPERTIES BUILD_WITH_INSTALL_RPATH true) + list(APPEND LIB + "-framework QuickLookThumbnailing" + "-fobjc-link-runtime" + "-fapplication-extension" + "-e _NSExtensionMain" + ) + target_link_libraries(blender-thumbnailer ${LIB}) if(DEFINED PTHREADS_LIBRARIES) target_link_libraries(blender-thumbnailer ${PTHREADS_LIBRARIES}) endif() diff --git a/source/blender/blendthumb/src/Base.lproj/PreviewViewController.xib b/source/blender/blendthumb/src/Base.lproj/PreviewViewController.xib new file mode 100644 index 00000000000..cb883fcbb35 --- /dev/null +++ b/source/blender/blendthumb/src/Base.lproj/PreviewViewController.xib @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/source/blender/blendthumb/src/Info.plist b/source/blender/blendthumb/src/Info.plist new file mode 100644 index 00000000000..fa814fd0ad3 --- /dev/null +++ b/source/blender/blendthumb/src/Info.plist @@ -0,0 +1,46 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + blender_thumbnailer + CFBundleExecutable + blender-thumbnailer + CFBundleIdentifier + org.blenderfoundation.blender.thumbnailer + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + blender-thumbnailer + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 1 + LSMinimumSystemVersion + 11.3 + NSExtension + + NSExtensionAttributes + + QLSupportedContentTypes + + org.blenderfoundation.blender.file + + QLThumbnailMinimumDimension + 0 + + NSExtensionPointIdentifier + com.apple.quicklook.preview + NSExtensionPrincipalClass + PreviewProvider + + + \ No newline at end of file diff --git a/source/blender/blendthumb/src/ThumbnailProvider.h b/source/blender/blendthumb/src/ThumbnailProvider.h new file mode 100644 index 00000000000..08c2c0918df --- /dev/null +++ b/source/blender/blendthumb/src/ThumbnailProvider.h @@ -0,0 +1,10 @@ +#include +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface PreviewViewController : NSViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/source/blender/blendthumb/src/ThumbnailProvider.mm b/source/blender/blendthumb/src/ThumbnailProvider.mm new file mode 100644 index 00000000000..987214750cc --- /dev/null +++ b/source/blender/blendthumb/src/ThumbnailProvider.mm @@ -0,0 +1,119 @@ +#include +#include +#include + +#import +#import +#import + +#import "ThumbnailProvider.h" + +#include "BLI_fileops.h" +#include "BLI_filereader.h" +#include "blendthumb.hh" + +class FileReaderRAII { + int src_file_ = -1; + + public: + explicit FileReaderRAII(int src_file) : src_file_(src_file) {} + ~FileReaderRAII() + { + if (src_file_ != -1) { + close(src_file_); + } + } + + bool good() + { + return src_file_ != -1; + } + + int get() + { + return src_file_; + } +}; + +static eThumbStatus creator_impl(const char *src_blend_path) +{ + eThumbStatus err; + + /* Open source file `src_blend`. */ + FileReaderRAII src_file_fd = FileReaderRAII(BLI_open(src_blend_path, O_BINARY | O_RDONLY, 0)); + if (!src_file_fd.good()) { + return BT_FILE_ERR; + } + + /* Thumbnail reading is responsible for freeing `file` and closing `src_file`. */ + FileReader *file_content = BLI_filereader_new_file(src_file_fd.get()); + if (file_content == nullptr) { + return BT_FILE_ERR; + } + + /* Extract thumbnail from file. */ + Thumbnail thumb; + err = blendthumb_create_thumb_from_file(file_content, &thumb); + if (err != BT_OK) { + return err; + } + + return err; +} + +@implementation PreviewViewController + +- (NSString *)nibName +{ + return @"PreviewViewController"; +} + +- (void)loadView +{ + [super loadView]; + // Do any additional setup after loading the view. +} + +/* + * Implement this method and set QLSupportsSearchableItems to YES in the Info.plist of the +extension if you support CoreSpotlight. + * +- (void)preparePreviewOfSearchableItemWithIdentifier:(NSString *)identifier queryString:(NSString +*)queryString completionHandler:(void (^)(NSError * _Nullable))handler { + + // Perform any setup necessary in order to prepare the view. + + // Call the completion handler so Quick Look knows that the preview is fully loaded. + // Quick Look will display a loading spinner while the completion handler is not called. + + handler(nil); +} +*/ + +- (void)preparePreviewOfFileAtURL:(NSURL *)url + completionHandler:(void (^)(NSError *_Nullable))handler +{ + + // Add the supported content types to the QLSupportedContentTypes array in the Info.plist of the + // extension. + + // Perform any setup necessary in order to prepare the view. + + // Call the completion handler so Quick Look knows that the preview is fully loaded. + // Quick Look will display a loading spinner while the completion handler is not called. + + NSLog(@"blender preparePreviewOfFileAtURL: %@", url); + std::ofstream file("/Users/ankit.kumar/apps/build_xcode/foobar.txt", + std::ios::out | std::ios::trunc | std::ios::binary); + file << "Hello World"; + file.close(); + std::cout << "Hello World" << std::endl; + // set image to file path /Users/ankit.kumar/Desktop/Screenshot 2021-09-02 at 1.59.47 PM.png + [[[self view] imageRepresentation] + setFileURL:[NSURL fileURLWithPath:@"file:///Users/ankit.kumar/Desktop/Screenshot.png" + isDirectory:NO]]; + [[self view] display]; + handler(nil); +} + +@end diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 3462fcd5b99..c7cf2bf4e99 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -1352,8 +1352,14 @@ elseif(APPLE) if(WITH_BLENDER_THUMBNAILER) install( TARGETS blender-thumbnailer - DESTINATION Blender.app/Contents/MacOS/ + DESTINATION Blender.app/Contents/Plugins ) + get_target_property(XIB_RESOURCE blender-thumbnailer XIB_RESOURCE) + install_dir( + ${XIB_RESOURCE} + Blender.app/Contents/Plugins/blender-thumbnailer.appex/Contents/Resources + ) + endif() if(PLATFORM_BUNDLED_LIBRARIES AND TARGETDIR_LIB) diff --git a/tests/gtests/runner/CMakeLists.txt b/tests/gtests/runner/CMakeLists.txt index f509c1df1b2..cbf82d42d30 100644 --- a/tests/gtests/runner/CMakeLists.txt +++ b/tests/gtests/runner/CMakeLists.txt @@ -34,7 +34,6 @@ endif() blender_src_gtest_ex( NAME blender SRC "${SRC}" - EXTRA_LIBS "${TEST_LIBS}" SKIP_ADD_TEST ) setup_platform_linker_libs(blender_test) -- 2.30.2 From d843b71fd524fd462bc205e5c8e9a598d5d2aeb0 Mon Sep 17 00:00:00 2001 From: Ankit Meel Date: Mon, 17 Apr 2023 09:48:57 +0530 Subject: [PATCH 2/7] Try thumbnail type --- source/blender/blendthumb/CMakeLists.txt | 4 +-- source/blender/blendthumb/src/Info.plist | 8 ++---- .../blendthumb/src/ThumbnailProvider.h | 6 ++++ .../blendthumb/src/ThumbnailProvider.mm | 28 +++++++++++++++++-- source/creator/CMakeLists.txt | 11 ++++---- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/source/blender/blendthumb/CMakeLists.txt b/source/blender/blendthumb/CMakeLists.txt index 08f8e15a143..df4d19d2100 100644 --- a/source/blender/blendthumb/CMakeLists.txt +++ b/source/blender/blendthumb/CMakeLists.txt @@ -76,8 +76,8 @@ if(APPLE) 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 - XIB_RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/Base.lproj") + # set_target_properties(blender-thumbnailer PROPERTIES + # XIB_RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/Base.lproj") # Doesn't affect other generators. So need to specify extension for others. set_target_properties(blender-thumbnailer PROPERTIES XCODE_PRODUCT_TYPE com.apple.product-type.app-extension) diff --git a/source/blender/blendthumb/src/Info.plist b/source/blender/blendthumb/src/Info.plist index fa814fd0ad3..9d531007e02 100644 --- a/source/blender/blendthumb/src/Info.plist +++ b/source/blender/blendthumb/src/Info.plist @@ -34,13 +34,11 @@ org.blenderfoundation.blender.file - QLThumbnailMinimumDimension - 0 NSExtensionPointIdentifier - com.apple.quicklook.preview - NSExtensionPrincipalClass - PreviewProvider + com.apple.quicklook.thumbnail + com.apple.showsInExtensionsManager + \ No newline at end of file diff --git a/source/blender/blendthumb/src/ThumbnailProvider.h b/source/blender/blendthumb/src/ThumbnailProvider.h index 08c2c0918df..af6ccf41c77 100644 --- a/source/blender/blendthumb/src/ThumbnailProvider.h +++ b/source/blender/blendthumb/src/ThumbnailProvider.h @@ -1,8 +1,14 @@ #include + #import +#import NS_ASSUME_NONNULL_BEGIN +@interface ThumbnailProvider : QLThumbnailProvider + +@end + @interface PreviewViewController : NSViewController @end diff --git a/source/blender/blendthumb/src/ThumbnailProvider.mm b/source/blender/blendthumb/src/ThumbnailProvider.mm index 987214750cc..9e099442da5 100644 --- a/source/blender/blendthumb/src/ThumbnailProvider.mm +++ b/source/blender/blendthumb/src/ThumbnailProvider.mm @@ -61,6 +61,30 @@ static eThumbStatus creator_impl(const char *src_blend_path) return err; } +@implementation ThumbnailProvider + +- (void)provideThumbnailForFileRequest:(QLFileThumbnailRequest *)request + completionHandler:(void (^)(QLThumbnailReply *_Nullable reply, + NSError *_Nullable error))handler +{ + @autoreleasepool { // Add the supported content types to the QLSupportedContentTypes array in + // the Info.plist of the + // extension. + + std::cout << "Hello World from blender Blender thumbnailer" << std::endl; + NSLog(@"hello world from blender"); + NSURL *foo = [[NSURL alloc] + initFileURLWithFileSystemRepresentation:"/Users/ankitkumar/Pictures/IMG_3158.JPG" + isDirectory:NO + relativeToURL:nil]; + QLThumbnailReply *reply = [QLThumbnailReply replyWithImageFileURL:foo]; + + handler(reply, nil); + } +} + +@end + @implementation PreviewViewController - (NSString *)nibName @@ -103,14 +127,14 @@ extension if you support CoreSpotlight. // Quick Look will display a loading spinner while the completion handler is not called. NSLog(@"blender preparePreviewOfFileAtURL: %@", url); - std::ofstream file("/Users/ankit.kumar/apps/build_xcode/foobar.txt", + std::ofstream file("/Users/ankitkumar/blender-build/build_darwin_debug_lite/foobar.txt", std::ios::out | std::ios::trunc | std::ios::binary); file << "Hello World"; file.close(); std::cout << "Hello World" << std::endl; // set image to file path /Users/ankit.kumar/Desktop/Screenshot 2021-09-02 at 1.59.47 PM.png [[[self view] imageRepresentation] - setFileURL:[NSURL fileURLWithPath:@"file:///Users/ankit.kumar/Desktop/Screenshot.png" + setFileURL:[NSURL fileURLWithPath:@"/Users/ankitkumar/Pictures/IMG_3158.JPG" isDirectory:NO]]; [[self view] display]; handler(nil); diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index c7cf2bf4e99..faf7b26e125 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -1354,12 +1354,11 @@ elseif(APPLE) TARGETS blender-thumbnailer DESTINATION Blender.app/Contents/Plugins ) - get_target_property(XIB_RESOURCE blender-thumbnailer XIB_RESOURCE) - install_dir( - ${XIB_RESOURCE} - Blender.app/Contents/Plugins/blender-thumbnailer.appex/Contents/Resources - ) - + # get_target_property(XIB_RESOURCE blender-thumbnailer XIB_RESOURCE) + # install_dir( + # ${XIB_RESOURCE} + # Blender.app/Contents/Plugins/blender-thumbnailer.appex/Contents/Resources + # ) endif() if(PLATFORM_BUNDLED_LIBRARIES AND TARGETDIR_LIB) -- 2.30.2 From 0f127ccc565f7ca527bf14e51d09855f244546e6 Mon Sep 17 00:00:00 2001 From: Ankit Meel Date: Mon, 17 Apr 2023 10:14:39 +0530 Subject: [PATCH 3/7] add entitlements --- .../src/ThumbnailExtensionMacOS.entitlements | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 source/blender/blendthumb/src/ThumbnailExtensionMacOS.entitlements diff --git a/source/blender/blendthumb/src/ThumbnailExtensionMacOS.entitlements b/source/blender/blendthumb/src/ThumbnailExtensionMacOS.entitlements new file mode 100644 index 00000000000..f2ef3ae0265 --- /dev/null +++ b/source/blender/blendthumb/src/ThumbnailExtensionMacOS.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + -- 2.30.2 From b437b0c80aa93ec2bd166d7551074c433fd77b0d Mon Sep 17 00:00:00 2001 From: Ankit Meel Date: Mon, 17 Apr 2023 18:13:27 +0530 Subject: [PATCH 4/7] codesign entitlements --- source/blender/blendthumb/CMakeLists.txt | 3 ++- source/creator/CMakeLists.txt | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/blender/blendthumb/CMakeLists.txt b/source/blender/blendthumb/CMakeLists.txt index df4d19d2100..918fd407119 100644 --- a/source/blender/blendthumb/CMakeLists.txt +++ b/source/blender/blendthumb/CMakeLists.txt @@ -82,7 +82,8 @@ if(APPLE) set_target_properties(blender-thumbnailer PROPERTIES XCODE_PRODUCT_TYPE com.apple.product-type.app-extension) set_target_properties(blender-thumbnailer PROPERTIES - BUNDLE_EXTENSION appex) + BUNDLE_EXTENSION appex + BL_CODESIGN_ENTITLEMENTS ${CMAKE_CURRENT_SOURCE_DIR}/src/ThumbnailExtensionMacOS.entitlements) setup_platform_linker_flags(blender-thumbnailer) set_target_properties(blender-thumbnailer PROPERTIES BUILD_WITH_INSTALL_RPATH true) list(APPEND LIB diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index faf7b26e125..34019f45945 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -1354,11 +1354,13 @@ elseif(APPLE) TARGETS blender-thumbnailer DESTINATION Blender.app/Contents/Plugins ) - # get_target_property(XIB_RESOURCE blender-thumbnailer XIB_RESOURCE) - # install_dir( - # ${XIB_RESOURCE} - # Blender.app/Contents/Plugins/blender-thumbnailer.appex/Contents/Resources - # ) + get_target_property(BL_CODESIGN_ENTITLEMENTS blender-thumbnailer BL_CODESIGN_ENTITLEMENTS) + install(CODE + "message(STATUS \"Codesigning thumbnailer with entitlements: ${BL_CODESIGN_ENTITLEMENTS}\")") + install(CODE + "execute_process( + COMMAND codesign --entitlements \"${BL_CODESIGN_ENTITLEMENTS}\" --force --deep --sign - \"${EXECUTABLE_OUTPUT_PATH}/Blender.app/Contents/Plugins/blender-thumbnailer.appex\" + )") endif() if(PLATFORM_BUNDLED_LIBRARIES AND TARGETDIR_LIB) -- 2.30.2 From aba69a15c03b9542dc59b45080eca9fde057b519 Mon Sep 17 00:00:00 2001 From: Ankit Meel Date: Mon, 17 Apr 2023 22:12:33 +0530 Subject: [PATCH 5/7] working version probably --- source/blender/blendthumb/CMakeLists.txt | 2 +- source/blender/blendthumb/src/README.md | 20 +++++++ ...umbnailProvider.h => ThumbnailProvider.hh} | 6 +- .../blendthumb/src/ThumbnailProvider.mm | 60 +------------------ source/creator/CMakeLists.txt | 7 ++- 5 files changed, 27 insertions(+), 68 deletions(-) create mode 100644 source/blender/blendthumb/src/README.md rename source/blender/blendthumb/src/{ThumbnailProvider.h => ThumbnailProvider.hh} (63%) diff --git a/source/blender/blendthumb/CMakeLists.txt b/source/blender/blendthumb/CMakeLists.txt index 918fd407119..b9821647c74 100644 --- a/source/blender/blendthumb/CMakeLists.txt +++ b/source/blender/blendthumb/CMakeLists.txt @@ -68,7 +68,7 @@ if(APPLE) set(SRC_CMD src/ThumbnailProvider.mm - src/ThumbnailProvider.h + src/ThumbnailProvider.hh src/Info.plist ) diff --git a/source/blender/blendthumb/src/README.md b/source/blender/blendthumb/src/README.md new file mode 100644 index 00000000000..e6f3290ab24 --- /dev/null +++ b/source/blender/blendthumb/src/README.md @@ -0,0 +1,20 @@ +lsregister and its listing and detection + +more logs in lldb + +more logs in console: look for anything qlmanage + +must sign the appex bundle with sandbox + +must launch the app + +appex cannot write at all : inferred from + +error 17:53:57.863578+0530 kernel Sandbox: qlmanage(37213) deny(1) file-write-data /dev/dtracehelper +error 17:53:58.033957+0530 kernel Sandbox: qlmanage(37213) deny(1) mach-register com.apple.axserver (per-pid) +error 17:53:58.071424+0530 kernel Sandbox: qlmanage(37213) deny(1) mach-register com.apple.tsm.portname (per-pid) +error 17:53:58.164827+0530 kernel Sandbox: qlmanage(37213) deny(1) user-preference-read com.apple.HIToolbox +error 17:54:00.837220+0530 kernel Sandbox: qlmanage(37213) deny(1) file-write-data /dev/dtracehelper +error 17:54:00.904484+0530 kernel Sandbox: qlmanage(37213) deny(1) file-write-create /Users/ankitkumar/Library/Saved Application State/com.apple.quicklook.qlmanage.savedState + +https://eclecticlight.co/2018/04/05/inside-quicklook-previews-with-qlmanage/ \ No newline at end of file diff --git a/source/blender/blendthumb/src/ThumbnailProvider.h b/source/blender/blendthumb/src/ThumbnailProvider.hh similarity index 63% rename from source/blender/blendthumb/src/ThumbnailProvider.h rename to source/blender/blendthumb/src/ThumbnailProvider.hh index af6ccf41c77..d07c9d3cf4d 100644 --- a/source/blender/blendthumb/src/ThumbnailProvider.h +++ b/source/blender/blendthumb/src/ThumbnailProvider.hh @@ -1,4 +1,4 @@ -#include +#pragma once #import #import @@ -9,8 +9,4 @@ NS_ASSUME_NONNULL_BEGIN @end -@interface PreviewViewController : NSViewController - -@end - NS_ASSUME_NONNULL_END diff --git a/source/blender/blendthumb/src/ThumbnailProvider.mm b/source/blender/blendthumb/src/ThumbnailProvider.mm index 9e099442da5..30466fead7b 100644 --- a/source/blender/blendthumb/src/ThumbnailProvider.mm +++ b/source/blender/blendthumb/src/ThumbnailProvider.mm @@ -6,7 +6,7 @@ #import #import -#import "ThumbnailProvider.h" +#import "ThumbnailProvider.hh" #include "BLI_fileops.h" #include "BLI_filereader.h" @@ -71,7 +71,6 @@ static eThumbStatus creator_impl(const char *src_blend_path) // the Info.plist of the // extension. - std::cout << "Hello World from blender Blender thumbnailer" << std::endl; NSLog(@"hello world from blender"); NSURL *foo = [[NSURL alloc] initFileURLWithFileSystemRepresentation:"/Users/ankitkumar/Pictures/IMG_3158.JPG" @@ -84,60 +83,3 @@ static eThumbStatus creator_impl(const char *src_blend_path) } @end - -@implementation PreviewViewController - -- (NSString *)nibName -{ - return @"PreviewViewController"; -} - -- (void)loadView -{ - [super loadView]; - // Do any additional setup after loading the view. -} - -/* - * Implement this method and set QLSupportsSearchableItems to YES in the Info.plist of the -extension if you support CoreSpotlight. - * -- (void)preparePreviewOfSearchableItemWithIdentifier:(NSString *)identifier queryString:(NSString -*)queryString completionHandler:(void (^)(NSError * _Nullable))handler { - - // Perform any setup necessary in order to prepare the view. - - // Call the completion handler so Quick Look knows that the preview is fully loaded. - // Quick Look will display a loading spinner while the completion handler is not called. - - handler(nil); -} -*/ - -- (void)preparePreviewOfFileAtURL:(NSURL *)url - completionHandler:(void (^)(NSError *_Nullable))handler -{ - - // Add the supported content types to the QLSupportedContentTypes array in the Info.plist of the - // extension. - - // Perform any setup necessary in order to prepare the view. - - // Call the completion handler so Quick Look knows that the preview is fully loaded. - // Quick Look will display a loading spinner while the completion handler is not called. - - NSLog(@"blender preparePreviewOfFileAtURL: %@", url); - std::ofstream file("/Users/ankitkumar/blender-build/build_darwin_debug_lite/foobar.txt", - std::ios::out | std::ios::trunc | std::ios::binary); - file << "Hello World"; - file.close(); - std::cout << "Hello World" << std::endl; - // set image to file path /Users/ankit.kumar/Desktop/Screenshot 2021-09-02 at 1.59.47 PM.png - [[[self view] imageRepresentation] - setFileURL:[NSURL fileURLWithPath:@"/Users/ankitkumar/Pictures/IMG_3158.JPG" - isDirectory:NO]]; - [[self view] display]; - handler(nil); -} - -@end diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 34019f45945..4a9e990a192 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -1356,10 +1356,11 @@ elseif(APPLE) ) get_target_property(BL_CODESIGN_ENTITLEMENTS blender-thumbnailer BL_CODESIGN_ENTITLEMENTS) install(CODE - "message(STATUS \"Codesigning thumbnailer with entitlements: ${BL_CODESIGN_ENTITLEMENTS}\")") - install(CODE "execute_process( - COMMAND codesign --entitlements \"${BL_CODESIGN_ENTITLEMENTS}\" --force --deep --sign - \"${EXECUTABLE_OUTPUT_PATH}/Blender.app/Contents/Plugins/blender-thumbnailer.appex\" + COMMAND codesign + --entitlements \"${BL_CODESIGN_ENTITLEMENTS}\" + --force --deep --sign - + \"${EXECUTABLE_OUTPUT_PATH}/Blender.app/Contents/Plugins/blender-thumbnailer.appex\" )") endif() -- 2.30.2 From c96a3caba4a9bf72ef0c5e1eccea14733ea1f98d Mon Sep 17 00:00:00 2001 From: Ankit Meel Date: Tue, 18 Apr 2023 03:09:42 +0530 Subject: [PATCH 6/7] working confirmed --- .../darwin/Blender.app/Contents/Info.plist | 2 -- source/blender/blendthumb/src/Info.plist | 8 +++++-- source/blender/blendthumb/src/README.md | 22 ++++++++++++++++++- .../src/ThumbnailExtensionMacOS.entitlements | 2 ++ .../blendthumb/src/ThumbnailProvider.mm | 4 ++-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/release/darwin/Blender.app/Contents/Info.plist b/release/darwin/Blender.app/Contents/Info.plist index 263bd8cbba1..3484738fcba 100644 --- a/release/darwin/Blender.app/Contents/Info.plist +++ b/release/darwin/Blender.app/Contents/Info.plist @@ -11,8 +11,6 @@ blend - CFBundleTypeIconFile - Blender_Legacy_Document_Icon.icns CFBundleTypeName Blender File CFBundleTypeOSTypes diff --git a/source/blender/blendthumb/src/Info.plist b/source/blender/blendthumb/src/Info.plist index 9d531007e02..7f6143c0e03 100644 --- a/source/blender/blendthumb/src/Info.plist +++ b/source/blender/blendthumb/src/Info.plist @@ -17,13 +17,13 @@ CFBundlePackageType XPC! CFBundleShortVersionString - 1.0 + 3.6.0 CFBundleSupportedPlatforms MacOSX CFBundleVersion - 1 + 3.6.0 2023-04-18 LSMinimumSystemVersion 11.3 NSExtension @@ -34,9 +34,13 @@ org.blenderfoundation.blender.file + QLThumbnailMinimumDimension + 0 NSExtensionPointIdentifier com.apple.quicklook.thumbnail + NSExtensionPrincipalClass + ThumbnailProvider com.apple.showsInExtensionsManager diff --git a/source/blender/blendthumb/src/README.md b/source/blender/blendthumb/src/README.md index e6f3290ab24..8d4ca956cac 100644 --- a/source/blender/blendthumb/src/README.md +++ b/source/blender/blendthumb/src/README.md @@ -17,4 +17,24 @@ error 17:53:58.164827+0530 kernel Sandbox: qlmanage(37213) deny(1) user-preferen error 17:54:00.837220+0530 kernel Sandbox: qlmanage(37213) deny(1) file-write-data /dev/dtracehelper error 17:54:00.904484+0530 kernel Sandbox: qlmanage(37213) deny(1) file-write-create /Users/ankitkumar/Library/Saved Application State/com.apple.quicklook.qlmanage.savedState -https://eclecticlight.co/2018/04/05/inside-quicklook-previews-with-qlmanage/ \ No newline at end of file +https://eclecticlight.co/2018/04/05/inside-quicklook-previews-with-qlmanage/ + +in info.plist, add NSExtensionPrincipalClass, add QLThumbnailMinimumDimension + +Try removing blend file thumbnail specificaion from blender.app info.plist + +Expect + +lender-thumbnailer __extensionPrincipalClass != nil - /AppleInternal/Library/BuildRoots/a0876c02-1788-11ed-b9c4-96898e02b808/Library/Caches/com.apple.xbs/Sources/ExtensionFoundation/ExtensionFoundation/Source/NSExtension/NSExtensionSupport/EXConcreteExtensionContextVendor.m:108: Unable to find NSExtensionPrincipalClass () in extension bundle! Please verify that the extension links the required frameworks and that the value for NSExtensionPrincipalClass is prefixed with '$(PRODUCT_MODULE_NAME).' if the class is implemented in Swift. +fault 00:55:16.449383+0530 blender-thumbnailer [__extensionPrincipalClass conformsToProtocol:@protocol(NSExtensionRequestHandling)] - /AppleInternal/Library/BuildRoots/a0876c02-1788-11ed-b9c4-96898e02b808/Library/Caches/com.apple.xbs/Sources/ExtensionFoundation/ExtensionFoundation/Source/NSExtension/NSExtensionSupport/EXConcreteExtensionContextVendor.m:109: NSExtensionPrincipalClass does not conform to NSExtensionRequestHandling protocol! + + +Signing blender.app + +move blender.app to /Applications or launch it at least once + +Don't access files outside sandbox or kernel denies: + +default 03:07:03.525360+0530 blender-thumbnailer hello world from blender +error 03:07:03.527837+0530 blender-thumbnailer Couldn't issue file extension for url: +error 03:07:03.531152+0530 kernel Sandbox: com.apple.quickl(476) deny(1) file-read-data /Users/ankitkumar/Pictures/IMG_3158.JPG diff --git a/source/blender/blendthumb/src/ThumbnailExtensionMacOS.entitlements b/source/blender/blendthumb/src/ThumbnailExtensionMacOS.entitlements index f2ef3ae0265..0aa4c41dd33 100644 --- a/source/blender/blendthumb/src/ThumbnailExtensionMacOS.entitlements +++ b/source/blender/blendthumb/src/ThumbnailExtensionMacOS.entitlements @@ -5,6 +5,8 @@ com.apple.security.app-sandbox com.apple.security.files.user-selected.read-only + + com.apple.security.get-task-allow diff --git a/source/blender/blendthumb/src/ThumbnailProvider.mm b/source/blender/blendthumb/src/ThumbnailProvider.mm index 30466fead7b..b170faaba66 100644 --- a/source/blender/blendthumb/src/ThumbnailProvider.mm +++ b/source/blender/blendthumb/src/ThumbnailProvider.mm @@ -67,11 +67,12 @@ static eThumbStatus creator_impl(const char *src_blend_path) completionHandler:(void (^)(QLThumbnailReply *_Nullable reply, NSError *_Nullable error))handler { - @autoreleasepool { // Add the supported content types to the QLSupportedContentTypes array in + // Add the supported content types to the QLSupportedContentTypes array in // the Info.plist of the // extension. NSLog(@"hello world from blender"); + // NSLog(@"%s", request.fileURL.path.UTF8String); NSURL *foo = [[NSURL alloc] initFileURLWithFileSystemRepresentation:"/Users/ankitkumar/Pictures/IMG_3158.JPG" isDirectory:NO @@ -79,7 +80,6 @@ static eThumbStatus creator_impl(const char *src_blend_path) QLThumbnailReply *reply = [QLThumbnailReply replyWithImageFileURL:foo]; handler(reply, nil); - } } @end -- 2.30.2 From 2cc09e6794c2c137f34d571d0bb8865fe3fb7d62 Mon Sep 17 00:00:00 2001 From: Ankit Meel Date: Tue, 18 Apr 2023 03:14:04 +0530 Subject: [PATCH 7/7] one more point --- source/blender/blendthumb/src/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/blender/blendthumb/src/README.md b/source/blender/blendthumb/src/README.md index 8d4ca956cac..e2b9d3d6eb4 100644 --- a/source/blender/blendthumb/src/README.md +++ b/source/blender/blendthumb/src/README.md @@ -38,3 +38,5 @@ Don't access files outside sandbox or kernel denies: default 03:07:03.525360+0530 blender-thumbnailer hello world from blender error 03:07:03.527837+0530 blender-thumbnailer Couldn't issue file extension for url: error 03:07:03.531152+0530 kernel Sandbox: com.apple.quickl(476) deny(1) file-read-data /Users/ankitkumar/Pictures/IMG_3158.JPG + +restart ? -- 2.30.2