8000 Add support for common URI Schemes by PrimozRatej · Pull Request #291 · humhub/app · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for common URI Schemes #291

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

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,53 @@
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.VIDEO_CAPTURE" />
<uses-permission android:name="android.permission.AUDIO_CAPTURE" />
<uses-permission android:name="android.permission.CALL_PHONE" />

<uses-permission
android:name="android.permission.USE_FULL_SCREEN_INTENT"
tools:node="remove" />

<application
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sms" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="mailto" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sip" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="whatsapp" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="viber" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="slack" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="msteams" />
</intent>
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
</queries>



<application
android:label="HumHub"
android:name="${applicationName}"
android:allowBackup="false"
Expand Down
13 changes: 13 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,18 @@
</array>
</dict>
</array>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>sms</string>
<string>tel</string>
<string>mailto</string>
<string>sip</string>
<string>whatsapp</string>
<string>viber</string>
<string>slack</string>
<string>msteams</string>
</array>
</dict>
</plist>
4 changes: 4 additions & 0 deletions lib/pages/web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class WebViewAppState extends ConsumerState<WebView> {
WebViewGlobalController.listenToImageOpen();
WebViewGlobalController.appendViewportFitCover();

if (WebViewGlobalController.isCommonURIScheme(webUri: action.request.url!)) {
return WebViewGlobalController.handleCommonURISchemes(webUri: action.request.url!);
}

final url = action.request.url!.rawValue;

/// First BLOCK everything that rules out as blocked.
Expand Down
54 changes: 54 additions & 0 deletions lib/util/web_view_global_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:humhub/models/global_package_info.dart';
import 'package:humhub/models/global_user_agent.dart';
import 'package:humhub/models/manifest.dart';
import 'package:loggy/loggy.dart';
import 'package:url_launcher/url_launcher.dart';

class WebViewGlobalController {
static InAppWebViewController? _value;
Expand All @@ -30,6 +32,17 @@ class WebViewGlobalController {
return false;
}

static List<String> commonSchemes = [
'tel',
'mailto',
'sms',
'sip',
'whatsapp',
'viber',
'slack',
'msteams',
];

static void setValue(InAppWebViewController newValue) {
_value = newValue;
}
Expand Down Expand Up @@ -61,6 +74,47 @@ class WebViewGlobalController {
}
}

/// [handleCommonURISchemes]
///
/// Intercepts and handles specific URI schemes to launch external apps or services.
///
/// - Supported URI schemes:
/// - Communication: `tel:`, `mailto:`, `sms:`, `sip:`
/// - Messaging/Social Apps: `whatsapp:`, `viber:`, `slack:`, `msteams:`
///
/// [webUri] : The URI to evaluate and handle. Must use a supported scheme.
///
/// - Behavior:
/// - Launches the appropriate app or service for supported schemes.
/// - Logs an error if the URI cannot be handled or the scheme is unsupported.
///
/// @return [NavigationActionPolicy.CANCEL] if handled, otherwise [NavigationActionPolicy.ALLOW].
static handleCommonURISchemes({required Uri webUri}) async {
// Extract the scheme from the URI
final scheme = webUri.scheme;
try {
if (commonSchemes.contains(scheme)) {
// Try launching the URI
bool canLaunch = await canLaunchUrl(webUri);
if (canLaunch) {
await launchUrl(webUri);
} else {
logError('Could not launch ${webUri.toString()}');
}

// Return cancel navigation policy
return NavigationActionPolicy.CANCEL;
}
} catch (er) {
logError(er);
return NavigationActionPolicy.CANCEL;
}
}

static bool isCommonURIScheme({required Uri webUri}) {
return commonSchemes.contains(webUri.scheme) ? true : false;
}

static Future<void> listenToImageOpen() async {
// Inject JavaScript to monitor changes to the blueimp-gallery element
bool opened = false;
Expand Down
0