Skip to content

Commit

Permalink
feat: option to disable daemon online/offline notifications
Browse files Browse the repository at this point in the history
- Notifications always go to Browser Console
- It is possible to disable notification popups: closes #282
- Updated some dependencies
  • Loading branch information
lidel committed Sep 27, 2017
1 parent 93c794d commit 7d3a5e0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
22 changes: 14 additions & 8 deletions add-on/src/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async function initStates (options) {
state.linkify = options.linkify
state.dnslink = options.dnslink
state.catchUnhandledProtocols = options.catchUnhandledProtocols
state.displayNotifications = options.displayNotifications
state.dnslinkCache = /* global LRUMap */ new LRUMap(1000)
}

Expand Down Expand Up @@ -324,19 +325,22 @@ async function sendStatusUpdateToBrowserAction () {
// ===================================================================

function notify (titleKey, messageKey, messageParam) {
const title = browser.i18n.getMessage(titleKey)
let message
if (messageKey.startsWith('notify_')) {
message = messageParam ? browser.i18n.getMessage(messageKey, messageParam) : browser.i18n.getMessage(messageKey)
} else {
message = messageKey
}

browser.notifications.create({
'type': 'basic',
'iconUrl': browser.extension.getURL('icons/ipfs-logo-on.svg'),
'title': browser.i18n.getMessage(titleKey),
'message': message
})
if (state.displayNotifications) {
browser.notifications.create({
'type': 'basic',
'iconUrl': browser.extension.getURL('icons/ipfs-logo-on.svg'),
'title': title,
'message': message
})
}
console.log(`[ipfs-companion] ${title}: ${message}`)
}

// contextMenus
Expand Down Expand Up @@ -418,7 +422,7 @@ function isIpfsPageActionsContext (url) {
}

async function onUpdatedTab (tabId, changeInfo, tab) {
if (tab && tab.url) {
if (tab && tab.url && !tab.url.startsWith('chrome://')) {
if (state.linkify && changeInfo.status === 'complete') {
console.log(`[ipfs-companion] Running linkfyDOM for ${tab.url}`)
try {
Expand Down Expand Up @@ -629,6 +633,8 @@ function onStorageChange (changes, area) { // eslint-disable-line no-unused-vars
state.linkify = change.newValue
} else if (key === 'catchUnhandledProtocols') {
state.catchUnhandledProtocols = change.newValue
} else if (key === 'displayNotifications') {
state.displayNotifications = change.newValue
} else if (key === 'automaticMode') {
state.automaticMode = change.newValue
} else if (key === 'dnslink') {
Expand Down
1 change: 1 addition & 0 deletions add-on/src/lib/option-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const optionDefaults = Object.freeze({ // eslint-disable-line no-unused-vars
linkify: false,
dnslink: false,
catchUnhandledProtocols: true,
displayNotifications: true,
customGatewayUrl: 'http://127.0.0.1:8080',
ipfsApiUrl: 'http://127.0.0.1:5001',
ipfsApiPollMs: 3000
Expand Down
11 changes: 10 additions & 1 deletion add-on/src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,16 @@
<form>
<fieldset>
<legend>Experiments</legend>
<div><span><strong>Note:</strong> these features are work-in-progress and may degrade browser performance. <abbr title="Your Mileage May Vary">YMMV</abbr>.</span></div>
<div><span><strong>Note:</strong> these features are new or work-in-progress. <abbr title="Your Mileage May Vary">YMMV</abbr>.</span></div>
<div>
<label for="displayNotifications">
<dl>
<dt>Enable Notifications</dt>
<dd>Displays system notifications when API state changes, a link is copied etc</dd>
</dl>
</label>
<input type="checkbox" id="displayNotifications" />
</div>
<div>
<label for="catchUnhandledProtocols">
<dl>
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@
"karma-mocha": "1.3.0",
"karma-mocha-reporter": "2.2.4",
"karma-sinon": "1.0.5",
"mocha": "3.5.0",
"mocha": "3.5.3",
"npm-run-all": "4.1.1",
"selenium-webdriver": "3.5.0",
"shx": "0.2.2",
"sinon": "3.2.1",
"sinon": "4.0.0",
"standard": "10.0.3",
"sinon-chrome": "2.2.1",
"web-ext": "2.0.0"
},
"dependencies": {
"ipfs-api": "14.3.4",
"ipfs-api": "14.3.5",
"is-ipfs": "0.3.2",
"lru_map": "0.3.3",
"webextension-polyfill": "0.1.1"
"webextension-polyfill": "0.1.2"
}
}

0 comments on commit 7d3a5e0

Please sign in to comment.