Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library: Add Email Entry #330

Merged
merged 14 commits into from
Jun 17, 2023
30 changes: 30 additions & 0 deletions src/Library/demos/Email/main.blp
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
37 changes: 37 additions & 0 deletions src/Library/demos/Email/main.js
Original file line number Diff line number Diff line change
@@ -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);
});
7 changes: 7 additions & 0 deletions src/Library/demos/Email/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Email",
"category": "platform",
"description": "Trigger an email",
"panels": ["code", "preview"],
"autorun": true
}