mirror of
https://github.com/ollama/ollama.git
synced 2025-11-10 17:28:11 +01:00
app: fix macOS file picker to support Uniform Type Identifiers (#12965)
This commit is contained in:
@@ -3,6 +3,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/syslimits.h>
|
#include <sys/syslimits.h>
|
||||||
|
|
||||||
|
// Import UniformTypeIdentifiers for macOS 11+
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
|
||||||
|
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void* NSStr(void* buf, int len) {
|
void* NSStr(void* buf, int len) {
|
||||||
return (void*)[[NSString alloc] initWithBytes:buf length:len encoding:NSUTF8StringEncoding];
|
return (void*)[[NSString alloc] initWithBytes:buf length:len encoding:NSUTF8StringEncoding];
|
||||||
}
|
}
|
||||||
@@ -109,12 +114,20 @@ DlgResult fileDlg(FileDlgParams* params) {
|
|||||||
if(self->params->title != nil) {
|
if(self->params->title != nil) {
|
||||||
[panel setTitle:[[NSString alloc] initWithUTF8String:self->params->title]];
|
[panel setTitle:[[NSString alloc] initWithUTF8String:self->params->title]];
|
||||||
}
|
}
|
||||||
#pragma clang diagnostic push
|
// Use modern allowedContentTypes API for better file type support (especially video files)
|
||||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
||||||
if(self->params->numext > 0) {
|
if(self->params->numext > 0) {
|
||||||
[panel setAllowedFileTypes:[NSArray arrayWithObjects:(NSString**)self->params->exts count:self->params->numext]];
|
NSMutableArray *utTypes = [NSMutableArray arrayWithCapacity:self->params->numext];
|
||||||
|
NSString** exts = (NSString**)self->params->exts;
|
||||||
|
for(int i = 0; i < self->params->numext; i++) {
|
||||||
|
UTType *type = [UTType typeWithFilenameExtension:exts[i]];
|
||||||
|
if(type) {
|
||||||
|
[utTypes addObject:type];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if([utTypes count] > 0) {
|
||||||
|
[panel setAllowedContentTypes:utTypes];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#pragma clang diagnostic pop
|
|
||||||
if(self->params->relaxext) {
|
if(self->params->relaxext) {
|
||||||
[panel setAllowsOtherFileTypes:YES];
|
[panel setAllowsOtherFileTypes:YES];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package cocoa
|
package cocoa
|
||||||
|
|
||||||
// #cgo darwin LDFLAGS: -framework Cocoa
|
// #cgo darwin LDFLAGS: -framework Cocoa -framework UniformTypeIdentifiers
|
||||||
// #include <stdlib.h>
|
// #include <stdlib.h>
|
||||||
// #include <sys/syslimits.h>
|
// #include <sys/syslimits.h>
|
||||||
// #include "dlg.h"
|
// #include "dlg.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user