Skip to content

Commit

Permalink
Ask for permission handler for ios.
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozRatej committed Sep 22, 2024
1 parent af8d653 commit ed39926
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 44 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<!-- For older versions (For Android 12 (API 31) and Below) -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<application
android:label="HumHub"
android:name="${applicationName}"
Expand Down
21 changes: 6 additions & 15 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,9 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/RunnerProfile.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 5439UTM27E;
DEVELOPMENT_TEAM = 5439UTM27E;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = HumHub;
Expand All @@ -407,7 +405,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.humhub.app;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = humhub_distribution_profile;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
Expand Down Expand Up @@ -536,11 +533,9 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 5439UTM27E;
DEVELOPMENT_TEAM = 5439UTM27E;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = HumHub;
Expand All @@ -553,7 +548,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.humhub.app;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = humhub_distribution_profile;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
Expand All @@ -574,11 +568,9 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 5439UTM27E;
DEVELOPMENT_TEAM = 5439UTM27E;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = HumHub;
Expand All @@ -591,7 +583,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.humhub.app;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = humhub_distribution_profile;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
Expand Down
6 changes: 6 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,11 @@
<string>14.4</string>
<key>FLTEnableImpeller</key>
<false />
<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photo library to save photos and videos.</string>
<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
</dict>
</plist>
1 change: 1 addition & 0 deletions ios/build/.last_build_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e728d5ba4e52068eb059d8c80cc8e750
8 changes: 6 additions & 2 deletions lib/app_opener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ class OpenerAppState extends ConsumerState<OpenerApp> {
void initState() {
super.initState();
SchedulerBinding.instance.addPostFrameCallback((_) async {
final status = await Permission.notification.status;
if (!status.isGranted) {
final notifications = await Permission.notification.status;
if (!notifications.isGranted) {
await Permission.notification.request();
}
final storage = await Permission.manageExternalStorage.status;
if (!storage.isGranted) {
await Permission.storage.request();
}
});
}

Expand Down
49 changes: 24 additions & 25 deletions lib/pages/web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ import 'package:humhub/util/providers.dart';
import 'package:humhub/util/openers/universal_opener_controller.dart';
import 'package:humhub/util/push/provider.dart';
import 'package:humhub/util/router.dart';
import 'package:humhub/util/show_dialog.dart';
import 'package:humhub/util/web_view_global_controller.dart';
import 'package:loggy/loggy.dart';
import 'package:open_file_plus/open_file_plus.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:humhub/util/router.dart' as m;
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '../util/show_dialog.dart';
import '../util/web_view_global_controller.dart';

class WebView extends ConsumerStatefulWidget {
const WebView({super.key});
static const String path = '/web_view';
Expand All @@ -40,12 +39,12 @@ class WebView extends ConsumerStatefulWidget {
}

class WebViewAppState extends ConsumerState<WebView> {
late AuthInAppBrowser authBrowser;
late Manifest manifest;
late AuthInAppBrowser _authBrowser;
late Manifest _manifest;
late URLRequest _initialRequest;
late PullToRefreshController _pullToRefreshController;
HeadlessInAppWebView? headlessWebView;
bool isInit = false;
HeadlessInAppWebView? _headlessWebView;
bool _isInit = false;

final _settings = InAppWebViewSettings(
useShouldOverrideUrlLoading: true,
Expand All @@ -60,11 +59,11 @@ class WebViewAppState extends ConsumerState<WebView> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (!isInit) {
if (!_isInit) {
_initialRequest = _initRequest;
_pullToRefreshController = PullToRefreshController(
settings: PullToRefreshSettings(
color: HexColor(manifest.themeColor),
color: HexColor(_manifest.themeColor),
),
onRefresh: () async {
if (Platform.isAndroid) {
Expand All @@ -77,20 +76,20 @@ class WebViewAppState extends ConsumerState<WebView> {
}
},
);
authBrowser = AuthInAppBrowser(
manifest: manifest,
_authBrowser = AuthInAppBrowser(
manifest: _manifest,
concludeAuth: (URLRequest request) {
_concludeAuth(request);
},
);
isInit = true;
_isInit = true;
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: HexColor(manifest.themeColor),
backgroundColor: HexColor(_manifest.themeColor),
body: SafeArea(
bottom: false,
// ignore: deprecated_member_use
Expand Down Expand Up @@ -118,25 +117,25 @@ class WebViewAppState extends ConsumerState<WebView> {
final args = ModalRoute.of(context)!.settings.arguments;
String? url;
if (args is Manifest) {
manifest = args;
_manifest = args;
}
if (args is UniversalOpenerController) {
UniversalOpenerController controller = args;
ref.read(humHubProvider).setInstance(controller.humhub);
manifest = controller.humhub.manifest!;
_manifest = controller.humhub.manifest!;
url = controller.url;
}
if (args == null) {
manifest = m.MyRouter.initParams;
_manifest = m.MyRouter.initParams;
}
if (args is ManifestWithRemoteMsg) {
ManifestWithRemoteMsg manifestPush = args;
manifest = manifestPush.manifest;
_manifest = manifestPush.manifest;
url = manifestPush.remoteMessage.data['url'];
}
String? payloadFromPush = InitFromPush.usePayload();
if (payloadFromPush != null) url = payloadFromPush;
return URLRequest(url: WebUri(url ?? manifest.startUrl), headers: ref.read(humHubProvider).customHeaders);
return URLRequest(url: WebUri(url ?? _manifest.startUrl), headers: ref.read(humHubProvider).customHeaders);
}

Future<NavigationActionPolicy?> _shouldOverrideUrlLoading(
Expand All @@ -145,8 +144,8 @@ class WebViewAppState extends ConsumerState<WebView> {

//Open in external browser
final url = action.request.url!.origin;
if (!url.startsWith(manifest.baseUrl) && action.isForMainFrame) {
authBrowser.launchUrl(action.request);
if (!url.startsWith(_manifest.baseUrl) && action.isForMainFrame) {
_authBrowser.launchUrl(action.request);
return NavigationActionPolicy.CANCEL;
}
// 2nd Append customHeader if url is in app redirect and CANCEL the requests without custom headers
Expand All @@ -163,15 +162,15 @@ class WebViewAppState extends ConsumerState<WebView> {

_onWebViewCreated(InAppWebViewController controller) async {
LoadingProvider.of(ref).showLoading();
headlessWebView = HeadlessInAppWebView();
headlessWebView!.run();
_headlessWebView = HeadlessInAppWebView();
_headlessWebView!.run();
await controller.addWebMessageListener(
WebMessageListener(
jsObjectName: "flutterChannel",
onPostMessage: (inMessage, sourceOrigin, isMainFrame, replyProxy) async {
logInfo(inMessage);
ChannelMessage message = ChannelMessage.fromJson(inMessage!.data);
await _handleJSMessage(message, headlessWebView!);
await _handleJSMessage(message, _headlessWebView!);
logDebug('flutterChannel triggered: ${message.type}');
},
),
Expand Down Expand Up @@ -231,7 +230,7 @@ class WebViewAppState extends ConsumerState<WebView> {
}

_concludeAuth(URLRequest request) {
authBrowser.close();
_authBrowser.close();
WebViewGlobalController.value!.loadUrl(urlRequest: request);
}

Expand Down Expand Up @@ -343,7 +342,7 @@ class WebViewAppState extends ConsumerState<WebView> {

@override
void dispose() {
if (headlessWebView != null) headlessWebView!.dispose();
if (_headlessWebView != null) _headlessWebView!.dispose();
//_pullToRefreshController.dispose();
super.dispose();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/util/file_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ class FileHandler {
Directory? directory;

if (Platform.isIOS) {
directory = await getApplicationDocumentsDirectory();
directory = await getDownloadsDirectory();
} else {
String check = "/storage/emulated/0/Download/";
String check = "/storage/emulated/0/Download";

bool dirDownloadExists = await Directory(check).exists();
if (dirDownloadExists) {
Expand Down

0 comments on commit ed39926

Please sign in to comment.