Skip to content

Commit a53fdcd

Browse files
Obtain default browser name on macOS
1 parent e10948e commit a53fdcd

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

certificates/certs.h

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ const char *installCert(const char *path);
22
const char *uninstallCert();
33
const char *evaluateCert();
44
const char *getExpirationDate(char *expirationDate);
5+
const char *getDefaultBrowserName();

certificates/certs.m

+12
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,15 @@
165165

166166
return "";
167167
}
168+
169+
const char *getDefaultBrowserName() {
170+
NSURL *defaultBrowserURL = [[NSWorkspace sharedWorkspace] URLForApplicationToOpenURL:[NSURL URLWithString:@"http://"]];
171+
if (defaultBrowserURL) {
172+
NSBundle *defaultBrowserBundle = [NSBundle bundleWithURL:defaultBrowserURL];
173+
NSString *defaultBrowser = [defaultBrowserBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
174+
175+
return [defaultBrowser cStringUsingEncoding:[NSString defaultCStringEncoding]];
176+
}
177+
178+
return "";
179+
}

certificates/install_darwin.go

+7
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,10 @@ func GetExpirationDate() (string, error) {
9595
date := C.GoString(dateString)
9696
return date, nil
9797
}
98+
99+
// GetDefaultBrowserName returns the name of the default browser
100+
func GetDefaultBrowserName() string {
101+
log.Infof("Retrieving default browser name")
102+
p := C.getDefaultBrowserName()
103+
return C.GoString(p)
104+
}

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)