hotfix use custom url scheme to open links if provided

This commit is contained in:
JanNiklas Grabowski
2023-12-22 12:25:59 +01:00
parent 59ee43ed5c
commit 5decccf6cb
18 changed files with 106 additions and 22 deletions

View File

@@ -21,12 +21,21 @@ extension UIApplication {
let application = UIApplication.shared
guard application.canOpenURL(url) else {
// bwi: override scheme if needed
var tmpURL = url
if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) {
if let newURL = CustomURLSchemeHelper.shared.overrideURLSchemeIfNeeded(urlComponents).url {
tmpURL = newURL
}
}
guard application.canOpenURL(tmpURL) else {
completion?(false)
return
}
application.open(url, options: [:], completionHandler: { success in
application.open(tmpURL, options: [:], completionHandler: { success in
completion?(success)
})
}

View File

@@ -2542,7 +2542,9 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro
-(void) gotoAppStore {
NSString *iTunesLink = BWIBuildSettings.shared.itunesAppLink;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink] options:@{} completionHandler:nil];
if (iTunesLink) {
[[UIApplication sharedApplication] vc_open:[NSURL URLWithString:iTunesLink] completionHandler:nil];
}
}
#pragma mark - SpaceChildRoomDetailBridgePresenterDelegate

View File

@@ -120,7 +120,7 @@ class VersionCheckCoordinator: Coordinator, VersionCheckBannerViewDelegate, Vers
}
if let url = Constants.supportURL {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
UIApplication.shared.vc_open(url, completionHandler: nil)
}
}

View File

@@ -355,7 +355,9 @@ NSString *const kMXKWebViewViewControllerJavaScriptEnableLog =
{
if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
// bwi: clicked links should be opened in system browser
[[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{} completionHandler:nil];
if (navigationAction.request.URL) {
[[UIApplication sharedApplication] vc_open:navigationAction.request.URL completionHandler:nil];
}
decisionHandler(WKNavigationActionPolicyCancel);
} else {
// bwi: Open url in webview

View File

@@ -419,4 +419,13 @@ manualChangeMessageForVideo:(NSString*)manualChangeMessageForVideo
*/
+ (NSString*)logForPushToken:(NSData*)pushToken;
#pragma mark - bwi
/**
Check if link is a permalink.
@param link the link to ceck.
@return true if link is a permalink, false if it is not a permalink.
*/
+ (BOOL)isLinkPermalink:(NSString*)link;
@end

View File

@@ -1079,8 +1079,10 @@ manualChangeMessageForVideo:(NSString*)manualChangeMessageForVideo
NSRange matchRange = [match range];
NSURL *matchUrl = [match URL];
NSURLComponents *url = [[NSURLComponents new] initWithURL:matchUrl resolvingAgainstBaseURL:NO];
url = [CustomURLSchemeHelper.shared overrideURLSchemeIfNeeded:url];
if (url.URL)
{
[mutableAttributedString addAttribute:NSLinkAttributeName value:url.URL range:matchRange];
[mutableAttributedString addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.colors.links range:matchRange];
}
}
@@ -1254,4 +1256,18 @@ manualChangeMessageForVideo:(NSString*)manualChangeMessageForVideo
return [NSString stringWithFormat:@"%@...", [pushToken subdataWithRange:NSMakeRange(0, len)]];
}
#pragma mark - bwi
+ (BOOL)isLinkPermalink:(NSString*)link
{
if ([permalinkRegex numberOfMatchesInString:link options:0 range:NSMakeRange(0, link.length)] == 0)
{
return NO;
}
else
{
return YES;
}
}
@end

View File

