1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00
Files
Boostnote/lib/main-window.js
wAuner 5ee4237510 fix incorrect app closing for linux mint cinnamon
excluded the cinnamon desktop for the macOS-like behavior which closes the window, but does not shutdown the app processes
2018-03-24 14:48:34 +01:00

78 lines
1.8 KiB
JavaScript

const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const path = require('path')
const Config = require('electron-config')
const config = new Config()
const _ = require('lodash')
var showMenu = process.platform !== 'win32'
const windowSize = config.get('windowsize') || { width: 1080, height: 720 }
const mainWindow = new BrowserWindow({
width: windowSize.width,
height: windowSize.height,
minWidth: 500,
minHeight: 320,
autoHideMenuBar: showMenu,
webPreferences: {
zoomFactor: 1.0,
blinkFeatures: 'OverlayScrollbars'
},
icon: path.resolve(__dirname, '../resources/app.png')
})
const url = path.resolve(__dirname, './main.html')
mainWindow.loadURL('file://' + url)
mainWindow.webContents.on('new-window', function (e) {
e.preventDefault()
})
mainWindow.webContents.sendInputEvent({
type: 'keyDown',
keyCode: '\u0008'
})
mainWindow.webContents.sendInputEvent({
type: 'keyUp',
keyCode: '\u0008'
})
if (process.platform === 'darwin') {
mainWindow.on('close', function (e) {
e.preventDefault()
if (mainWindow.isFullScreen()) {
mainWindow.once('leave-full-screen', function () {
mainWindow.hide()
})
mainWindow.setFullScreen(false)
} else {
mainWindow.hide()
}
})
app.on('before-quit', function (e) {
mainWindow.removeAllListeners()
})
}
mainWindow.on('resize', _.throttle(storeWindowSize, 500))
function storeWindowSize () {
try {
config.set('windowsize', mainWindow.getBounds())
} catch (e) {
// ignore any errors because an error occurs only on update
// refs: https://github.com/BoostIO/Boostnote/issues/243
}
}
app.on('activate', function () {
if (mainWindow == null) return null
mainWindow.show()
})
module.exports = mainWindow