Files
pointvec/desktop/main.js

82 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-11-03 20:44:31 -05:00
'use strict'
/* global createWindow */
const { app, BrowserWindow, Menu } = require('electron')
2017-11-05 14:52:05 +14:00
const path = require('path')
2019-01-09 16:53:28 +12:00
let isShown = true
2017-11-05 14:52:05 +14:00
2019-02-07 16:06:55 +12:00
app.win = null
2018-10-04 11:27:40 +12:00
app.on('ready', () => {
2018-09-14 09:38:14 +12:00
app.win = new BrowserWindow({
2019-11-03 20:49:08 -05:00
width: 780,
height: 462,
minWidth: 380,
minHeight: 360,
2019-02-17 07:51:09 +09:00
backgroundColor: '#000',
2019-05-26 19:59:27 +09:00
icon: path.join(__dirname, { darwin: 'icon.icns', linux: 'icon.png', win32: 'icon.ico' }[process.platform] || 'icon.ico'),
2019-02-07 16:06:55 +12:00
resizable: true,
2019-02-21 15:13:29 +09:00
frame: process.platform !== 'darwin',
skipTaskbar: process.platform === 'darwin',
2019-05-26 19:59:27 +09:00
autoHideMenuBar: process.platform === 'darwin',
webPreferences: { zoomFactor: 1.0, nodeIntegration: true, backgroundThrottling: false }
2018-09-14 09:38:14 +12:00
})
2018-10-04 11:27:40 +12:00
app.win.loadURL(`file://${__dirname}/sources/index.html`)
2019-11-03 20:49:08 -05:00
// app.inspect()
2018-10-04 11:27:40 +12:00
2018-01-13 16:03:21 +13:00
app.win.on('closed', () => {
2017-11-05 14:52:05 +14:00
app.quit()
})
2018-10-04 11:27:40 +12:00
app.win.on('hide', function () {
2019-01-09 16:53:28 +12:00
isShown = false
2017-11-05 14:52:05 +14:00
})
2018-10-04 11:27:40 +12:00
app.win.on('show', function () {
2019-01-09 16:53:28 +12:00
isShown = true
2017-11-05 14:52:05 +14:00
})
2018-09-14 09:38:14 +12:00
2018-10-04 11:27:40 +12:00
app.on('window-all-closed', () => {
2018-09-14 09:38:14 +12:00
app.quit()
})
app.on('activate', () => {
if (app.win === null) {
createWindow()
2018-10-04 11:27:40 +12:00
} else {
app.win.show()
2018-09-14 09:38:14 +12:00
}
})
2017-11-05 14:52:05 +14:00
})
2018-10-04 11:27:40 +12:00
app.inspect = function () {
app.win.toggleDevTools()
2018-09-14 09:38:14 +12:00
}
2017-11-05 14:52:05 +14:00
2019-01-10 09:00:52 +12:00
app.toggleFullscreen = function () {
2018-10-04 11:27:40 +12:00
app.win.setFullScreen(!app.win.isFullScreen())
2018-09-14 09:38:14 +12:00
}
2019-11-06 20:32:09 -05:00
app.toggleMenubar = function () {
app.win.setMenuBarVisibility(!app.win.isMenuBarVisible())
}
2019-01-10 09:00:52 +12:00
app.toggleVisible = function () {
if (process.platform !== 'darwin') {
2018-10-04 11:27:40 +12:00
if (!app.win.isMinimized()) { app.win.minimize() } else { app.win.restore() }
} else {
2019-01-09 16:53:28 +12:00
if (isShown && !app.win.isFullScreen()) { app.win.hide() } else { app.win.show() }
2018-09-14 15:34:07 +12:00
}
2018-09-14 09:38:14 +12:00
}
2019-02-07 16:06:55 +12:00
app.injectMenu = function (menu) {
2018-10-04 11:27:40 +12:00
try {
Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
} catch (err) {
console.warn('Cannot inject menu.')
2018-09-14 15:34:07 +12:00
}
2018-10-04 11:27:40 +12:00
}