I want to code an app in go that is able to open a custom filetype (.slc) on MacOS. I created a blank xcode project to get all the necessary code and implemented it via cgo into my app. When I double click a file the app opens but complains that it cannot open files in this format:
This is my Info.plist:
Implementation as follows:
/surge/appDelegate_darwin.go
package surge
//#cgo CFLAGS: -x objective-c
//#cgo LDFLAGS: -framework Cocoa
//#include "appDelegate_darwin.h"
import "C"
/surge/appDelegate_darwin.h
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@end
/surge/appDelegate_darwin.m
#include "appDelegate_darwin.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
-(BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
{
NSLog(@"%@", filename);
YES;
}
-(void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
{
NSLog(@"%@", filenames);
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
@end
Additional information: I use the wails framework (https://wails.app) to add a nice vue.js frontend to the app and use the built-in wails build
command.
Other implementations in cgo and objective-c (like custom protocol handler) work.