Skip to content

Commit

Permalink
feat: restart daemon when connection changes (#942)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias authored May 31, 2019
1 parent fe76282 commit eb9c60c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/late/register-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const STATUS = {
export default async function (ctx) {
let ipfsd = null
let status = null
let wasOnline = null

const updateStatus = (stat) => {
status = stat
Expand Down Expand Up @@ -100,22 +101,23 @@ export default async function (ctx) {
})
}

ipcMain.on('startIpfs', () => {
startIpfs()
})

ipcMain.on('stopIpfs', () => {
stopIpfs()
})

ipcMain.on('restartIpfs', async () => {
const restartIpfs = async () => {
await stopIpfs()
await startIpfs()
})
}

ipcMain.on('startIpfs', startIpfs)
ipcMain.on('stopIpfs', stopIpfs)
ipcMain.on('restartIpfs', restartIpfs)
app.on('before-quit', stopIpfs)

await startIpfs()

app.on('before-quit', async () => {
await stopIpfs()
ipcMain.on('online-status-changed', (_, isOnline) => {
if (wasOnline === false && isOnline) {
restartIpfs()
}

wasOnline = isOnline
})
}
11 changes: 11 additions & 0 deletions src/late/webui/connection-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { ipcRenderer } = require('electron')

module.exports = function () {
const handler = () => {
ipcRenderer.send('online-status-changed', navigator.onLine)
}

window.addEventListener('online', handler)
window.addEventListener('offline', handler)
handler()
}
2 changes: 2 additions & 0 deletions src/late/webui/preload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { ipcRenderer, remote } = require('electron')
const screenshotHook = require('./screenshot')
const connectionHook = require('./connection-status')
const toPull = require('stream-to-pull-stream')
const readdir = require('recursive-readdir')
const fs = require('fs-extra')
Expand All @@ -9,6 +10,7 @@ const COUNTLY_KEY = '47fbb3db3426d2ae32b3b65fe40c564063d8b55d'
const COUNTLY_KEY_TEST = '6b00e04fa5370b1ce361d2f24a09c74254eee382'

screenshotHook()
connectionHook()

var originalSetItem = window.localStorage.setItem
window.localStorage.setItem = function () {
Expand Down

0 comments on commit eb9c60c

Please sign in to comment.