-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
122 lines (89 loc) · 2.67 KB
/
app.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
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
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const ipc = electron.ipcMain;
const dialog = electron.dialog;
const merge = require('easy-pdf-merge');
app.on('ready',function(){
var mainWindow = new BrowserWindow({
width : 800,
height : 600
});
mainWindow.loadURL('file://' + __dirname + '/index.html');
//mainWindow.openDevTools();
});
ipc.on('src-files-dialog',function(event){
var window = BrowserWindow.fromWebContents(event.sender);
var srcFileChooseOptions = {
title : 'Choose the PDFs to merge',
buttonLabel : 'OK',
filters : [
{
name : 'PDFs',
extensions : ['pdf']
}
],
properties : [
'multiSelections',
'openFile'
]
};
dialog.showOpenDialog(window,srcFileChooseOptions,function(files){
if(files)
event.sender.send('src-files-selected',files);
});
});
ipc.on('dest-file-dialog',function(event){
var window = BrowserWindow.fromWebContents(event.sender);
var destFileChooseOptions = {
title : 'Choose a destination for the merged PDF',
buttonLabel : 'OK',
filters : [
{
name : 'PDF',
extensions : ['pdf']
}
],
};
dialog.showSaveDialog(window,destFileChooseOptions,function(file){
if(file)
event.sender.send('dest-file-selected',file);
});
});
ipc.on('merge',function(event,srcFiles,destFile){
var window = BrowserWindow.fromWebContents(event.sender);
merge(srcFiles,destFile,function(err){
var statusMessage = "";
var statusTitle = "";
if(err) {
console.log(err);
statusTitle = "Error!";
statusMessage = "Some error occured while merging";
}
else{
statusTitle = "Success!";
statusMessage = "Successfully merged";
}
var infoOptions = {
type : 'info',
title : statusTitle,
message : statusMessage,
buttons : ['OK']
};
dialog.showMessageBox(window,infoOptions);
if(err)
event.sender.send('merged-files',false);
else
event.sender.send('merged-files',true);
});
});
ipc.on('show-message',function(event,messageBody){
var window = BrowserWindow.fromWebContents(event.sender);
var infoOptions = {
type : 'info',
title : 'Information',
message : messageBody,
buttons : ['OK']
};
dialog.showMessageBox(window,infoOptions);
});