index.js
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { app, BrowserWindow } from "electron";
import "../renderer/store";
import { ipcMain } from "electron";
var path = require("path");
var nodemailer = require("nodemailer");
const compressing = require("compressing");
const { exec } = require("child_process");
/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
*/
if (process.env.NODE_ENV !== "development") {
global.__static = require("path")
.join(__dirname, "/static")
.replace(/\\/g, "\\\\");
}
let mainWindow;
const winURL =
process.env.NODE_ENV === "development"
? `http://localhost:9080`
: `file://${__dirname}/index.html`;
function createWindow() {
/**
* Initial window options
*/
mainWindow = new BrowserWindow({
height: 563,
useContentSize: true,
width: 1000,
});
mainWindow.loadURL(winURL);
mainWindow.on("closed", () => {
mainWindow = null;
});
}
app.on("ready", createWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
ipcMain.on("aaa", (event, data) => {
event.sender.send("bbb", 1);
});
app.on("activate", () => {
if (mainWindow === null) {
createWindow();
}
});
ipcMain.on("send-email", (event, data) => {
var dataInfo = data.emailForm;
var {
title,
pass,
fromPeople,
toPeople,
ccPeople,
fileInfo,
htmlContent,
isFile,
} = dataInfo;
var attachments = [];
if (fileInfo.length > 0 && isFile == 1) {
fileInfo.forEach((fileItem) => {
attachments.push({
filename: fileItem.fileName,
path: fileItem.filePath,
});
});
}
var transporter = nodemailer.createTransport({
service: "IMAP",
secureConnection: true, // 使用 SSL
host: "smtphz.qiye.163.com",
port: 465,
auth: {
user: fromPeople,
pass, //授权码
},
});
var mailOptions = {
from: fromPeople, // 发送者
to: toPeople, // 接受者,可以同时发送多个,以逗号隔开
cc: ccPeople, // 抄送者,可以同时发送多个,以逗号隔开
subject: title, // 标题
//text: '', // 文本
html: htmlContent,
attachments,
};
transporter.sendMail(mailOptions, function (err, info) {
if (err) {
event.sender.send("send-message", {
code: -1,
info: err,
});
return;
}
event.sender.send("send-message", {
code: 0,
info: "ok",
});
});
});
ipcMain.on("send-build", (event, data) => {
var fileInfo = data.fileInfo;
const disk = fileInfo.path.split(":")[0];
const packageParth = fileInfo.path;
let build = exec(`cd /d ${packageParth} && npm run build`, (err) => {
if (err) throw err;
});
build.stdout.pipe(process.stdout);
build.on("exit", () => {
compress();
});
function compress() {
compressing.zip
.compressDir(
path.join(fileInfo.filePath.split(".zip")[0]),
path.join(fileInfo.filePath)
)
.then(() => {
event.sender.send("build-message", {
code: 0,
info: "ok",
});
})
.catch((err) => {
event.sender.send("build-message", {
code: -1,
info: err,
});
});
}
});