Skip to content

Commit b0f6e1d

Browse files
authored
Merge pull request #352 from wakatime/bugfix/apiurl
Support opening custom api_url dashboard
2 parents 8501306 + 857b8e7 commit b0f6e1d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

WakaTime/AppDelegate.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,27 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate, UNUserNot
107107
}
108108

109109
@objc func dashboardClicked(_ sender: AnyObject) {
110-
if let url = URL(string: "https://wakatime.com/") {
110+
let defaultUrl = "https://wakatime.com/"
111+
112+
var url = ConfigFile.getSetting(section: "settings", key: "api_url") ?? defaultUrl
113+
if url.isEmpty {
114+
url = defaultUrl
115+
}
116+
117+
url = url
118+
.replacingOccurrences(of: "://api.", with: "://")
119+
.replacingOccurrences(of: "/api/v1", with: "")
120+
.replacingOccurrences(of: "^api\\.", with: "", options: .regularExpression)
121+
.replacingOccurrences(of: "/api", with: "")
122+
123+
if let url = URL(string: url) {
111124
NSWorkspace.shared.open(url)
125+
} else {
126+
if url != defaultUrl {
127+
if let url = URL(string: defaultUrl) {
128+
NSWorkspace.shared.open(url)
129+
}
130+
}
112131
}
113132
}
114133

0 commit comments

Comments
 (0)