@@ -3436,11 +3436,11 @@ SSOAuthenticationPresenterDelegate>
}
else if (row == ABOUT_COPYRIGHT_INDEX)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:BWIBuildSettings.shared.applicationCopyrightUrlString] options:@{} completionHandler:nil];
[[UIApplication sharedApplication] vc_open:[NSURL URLWithString:BWIBuildSettings.shared.applicationCopyrightUrlString] completionHandler:nil];
}
else if (row == ABOUT_ACCEPTABLE_USE_INDEX)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:BuildSettings.applicationAcceptableUsePolicyUrlString] options:@{} completionHandler:nil];
[[UIApplication sharedApplication] vc_open:[NSURL URLWithString: BuildSettings.applicationAcceptableUsePolicyUrlString] completionHandler:nil];
}
else if (row == ABOUT_SUPPORT_INDEX)
{
@@ -3457,11 +3457,11 @@ SSOAuthenticationPresenterDelegate>
{
if (BWIBuildSettings.shared.bwiUseWellKnownPrivacyPolicyLink)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.mainSession.homeserverWellknown.dataPrivacyURL] options:@{} completionHandler:nil];
[[UIApplication sharedApplication] vc_open:[NSURL URLWithString: self.mainSession.homeserverWellknown.dataPrivacyURL] completionHandler:nil];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:BWIBuildSettings.shared.applicationPrivacyPolicyUrlString] options:@{} completionHandler:nil];
[[UIApplication sharedApplication] vc_open:[NSURL URLWithString: BWIBuildSettings.shared.applicationPrivacyPolicyUrlString] completionHandler:nil];
}
}
else if (row == ABOUT_ACCESSIBILITY_DECLARATION_INDEX)
@@ -3481,7 +3481,7 @@ SSOAuthenticationPresenterDelegate>
}
else if (row == ABOUT_IMPRINT_INDEX)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self.mainSession.homeserverWellknown imprintURL]] options:@{} completionHandler:nil];
[[UIApplication sharedApplication] vc_open:[NSURL URLWithString: [self.mainSession.homeserverWellknown imprintURL]] completionHandler:nil];
}
}
else if (section == SECTION_TAG_USER_SETTINGS)

View File

