Skip to content

Commit

Permalink
fix: notification error on pin/unpin
Browse files Browse the repository at this point in the history
- closes #338
- as a side-effect may improve situation with #318
  • Loading branch information
lidel committed Jan 7, 2018
1 parent cf63fcc commit 6081df0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions add-on/src/popup/browser-action/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ module.exports = (state, emitter) => {
port = browser.runtime.connect({name: 'browser-action-port'})
port.onMessage.addListener(async (message) => {
if (message.statusUpdate) {
// quick initial redraw with cached values
emitter.emit('render')
console.log('In browser action, received message from background:', message)
await updateBrowserActionState(message.statusUpdate)
// another redraw after laggy state update finished
emitter.emit('render')
}
})
Expand All @@ -57,8 +60,8 @@ module.exports = (state, emitter) => {
const currentPath = await resolveToIPFS(new URL(state.currentTabUrl).pathname)
const pinResult = await ipfsCompanion.ipfs.pin.add(currentPath, { recursive: true })
console.log('ipfs.pin.add result', pinResult)
notify('notify_pinnedIpfsResourceTitle', currentPath)
state.isPinned = true
notify('notify_pinnedIpfsResourceTitle', currentPath)
} catch (error) {
handlePinError('notify_pinErrorTitle', error)
}
Expand All @@ -75,13 +78,13 @@ module.exports = (state, emitter) => {
const { ipfsCompanion } = await getBackgroundPage()
const currentPath = await resolveToIPFS(new URL(state.currentTabUrl).pathname)
const result = await ipfsCompanion.ipfs.pin.rm(currentPath, {recursive: true})
state.isPinned = false
console.log('ipfs.pin.rm result', result)
notify('notify_unpinnedIpfsResourceTitle', currentPath)
state.isPinned = false
} catch (error) {
handlePinError('notify_unpinErrorTitle', error)
}
state.isUnPinning = true
state.isUnPinning = false
emitter.emit('render')
window.close()
})
Expand All @@ -90,8 +93,8 @@ module.exports = (state, emitter) => {
console.error(browser.i18n.getMessage(errorMessageKey), error)
try {
notify(errorMessageKey, error.message)
} catch (error) {
console.error('unable to access background page', error)
} catch (notifyError) {
console.error('Unable to notify user about pin-related error', notifyError)
}
}

Expand Down Expand Up @@ -209,7 +212,8 @@ module.exports = (state, emitter) => {
}

function notify (title, message) {
port.postMessage({event: 'notification', title: title, message: message}).catch((err) => console.log(err))
// console.log('Sending notification (' + title + '): ' + message + ')')
return port.postMessage({event: 'notification', title: title, message: message})
}
}

Expand Down

0 comments on commit 6081df0

Please sign in to comment.