From 038287ba4c8370bb20e2fe71817f9984559226da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Fri, 23 May 2025 22:23:52 +0200 Subject: [PATCH] Added copy-curl button --- flutter/lib/pages/send/send.dart | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/flutter/lib/pages/send/send.dart b/flutter/lib/pages/send/send.dart index 84edde3..be6e873 100644 --- a/flutter/lib/pages/send/send.dart +++ b/flutter/lib/pages/send/send.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; import 'package:qr_flutter/qr_flutter.dart'; @@ -95,6 +96,14 @@ class _SendRootPageState extends State { const SizedBox(height: 16), Row( children: [ + UI.buttonIconOnly( + icon: FontAwesomeIcons.webhook, + onPressed: _copyCurl, + square: true, + color: Theme.of(context).colorScheme.secondary.withAlpha(128), + iconColor: Theme.of(context).colorScheme.onSecondary, + ), + const SizedBox(width: 8), Expanded( child: UI.button( text: 'Send', @@ -188,6 +197,14 @@ class _SendRootPageState extends State { const SizedBox(height: 16), Row( children: [ + UI.buttonIconOnly( + icon: FontAwesomeIcons.webhook, + onPressed: _copyCurl, + square: true, + color: Theme.of(context).colorScheme.secondary.withAlpha(128), + iconColor: Theme.of(context).colorScheme.onSecondary, + ), + const SizedBox(width: 8), Expanded( child: UI.button( text: 'Send', @@ -332,4 +349,35 @@ class _SendRootPageState extends State { _senderName.text = Globals().deviceName; }); } + + void _copyCurl() { + final userAcc = Provider.of(context, listen: false); + + if (!userAcc.isAuth()) { + Toaster.error("Error", 'Must be logged in to send messages'); + return; + } + + String curl = 'curl'; + curl += ' --data user_id="${userAcc.userID}"'; + curl += ' --data key="${userAcc.tokenSend}"'; + curl += ' --data title="${shellEscape(_msgTitle.text)}"'; + curl += ' --data content="${shellEscape(_msgContent.text)}"'; + + if (_expanded) { + curl += ' --data channel="${shellEscape(_channelName.text)}"'; + curl += ' --data sender_name="${shellEscape(_senderName.text)}"'; + curl += ' --data priority="${_priority}"'; + } + + curl += ' "https://simplecloudnotifier.de/"'; + + Clipboard.setData(new ClipboardData(text: curl)); + Toaster.info("Clipboard", 'Copied curl-command to Clipboard'); + print('================= [CLIPBOARD] =================\n${curl}\n================= [/CLIPBOARD] ================='); + } + + String shellEscape(String str) { + return str.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('\n', '\\n').replaceAll('\t', '\\t'); + } }