From b91b0139e398be381a20501d59aa3688209edc37 Mon Sep 17 00:00:00 2001 From: Sriyansh Shivam <96797205+SoNiC-HeRE@users.noreply.github.com> Date: Sat, 17 Jun 2023 22:49:44 +0530 Subject: [PATCH] library: Add Email Entry (#330) --- src/Library/demos/Email/main.blp | 30 +++++++++++++++++++++++++ src/Library/demos/Email/main.js | 37 +++++++++++++++++++++++++++++++ src/Library/demos/Email/main.json | 7 ++++++ 3 files changed, 74 insertions(+) create mode 100644 src/Library/demos/Email/main.blp create mode 100644 src/Library/demos/Email/main.js create mode 100644 src/Library/demos/Email/main.json diff --git a/src/Library/demos/Email/main.blp b/src/Library/demos/Email/main.blp new file mode 100644 index 000000000..c70c9727a --- /dev/null +++ b/src/Library/demos/Email/main.blp @@ -0,0 +1,30 @@ +using Gtk 4.0; +using Adw 1; + +Adw.StatusPage { + title: _("Email"); + description: _("Trigger an email"); + margin-top: 48; + + Box { + orientation: vertical; + halign: center; + + Entry entry { + placeholder-text: _("Enter your email address"); + margin-bottom: 18; + } + + Button button { + label: _("Send Email"); + margin-bottom: 42; + halign: center; + styles ["suggested-action", "pill"] + } + + LinkButton { + label: "API Reference"; + uri: "https://libportal.org/method.Portal.compose_email.html"; + } + } +} diff --git a/src/Library/demos/Email/main.js b/src/Library/demos/Email/main.js new file mode 100644 index 000000000..55822b5b9 --- /dev/null +++ b/src/Library/demos/Email/main.js @@ -0,0 +1,37 @@ +import Xdp from "gi://Xdp"; +import XdpGtk from "gi://XdpGtk4"; +import Gio from "gi://Gio"; + +Gio._promisify(Xdp.Portal.prototype, "compose_email", "compose_email_finish"); + +const portal = new Xdp.Portal(); +const parent = XdpGtk.parent_new_gtk(workbench.window); + +const button = workbench.builder.get_object("button"); +const entry = workbench.builder.get_object("entry"); + +async function onClicked() { + const email_address = entry.get_text(); + + const success = await portal.compose_email( + parent, + [email_address], // addresses + null, // cc + null, // bcc + "Email from Workbench", // subject + "Hello World!", // body + null, // attachments + Xdp.EmailFlags.NONE, // flags + null, // cancellable + ); + + if (success) { + console.log("Success"); + } else { + console.log("Failure, verify that you have an email application."); + } +} + +button.connect("clicked", () => { + onClicked().catch(logError); +}); diff --git a/src/Library/demos/Email/main.json b/src/Library/demos/Email/main.json new file mode 100644 index 000000000..7d26cf566 --- /dev/null +++ b/src/Library/demos/Email/main.json @@ -0,0 +1,7 @@ +{ + "name": "Email", + "category": "platform", + "description": "Trigger an email", + "panels": ["code", "preview"], + "autorun": true +}