diff options
author | Teddy Wing | 2018-09-05 19:57:58 +0200 |
---|---|---|
committer | Teddy Wing | 2018-09-05 19:57:58 +0200 |
commit | 8c20b1ce79316ccda8dd2c91c66f2388f16c45bf (patch) | |
tree | 802f8105344ad9daa01ac3b6ffa8f645fd39f204 /CopyMailto | |
parent | 83b7beb0c532a199e606d7ba05ffc38ea7e2cd7f (diff) | |
download | Copy-Mailto-8c20b1ce79316ccda8dd2c91c66f2388f16c45bf.tar.bz2 |
DefaultURLHandler: Add `saveDefaultURLHandler`
This method is supposed to set CopyMailto as the default application for
"mailto" URLs. But it keeps giving me a `-54` error, or `202` status
code on the shell. WTF is going on?
Diffstat (limited to 'CopyMailto')
-rw-r--r-- | CopyMailto/DefaultURLHandler.h | 1 | ||||
-rw-r--r-- | CopyMailto/DefaultURLHandler.m | 13 | ||||
-rw-r--r-- | CopyMailto/main.m | 5 |
3 files changed, 18 insertions, 1 deletions
diff --git a/CopyMailto/DefaultURLHandler.h b/CopyMailto/DefaultURLHandler.h index 7bad3d0..fb54e9e 100644 --- a/CopyMailto/DefaultURLHandler.h +++ b/CopyMailto/DefaultURLHandler.h @@ -10,6 +10,7 @@ @interface DefaultURLHandler : NSObject ++ (OSStatus)setDefaultURLHandler; + (void)saveDefaultURLHandler; @end diff --git a/CopyMailto/DefaultURLHandler.m b/CopyMailto/DefaultURLHandler.m index 6ea69c1..8ce1728 100644 --- a/CopyMailto/DefaultURLHandler.m +++ b/CopyMailto/DefaultURLHandler.m @@ -10,6 +10,19 @@ @implementation DefaultURLHandler ++ (OSStatus)setDefaultURLHandler { + CFStringRef scheme = (CFStringRef)@"mailto"; + CFStringRef bundle_identifier = (__bridge CFStringRef)[[NSBundle mainBundle] bundleIdentifier]; + NSLog(@"%@", bundle_identifier); + + OSStatus status = LSSetDefaultHandlerForURLScheme(scheme, bundle_identifier); + NSLog(@"%d", status); + + CFRelease(scheme); + + return status; +} + + (void)saveDefaultURLHandler { CFStringRef mailto = (CFStringRef)@"mailto"; CFStringRef bundle_identifier = LSCopyDefaultHandlerForURLScheme(mailto); diff --git a/CopyMailto/main.m b/CopyMailto/main.m index 8dfe2c1..e61f04e 100644 --- a/CopyMailto/main.m +++ b/CopyMailto/main.m @@ -11,6 +11,9 @@ #import "DefaultURLHandler.h" int main(int argc, const char * argv[]) { - [DefaultURLHandler saveDefaultURLHandler]; + if (argc == 2 && strcmp(argv[1], "--set-url-handler") == 0) { + return [DefaultURLHandler setDefaultURLHandler]; + } + return NSApplicationMain(argc, argv); } |