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:
parent
0d8244748c
commit
430b733da6
@ -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;
|
||||
|
@ -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)
|
||||
@ -30,11 +28,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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user