Skip to content

Commit 0559b11

Browse files
Obtain default browser name on macOS
1 parent e0d0bdb commit 0559b11

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
@@ -188,6 +188,18 @@ const char *getExpirationDate(char *expirationDate){
188188
189189
return "";
190190
}
191+
192+
const char *getDefaultBrowserName() {
193+
NSURL *defaultBrowserURL = [[NSWorkspace sharedWorkspace] URLForApplicationToOpenURL:[NSURL URLWithString:@"http://"]];
194+
if (defaultBrowserURL) {
195+
NSBundle *defaultBrowserBundle = [NSBundle bundleWithURL:defaultBrowserURL];
196+
NSString *defaultBrowser = [defaultBrowserBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
197+
198+
return [defaultBrowser cStringUsingEncoding:[NSString defaultCStringEncoding]];
199+
}
200+
201+
return "";
202+
}
191203
*/
192204
import "C"
193205
import (
@@ -260,3 +272,10 @@ func GetExpirationDate() (string, error) {
260272
date := C.GoString(dateString)
261273
return date, nil
262274
}
275+
276+
// GetDefaultBrowserName returns the name of the default browser
277+
func GetDefaultBrowserName() string {
278+
log.Infof("Retrieving default browser name")
279+
p := C.getDefaultBrowserName()
280+
return C.GoString(p)
281+
}

certificates/install_default.go

+6
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ func GetExpirationDate() (string, error) {
4848
log.Warn("platform not supported for retrieving certificates expiration date")
4949
return "", errors.New("platform not supported for retrieving certificates expiration date")
5050
}
51+
52+
// GetDefaultBrowserName won't do anything on unsupported Operative Systems
53+
func GetDefaultBrowserName() string {
54+
log.Warn("platform not supported for retrieving default browser name")
55+
return ""
56+
}

0 commit comments

Comments
 (0)