@@ -1092,10 +1092,10 @@
[alert addAction:[UIAlertAction actionWithTitle:BWIL10n.bwiAnalyticsAlertInfoButton style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
if (BWIBuildSettings.shared.bwiUseWellKnownPrivacyPolicyLink) {
if (self->mxSessionArray.firstObject.homeserverWellknown.dataPrivacyURL != nil) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:self->mxSessionArray.firstObject.homeserverWellknown.dataPrivacyURL] options:@{} completionHandler:nil];
[[UIApplication sharedApplication] vc_open:[NSURL URLWithString: self->mxSessionArray.firstObject.homeserverWellknown.dataPrivacyURL] completionHandler:nil];
}
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:BWIBuildSettings.shared.applicationPrivacyPolicyUrlString] options:@{} completionHandler:nil];
[[UIApplication sharedApplication] vc_open:[NSURL URLWithString: BWIBuildSettings.shared.applicationPrivacyPolicyUrlString] completionHandler:nil];
}
}]];
[alert addAction:[UIAlertAction actionWithTitle:BWIL10n.bwiAnalyticsAlertCancelButton style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {

View File

@@ -57,6 +57,7 @@ targets:
- path: ../bwi/MatomoAnalytics/AnalyticsConfiguration.swift
- path: ../bwi/MatomoAnalytics/DecryptedEvent.swift
- path: ../bwi/MatomoAnalytics/E2EEError.swift
- path: ../bwi/URLScheme/CustomURLSchemeHelper.swift
- path: ../Riot/Managers/Settings/RiotSettings.swift
- path: ../Config/BuildSettings.swift
- path: ../Config/BWIBuildSettings.swift

View File

@@ -86,7 +86,7 @@ class AuthenticationLoginViewModel: AuthenticationLoginViewModelType, Authentica
message: BWIL10n.bwiDeprecatedVersionWarningMessage,
primaryButton: (BWIL10n.bwiDeprecatedVersionAppstoreButton, {
UIApplication.shared.open(URL(string: BWIBuildSettings.shared.itunesAppLink)!)
UIApplication.shared.vc_open(URL(string: BWIBuildSettings.shared.itunesAppLink)!, completionHandler: nil)
}),
secondaryButton: (VectorL10n.ok, {}))

View File

@@ -218,9 +218,8 @@ struct AuthenticationLoginScreen: View {
return
}
let tosURL = URL.init(string: urlString)! // add your link here
if UIApplication.shared.canOpenURL(tosURL) {
UIApplication.shared.open(tosURL)
}
UIApplication.shared.vc_open(tosURL, completionHandler: nil)
}, label: {
Text(BWIL10n.authenticationDataprivacyText)
.font(theme.fonts.footnote)

View File

@@ -130,7 +130,7 @@ final class AuthenticationServerSelectionCoordinator: Coordinator, Presentable {
stopLoading()
let primaryButtonCompletion: (() -> Void)? = { () in
if let url = URL(string: BWIBuildSettings.shared.bumAdvertizementURLString) {
UIApplication.shared.open(url)
UIApplication.shared.vc_open(url, completionHandler: nil)
}
}

View File

@@ -263,7 +263,7 @@ struct AuthenticationServerSelectionScreen: View {
return Alert(
title: Text(BWIL10n.authenticationServerSelectionServerDeniedTitle),
message: Text(BWIL10n.authenticationServerSelectionServerDeniedMessage),
primaryButton: .default(Text(BWIL10n.authenticationServerSelectionServerDeniedAdvertizementWebsiteButton), action: {UIApplication.shared.open(url)}),
primaryButton: .default(Text(BWIL10n.authenticationServerSelectionServerDeniedAdvertizementWebsiteButton), action: {UIApplication.shared.vc_open(url, completionHandler: nil)}),
secondaryButton: .default(Text(VectorL10n.ok)))
} else {

View File

@@ -123,7 +123,7 @@ struct LiveLocationSharingViewer: View {
.bottomSheet(sheet, if: viewModel.viewState.isBottomSheetVisible)
.actionSheet(isPresented: $viewModel.showMapCreditsSheet) {
MapCreditsActionSheet(openURL: { url in
openURL(url)
UIApplication.shared.vc_open(url, completionHandler: nil)
}).sheet
}
.alert(item: $viewModel.alertInfo) { info in

View File

@@ -49,7 +49,7 @@ struct LocationSharingView: View {
.padding(.bottom, 10.0)
.actionSheet(isPresented: $context.showMapCreditsSheet) {
MapCreditsActionSheet(openURL: { url in
openURL(url)
UIApplication.shared.vc_open(url, completionHandler: nil)
}).sheet
}
}

View File

@@ -59,7 +59,7 @@ struct StaticLocationView: View {
.padding(.bottom, 10.0 + safeAreaInsets.bottom)
.actionSheet(isPresented: $viewModel.showMapCreditsSheet) {
MapCreditsActionSheet(openURL: { url in
openURL(url)
UIApplication.shared.vc_open(url, completionHandler: nil)
}).sheet
}
}

View File

@@ -190,7 +190,7 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
message: Text(BWIL10n.bwiOutdatedVersionWarningMessage(AppInfo.current.displayName)),
dismissButton: .destructive(Text(BWIL10n.bwiOutdatedVersionAppstoreButton), action: {
let iTunesLink = BWIBuildSettings.shared.itunesAppLink
UIApplication.shared.open(URL(string: iTunesLink)!, options: [:], completionHandler: nil)
UIApplication.shared.vc_open(URL(string: iTunesLink)!, completionHandler: nil)
}))
case .showDowntimeTimeAlert:
if BWIBuildSettings.shared.ignoreBlockingMaintenance && isBlocking() {

View File

@@ -0,0 +1,46 @@
//
/*
* Copyright (c) 2023 BWI GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
@objcMembers class CustomURLSchemeHelper : NSObject {
static let shared = CustomURLSchemeHelper()
func overrideURLSchemeIfNeeded(_ urlComponents: URLComponents) -> URLComponents {
if AppConfigService.shared.externalUrlScheme() != nil {
guard let url = urlComponents.url else {
return urlComponents
}
// Check if link is a permalink
if MXKTools.isLinkPermalink(url.absoluteString) {
return urlComponents
}
// Only override http / https
if (urlComponents.scheme ?? "http").elementsEqual("http") || (urlComponents.scheme ?? "https").elementsEqual("https") {
var newURLComponents = urlComponents
if let urlScheme = AppConfigService.shared.externalUrlScheme() {
newURLComponents.scheme = urlScheme
}
return newURLComponents
} else {
return urlComponents
}
} else {
return urlComponents
}
}
}