Skip to content

Support setting browser preference #1400

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 4 commits into from
Mar 15, 2025
Merged

Support setting browser preference #1400

merged 4 commits into from
Mar 15, 2025

Conversation

PIG208
Copy link
Member

@PIG208 PIG208 commented Mar 11, 2025

Fixes #1228.

This is taken from #1167, addressing the reviews there.

@PIG208 PIG208 added the integration review Added by maintainers when PR may be ready for integration label Mar 11, 2025
@PIG208 PIG208 requested a review from gnprice March 11, 2025 22:51
Comment on lines 73 to 75
final openLinksWithInAppBrowser =
GlobalStoreWidget.of(context).globalSettings.urlLaunchMode
== UrlLaunchMode.platformDefault;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we'll be presenting the setting as either "in-app: yes" or "in-app: no", let's make the semantics of our default match that presentation. IOW on Android let's adjust our default behavior so that it's the same as the behavior we end up with if the database says inApp.

That'd be good to do as a prep commit, before introducing the setting.

@PIG208 PIG208 force-pushed the pr-settings branch 2 times, most recently from 3ec51af to 85c0d5b Compare March 12, 2025 00:49
@PIG208
Copy link
Member Author

PIG208 commented Mar 12, 2025

Thanks! This is ready for review.

Screenshot

Comment on lines -859 to +872
.single.equals((url: Uri.parse('https://a/'), mode: LaunchMode.platformDefault));
.single.equals((url: Uri.parse('https://a/'), mode: LaunchMode.inAppBrowserView));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting: Make in-app explicitly the default browser preference on Android

This way, the default behavior when opening links on Android is
equivalent as if the browser preference is set to in-app.

I think both these two commits:
d1242a2 content [nfc]: Follow browser preference setting when opening links
f2a8d6a setting: Make in-app explicitly the default browser preference on Android

will be clearer to understand if the "explicitly in-app" commit comes first, as I suggested at #1400 (comment) .

Let's save making that revision for our call tomorrow. I can demonstrate how I'd go about re-splitting these changes (I think this is a case where that will be easier than trying to treat it as a rebase), and I think it'll be a good example.

@PIG208
Copy link
Member Author

PIG208 commented Mar 13, 2025

Thanks for the help! I have updated the PR.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

This is quite close now — a handful of nits below, following the revision I just pushed which expands some of the explanation in this commit:
f06b14c setting [nfc]: Make in-app explicitly the browser preference on Android


/// What browser the user has set to use for opening links in messages.
///
/// See https://chat.zulip.org/#narrow/stream/48-mobile/topic/in-app.20browser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: always use a permalink (so for Zulip topics, either /near/ or /with/)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the link because I think the dartdoc on the individual enum options explain them well enough, and that we have links to this conversation from effectiveBrowserPreference.

This line was originally from zulip/zulip-mobile#4679 (comment), where the code that interprets the enum values live elsewhere.

Comment on lines 66 to 67
BrowserPreference.inApp => url.scheme == 'http' || url.scheme == 'https'
? UrlLaunchMode.inAppBrowserView : UrlLaunchMode.platformDefault,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition calls for a comment to explain why we need this (and why it takes the particular shape it does).

Much of the needed information is in the commit message, so just needs to be moved from there. I also had some changes I wanted to make to the framing of that, so I made a revision which I'll push along with this review.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see! It makes sense that the upstream behavior needs to change.

Comment on lines 20 to 21
defaultTargetPlatform == TargetPlatform.iOS
? UrlLaunchMode.externalApplication : UrlLaunchMode.inAppBrowserView);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the conditions in these two tests are confusing because they go opposite ways (so the expected values come in opposite orders) — either way seems fine, just make them consistent

Comment on lines +17 to +18
final globalStore = eg.globalStore(globalSettings: eg.globalSettings(
browserPreference: null));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this bit of setup should arrive in the "follow setting" commit, rather than the preceding commit where the setting isn't yet involved

@@ -811,6 +811,10 @@
"@themeSettingSystem": {
"description": "Label for system theme setting."
},
"openLinksWithInAppBrowser": "Open links with in-app browser",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The translation for the label is taken from zulip-mobile. The user
facing string refers to "in in-app browser" when the actual value is
`UrlLaunchMode.platformDefault`. This is consistent with the behavior
the user sees when the link is a HTTP URL on Android and iOS, which
should cover the majority of use cases of this setting (and probably
what the user would expect).

This apologetic paragraph can get a lot simpler now 🙂 — I think really can just be cut.

The exact semantics are now "Open links with in-app browser where possible", and the implementation code now makes clear that those are the semantics. And having a "where possible" qualifier be implicit is pretty normal for UI text (outside of UIs for quite technical domains).

@PIG208
Copy link
Member Author

PIG208 commented Mar 14, 2025

Thanks! Updated the PR.

@gnprice
Copy link
Member

gnprice commented Mar 15, 2025

Thanks! Looks good; merging.

PIG208 and others added 4 commits March 14, 2025 21:04
The url_launcher documentation warns that the meaning of
platformDefault may change at any time.  We've chosen
particular behaviors we want on different platforms, so
express those choices explicitly.

This change is NFC given the current behavior of url_launcher,
which appears to be that platformDefault means an in-app browser
for at least HTTP links.

Co-authored-by: Greg Price <[email protected]>
Signed-off-by: Zixuan James Li <[email protected]>
This preserves the previous behavior (external application on iOS,
and in-app browser on Android) when browserPreference is `null`.

There is no way for the client to update the setting for now, hence the
NFC.

The helper could have been a static method instead of an extension,
similar to ThemeSetting.displayName, but that will be a lot more verbose
for the caller.

Signed-off-by: Zixuan James Li <[email protected]>
The UI currently does not have a design, and is made to be as simple as
possible to implement for now.

Fixes: zulip#1228

Signed-off-by: Zixuan James Li <[email protected]>
@gnprice gnprice merged commit b030737 into zulip:main Mar 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Offer "Open links with in-app browser" setting
2 participants