Skip to content
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

fix url redirect pattern #42

Merged
merged 1 commit into from
Sep 12, 2024
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
5 changes: 5 additions & 0 deletions lib/pages/add_bridge/model/social_network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SocialNetwork {
displayNameSuffix; // The `(Network)` suffix to remove from displayname)
final String? urlLogin;
final String? urlRedirect;
final RegExp? urlRedirectPattern;
bool loading; // To find out if state is loading
bool connected; // To find out if state is disconnected
bool error; // Bool to indicate if there is an error
Expand All @@ -29,6 +30,7 @@ class SocialNetwork {
this.displayNameSuffix = "",
this.urlLogin,
this.urlRedirect,
this.urlRedirectPattern,
this.loading = true, // Default value true for loading
this.connected = false, // Default value false for connected
this.error = false, // Défaut à false
Expand Down Expand Up @@ -77,6 +79,7 @@ class SocialNetworkManager {
mxidPrefix: "@messenger2_",
urlLogin: "https://www.messenger.com/login/",
urlRedirect: "https://www.messenger.com/t/",
urlRedirectPattern: RegExp(r'^https:\/\/www\.messenger\.com\/.*\/t\/.*$'),
),
SocialNetwork(
logo: Logo(Logos.instagram),
Expand All @@ -89,6 +92,7 @@ class SocialNetworkManager {
mxidPrefix: "@instagram2_",
urlLogin: "https://www.instagram.com/accounts/login/",
urlRedirect: "https://www.instagram.com/",
urlRedirectPattern: RegExp(r'^https:\/\/www\.instagram\.com\/.*$'),
),
SocialNetwork(
logo: Logo(Logos.whatsapp),
Expand All @@ -111,6 +115,7 @@ class SocialNetworkManager {
mxidPrefix: "@linkedin_",
urlLogin: "https://www.linkedin.com/login/",
urlRedirect: "https://www.linkedin.com/feed/",
urlRedirectPattern: RegExp(r'^https:\/\/www\.linkedin\.com\/feed\/.*$'),
),
SocialNetwork(
logo: Container(),
Expand Down
11 changes: 6 additions & 5 deletions lib/pages/add_bridge/web_view_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ class _WebViewConnectionState extends State<WebViewConnection> {
_webViewController = controller;
},
onLoadStop: (InAppWebViewController controller, Uri? url) async {
final urlString = url?.toString();
// Check the URL when the page finishes loading
switch (widget.network.name) {
case "Facebook Messenger":
final successfullyRedirected = !_facebookBridgeCreated &&
url != null &&
url.toString() != widget.network.urlLogin! &&
url.toString().contains(widget.network.urlRedirect!);
urlString != widget.network.urlLogin! &&
widget.network.urlRedirectPattern?.hasMatch(urlString!) == true;

if (successfullyRedirected) {
await _closeWebView();
Expand All @@ -138,8 +139,8 @@ class _WebViewConnectionState extends State<WebViewConnection> {
case "Instagram":
if (!_instagramBridgeCreated &&
url != null &&
url.toString() != widget.network.urlLogin! &&
url.toString().contains(widget.network.urlRedirect!)) {
urlString != widget.network.urlLogin! &&
widget.network.urlRedirectPattern?.hasMatch(urlString!) == true) {
// Close the WebView
await _closeWebView();
await showCustomLoadingDialog(
Expand All @@ -158,7 +159,7 @@ class _WebViewConnectionState extends State<WebViewConnection> {
case "Linkedin":
if (!_linkedinBridgeCreated &&
url != null &&
url.toString().contains(widget.network.urlRedirect!)) {
widget.network.urlRedirectPattern?.hasMatch(urlString!) == true) {
// Close the WebView
await _closeWebView();
await showCustomLoadingDialog(
Expand Down
Loading