This repository has been archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (63 loc) · 1.51 KB
/
index.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
const electron = require('electron');
const {app, BrowserWindow, Menu, ipcMain} = electron
const url = require('url');
const path = require('path');
var Tesseract = require('tesseract.js');
var fs = require('fs');
/*
* OCR Scanner with GUI using the tesseract package.
*
* @author CuzImPeter
* @github peter12908
* @date 15.10.2020
*/
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 750,
height: 650
})
// Load the index.html file
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
mainWindow.setMenu(null)
mainWindow.on('closed', () => {
mainWindow = null
})
}
ipcMain.on('convert', function(e, image){
e.sender.send('get_result', "Loading...\nPlease be Patient")
Tesseract.recognize(
image,
'eng',
'stdout'
).then(({ data: { text } }) => {
e.sender.send('get_result', text)
})
});
// Create the window then the app is ready
app.on('ready', () => {
createWindow()
electron.powerMonitor.on('on-ac', () => {
mainWindow.restore()
})
electron.powerMonitor.on('on-battery', () => {
mainWindow.minimize()
})
})
// Quit when all windows are closed
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
// Reopen the app on macOS
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})