Disabled Quick Look preview/thumbnail cancelation. It seems that the API sometime return true for no reason, and documentation of QL APIs is extremely poor.

This commit is contained in:
Lior Halphon 2017-01-22 21:04:10 +02:00
parent 0d8244748c
commit 430b733da6
3 changed files with 7 additions and 20 deletions

View File

@ -2,7 +2,7 @@
#include <Cocoa/Cocoa.h>
#include "get_image_for_rom.h"
static OSStatus render(CGContextRef cgContext, CFURLRef url, cancel_callback_t cancelCallback, void *cancelData, bool showBorder)
static OSStatus render(CGContextRef cgContext, CFURLRef url, bool showBorder)
{
/* Load the template NSImages when generating the first thumbnail */
static NSImage *template = nil;
@ -24,7 +24,7 @@ static OSStatus render(CGContextRef cgContext, CFURLRef url, cancel_callback_t c
/* The cgb_boot_fast boot ROM skips the boot animation */
if (get_image_for_rom([[(__bridge NSURL *)url path] UTF8String],
[[bundle pathForResource:@"cgb_boot_fast" ofType:@"bin"] UTF8String],
bitmap, &cgbFlag, cancelCallback, cancelData)) {
bitmap, &cgbFlag)) {
return -1;
}
@ -93,7 +93,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
{
@autoreleasepool {
CGContextRef cgContext = QLPreviewRequestCreateContext(preview, ((NSSize){640, 576}), true, nil);
if (render(cgContext, url, (cancel_callback_t)QLPreviewRequestIsCancelled, preview, false) == noErr) {
if (render(cgContext, url, false) == noErr) {
QLPreviewRequestFlushContext(preview, cgContext);
CGContextRelease(cgContext);
return noErr;
@ -107,7 +107,7 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
{
@autoreleasepool {
CGContextRef cgContext = QLThumbnailRequestCreateContext(thumbnail, ((NSSize){1024, 1024}), true, (__bridge CFDictionaryRef)(@{@"IconFlavor" : @(0)}));
if (render(cgContext, url, (cancel_callback_t)QLThumbnailIsCancelled, thumbnail, true) == noErr) {
if (render(cgContext, url, true) == noErr) {
QLThumbnailRequestFlushContext(thumbnail, cgContext);
CGContextRelease(cgContext);
return noErr;

View File

@ -11,8 +11,6 @@
struct local_data {
unsigned long frames;
bool running;
cancel_callback_t cancel_callback;
void *callback_data;
};
static char *async_input_callback(GB_gameboy_t *gb)
@ -31,11 +29,6 @@ static void vblank(GB_gameboy_t *gb)
struct local_data *local_data = (struct local_data *)gb->user_data;
if (local_data->cancel_callback(local_data->callback_data)) {
local_data->running = false;
return;
}
if (local_data->frames == LENGTH) {
local_data->running = false;
}
@ -51,8 +44,7 @@ static uint32_t rgb_encode(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b)
return (b << 16) | (g << 8) | (r) | 0xFF000000;
}
int get_image_for_rom(const char *filename, const char *boot_path, uint32_t *output, uint8_t *cgb_flag,
cancel_callback_t cancel_callback, void *callback_data)
int get_image_for_rom(const char *filename, const char *boot_path, uint32_t *output, uint8_t *cgb_flag)
{
GB_gameboy_t gb;
GB_init_cgb(&gb);
@ -77,19 +69,15 @@ int get_image_for_rom(const char *filename, const char *boot_path, uint32_t *out
gb.user_data = &local_data;
local_data.running = true;
local_data.frames = 0;
local_data.cancel_callback = cancel_callback;
local_data.callback_data = callback_data;
gb.turbo = gb.turbo_dont_skip = gb.disable_rendering = true;
while (local_data.running) {
GB_run(&gb);
}
*cgb_flag = gb.rom[0x143] & 0xC0;
GB_free(&gb);
/* Report failure if cancelled */
return local_data.frames != LENGTH + 1;
return 0;
}

View File

@ -4,8 +4,7 @@
typedef bool (*cancel_callback_t)(void*);
int get_image_for_rom(const char *filename, const char *boot_path, uint32_t *output, uint8_t *cgb_flag,
cancel_callback_t cancel_callback, void *callback_data);
int get_image_for_rom(const char *filename, const char *boot_path, uint32_t *output, uint8_t *cgb_flag);
#endif