1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

IPC setup for windows & remove old updater code

This commit is contained in:
Rokt33r
2015-12-21 20:15:43 +09:00
parent 8e64abc4bc
commit 7eb767a268
3 changed files with 99 additions and 104 deletions

View File

@@ -8,6 +8,7 @@ const Tray = electron.Tray
const path = require('path') const path = require('path')
const nodeIpc = require('@rokt33r/node-ipc') const nodeIpc = require('@rokt33r/node-ipc')
var appQuit = false
var isFinderLoaded = false var isFinderLoaded = false
nodeIpc.config.id = 'finder' nodeIpc.config.id = 'finder'
@@ -18,35 +19,37 @@ nodeIpc.connectTo(
'main', 'main',
path.join(app.getPath('userData'), 'boost.service'), path.join(app.getPath('userData'), 'boost.service'),
function () { function () {
nodeIpc.of.main.on( nodeIpc.of.main.on(
'error', 'error',
function (err) { function (err) {
nodeIpc.log('<< ## err ##'.rainbow, nodeIpc.config.delay) nodeIpc.log('<< ## err ##'.rainbow, nodeIpc.config.delay)
nodeIpc.log(err) nodeIpc.log(err)
}
)
nodeIpc.of.main.on(
'connect',
function () {
nodeIpc.log('<< ## connected to world ##'.rainbow, nodeIpc.config.delay)
}
)
nodeIpc.of.main.on(
'disconnect',
function () {
nodeIpc.log('<< disconnected from main'.notice)
appQuit = true
app.quit()
}
)
nodeIpc.of.main.on(
'message',
function (payload) {
switch (payload.type) {
case 'open-finder':
if (isFinderLoaded) openFinder()
break
} }
) }
nodeIpc.of.main.on( )
'connect',
function () {
nodeIpc.log('<< ## connected to world ##'.rainbow, nodeIpc.config.delay)
}
)
nodeIpc.of.main.on(
'disconnect',
function(){
nodeIpc.log('<< disconnected from main'.notice)
}
)
nodeIpc.of.main.on(
'message',
function (payload) {
switch (payload.type) {
case 'open-finder':
if (isFinderLoaded) openFinder()
break
}
}
)
} }
) )
@@ -91,6 +94,12 @@ finderWindow.on('blur', function () {
hideFinder() hideFinder()
}) })
finderWindow.on('close', function (e) {
if (appQuit) return true
e.preventDefault()
finderWindow.hide()
})
finderWindow.webContents.on('did-finish-load', function () { finderWindow.webContents.on('did-finish-load', function () {
var appIcon = new Tray(path.join(__dirname, '../resources/tray-icon.png')) var appIcon = new Tray(path.join(__dirname, '../resources/tray-icon.png'))
appIcon.setToolTip('Boost') appIcon.setToolTip('Boost')
@@ -112,7 +121,8 @@ finderWindow.webContents.on('did-finish-load', function () {
label: 'Quit', label: 'Quit',
click: function () { click: function () {
emit('quit-app') emit('quit-app')
} })) }
}))
appIcon.setContextMenu(trayMenu) appIcon.setContextMenu(trayMenu)
appIcon.on('click', function (e) { appIcon.on('click', function (e) {

View File

@@ -4,7 +4,6 @@ const Menu = electron.Menu
var finderWindow = null var finderWindow = null
var appQuit = false
app.on('ready', function () { app.on('ready', function () {
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
app.dock.hide() app.dock.hide()
@@ -15,10 +14,4 @@ app.on('ready', function () {
Menu.setApplicationMenu(menu) Menu.setApplicationMenu(menu)
finderWindow = require('./atom-lib/finder-window') finderWindow = require('./atom-lib/finder-window')
finderWindow.on('close', function (e) {
if (appQuit) return true
e.preventDefault()
finderWindow.hide()
})
}) })

128
main.js
View File

@@ -94,7 +94,7 @@ var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory)
}) })
if (shouldQuit) { if (shouldQuit) {
app.quit() quitApp()
return return
} }
@@ -114,82 +114,71 @@ function notify (title, body) {
} }
var isUpdateReady = false var isUpdateReady = false
if (process.platform === 'darwin') { var GhReleases = require('electron-gh-releases')
autoUpdater.setFeedURL('https://orbital.b00st.io/rokt33r/boost-app/latest?version=' + version)
autoUpdater
.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
update = quitAndUpdate
if (mainWindow != null) { var ghReleasesOpts = {
notify('Ready to Update! ' + releaseName, 'Click update button on Main window.') repo: 'BoostIO/boost-releases',
mainWindow.webContents.send('update-available', 'Update available!') currentVersion: app.getVersion()
} }
})
.on('error', function (err, message) { const updater = new GhReleases(ghReleasesOpts)
console.error('error')
// Check for updates
// `status` returns true if there is a new update available
function checkUpdate () {
updater.check((err, status) => {
if (err) {
console.error(err) console.error(err)
if (!versionNotified) { if (!versionNotified) notify('Updater error!', message)
notify('Updater error!', message) }
} if (!err) {
}) if (status) {
.on('update-available', function () { notify('Update is available!', 'Download started.. wait for the update ready.')
notify('Update is available!', 'Download started.. wait for the update ready.') updater.download()
}) } else {
.on('update-not-available', function () { if (!versionNotified) {
if (!versionNotified) { versionNotified = true
versionNotified = true notify('Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
notify('Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
}
})
} else if (process.platform === 'win32') {
var GhReleases = require('electron-gh-releases')
var ghReleasesOpts = {
repo: 'BoostIO/boost-releases',
currentVersion: app.getVersion()
}
const updater = new GhReleases(ghReleasesOpts)
// Check for updates
// `status` returns true if there is a new update available
function checkUpdate () {
updater.check((err, status) => {
if (err) {
console.error(err)
if (!versionNotified) notify('Updater error!', message)
}
if (!err) {
if (status) {
notify('Update is available!', 'Download started.. wait for the update ready.')
updater.download()
} else {
if (!versionNotified) {
versionNotified = true
notify('Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
}
} }
} }
})
}
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!')
isUpdateReady = true
} }
}) })
} }
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!')
isUpdateReady = true
}
})
const nodeIpc = require('@rokt33r/node-ipc') const nodeIpc = require('@rokt33r/node-ipc')
nodeIpc.config.id = 'node' nodeIpc.config.id = 'node'
nodeIpc.config.retry = 1500 nodeIpc.config.retry = 1500
// nodeIpc.config.silent = true // nodeIpc.config.silent = true
function spawnFinder() {
if (process.platform === 'darwin') {
var finderArgv = [path.join(__dirname, 'finder.js'), '--finder']
if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
finderProcess = ChildProcess
.execFile(process.execPath, finderArgv)
}
}
nodeIpc.serve( nodeIpc.serve(
path.join(app.getPath('userData'), 'boost.service'), path.join(app.getPath('userData'), 'boost.service'),
function () { function () {
nodeIpc.server.on(
'connect',
function (socket) {
socket.on('close', function () {
console.log('socket dead')
if (!appQuit) spawnFinder()
})
}
)
nodeIpc.server.on( nodeIpc.server.on(
'message', 'message',
function (data, socket) { function (data, socket) {
@@ -209,8 +198,12 @@ nodeIpc.serve(
function format (payload) { function format (payload) {
switch (payload.type) { switch (payload.type) {
case 'show-main-window': case 'show-main-window':
mainWindow.minimize() if (process.platform === 'darwin') {
mainWindow.restore() mainWindow.show()
} else {
mainWindow.minimize()
mainWindow.restore()
}
break break
case 'copy-finder': case 'copy-finder':
mainWindow.webContents.send('copy-finder') mainWindow.webContents.send('copy-finder')
@@ -220,6 +213,7 @@ function format (payload) {
break break
} }
} }
function quitApp () { function quitApp () {
appQuit = true appQuit = true
if (finderProcess) finderProcess.kill() if (finderProcess) finderProcess.kill()
@@ -228,8 +222,9 @@ function quitApp () {
app.on('ready', function () { app.on('ready', function () {
app.on('before-quit', function () { app.on('before-quit', function () {
if (finderProcess) finderProcess.kill() console.log('before quite')
appQuit = true appQuit = true
if (finderProcess) finderProcess.kill()
}) })
var template = require('./atom-lib/menu-template') var template = require('./atom-lib/menu-template')
@@ -281,10 +276,7 @@ app.on('ready', function () {
mainWindow.webContents.on('did-finish-load', function () { mainWindow.webContents.on('did-finish-load', function () {
if (finderProcess == null && process.platform === 'darwin') { if (finderProcess == null && process.platform === 'darwin') {
var finderArgv = [path.join(__dirname, 'finder.js'), '--finder'] spawnFinder()
if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
finderProcess = ChildProcess
.execFile(process.execPath, finderArgv)
} else { } else {
finderWindow = require('./atom-lib/finder-window') finderWindow = require('./atom-lib/finder-window')