Skip to content

Commit

Permalink
feat: hide update indicator on click
Browse files Browse the repository at this point in the history
this hides new release notes indicator until new version is  released
and persists it until the newer release shipps

it also converts old opt-out for opening releasenotes in a new tab to an opt-in
  • Loading branch information
lidel committed Oct 26, 2020
1 parent 62ecb6b commit 2fa86be
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
16 changes: 2 additions & 14 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ module.exports = async function init () {
redirect: state.redirect,
enabledOn: state.enabledOn,
disabledOn: state.disabledOn,
showUpdateIndicator: state.dismissedUpdate !== browser.runtime.getManifest().version,
currentTab
}
try {
Expand Down Expand Up @@ -687,20 +688,7 @@ module.exports = async function init () {
shouldReloadExtension = true
state[key] = localStorage.debug = change.newValue
break
case 'recoverFailedHttpRequests':
case 'importDir':
case 'linkify':
case 'catchUnhandledProtocols':
case 'displayNotifications':
case 'displayReleaseNotes':
case 'automaticMode':
case 'detectIpfsPathHeader':
case 'preloadAtPublicGateway':
case 'openViaWebUI':
case 'useLatestWebUI':
case 'enabledOn':
case 'disabledOn':
case 'dnslinkRedirect':
default:
state[key] = change.newValue
break
}
Expand Down
15 changes: 6 additions & 9 deletions add-on/src/lib/on-installed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-env browser */

const browser = require('webextension-polyfill')
const { version } = browser.runtime.getManifest()

exports.welcomePage = '/dist/landing-pages/welcome/index.html'
exports.updatePage = 'https://github.com/ipfs-shipyard/ipfs-companion/releases/tag/v'
Expand All @@ -16,21 +17,17 @@ exports.onInstalled = async (details) => {
}

exports.showPendingLandingPages = async () => {
const hint = await browser.storage.local.get([
'showLandingPage',
'displayReleaseNotes'
])
switch (hint.showLandingPage) {
const { showLandingPage, displayReleaseNotes } = await browser.storage.local.get(['showLandingPage', 'displayReleaseNotes'])
switch (showLandingPage) {
case 'onInstallWelcome':
await browser.storage.local.remove('showLandingPage')
return browser.tabs.create({
url: exports.welcomePage
})
case 'onVersionUpdate':
await browser.storage.local.remove('showLandingPage')
if (!hint.displayReleaseNotes) return
return browser.tabs.create({
url: exports.updatePage + browser.runtime.getManifest().version
})
if (!displayReleaseNotes) return
await browser.storage.local.set({ dismissedUpdate: version })
return browser.tabs.create({ url: exports.updatePage + version })
}
}
9 changes: 9 additions & 0 deletions add-on/src/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports.optionDefaults = Object.freeze({
logNamespaces: 'jsipfs*,ipfs*,libp2p:mdns*,libp2p-delegated*,-*:ipns*,-ipfs:preload*,-ipfs-http-client:request*,-ipfs:http-api*',
importDir: '/ipfs-companion-imports/%Y-%M-%D_%h%m%s/',
useLatestWebUI: false,
dismissedUpdate: null,
openViaWebUI: true
})

Expand Down Expand Up @@ -213,4 +214,12 @@ exports.migrateOptions = async (storage, debug) => {
await storage.set({ disabledOn })
}
}

{ // ~v2.15.1: change displayReleaseNotes opt-out flag to opt-in
const { displayReleaseNotes, dismissedUpdate } = await storage.get(['displayReleaseNotes', 'dismissedUpdate'])
if (!dismissedUpdate && displayReleaseNotes) {
log('converting displayReleaseNotes from out-out to opt-in')
await storage.set({ displayReleaseNotes: false })
}
}
}
6 changes: 3 additions & 3 deletions add-on/src/popup/browser-action/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ipfsVersion = require('./ipfs-version')
const gatewayStatus = require('./gateway-status')

module.exports = function header (props) {
const { ipfsNodeType, active, onToggleActive, onOpenPrefs, onOpenReleaseNotes, isIpfsOnline, onOpenWelcomePage } = props
const { ipfsNodeType, active, onToggleActive, onOpenPrefs, onOpenReleaseNotes, isIpfsOnline, onOpenWelcomePage, showUpdateIndicator } = props
return html`
<div class="br2 br--top ba bw1 b--white ipfs-gradient-0">
<div class="pt3 pr3 pb2 pl3 no-user-select flex justify-between items-center">
Expand All @@ -36,11 +36,11 @@ module.exports = function header (props) {
</div>
</div>
<div class="tr ma0 pb1">
${versionUpdateIcon({
${showUpdateIndicator ? versionUpdateIcon({
active,
title: 'panel_headerNewVersionTitle',
action: onOpenReleaseNotes
})}
}) : null}
${powerIcon({
active,
title: 'panel_headerActiveToggleTitle',
Expand Down
6 changes: 5 additions & 1 deletion add-on/src/popup/browser-action/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ module.exports = (state, emitter) => {
}
})

emitter.on('openReleaseNotes', async (page = '/') => {
emitter.on('openReleaseNotes', async () => {
const url = `https://github.com/ipfs-shipyard/ipfs-companion/releases/tag/v${browser.runtime.getManifest().version}`
try {
const { version } = browser.runtime.getManifest()
await browser.storage.local.set({ dismissedUpdate: version })
// Note: opening tab needs to happen after storage.local.set because in Chromium 86
// it triggers a premature window.close, which aborts storage update
await browser.tabs.create({ url })
window.close()
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions test/functional/lib/ipfs-companion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('init', function () {
global.browser = browser
global.URL = URL
global.screen = {}
browser.runtime.getManifest.returns({ version: '0.0.0' }) // on-installed.js
init = require('../../../add-on/src/lib/ipfs-companion')
})

Expand Down

0 comments on commit 2fa86be

Please sign in to comment.