/
main.js
79 lines (64 loc) · 1.94 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
const { app, BrowserWindow, webContents, shell, autoUpdater, ipcMain } = require('electron')
const path = require('path')
const url = require('url')
const cld = require('cld')
const tldExtract = require('tld-extract')
const registerIpc = require('electron-ipc-tunnel/server').default
const rtlDetect = require('rtl-detect')
let win
function createWindow() {
win = new BrowserWindow({
width: 800,
height: 600,
minWidth: 800,
minHeight: 600,
frame: false
})
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist', 'index.html'),
protocol: 'file:',
slashes: true
}))
win.webContents.openDevTools()
win.webContents.on('will-navigate', (event, url) => {
const focused = webContents.getFocusedWebContents()
if (!focused || url === focused.getURL()) return
event.preventDefault()
shell.openExternal(url)
})
win.on('closed', () => { win = null })
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') { app.quit() }
})
app.on('activate', () => {
if (win === null) { createWindow() }
})
// Language Detection
registerIpc('is-rtl', async (reply, [content, url]) => {
return await new Promise((resolve, reject) => {
cld.detect(content, {
isHTML: true,
tldHint: tldExtract(url).tld
}, (err, result) => {
resolve(rtlDetect.isRtlLang(result.languages[0].code))
})
})
})
// Autoupdate
autoUpdater.setFeedURL(`http://alduin-update:3000/update/${process.platform}/${app.getVersion()}}`)
registerIpc('update-waiter', async reply => {
return await new Promise(resolve => {
autoUpdater.on('update-downloaded', async event => {
console.log('resolve lel')
resolve()
})
setInterval(() => {
autoUpdater.checkForUpdates()
}, 1000)
})
})
registerIpc('update-start', async reply => {
autoUpdater.quitAndInstall()
})