1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-15 10:46:32 +00:00

fixed opening finder on Windows and Linux

fixes #1291 - tested on Ubuntu Linux Mate and Windows 10
This commit is contained in:
Maurits Lourens
2017-12-15 12:57:18 +01:00
parent 820a2a093c
commit 775200bdd6

View File

@@ -1,126 +1,125 @@
const electron = require('electron') const electron = require('electron')
const app = electron.app const app = electron.app
const Menu = electron.Menu const Menu = electron.Menu
const ipc = electron.ipcMain const ipc = electron.ipcMain
const path = require('path') const path = require('path')
const ChildProcess = require('child_process') const ChildProcess = require('child_process')
const _ = require('lodash') const _ = require('lodash')
const GhReleases = require('electron-gh-releases') const GhReleases = require('electron-gh-releases')
// electron.crashReporter.start() // electron.crashReporter.start()
var ipcServer = null var ipcServer = null
var mainWindow = null var mainWindow = null
var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) { var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
if (mainWindow) { if (mainWindow) {
if (process.platform === 'win32') { if (process.platform === 'win32') {
mainWindow.minimize() mainWindow.minimize()
mainWindow.restore() mainWindow.restore()
} }
mainWindow.focus() mainWindow.focus()
} }
return true return true
}) })
if (shouldQuit) { if (shouldQuit) {
app.quit() app.quit()
} }
var isUpdateReady = false var isUpdateReady = false
var ghReleasesOpts = { var ghReleasesOpts = {
repo: 'BoostIO/boost-releases', repo: 'BoostIO/boost-releases',
currentVersion: app.getVersion() currentVersion: app.getVersion()
} }
const updater = new GhReleases(ghReleasesOpts) const updater = new GhReleases(ghReleasesOpts)
// Check for updates // Check for updates
// `status` returns true if there is a new update available // `status` returns true if there is a new update available
function checkUpdate () { function checkUpdate () {
if (process.platform === 'linux' || isUpdateReady) { if (process.platform === 'linux' || isUpdateReady) {
return true return true
} }
updater.check((err, status) => { updater.check((err, status) => {
if (err) { if (err) {
var isLatest = err.message === 'There is no newer version.' var isLatest = err.message === 'There is no newer version.'
if (!isLatest) console.error('Updater error! %s', err.message) if (!isLatest) console.error('Updater error! %s', err.message)
return return
} }
if (status) { if (status) {
mainWindow.webContents.send('update-found', 'Update available!') mainWindow.webContents.send('update-found', 'Update available!')
updater.download() updater.download()
} }
}) })
} }
updater.on('update-downloaded', (info) => { updater.on('update-downloaded', (info) => {
if (mainWindow != null) { if (mainWindow != null) {
mainWindow.webContents.send('update-ready', 'Update available!') mainWindow.webContents.send('update-ready', 'Update available!')
isUpdateReady = true isUpdateReady = true
} }
}) })
updater.autoUpdater.on('error', (err) => { updater.autoUpdater.on('error', (err) => {
console.log(err) console.log(err)
}) })
ipc.on('update-check', function (event, msg) { ipc.on('update-check', function (event, msg) {
if (isUpdateReady) { if (isUpdateReady) {
mainWindow.webContents.send('update-ready', 'Update available!') mainWindow.webContents.send('update-ready', 'Update available!')
} else { } else {
checkUpdate() checkUpdate()
} }
}) })
ipc.on('update-app-confirm', function (event, msg) { ipc.on('update-app-confirm', function (event, msg) {
if (isUpdateReady) { if (isUpdateReady) {
mainWindow.removeAllListeners() mainWindow.removeAllListeners()
updater.install() updater.install()
} }
}) })
function spawnFinder () { function spawnFinder () {
var finderArgv = [path.join(__dirname, 'finder-app.js'), '--finder'] var finderArgv = [path.join(__dirname, 'finder-app.js'), '--finder']
if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot') if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
var finderProcess = ChildProcess var finderProcess = ChildProcess
.execFile(process.execPath, finderArgv) .execFile(process.execPath, finderArgv)
app.on('before-quit', function () { app.on('before-quit', function () {
finderProcess.kill() finderProcess.kill()
}) })
} }
app.on('ready', function () { app.on('ready', function () {
mainWindow = require('./main-window') mainWindow = require('./main-window')
var template = require('./main-menu') var template = require('./main-menu')
var menu = Menu.buildFromTemplate(template) var menu = Menu.buildFromTemplate(template)
switch (process.platform) { switch (process.platform) {
case 'darwin': case 'darwin':
spawnFinder() spawnFinder()
Menu.setApplicationMenu(menu) Menu.setApplicationMenu(menu)
break break
case 'win32': case 'win32':
/* eslint-disable */ require('./finder-window')
finderWindow = require('./finder-window') mainWindow.setMenu(menu)
/* eslint-disable */ break
mainWindow.setMenu(menu) case 'linux':
break require('./finder-window')
case 'linux': Menu.setApplicationMenu(menu)
Menu.setApplicationMenu(menu) mainWindow.setMenu(menu)
mainWindow.setMenu(menu) }
}
// Check update every hour
// Check update every hour setInterval(function () {
setInterval(function () { checkUpdate()
checkUpdate() }, 1000 * 60 * 60)
}, 1000 * 60 * 60)
checkUpdate()
checkUpdate() ipcServer = require('./ipcServer')
ipcServer = require('./ipcServer') ipcServer.server.start()
ipcServer.server.start() })
})
module.exports = app
module.exports = app