Skip to content

Commit

Permalink
Browser preference
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan James Li <zixuan@zulip.com>
  • Loading branch information
PIG208 committed Dec 26, 2024
1 parent 8e0efd5 commit bcf97a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/widgets/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import '../model/avatar_url.dart';
import '../model/binding.dart';
import '../model/content.dart';
import '../model/internal_link.dart';
import '../model/settings.dart';
import 'code_block.dart';
import 'dialog.dart';
import 'icons.dart';
Expand Down Expand Up @@ -1342,17 +1343,20 @@ void _launchUrl(BuildContext context, String urlString) async {
return;
}

final globalSettings = GlobalStoreWidget.of(context).globalSettings;
bool launched = false;
String? errorMessage;
try {
launched = await ZulipBinding.instance.launchUrl(url,
mode: switch (defaultTargetPlatform) {
mode: switch ((globalSettings.browserPreference, defaultTargetPlatform)) {
(BrowserPreference.embedded, _) => UrlLaunchMode.inAppBrowserView,
(BrowserPreference.external, _) => UrlLaunchMode.externalApplication,
// On iOS we prefer LaunchMode.externalApplication because (for
// HTTP URLs) LaunchMode.platformDefault uses SFSafariViewController,
// which gives an awkward UX as described here:
// https://chat.zulip.org/#narrow/stream/48-mobile/topic/in-app.20browser/near/1169118
TargetPlatform.iOS => UrlLaunchMode.externalApplication,
_ => UrlLaunchMode.platformDefault,
(BrowserPreference.unset, TargetPlatform.iOS) => UrlLaunchMode.externalApplication,
(BrowserPreference.unset, _) => UrlLaunchMode.platformDefault,
});
} on PlatformException catch (e) {
errorMessage = e.message;
Expand Down
1 change: 1 addition & 0 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ ChannelUpdateEvent channelUpdateEvent(

const defaultGlobalSettings = GlobalSettingsData(
themeSetting: ThemeSetting.unset,
browserPreference: BrowserPreference.unset,
);

TestGlobalStore globalStore({
Expand Down

0 comments on commit bcf97a4

Please sign in to comment.