An open-source cross-platform alternative to AirDrop
feat: detect if message is a link and add a button to open the link
Tien Do Namf9168fce32d3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3a43b469..1ab6ebeb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,6 +1,7 @@## 1.4.0 (2023-01-)- feat: support multiple local IP addresses+- feat: detect if message is a link and add a button to open the link## 1.3.1 (2023-01-03)diff --git a/assets/i18n/strings.i18n.json b/assets/i18n/strings.i18n.jsonindex 20cec167..bff3f122 100644--- a/assets/i18n/strings.i18n.json+++ b/assets/i18n/strings.i18n.json@@ -9,6 +9,7 @@"confirm": "Confirm","continueStr": "Continue","copy": "Copy",+ "copiedToClipboard": "Copied to Clipboard","decline": "Decline","done": "Done","edit": "Edit",@@ -19,6 +20,7 @@"no": "No","offline": "Offline","online": "Online",+ "open": "Open","queue": "Queue","restart": "Restart","skipped": "Skipped",@@ -93,6 +95,7 @@"other": "wants to send you {n} files."},"subTitleMessage": "sent you a message:",+ "subTitleLink": "sent you a link:","canceled": "The sender has canceled the request."},"sendPage": {diff --git a/assets/i18n/strings_de.i18n.json b/assets/i18n/strings_de.i18n.jsonindex e9a2151e..9f3ab37e 100644--- a/assets/i18n/strings_de.i18n.json+++ b/assets/i18n/strings_de.i18n.json@@ -9,6 +9,7 @@"confirm": "Bestätigen","continueStr": "Weiter","copy": "Kopieren",+ "copiedToClipboard": "In die Zwischenablage kopiert","decline": "Ablehnen","done": "Fertig","edit": "Bearbeiten",@@ -19,6 +20,7 @@"no": "Nein","offline": "Offline","online": "Online",+ "open": "Öffnen","queue": "Warteschlange","restart": "Neustarten","skipped": "Übersprungen",@@ -93,6 +95,7 @@"other": "möchte dir {n} Dateien senden."},"subTitleMessage": "sendet dir eine Nachricht:",+ "subTitleLink": "sendet dir einen Link:","canceled": "Der Absender hat die Anfrage abgebrochen."},"sendPage": {diff --git a/lib/pages/receive_page.dart b/lib/pages/receive_page.dartindex 4a81abaa..d96470e8 100644--- a/lib/pages/receive_page.dart+++ b/lib/pages/receive_page.dart@@ -8,9 +8,12 @@ import 'package:localsend_app/model/session_status.dart';import 'package:localsend_app/pages/progress_page.dart';import 'package:localsend_app/provider/network/server_provider.dart';import 'package:localsend_app/util/ip_helper.dart';+import 'package:localsend_app/util/platform_check.dart';+import 'package:localsend_app/util/snackbar.dart';import 'package:localsend_app/widget/device_bage.dart';import 'package:localsend_app/widget/responsive_list_view.dart';import 'package:routerino/routerino.dart';+import 'package:url_launcher/url_launcher.dart';class ReceivePage extends ConsumerWidget {const ReceivePage({Key? key}) : super(key: key);@@ -40,6 +43,7 @@ class ReceivePage extends ConsumerWidget {final firstFile = receiveState.files.values.first.file;// show message if there is only one text filefinal message = receiveState.files.length == 1 && firstFile.fileType == FileType.text && firstFile.preview != null ? firstFile.preview : null;+ final isLink = message != null && (message.startsWith('http://') || message.startsWith('https'));return WillPopScope(onWillPop: () async {@@ -95,7 +99,7 @@ class ReceivePage extends ConsumerWidget {),const SizedBox(height: 40),Text(- message != null ? t.receivePage.subTitleMessage : t.receivePage.subTitle(n: receiveState.files.length),+ message != null ? (isLink ? t.receivePage.subTitleLink : t.receivePage.subTitleMessage) : t.receivePage.subTitle(n: receiveState.files.length),style: smallUi ? null : Theme.of(context).textTheme.headline6,textAlign: TextAlign.center,),@@ -120,14 +124,34 @@ class ReceivePage extends ConsumerWidget {),),const SizedBox(height: 10),- Center(- child: ElevatedButton(- onPressed: () {- Clipboard.setData(ClipboardData(text: message));- },- child: Text(t.general.copy),- ),- )+ Row(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ ElevatedButton(+ onPressed: () {+ Clipboard.setData(ClipboardData(text: message));+ if (checkPlatformIsDesktop()) {+ context.showSnackBar(t.general.copiedToClipboard);+ }+ },+ child: Text(t.general.copy),+ ),+ if (isLink)+ Padding(+ padding: const EdgeInsets.only(left: 20),+ child: ElevatedButton(+ style: ElevatedButton.styleFrom(+ backgroundColor: Theme.of(context).buttonTheme.colorScheme!.primary,+ foregroundColor: Theme.of(context).buttonTheme.colorScheme!.onPrimary,+ ),+ onPressed: () {+ launchUrl(Uri.parse(message));+ },+ child: Text(t.general.open),+ ),+ ),+ ],+ ),],),],@@ -151,36 +175,18 @@ class ReceivePage extends ConsumerWidget {),]else if (message != null)- Row(- mainAxisAlignment: MainAxisAlignment.center,- children: [- TextButton.icon(- style: TextButton.styleFrom(- foregroundColor: Theme.of(context).colorScheme.onSurface,- ),- onPressed: () {- _acceptNothing(ref, receiveState);- context.pop();- },- icon: const Icon(Icons.close),- label: Text(t.general.close),- ),- const SizedBox(width: 20),- TextButton.icon(- style: ElevatedButton.styleFrom(- foregroundColor: Theme.of(context).colorScheme.onSurface,- ),- onPressed: () {- _acceptAll(ref, receiveState);- context.pushAndRemoveUntilImmediately(- removeUntil: ReceivePage,- builder: () => const ProgressPage(),- );- },- icon: const Icon(Icons.save),- label: Text(t.general.save),+ Center(+ child: TextButton.icon(+ style: TextButton.styleFrom(+ foregroundColor: Theme.of(context).colorScheme.onSurface,),- ],+ onPressed: () {+ _acceptNothing(ref, receiveState);+ context.pop();+ },+ icon: const Icon(Icons.close),+ label: Text(t.general.close),+ ),)elseRow(