-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
195 lines (168 loc) · 5.28 KB
/
main.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
console.log("Process is running");
const electron = require("electron");
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const path = require("path");
const url = require("url");
const ipcMain = electron.ipcMain;
const dialog =electron.dialog;
const Menu = electron.Menu;
const MenuItem = electron.MenuItem
const globalShortcut = electron.globalShortcut;
var pyshell = require('python-shell');
let winone,wintwo,choosingWindow;
const PDFWindow = require('electron-pdf-window');
function createWindow(){
winone = new BrowserWindow({width: 900,height: 1024,x:0,y:0,frame:true});
choosingWindow = new BrowserWindow({width: 600,height: 600,x:750,y:200});
//wintwo = new BrowserWindow({width: 900,height: 1024,x:0,y:0});
//we can add modal window, parent-child window depending on the need
winone.on('closed', () =>{
winone = null;
})
choosingWindow.loadURL(url.format(
{
pathname: path.join(__dirname,'index.html'),
protocol: 'file',
slashes:true
}));
winone.loadURL(url.format(
{
pathname: path.join(__dirname,'temp.html'),
protocol: 'file',
slashes:true
}));
/* pdfwin.loadURL(url.format(
{
pathname: path.join(__dirname,'index.html'),
protocol: 'file',
slashes:true
}));
*/
/*wintwo.on('closed', () =>{
wintwo = null;
})*/
}
ipcMain.on('openFile', (event, path) => {
const fs = require('fs')
dialog.showOpenDialog({
properties: ['openFile'], // set to use openFileDialog
}, (fileNames) =>{
// fileNames is an array that contains all the selected
if(fileNames === undefined) {
console.log("No file selected");
} else {
msg = fileNames;
var subpy = require("child_process").spawn("python", [ "./try.py msg" ])
var rp = require( "request-promise" );
readFile(fileNames[0]);
openPDf();
}
});
function readFile(filepath) {
fs.readFile(filepath, 'utf-8', (err, data) => {
if(err){
alert("An error ocurred reading the file :" + err.message)
return
}
// handle the file content
event.sender.send('fileData', data,msg)
})
}
})
app.on('ready', function(){
createWindow()
const template = [
{
label: 'demo',
submenu: [
{
label: 'submenu1',
click: function(){
console.log("CLicked submenu 1")
}
},
{
type: 'separator'
},
{
label: 'submenu2'
}
]
},
{
label:'Help',
submenu: [{
label: 'About electron',
click:function(){
electron.shell.openExternal('https://www.google.com/')
},
accelerator: 'CmdOrCtrl + Shift + H'
}
]
},
{
label : 'Edit',
submenu: [
{ role: 'undo'},
{ role: 'redo'},
{ role: 'separator'},
{ role: 'cut'},
{ role: 'copy'},
{ role: 'paste'},
{ role: 'selectall'},
]
}
]
// const menu = Menu.buildFromTemplate(template)
//Menu.setApplicationMenu(menu)
const ctxMenu = new Menu();
ctxMenu.append(new MenuItem({
label : 'Hello',
click : function(){
console.log("Context menu clicked")
}
}))
ctxMenu.append(new MenuItem({ role: 'selectall'}))
winone.webContents.on('context-menu',function(e,params){
ctxMenu.popup(winone,params.x,params.y)
})
globalShortcut.register('Alt + 1',function(){
winone.show()
})
})
ipcMain.on('senddata',function(e,item){
console.log("send data successful")
winone.webContents.send('senddata',item);
choosingWindow.close();
});
ipcMain.on('senditem',function(e,item){
console.log(item)
wintwo.webContents.send('senditem',item);
});
function openPDf(){
wintwo = new BrowserWindow({width: 900,height: 1024,x:900,y:0});
console.log(msg)
var msg_new = msg.toString();
//console.log(path.format(msg));
wintwo.loadURL(url.format(
{
pathname: path.join(__dirname,'result.html'),
protocol: 'file',
}));
//console.log(data);
// choosingWindow.close();
}
app.on('window-all-closed', () =>{
if(process.platform !== "darwin"){
app.quit();
}
});
app.on('will-quit',function(){
globalShortcut.unregiserAll()
})
app.on('activate', () =>{
if(win=== null){
createWindow();
}
});