Skip to content

Commit 5699410

Browse files
Obtain default browser name on macOS
1 parent e370cee commit 5699410

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

certificates/install_darwin.go

+19
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ const char *getExpirationDate(char *expirationDate){
138138
139139
return "";
140140
}
141+
142+
const char *getDefaultBrowserName() {
143+
NSURL *defaultBrowserURL = [[NSWorkspace sharedWorkspace] URLForApplicationToOpenURL:[NSURL URLWithString:@"http://"]];
144+
if (defaultBrowserURL) {
145+
NSBundle *defaultBrowserBundle = [NSBundle bundleWithURL:defaultBrowserURL];
146+
NSString *defaultBrowser = [defaultBrowserBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
147+
148+
return [defaultBrowser cStringUsingEncoding:[NSString defaultCStringEncoding]];
149+
}
150+
151+
return "";
152+
}
141153
*/
142154
import "C"
143155
import (
@@ -196,3 +208,10 @@ func GetExpirationDate() (string, error) {
196208
date := C.GoString(dateString)
197209
return date, nil
198210
}
211+
212+
// GetDefaultBrowserName returns the name of the default browser
213+
func GetDefaultBrowserName() string {
214+
log.Infof("Retrieving default browser name")
215+
p := C.getDefaultBrowserName()
216+
return C.GoString(p)
217+
}

certificates/install_default.go

+6
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ func GetExpirationDate() (string, error) {
4242
log.Warn("platform not supported for retrieving certificates expiration date")
4343
return "", errors.New("platform not supported for retrieving certificates expiration date")
4444
}
45+
46+
// GetDefaultBrowserName won't do anything on unsupported Operative Systems
47+
func GetDefaultBrowserName() string {
48+
log.Warn("platform not supported for retrieving default browser name")
49+
return ""
50+
}

0 commit comments

Comments
 (0)