Added copy-curl button
All checks were successful
Build Docker and Deploy / Build Docker Container (push) Successful in 1m30s
Build Docker and Deploy / Run Unit-Tests (push) Successful in 8m46s
Build Docker and Deploy / Deploy to Server (push) Successful in 12s

This commit is contained in:
Mike Schwörer 2025-05-23 22:23:52 +02:00
parent 3ae2742033
commit 038287ba4c
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF

View File

@ -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<SendRootPage> {
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<SendRootPage> {
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<SendRootPage> {
_senderName.text = Globals().deviceName;
});
}
void _copyCurl() {
final userAcc = Provider.of<AppAuth>(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');
}
}