feat: Permission dialog before open link in browser

This commit is contained in:
Krille 2023-05-02 14:09:46 +02:00
parent 17bccc0dea
commit ce18cfdf2a
No known key found for this signature in database
3 changed files with 13 additions and 21 deletions

View File

@ -2529,5 +2529,6 @@
},
"jumpToLastReadMessage": "Jump to last read message",
"readUpToHere": "Read up to here",
"jump": "Jump"
"jump": "Jump",
"openLinkInBrowser": "Open link in browser"
}

View File

@ -7,7 +7,6 @@ import 'package:matrix/matrix.dart';
import 'package:fluffychat/widgets/matrix.dart';
import '../../../config/app_config.dart';
import '../../../config/setting_keys.dart';
import '../../../pages/image_viewer/image_viewer.dart';
import '../../../utils/matrix_sdk_extensions/matrix_locals.dart';
import '../../../utils/url_launcher.dart';
@ -83,24 +82,7 @@ class HtmlMessage extends StatelessWidget {
)
.toString();
},
onImageTap: (String mxc) => showDialog(
context: Matrix.of(context).navigatorContext,
useRootNavigator: false,
builder: (_) => ImageViewer(
Event(
type: EventTypes.Message,
content: <String, dynamic>{
'body': mxc,
'url': mxc,
'msgtype': MessageTypes.Image,
},
senderId: room.client.userID!,
originServerTs: DateTime.now(),
eventId: 'fake_event',
room: room,
),
),
),
onImageTap: (url) => UrlLauncher(context, url).launchUrl(),
setCodeLanguage: (String key, String value) async {
await matrix.store.setItem('${SettingKeys.codeLanguage}.$key', value);
},

View File

@ -22,7 +22,7 @@ class UrlLauncher {
const UrlLauncher(this.context, this.url);
void launchUrl() {
void launchUrl() async {
if (url!.toLowerCase().startsWith(AppConfig.deepLinkPrefix) ||
url!.toLowerCase().startsWith(AppConfig.inviteLinkPrefix) ||
{'#', '@', '!', '+', '\$'}.contains(url![0]) ||
@ -37,6 +37,15 @@ class UrlLauncher {
);
return;
}
final consent = await showOkCancelAlertDialog(
context: context,
title: L10n.of(context)!.openLinkInBrowser,
message: url,
okLabel: L10n.of(context)!.ok,
cancelLabel: L10n.of(context)!.cancel,
);
if (consent != OkCancelResult.ok) return;
if (!{'https', 'http'}.contains(uri.scheme)) {
// just launch non-https / non-http uris directly