mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Finder
This commit is contained in:
195
lib/main-app.js
195
lib/main-app.js
@@ -12,7 +12,6 @@ const GhReleases = require('electron-gh-releases')
|
||||
var mainWindow = null
|
||||
var finderProcess = null
|
||||
var finderWindow = null
|
||||
var update = null
|
||||
|
||||
const appRootPath = path.join(process.execPath, '../..')
|
||||
const updateDotExePath = path.join(appRootPath, 'Update.exe')
|
||||
@@ -58,20 +57,19 @@ var handleStartupEvent = function () {
|
||||
switch (squirrelCommand) {
|
||||
case '--squirrel-install':
|
||||
spawnUpdate(['--createShortcut', exeName], function (err) {
|
||||
quitApp()
|
||||
app.quit()
|
||||
})
|
||||
return true
|
||||
case '--squirrel-updated':
|
||||
quitApp()
|
||||
app.quit()
|
||||
return true
|
||||
case '--squirrel-uninstall':
|
||||
spawnUpdate(['--removeShortcut', exeName], function (err) {
|
||||
quitApp()
|
||||
app.quit()
|
||||
})
|
||||
quitApp()
|
||||
return true
|
||||
case '--squirrel-obsolete':
|
||||
quitApp()
|
||||
app.quit()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -92,24 +90,13 @@ var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory)
|
||||
})
|
||||
|
||||
if (shouldQuit) {
|
||||
quitApp()
|
||||
if (mainWindow != null) mainWindow.removeAllListeners()
|
||||
app.quit()
|
||||
return
|
||||
}
|
||||
|
||||
var appQuit = false
|
||||
|
||||
var version = app.getVersion()
|
||||
var versionText = (version == null || version.length === 0) ? 'DEV version' : 'v' + version
|
||||
var versionNotified = false
|
||||
|
||||
function notify (title, body) {
|
||||
if (mainWindow != null) {
|
||||
mainWindow.webContents.send('notify', {
|
||||
title: title,
|
||||
body: body
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var isUpdateReady = false
|
||||
|
||||
@@ -129,17 +116,15 @@ function checkUpdate () {
|
||||
updater.check((err, status) => {
|
||||
if (err) {
|
||||
var isLatest = err.message === 'There is no newer version.'
|
||||
if (!isLatest && !versionNotified) console.error('Updater error! %s', err.message)
|
||||
if (!isLatest) console.error('Updater error! %s', err.message)
|
||||
}
|
||||
if (!err) {
|
||||
if (status) {
|
||||
notify('Update is available!', 'Download started.. wait for the update ready.')
|
||||
// Download start
|
||||
mainWindow.webContents.send('update-found', 'Update found!')
|
||||
updater.download()
|
||||
} else {
|
||||
if (!versionNotified) {
|
||||
versionNotified = true
|
||||
notify('Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
|
||||
}
|
||||
// Latest version
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -147,167 +132,73 @@ function checkUpdate () {
|
||||
|
||||
updater.on('update-downloaded', (info) => {
|
||||
if (mainWindow != null) {
|
||||
notify('Ready to Update!', 'Click update button on Main window.')
|
||||
mainWindow.webContents.send('update-available', 'Update available!')
|
||||
mainWindow.webContents.send('update-ready', 'Update available!')
|
||||
isUpdateReady = true
|
||||
}
|
||||
})
|
||||
|
||||
// nodeIpc.config.id = 'node'
|
||||
// nodeIpc.config.retry = 1500
|
||||
// nodeIpc.config.silent = true
|
||||
|
||||
// nodeIpc.serve(
|
||||
// path.join(app.getPath('userData'), 'boost.service'),
|
||||
// function () {
|
||||
// nodeIpc.server.on(
|
||||
// 'connect',
|
||||
// function (socket) {
|
||||
// socket.on('close', function () {
|
||||
// console.log('socket dead')
|
||||
// if (!appQuit) spawnFinder()
|
||||
// })
|
||||
// }
|
||||
// )
|
||||
// nodeIpc.server.on(
|
||||
// 'message',
|
||||
// function (data, socket) {
|
||||
// console.log('>>', data)
|
||||
// handleIpcEvent(data)
|
||||
// }
|
||||
// )
|
||||
// nodeIpc.server.on(
|
||||
// 'error',
|
||||
// function (err) {
|
||||
// console.log('>>', err)
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
// )
|
||||
|
||||
function handleIpcEvent (payload) {
|
||||
switch (payload.type) {
|
||||
case 'show-main-window':
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
mainWindow.show()
|
||||
case 'win32':
|
||||
mainWindow.minimize()
|
||||
mainWindow.restore()
|
||||
case 'linux':
|
||||
// Do nothing
|
||||
// due to bug of `app.focus()` some desktop Env
|
||||
}
|
||||
break
|
||||
case 'copy-finder':
|
||||
mainWindow.webContents.send('copy-finder')
|
||||
break
|
||||
case 'quit-app':
|
||||
quitApp()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function spawnFinder() {
|
||||
// if (process.platform === 'darwin') {
|
||||
// var finderArgv = [path.join(__dirname, 'finder-app.js'), '--finder']
|
||||
// if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
|
||||
// finderProcess = ChildProcess
|
||||
// .execFile(process.execPath, finderArgv)
|
||||
// }
|
||||
}
|
||||
|
||||
function quitApp () {
|
||||
appQuit = true
|
||||
if (finderProcess) finderProcess.kill()
|
||||
app.quit()
|
||||
if (process.platform === 'darwin') {
|
||||
var finderArgv = [path.join(__dirname, 'finder-app.js'), '--finder']
|
||||
if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
|
||||
finderProcess = ChildProcess
|
||||
.execFile(process.execPath, finderArgv)
|
||||
}
|
||||
}
|
||||
|
||||
app.on('ready', function () {
|
||||
app.on('before-quit', function () {
|
||||
appQuit = true
|
||||
if (finderProcess) finderProcess.kill()
|
||||
})
|
||||
|
||||
var template = require('./main-menu')
|
||||
if (process.platform === 'win32') {
|
||||
template.unshift({
|
||||
label: 'Boostnote',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Quit',
|
||||
accelerator: 'Control+Q',
|
||||
click: function (e) {
|
||||
quitApp()
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
var menu = Menu.buildFromTemplate(template)
|
||||
if (process.platform === 'darwin' || process.platform === 'linux') {
|
||||
Menu.setApplicationMenu(menu)
|
||||
}
|
||||
|
||||
// Check update every 24 hours
|
||||
setInterval(function () {
|
||||
checkUpdate()
|
||||
}, 1000 * 60 * 60 * 24)
|
||||
|
||||
ipc.on('check-update', function (event, msg) {
|
||||
if (update == null) checkUpdate()
|
||||
checkUpdate()
|
||||
})
|
||||
|
||||
ipc.on('update-app', function (event, msg) {
|
||||
ipc.on('update-app-confirm', function (event, msg) {
|
||||
if (isUpdateReady) {
|
||||
appQuit = true
|
||||
mainWindow.removeAllListeners()
|
||||
updater.install()
|
||||
}
|
||||
})
|
||||
|
||||
ipc.on('quit-app-confirm', function () {
|
||||
mainWindow.removeAllListeners()
|
||||
app.quit()
|
||||
})
|
||||
|
||||
checkUpdate()
|
||||
|
||||
mainWindow = require('./main-window')
|
||||
if (process.platform === 'win32' || process.platform === 'linux') {
|
||||
mainWindow.setMenu(menu)
|
||||
}
|
||||
mainWindow.on('close', function (e) {
|
||||
if (appQuit || process.platform != 'darwin') {
|
||||
app.quit()
|
||||
} else {
|
||||
mainWindow.hide()
|
||||
e.preventDefault()
|
||||
}
|
||||
})
|
||||
// switch (process.platform) {
|
||||
// case 'darwin':
|
||||
// spawnFinder()
|
||||
// break
|
||||
// case 'win32':
|
||||
// finderWindow = require('./finder-window')
|
||||
// finderWindow.on('close', function (e) {
|
||||
// if (appQuit) return true
|
||||
// e.preventDefault()
|
||||
// finderWindow.hide()
|
||||
// })
|
||||
// break
|
||||
// case 'linux':
|
||||
// if (process.env.DESKTOP_SESSION === 'cinnamon') {
|
||||
// finderWindow = require('./finder-window')
|
||||
// finderWindow.on('close', function (e) {
|
||||
// if (appQuit) return true
|
||||
// e.preventDefault()
|
||||
// finderWindow.hide()
|
||||
// })
|
||||
// }
|
||||
// // Do nothing.
|
||||
// }
|
||||
|
||||
// nodeIpc.server.start(function (err) {
|
||||
// if (err.code === 'EADDRINUSE') {
|
||||
// notify('Error occurs!', 'You have to kill other Boostnote processes.')
|
||||
// quitApp()
|
||||
// }
|
||||
// })
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
spawnFinder()
|
||||
break
|
||||
case 'win32':
|
||||
finderWindow = require('./finder-window')
|
||||
finderWindow.on('close', function (e) {
|
||||
e.preventDefault()
|
||||
finderWindow.hide()
|
||||
})
|
||||
break
|
||||
case 'linux':
|
||||
// Finder is available on cinnamon only.
|
||||
if (process.env.DESKTOP_SESSION === 'cinnamon') {
|
||||
finderWindow = require('./finder-window')
|
||||
}
|
||||
}
|
||||
|
||||
require('./hotkey')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user