Skip to content

Commit

Permalink
Merge pull request #238 from humhub/f-iinternal-update-info-plist-and…
Browse files Browse the repository at this point in the history
…-merge-web-view-settings

Update info.plist and settings
  • Loading branch information
luke- authored Oct 4, 2024
2 parents b2508be + 811d944 commit 4b8fb78
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<false/>
<key>NSCameraUsageDescription</key>
<string>We need access to your camera to take photos and videos for sharing in the app.</string>
<key>NSMicrophoneUsageDescription</key>
<string>We need access to your microphone to take videos for sharing in the app.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need access your photo library to allow you to upload, view, and manage photos within the app.</string>
<key>NSAppTransportSecurity</key>
Expand Down
17 changes: 1 addition & 16 deletions lib/flavored/web_view.f.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class FlavoredWebViewState extends ConsumerState<WebViewF> {
bottom: false,
child: InAppWebView(
initialUrlRequest: _initialRequest,
initialSettings: _settings,
initialSettings: WebViewGlobalController.settings,
pullToRefreshController: pullToRefreshController,
shouldOverrideUrlLoading: _shouldOverrideUrlLoading,
shouldInterceptFetchRequest: _shouldInterceptFetchRequest,
Expand All @@ -90,10 +90,6 @@ class FlavoredWebViewState extends ConsumerState<WebViewF> {
onReceivedError: _onLoadError,
onProgressChanged: _onProgressChanged,
onDownloadStartRequest: _onDownloadStartRequest,
onPermissionRequest: (controller, permissionRequest) {
logInfo('onPermissionRequest', [controller, permissionRequest]);
return Future.value(PermissionResponse(action: PermissionResponseAction.DENY));
},
),
),
),
Expand All @@ -111,17 +107,6 @@ class FlavoredWebViewState extends ConsumerState<WebViewF> {
return URLRequest(url: WebUri(url), headers: instance.customHeaders);
}

InAppWebViewSettings get _settings => InAppWebViewSettings(
useShouldOverrideUrlLoading: true,
useShouldInterceptFetchRequest: true,
javaScriptEnabled: true,
supportZoom: false,
javaScriptCanOpenWindowsAutomatically: true,
supportMultipleWindows: true,
useHybridComposition: true,
allowsInlineMediaPlayback: true,
);

Future<NavigationActionPolicy?> _shouldOverrideUrlLoading(
InAppWebViewController controller, NavigationAction action) async {
// 1st check if url is not def. app url and open it in a browser or inApp.
Expand Down
16 changes: 5 additions & 11 deletions lib/pages/web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ class WebViewAppState extends ConsumerState<WebView> {
bool _isInit = false;
late double downloadProgress = 0;

final _settings = InAppWebViewSettings(
useShouldOverrideUrlLoading: true,
useShouldInterceptFetchRequest: true,
javaScriptEnabled: true,
supportZoom: false,
javaScriptCanOpenWindowsAutomatically: true,
supportMultipleWindows: true,
useHybridComposition: true,
);

@override
void didChangeDependencies() {
super.didChangeDependencies();
Expand Down Expand Up @@ -99,7 +89,7 @@ class WebViewAppState extends ConsumerState<WebView> {
onWillPop: () => exitApp(context, ref),
child: InAppWebView(
initialUrlRequest: _initialRequest,
initialSettings: _settings,
initialSettings: WebViewGlobalController.settings,
pullToRefreshController: _pullToRefreshController,
shouldOverrideUrlLoading: _shouldOverrideUrlLoading,
onWebViewCreated: _onWebViewCreated,
Expand Down Expand Up @@ -143,8 +133,10 @@ class WebViewAppState extends ConsumerState<WebView> {
Future<NavigationActionPolicy?> _shouldOverrideUrlLoading(
InAppWebViewController controller, NavigationAction action) async {
WebViewGlobalController.ajaxSetHeaders(headers: ref.read(humHubProvider).customHeaders);
WebViewGlobalController.injectWebSupportScript();

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

/// First BLOCK everything that rules out as blocked.
if (BlackListRules.check(url)) {
return NavigationActionPolicy.CANCEL;
Expand Down Expand Up @@ -226,11 +218,13 @@ class WebViewAppState extends ConsumerState<WebView> {
"document.querySelector('#account-login-form > div.form-group.field-login-rememberme').style.display='none';");
}
WebViewGlobalController.ajaxSetHeaders(headers: ref.read(humHubProvider).customHeaders);
WebViewGlobalController.injectWebSupportScript();
LoadingProvider.of(ref).dismissAll();
}

void _onLoadStart(InAppWebViewController controller, Uri? url) async {
WebViewGlobalController.ajaxSetHeaders(headers: ref.read(humHubProvider).customHeaders);
WebViewGlobalController.injectWebSupportScript();
}

_onProgressChanged(InAppWebViewController controller, int progress) {
Expand Down
24 changes: 24 additions & 0 deletions lib/util/web_view_global_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,28 @@ class WebViewGlobalController {
String jsCode = "\$.ajaxSetup({headers: ${jsonEncode(headers).toString()}});";
value?.evaluateJavascript(source: jsCode);
}

static void injectWebSupportScript() {
String script = """
var head = document.head || document.getElementsByTagName('head')[0];
var scriptElement = document.createElement('script');
scriptElement.type = 'application/javascript';
scriptElement.src = '/assets/packages/flutter_inappwebview/assets/web/web_support.js';
scriptElement.defer = true;
head.appendChild(scriptElement);
""";

value?.evaluateJavascript(source: script);
}

static InAppWebViewSettings get settings => InAppWebViewSettings(
useShouldOverrideUrlLoading: true,
useShouldInterceptFetchRequest: true,
javaScriptEnabled: true,
supportZoom: false,
javaScriptCanOpenWindowsAutomatically: true,
supportMultipleWindows: true,
useHybridComposition: true,
allowsInlineMediaPlayback: true,
mediaPlaybackRequiresUserGesture: false);
}

0 comments on commit 4b8fb78

Please sign in to comment.