-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Handle .ton domains correctly in WebAppController and WebAppWebView #1799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
NikGariel
commented
Jun 26, 2025
- Modified WebAppController.swift to check for .ton domains and convert to tonsite scheme
- Added TonSchemeHandler in WebAppWebView.swift to handle tonsite URL scheme
- Ensures proper loading of .ton URLs without introducing new features
- Modified WebAppController.swift to check for .ton domains and convert to tonsite scheme - Added TonSchemeHandler in WebAppWebView.swift to handle tonsite URL scheme - Ensures proper loading of .ton URLs without introducing new features Handle .ton domains correctly in WebAppController and WebAppWebView - Modified WebAppController.swift to check for .ton domains and convert to tonsite scheme - Added TonSchemeHandler in WebAppWebView.swift to handle tonsite URL scheme - Ensures proper loading of .ton URLs without introducing new features
| if let host = parsedUrl.host, host.lowercased().hasSuffix(".ton") { | ||
| // Convert to tonsite scheme | ||
| var urlComponents = URLComponents(string: url) | ||
| urlComponents?.scheme = "tonsite" | ||
| if let updatedUrl = urlComponents?.url { | ||
| self.webView?.load(URLRequest(url: updatedUrl)) | ||
| } else { | ||
| self.webView?.load(URLRequest(url: parsedUrl)) | ||
| } | ||
| } else { | ||
| self.webView?.load(URLRequest(url: parsedUrl)) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be simplified like this to avoid multiple if-else statements ?
let urlToLoad: URL
if parsedUrl.host?.lowercased().hasSuffix(".ton") == true,
var components = URLComponents(url: parsedUrl, resolvingAgainstBaseURL: false) {
components.scheme = "tonsite"
urlToLoad = components.url ?? parsedUrl
} else {
urlToLoad = parsedUrl
}
self.webView?.load(URLRequest(url: urlToLoad))
| if let host = parsedUrl.host, host.lowercased().hasSuffix(".ton") { | ||
| // Convert to tonsite scheme | ||
| var urlComponents = URLComponents(string: result.url) | ||
| urlComponents?.scheme = "tonsite" | ||
| if let updatedUrl = urlComponents?.url { | ||
| strongSelf.webView?.load(URLRequest(url: updatedUrl)) | ||
| } else { | ||
| strongSelf.webView?.load(URLRequest(url: parsedUrl)) | ||
| } | ||
| } else { | ||
| strongSelf.webView?.load(URLRequest(url: parsedUrl)) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this probably also could be simplified.
let urlToLoad: URL
if parsedUrl.host?.lowercased().hasSuffix(".ton") == true,
var components = URLComponents(url: parsedUrl, resolvingAgainstBaseURL: false) {
components.scheme = "tonsite"
urlToLoad = components.url ?? parsedUrl
} else {
urlToLoad = parsedUrl
}
strongSelf.webView?.load(URLRequest(url: urlToLoad))
| // Check if the URL has a .ton domain | ||
| if let host = parsedUrl.host, host.lowercased().hasSuffix(".ton") { | ||
| // Convert to tonsite scheme | ||
| var urlComponents = URLComponents(string: result.url) | ||
| urlComponents?.scheme = "tonsite" | ||
| if let updatedUrl = urlComponents?.url { | ||
| strongSelf.webView?.load(URLRequest(url: updatedUrl)) | ||
| } else { | ||
| strongSelf.webView?.load(URLRequest(url: parsedUrl)) | ||
| } | ||
| } else { | ||
| strongSelf.webView?.load(URLRequest(url: parsedUrl)) | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also could be simplified
| if let host = parsedUrl.host, host.lowercased().hasSuffix(".ton") { | ||
| // Convert to tonsite scheme | ||
| var urlComponents = URLComponents(string: result.url) | ||
| urlComponents?.scheme = "tonsite" | ||
| if let updatedUrl = urlComponents?.url { | ||
| self.webView?.load(URLRequest(url: updatedUrl)) | ||
| } else { | ||
| self.webView?.load(URLRequest(url: parsedUrl)) | ||
| } | ||
| } else { | ||
| self.webView?.load(URLRequest(url: parsedUrl)) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also could be simplified
| mappedPath = "/\(mappedPath)" | ||
| } | ||
| } | ||
| let mappedUrl = "https://\(mappedHost).\(proxyServerHost)\(mappedPath)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use here a function like this
private static func mappedUrl(from url: URL?, proxyHost: String) -> URL {
let mappedHost = url?.host?
.replacingOccurrences(of: "-", with: "-h")
.replacingOccurrences(of: ".", with: "-d") ?? ""
let mappedPath: String
if let path = url?.path, !path.isEmpty {
mappedPath = path.hasPrefix("/") ? path : "/" + path
} else {
mappedPath = ""
}
return URL(string: "https://\(mappedHost).\(proxyHost)\(mappedPath)")!
}
| } | ||
| let mappedUrl = "https://\(mappedHost).\(proxyServerHost)\(mappedPath)" | ||
| let isCompleted = self.isCompleted | ||
| self.urlSessionTask = URLSession.shared.dataTask(with: URLRequest(url: URL(string: mappedUrl)!), completionHandler: { data, response, error in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| self.urlSessionTask = URLSession.shared.dataTask(with: URLRequest(url: URL(string: mappedUrl)!), completionHandler: { data, response, error in | |
| self.urlSessionTask = URLSession.shared.dataTask(with: URLRequest(url: url: mappedUrl), completionHandler: { data, response, error in |
You can the the output of the function above that I suggested mappedUrl(from url: URL?, proxyHost: String) -> URL