Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Jun 17, 2023
1 parent c993274 commit 27fad69
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/Library/demos/Email/main.blp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ Adw.StatusPage {
halign: center;

Entry entry {
overwrite-mode: true;
placeholder-text: _("Enter the email address");
has-frame: true;
placeholder-text: _("Enter your email address");
margin-bottom: 18;
}

Expand Down
46 changes: 18 additions & 28 deletions src/Library/demos/Email/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,33 @@ 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");

Gio._promisify(Xdp.Portal.prototype, "compose_email", "compose_email_finish");

//E-Mail Validator
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}

async function onClicked() {
const email = entry.get_text();
if (isValidEmail(email)) {
const success = await portal.compose_email(
parent,
[email], //address
null, //cc
null, //bcc
"Email from Workbench", //subject
"Hello World!", //message
null, //attachments
Xdp.EmailFlags.NONE,
null,
);
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 a email application.");
}
if (success) {
console.log("Success");
} else {
console.log("Invalid email address");
return;
console.log("Failure, verify that you have an email application.");
}
}

Expand Down

0 comments on commit 27fad69

Please sign in to comment.