Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: restart daemon when connection changes #942

Merged
merged 3 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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