-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathipc.js
48 lines (43 loc) · 1.32 KB
/
ipc.js
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
const fs = require('fs');
const Zip = require('node-zip');
const electron = require('electron');
const ipcMain = electron.ipcMain;
const dialog = electron.dialog;
ipcMain.on('export', function (event, yamlContent) {
const dialogOpts = {
filters: [
{name: 'Docker-Compose-File', extensions: ['yml', 'yaml']}
]
};
const file = dialog.showSaveDialog(dialogOpts);
if (file) {
fs.writeFileSync(file, yamlContent, 'utf8');
}
});
ipcMain.on('export.docker-service', function (event, data) {
const dialogOpts = {
filters: [
{name: 'Bash-Script', extensions: ['sh']}
]
};
const file = dialog.showSaveDialog(dialogOpts);
if (file) {
fs.writeFileSync(file, data, 'utf8');
}
});
ipcMain.on('save', function (event, data) {
const dialogOpts = {
filters: [
{name: 'DCE-Project', extensions: ['dce']}
]
};
if (!electron.app.currentProjectFile) {
electron.app.currentProjectFile = dialog.showSaveDialog(dialogOpts);
}
if (electron.app.currentProjectFile) {
const zip = new Zip();
zip.file('data.json', data);
const zippedData = zip.generate({base64: false, compression: 'DEFLATE'});
fs.writeFileSync(electron.app.currentProjectFile, zippedData, 'binary');
}
});