Skip to content

Commit 7eb767a

Browse files
committed
IPC setup for windows & remove old updater code
1 parent 8e64abc commit 7eb767a

3 files changed

Lines changed: 98 additions & 103 deletions

File tree

atom-lib/finder-window.js

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const Tray = electron.Tray
88
const path = require('path')
99
const nodeIpc = require('@rokt33r/node-ipc')
1010

11+
var appQuit = false
1112
var isFinderLoaded = false
1213

1314
nodeIpc.config.id = 'finder'
@@ -18,35 +19,37 @@ nodeIpc.connectTo(
1819
'main',
1920
path.join(app.getPath('userData'), 'boost.service'),
2021
function () {
21-
nodeIpc.of.main.on(
22-
'error',
23-
function (err) {
24-
nodeIpc.log('<< ## err ##'.rainbow, nodeIpc.config.delay)
25-
nodeIpc.log(err)
22+
nodeIpc.of.main.on(
23+
'error',
24+
function (err) {
25+
nodeIpc.log('<< ## err ##'.rainbow, nodeIpc.config.delay)
26+
nodeIpc.log(err)
27+
}
28+
)
29+
nodeIpc.of.main.on(
30+
'connect',
31+
function () {
32+
nodeIpc.log('<< ## connected to world ##'.rainbow, nodeIpc.config.delay)
33+
}
34+
)
35+
nodeIpc.of.main.on(
36+
'disconnect',
37+
function () {
38+
nodeIpc.log('<< disconnected from main'.notice)
39+
appQuit = true
40+
app.quit()
41+
}
42+
)
43+
nodeIpc.of.main.on(
44+
'message',
45+
function (payload) {
46+
switch (payload.type) {
47+
case 'open-finder':
48+
if (isFinderLoaded) openFinder()
49+
break
2650
}
27-
)
28-
nodeIpc.of.main.on(
29-
'connect',
30-
function () {
31-
nodeIpc.log('<< ## connected to world ##'.rainbow, nodeIpc.config.delay)
32-
}
33-
)
34-
nodeIpc.of.main.on(
35-
'disconnect',
36-
function(){
37-
nodeIpc.log('<< disconnected from main'.notice)
38-
}
39-
)
40-
nodeIpc.of.main.on(
41-
'message',
42-
function (payload) {
43-
switch (payload.type) {
44-
case 'open-finder':
45-
if (isFinderLoaded) openFinder()
46-
break
47-
}
48-
}
49-
)
51+
}
52+
)
5053
}
5154
)
5255

@@ -91,6 +94,12 @@ finderWindow.on('blur', function () {
9194
hideFinder()
9295
})
9396

97+
finderWindow.on('close', function (e) {
98+
if (appQuit) return true
99+
e.preventDefault()
100+
finderWindow.hide()
101+
})
102+
94103
finderWindow.webContents.on('did-finish-load', function () {
95104
var appIcon = new Tray(path.join(__dirname, '../resources/tray-icon.png'))
96105
appIcon.setToolTip('Boost')
@@ -112,7 +121,8 @@ finderWindow.webContents.on('did-finish-load', function () {
112121
label: 'Quit',
113122
click: function () {
114123
emit('quit-app')
115-
} }))
124+
}
125+
}))
116126

