Skip to content

Commit

Permalink
Merge pull request #27 from luke-/26-hidechooser-only-when-javascript…
Browse files Browse the repository at this point in the history
…-channel-message-is-received

hideOpener only when Javascript Channel message is received
  • Loading branch information
PrimozRatej committed Feb 2, 2023
2 parents bfd3b31 + 302066b commit 08ed997
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pages/opener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class OpenerState extends ConsumerState<Opener> {
// Set the manifestStateProvider with the manifest value so that it's globally accessible
ref
.read(humHubProvider)
.setInstance(HumHub(manifest: manifest, isHideDialog: true));
.setInstance(HumHub(manifest: manifest));
redirect();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WebViewAppState extends ConsumerState<WebViewApp> {
Widget build(BuildContext context) {
return SafeArea(
child: WillPopScope(
onWillPop: () => webViewController.exitApp(context),
onWillPop: () => webViewController.exitApp(context, ref),
child: Scaffold(
key: scaffoldKey,
body: WebViewWidget(controller: webViewController)),
Expand Down
20 changes: 17 additions & 3 deletions lib/util/extensions.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:humhub/models/manifest.dart';
import 'package:humhub/pages/opener.dart';
import 'package:humhub/util/providers.dart';
import 'package:webview_flutter/webview_flutter.dart';

extension MyCookies on WebViewCookieManager {
Expand All @@ -16,7 +19,7 @@ extension MyCookies on WebViewCookieManager {
}

extension MyWebViewController on WebViewController {
Future<bool> exitApp(BuildContext context) async {
Future<bool> exitApp(BuildContext context, ref) async {
bool canGoBack = await this.canGoBack();
if (canGoBack) {
goBack();
Expand All @@ -33,7 +36,9 @@ extension MyWebViewController on WebViewController {
child: const Text('No'),
),
TextButton(
onPressed: () => SystemNavigator.pop(),
onPressed: () {
closeOrOpenDialog(context, ref);
},
child: const Text('Yes'),
),
],
Expand All @@ -42,6 +47,15 @@ extension MyWebViewController on WebViewController {
return exitConfirmed ?? false;
}
}

closeOrOpenDialog(BuildContext context, WidgetRef ref) {
var isHide = ref.read(humHubProvider).isHideDialog;
isHide
? SystemNavigator.pop()
: Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (context) => const Opener()),
(Route<dynamic> route) => false);
}
}

class HexColor extends Color {
Expand All @@ -54,4 +68,4 @@ class HexColor extends Color {
}

HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
}
}

0 comments on commit 08ed997

Please sign in to comment.