-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
84 lines (61 loc) · 1.84 KB
/
main.js
File metadata and controls
84 lines (61 loc) · 1.84 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
const { app, BrowserWindow, ipcMain } = require('electron');
process.env.NODE_ENV = 'production'; // Production Flag.
// INITILIZING...
const singleApp = app.requestSingleInstanceLock();
let mainWindow = null;
let argv = process.argv[1];
const createWindow = ()=>{
mainWindow = new BrowserWindow({
width: 400,
height: 600,
webPreferences: {
nodeIntegration: true
}
});
mainWindow.setMenu(null);
mainWindow.loadFile("view/index.html");
//mainWindow.openDevTools(); // Debag Only.
};//CreateWindow.
const saveB64Image = (_, data)=>{
let base64Data = data.replace(/^data:image\/jpeg;base64,/, "");
require("fs").writeFile(argv+".jpg", base64Data, 'base64', function(err) {
if(err==null){
app.quit();
}
});
};//SaveB64Image.
const secendInstent = (event, commandLine, workingDirectory) =>{
argv = commandLine[3];// Command From Secend Instent.
mainWindow.send("GET_IMAGE", argv);
if (mainWindow){
if (mainWindow.isMinimized()){
mainWindow.restore();
mainWindow.focus();
}
}
};//secend iinstent event.
/* Arg Filter. */
if(argv[0]=='"'&&argv[argv.length]=='"')argv=argv.slice(1,argv.length-1);
function main(){
ipcMain.on("GIVE_IMAGE", (event)=>{
event.sender.send("GET_IMAGE", argv);
});//ipcOn GIVE_IMAGE.
ipcMain.on("SAVE", saveB64Image);
/* Exception Handling. */
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
app.quit();
});//On window-all-closed event.
process.on('uncaughtException', function(err) {
app.quit();
});//On uncaughtException handleing;
app.on('second-instance', secendInstent);
// Create Window And Show Application.
app.once('ready', createWindow);
};//main.
if( singleApp ){
main();
}else{
app.quit();
}