117127
appIcon.setContextMenu(trayMenu)
118128
appIcon.on('click', function (e) {

finder.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const Menu = electron.Menu
44

55
var finderWindow = null
66

7-
var appQuit = false
87
app.on('ready', function () {
98
if (process.platform === 'darwin') {
109
app.dock.hide()
@@ -15,10 +14,4 @@ app.on('ready', function () {
1514
Menu.setApplicationMenu(menu)
1615

1716
finderWindow = require('./atom-lib/finder-window')
18-
19-
finderWindow.on('close', function (e) {
20-
if (appQuit) return true
21-
e.preventDefault()
22-
finderWindow.hide()
23-
})
2417
})

main.js

Lines changed: 59 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory)
9494
})
9595

9696
if (shouldQuit) {
97-
app.quit()
97+
quitApp()
9898
return
9999
}
100100

@@ -114,82 +114,71 @@ function notify (title, body) {
114114
}
115115

116116
var isUpdateReady = false
117-
if (process.platform === 'darwin') {
118-
autoUpdater.setFeedURL('https://orbital.b00st.io/rokt33r/boost-app/latest?version=' + version)
119-
autoUpdater
120-
.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
121-
update = quitAndUpdate
122-
123-
if (mainWindow != null) {
124-
notify('Ready to Update! ' + releaseName, 'Click update button on Main window.')
125-
mainWindow.webContents.send('update-available', 'Update available!')
126-
}
127-
})
128-
.on('error', function (err, message) {
129-
console.error('error')
130-
console.error(err)
131-
if (!versionNotified) {
132-
notify('Updater error!', message)
133-
}
134-
})
135-
.on('update-available', function () {
136-
notify('Update is available!', 'Download started.. wait for the update ready.')
137-
})
138-
.on('update-not-available', function () {
139-
if (!versionNotified) {
140-
versionNotified = true
141-
notify('Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
142-
}
143-
})
144-
} else if (process.platform === 'win32') {
145-
var GhReleases = require('electron-gh-releases')
117+
var GhReleases = require('electron-gh-releases')
146118

147-
var ghReleasesOpts = {
148-
repo: 'BoostIO/boost-releases',
149-
currentVersion: app.getVersion()
150-
}
119+
var ghReleasesOpts = {
120+
repo: 'BoostIO/boost-releases',
121+
currentVersion: app.getVersion()
122+
}
151123

152-
const updater = new GhReleases(ghReleasesOpts)
124+
const updater = new GhReleases(ghReleasesOpts)
153125

154-
// Check for updates
155-
// `status` returns true if there is a new update available
156-
function checkUpdate () {
157-
updater.check((err, status) => {
158-
if (err) {
159-
console.error(err)
160-
if (!versionNotified) notify('Updater error!', message)
161-
}
162-
if (!err) {
163-
if (status) {
164-
notify('Update is available!', 'Download started.. wait for the update ready.')
165-
updater.download()
166-
} else {
167-
if (!versionNotified) {
168-
versionNotified = true
169-
notify('Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
170-
}
126+
// Check for updates
127+
// `status` returns true if there is a new update available
128+
function checkUpdate () {
129+
updater.check((err, status) => {
130+
if (err) {
131+
console.error(err)
132+
if (!versionNotified) notify('Updater error!', message)
133+
}
134+
if (!err) {
135+
if (status) {
136+
notify('Update is available!', 'Download started.. wait for the update ready.')
137+
updater.download()
138+
} else {
139+
if (!versionNotified) {
140+
versionNotified = true
141+
notify('Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
171142
}
172143
}
173-
})
174-
}
175-
176-
updater.on('update-downloaded', (info) => {
177-
if (mainWindow != null) {
178-
notify('Ready to Update!', 'Click update button on Main window.')
179-
mainWindow.webContents.send('update-available', 'Update available!')
180-
isUpdateReady = true
181144
}
182145
})
183146
}
184147

148+
updater.on('update-downloaded', (info) => {
149+
if (mainWindow != null) {
150+
notify('Ready to Update!', 'Click update button on Main window.')
151+
mainWindow.webContents.send('update-available', 'Update available!')
152+
isUpdateReady = true
153+
}
154+
})
155+
185156
const nodeIpc = require('@rokt33r/node-ipc')
186157
nodeIpc.config.id = 'node'
187158
nodeIpc.config.retry = 1500
188159
// nodeIpc.config.silent = true
189160

161+
function spawnFinder() {
162+
if (process.platform === 'darwin') {
163+
var finderArgv = [path.join(__dirname, 'finder.js'), '--finder']
164+
if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
165+
finderProcess = ChildProcess
166+
.execFile(process.execPath, finderArgv)
167+
}
168+
}
169+
190170
nodeIpc.serve(
191171
path.join(app.getPath('userData'), 'boost.service'),
192172
function () {
173+
nodeIpc.server.on(
174+
'connect',
175+
function (socket) {
176+
socket.on('close', function () {
177+
console.log('socket dead')
178+
if (!appQuit) spawnFinder()
179+
})
180+
}
181+
)
193182
nodeIpc.server.on(
194183
'message',
195184
function (data, socket) {
@@ -209,8 +198,12 @@ nodeIpc.serve(
209198
function format (payload) {
210199
switch (payload.type) {
211200
case 'show-main-window':
212-
mainWindow.minimize()
213-
mainWindow.restore()
201+
if (process.platform === 'darwin') {
202+
mainWindow.show()
203+
} else {
204+
mainWindow.minimize()
205+
mainWindow.restore()
206+
}
214207
break
215208
case 'copy-finder':
216209
mainWindow.webContents.send('copy-finder')
@@ -220,6 +213,7 @@ function format (payload) {
220213
break
221214
}
222215
}
216+
223217
function quitApp () {
224218
appQuit = true
225219
if (finderProcess) finderProcess.kill()
@@ -228,8 +222,9 @@ function quitApp () {
228222

229223
app.on('ready', function () {
230224
app.on('before-quit', function () {
231-
if (finderProcess) finderProcess.kill()
225+
console.log('before quite')
232226
appQuit = true
227+
if (finderProcess) finderProcess.kill()
233228
})
234229

235230
var template = require('./atom-lib/menu-template')
@@ -281,10 +276,7 @@ app.on('ready', function () {
281276

282277
mainWindow.webContents.on('did-finish-load', function () {
283278
if (finderProcess == null && process.platform === 'darwin') {
284-
var finderArgv = [path.join(__dirname, 'finder.js'), '--finder']
285-
if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
286-
finderProcess = ChildProcess
287-
.execFile(process.execPath, finderArgv)
279+
spawnFinder()
288280
} else {
289281
finderWindow = require('./atom-lib/finder-window')
290282

0 commit comments

Comments
 (0)