Skip to content

Commit

Permalink
fix: show Files after import on windows
Browse files Browse the repository at this point in the history
this aims to fix issue from
#1815
  • Loading branch information
lidel committed Jun 24, 2021
1 parent 2a0268d commit 12797b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/add-to-ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ function sendNotification (failures, successes, launchWebUI, path) {
}

fn({ title, body }, () => {
// force refresh for Files screen to pick up newly added items
// https://github.com/ipfs/ipfs-desktop/issues/1763
launchWebUI(link, { forceRefresh: true })
})
}
Expand Down
7 changes: 3 additions & 4 deletions src/webui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,15 @@ module.exports = async function (ctx) {
url.hash = '/blank'
url.searchParams.set('deviceId', ctx.countlyDeviceId)

ctx.launchWebUI = (path, { focus = true, forceRefresh = false } = {}) => {
if (forceRefresh) window.webContents.reload()
ctx.launchWebUI = async (path, { focus = true, forceRefresh = false } = {}) => {
if (!path) {
logger.info('[web ui] launching web ui')
} else {
logger.info(`[web ui] navigate to ${path}`)
window.webContents.send('updatedPage', path)
url.hash = path
await window.loadURL(url.toString())
}

if (forceRefresh) window.webContents.reload()
if (focus) {
window.show()
window.focus()
Expand Down
13 changes: 8 additions & 5 deletions src/webui/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ const urlParams = new URLSearchParams(window.location.search)

function checkIfVisible () {
if (document.hidden) {
if (window.location.hash === '#/blank') return // skip, already blank
previousHash = window.location.hash
window.location.hash = '/blank'
} else {
if (previousHash === '#/blank') return // skip
window.location.hash = previousHash
}
}
Expand All @@ -28,11 +30,6 @@ window.localStorage.setItem = function () {

let previousHash = null

ipcRenderer.on('updatedPage', (_, url) => {
previousHash = url
window.location.hash = url
})

document.addEventListener('visibilitychange', () => {
checkIfVisible()
})
Expand All @@ -41,6 +38,12 @@ document.addEventListener('DOMContentReady', () => {
checkIfVisible()
})

// track hash changes, so checkIfVisible always has the right previousHash
document.addEventListener('hashchange', () => {
if (window.location.hash === '#/blank') return // skip
previousHash = window.location.hash
})

window.ipfsDesktop = {
countlyAppKey: COUNTLY_KEY,

Expand Down

0 comments on commit 12797b9

Please sign in to comment.