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

fix: keep track of last opened page #1452

Merged
merged 3 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 10 additions & 8 deletions src/webui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ module.exports = async function (ctx) {

ctx.webui = window

ctx.launchWebUI = (url, { focus = true } = {}) => {
if (!url) {
const url = new URL('/', 'webui://-')
url.hash = '/blank'
url.searchParams.set('deviceId', ctx.countlyDeviceId)

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

if (focus) {
Expand All @@ -111,10 +116,6 @@ module.exports = async function (ctx) {
}
}

const url = new URL('/', 'webui://-')
url.hash = '/blank'
url.searchParams.set('deviceId', ctx.countlyDeviceId)

function updateLanguage () {
url.searchParams.set('lng', store.get('language'))
}
Expand All @@ -126,6 +127,7 @@ module.exports = async function (ctx) {
apiAddress = ipfsd.apiAddr
url.searchParams.set('api', apiAddress)
updateLanguage()
console.log(url.toString())
lidel marked this conversation as resolved.
Show resolved Hide resolved
window.loadURL(url.toString())
}
})
Expand Down
20 changes: 14 additions & 6 deletions src/webui/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ connectionHook()

const urlParams = new URLSearchParams(window.location.search)

function checkIfVisible () {
if (document.hidden) {
previousHash = window.location.hash
window.location.hash = '/blank'
} else {
window.location.hash = previousHash
}
}

var originalSetItem = window.localStorage.setItem
window.localStorage.setItem = function () {
if (arguments[0] === 'i18nextLng') {
Expand All @@ -29,12 +38,11 @@ ipcRenderer.on('updatedPage', (_, url) => {
})

document.addEventListener('visibilitychange', () => {
if (document.hidden) {
previousHash = window.location.hash
window.location.hash = '/blank'
} else {
window.location.hash = previousHash
}
checkIfVisible()
})

document.addEventListener('DOMContentReady', () => {
checkIfVisible()
})

window.ipfsDesktop = {
Expand Down