-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.development.js
97 lines (77 loc) · 2.16 KB
/
main.development.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
import { app, BrowserWindow, ipcMain as IPC } from 'electron'
import { exec } from 'child_process'
import { compose, join, keys, filter, map, toPairs } from 'ramda'
import Config from 'electron-config'
const config = new Config()
let mainWindow = null
if (process.env.NODE_ENV === 'development') {
require('electron-debug')()
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
const installExtensions = async () => {
if (process.env.NODE_ENV === 'development') {
const installer = require('electron-devtools-installer')
const extensions = [
'REACT_DEVELOPER_TOOLS',
'REDUX_DEVTOOLS'
]
const forceDownload = !!process.env.UPGRADE_EXTENSIONS
for (const name of extensions) {
try {
await installer.default(installer[name], forceDownload)
} catch (e) {}
}
}
}
app.on('ready', async () => {
await installExtensions()
mainWindow = new BrowserWindow({
show: false,
width: 1280,
height: 720
})
mainWindow.loadURL(`file://${__dirname}/app/app.html`)
if (process.env.NODE_ENV === 'development') {
mainWindow.maximize()
} else {
mainWindow.setFullScreen(true)
}
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.show()
// mainWindow.focus()
})
mainWindow.on('closed', () => {
mainWindow = null
})
if (process.env.NODE_ENV === 'development') {
mainWindow.openDevTools()
}
})
// TODO: move function below to some utils file
const flags = compose(
join(' '),
keys,
filter(value => value === true),
)
const flagsWithParam = compose(
join(' '),
map(join(' ')),
toPairs,
filter(value => (typeof value === 'number' || typeof value === 'string')),
)
const build = args => join(' ', map(fn => fn(args), [flags, flagsWithParam]))
IPC.on('play', (event, movie) => {
const { location } = movie
const base = 'mpv --no-border --ontop --fullscreen'
const args = {
'--save-position-on-quit': config.get('savePositionOnQuit')
}
const command = join(' ', [base, build(args), `"${location}"`])
exec(command, (err, stdout, stderr) => {
console.log(err)
console.log(stdout)
console.log(stderr)
})
})