From d8e8a6f465694227a2f22b9a3df35b846504561c Mon Sep 17 00:00:00 2001 From: Hoh Shen Yien <55322546+HohShenYien@users.noreply.github.com> Date: Sat, 25 Dec 2021 23:27:12 +0800 Subject: [PATCH] Fixed my async functions and will now display all emails that failed --- design.json | 2 +- mydesign.json | 1 + src/App.vue | 15 +++++++++------ src/background.js | 25 +++++++++++-------------- src/views/Home.vue | 16 ++++++++++------ 5 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 mydesign.json diff --git a/design.json b/design.json index eedc395..c822ad5 100644 --- a/design.json +++ b/design.json @@ -1 +1 @@ -{"counters":{"u_column":2,"u_row":2,"u_content_heading":1,"u_content_image":1,"u_content_text":1},"body":{"rows":[{"cells":[1],"columns":[{"contents":[{"type":"heading","values":{"containerPadding":"10px","headingType":"h1","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"fontSize":"22px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"hideDesktop":false,"_meta":{"htmlID":"u_content_heading_1","htmlClassNames":"u_content_heading"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"Forehead slapping time 🤚"}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_1","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_1","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}},{"cells":[1],"columns":[{"contents":[{"type":"text","values":{"containerPadding":"10px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"_meta":{"htmlID":"u_content_text_1","htmlClassNames":"u_content_text"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"

Your forehead gonna be slapped soon! ^*name*^

"}},{"type":"image","values":{"containerPadding":"10px","src":{"url":"https://unroll-images-production.s3.amazonaws.com/projects/0/1633946756049-46250.jpg","width":1920,"height":1200},"textAlign":"center","altText":"","action":{"name":"web","values":{"href":"","target":"_blank"}},"hideDesktop":false,"_meta":{"htmlID":"u_content_image_1","htmlClassNames":"u_content_image"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}}],"values":{"backgroundColor":"","padding":"0px","border":{},"borderRadius":"0px","_meta":{"htmlID":"u_column_2","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_2","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}}],"values":{"textColor":"#000000","backgroundColor":"#e7e7e7","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"contentWidth":"900px","contentAlign":"center","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"preheaderText":"","linkStyle":{"body":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"_meta":{"htmlID":"u_body","htmlClassNames":"u_body"}}},"schemaVersion":6} \ No newline at end of file +{"counters":{"u_column":3,"u_row":3,"u_content_heading":1,"u_content_image":1,"u_content_text":1},"body":{"rows":[{"cells":[1],"columns":[{"contents":[{"type":"heading","values":{"containerPadding":"10px","headingType":"h1","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"fontSize":"22px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"hideDesktop":false,"_meta":{"htmlID":"u_content_heading_1","htmlClassNames":"u_content_heading"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"Hello brainy girl"}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_1","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_1","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}},{"cells":[1],"columns":[{"contents":[{"type":"text","values":{"containerPadding":"10px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"hideDesktop":false,"_meta":{"htmlID":"u_content_text_1","htmlClassNames":"u_content_text"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"

Hi :D

"}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_2","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_2","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}}],"values":{"textColor":"#000000","backgroundColor":"#e7e7e7","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"contentWidth":"900px","contentAlign":"center","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"preheaderText":"","linkStyle":{"body":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"_meta":{"htmlID":"u_body","htmlClassNames":"u_body"}}},"schemaVersion":6} \ No newline at end of file diff --git a/mydesign.json b/mydesign.json new file mode 100644 index 0000000..b72af05 --- /dev/null +++ b/mydesign.json @@ -0,0 +1 @@ +{"counters":{"u_column":3,"u_row":3,"u_content_heading":1,"u_content_image":1,"u_content_text":1},"body":{"rows":[{"cells":[1],"columns":[{"contents":[{"type":"heading","values":{"containerPadding":"10px","headingType":"h1","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"fontSize":"22px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"hideDesktop":false,"_meta":{"htmlID":"u_content_heading_1","htmlClassNames":"u_content_heading"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"Hello world"}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_1","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_1","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}},{"cells":[1],"columns":[{"contents":[{"type":"image","values":{"containerPadding":"10px","src":{"url":"https://s3.amazonaws.com/unroll-images-production/projects%2F0%2F1634221866389-thailand_malaysia_registering_marriage_bangkok_thailand_mrdefinite.net_kenneth_kusala.webp","width":672,"height":372},"textAlign":"center","altText":"","action":{"name":"web","values":{"href":"","target":"_blank"}},"hideDesktop":false,"_meta":{"htmlID":"u_content_image_1","htmlClassNames":"u_content_image"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_3","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_3","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}},{"cells":[1],"columns":[{"contents":[{"type":"text","values":{"containerPadding":"10px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"_meta":{"htmlID":"u_content_text_1","htmlClassNames":"u_content_text"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"

Hi ^*name*^

"}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_2","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_2","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}}],"values":{"textColor":"#000000","backgroundColor":"#e7e7e7","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"contentWidth":"900px","contentAlign":"center","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"preheaderText":"","linkStyle":{"body":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"_meta":{"htmlID":"u_body","htmlClassNames":"u_body"}}},"schemaVersion":6} \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 1b1a366..ce6d8a3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,10 +5,10 @@
- {{progress * 100}}% + {{progress}}
@@ -67,7 +67,8 @@ export default { html: '', sending: false, progress: 0, - cert: null + cert: null, + cur: 0 }), methods: { goHome() { @@ -95,16 +96,18 @@ export default { console.log(design); this.html = design; }, - changeProgress(p) { + changeProgress(n, t) { this.sending = true; - this.progress = p; + this.progress = n + " / " + t; + this.cur = n / t; }, completed(e) { console.log("Completed2"); this.sending = false; this.progress = 0; + this.cur = 0; if (!e) { - alert("Failed to send some emails, please refer error log to see what is missing"); + alert("Failed to send some emails, please check the new data on table for details"); } } }, diff --git a/src/background.js b/src/background.js index d19c7e5..c3717e4 100644 --- a/src/background.js +++ b/src/background.js @@ -83,8 +83,9 @@ if (isDevelopment) { // events from renderers ipcMain.on('send-email', async (event, arg) => { await sendIt(arg).then(res=> { - event.reply("email-reply", "success"); - }).catch((res,err) => { + event.reply("email-reply", "success"); + }).catch(err => { + console.log(err); event.reply("email-reply", "fails"); }) }) @@ -97,7 +98,6 @@ async function sendIt(val) { pass: val.password, }, }); - const mailOptions = { from: val.email, to: val.to, @@ -105,16 +105,13 @@ async function sendIt(val) { html: val.html, attachments: val.attachments }; - - transporter.sendMail(mailOptions, function (err, info) { - if (err) { - return new Promise(function(resolve, reject) { - reject(); - }); - } else { - return new Promise(resolve => { + return new Promise(function(resolve, reject) { + transporter.sendMail(mailOptions, function (err, info) { + if (err) { + reject(err); + } else { resolve(); - }); - } - }); + } + }); + }) } diff --git a/src/views/Home.vue b/src/views/Home.vue index aeb3c39..8137fde 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -195,7 +195,7 @@ export default { }, methods: { async sendEmail() { - let obj = await this.emailObj(); + let obj = this.emailObj(); ipcRenderer.send('send-email', obj); }, send() { @@ -225,14 +225,18 @@ export default { }, emailListener(evt, message) { if (message == 'fails') { - console.log("FAILED"); + console.log(this.selected[this.currentId]); this.failed.push(this.selected[this.currentId]); } if (++this.currentId < this.selected.length) { - this.$emit('progress', this.currentId / this.selected.length); - this.sendEmail(); + this.$emit('progress', this.currentId, this.selected.length); + setTimeout(() => this.sendEmail(), 500); } else { - this.$emit("completed", this.failed.length == 0); + this.currentId = 0; + console.log(this.failed); + this.$emit("completed", this.failed.length === 0); + this.selected = []; + this.recipients = this.failed; } }, goTo(link) { @@ -285,7 +289,7 @@ export default { } } }, - async emailObj() { + emailObj() { let formatHtml = this.html; for (let header of this.headers) { formatHtml = formatHtml.replace('^*' + header.value + '*^', this.selected[this.currentId][header.value]);