-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
148 lines (117 loc) · 3.79 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
var { app, BrowserWindow, ipcMain, ipcRenderer } = require("electron");
var java = require('java');
var path = require("path");
var url = require("url");
var fs = require("fs");
var os = require('os');
var javaInit = require('./javaInit')
var childProcess = require('child_process');
// let mainWindow = BrowserWindow = undefined;
// let workerWindow = BrowserWindow = undefined;
let win;
function createWindow() {
win = new BrowserWindow({ width: 1000, height: 800 });
win.webContents.getPrinters();
console.log('printer', win.webContents.getPrinters());
//to remove menu
win.setMenu(null);
// load the dist folder from Angular
win.loadURL(
url.format({
pathname: path.join(__dirname, `/dist/index.html`),
protocol: "file:",
slashes: true,
})
);
win.on("closed", () => {
win = null;
});
//added this line to open developer tools for debugging
//win.webContents.openDevTools();
// The following is optional and will open the DevTools:
win.webContents.openDevTools()
// workerWindow = new BrowserWindow({ width: 1000, height: 800 });
// workerWindow.loadURL("file://" + __dirname + "/worker.html");
// // workerWindow.hide();
// workerWindow.webContents.openDevTools();
// workerWindow.on("closed", () => {
// workerWindow = undefined;
// });
}
//camera access code
app.on("ready", createWindow);
// on macOS, closing the window doesn't quit the app
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
// initialize the app's main window
app.on("activate", () => {
if (win === null) {
createWindow();
}
});
/*
* Read SmartCard Functionality Start Here
*/
ipcMain.on('readSmartcard', (event, arg) => {
var javaInstancePath = "com.genfare.applet.encoder.EncoderApplet"
var cardName = "ACS ACR1252 1S CL Reader PICC 0"
var cardConfig = {
"agency_id": 194,
"end_of_transit_day_desfire": null,
"priorities_and_configuration_type": 1,
"printed_id_file_version": 2,
"card_properties_file_version": 0,
"transfer_file_version": 1,
"product_list_file_version": 0,
"product_file_version": 3,
"journal_file_version": 1,
"equipment_id": 0,
"first_product_must_be_stored_value": true,
"number_of_products": 4,
"number_of_transfers": 1,
"number_of_bonus_passes": 1,
"number_of_pay_as_you_go_passes": 1,
"max_stored_value": 20000,
"max_pending_passes": 3,
"agency_timezone_offset": -21600000,
"accountFlag": false
}
var EncoderApplet = java.import(javaInstancePath);
var EncoderInstance = new EncoderApplet()
console.log("before java call Data", EncoderInstance)
var result = EncoderInstance.setEncoderSync(cardName, JSON.stringify(cardConfig), "49 A8 B4 8B 3F 45 9F BC 3A 31 9B 53 90 EB 68 08",
"79 AA EF 33 FB EF C1 2C E3 13 04 9F 91 16 B4 86", "90 CF 88 CB E0 8E D1 7C F3 37 C2 93 2B E9 CF E2");
console.log("setEncoder Data", '' +result)
try {
var smartread = EncoderInstance.readCardSync();
} catch (error) {
console.log(error);
}
event.sender.send('updateResult', smartread);
})
/*
* Read SmartCard Functionality End Here
*/
// // retransmit it to workerWindow
// ipcMain.on("printPDF", (event, content) => {
// console.log(content);
// workerWindow.webContents.send("printPDF", content);
// });
// // when worker window is ready
// ipcMain.on("readyToPrintPDF", (event) => {
// const pdfPath = path.join(os.tmpdir(), 'print.pdf');
// // Use default printing options
// workerWindow.webContents.print({}, function (error, data) {
// if (error) throw error
// fs.writeFile(pdfPath, data, function (error) {
// if (error) {
// throw error
// }
// shell.openItem(pdfPath)
// event.sender.send('wrote-pdf', pdfPath)
// })
// })
// })