Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #641 from beakerbrowser/auto-reload-when-found
Browse files Browse the repository at this point in the history
Automatically reload the page if a timedout dat is found
  • Loading branch information
pfrazee authored Aug 4, 2017
2 parents 3bacc0e + a6970d8 commit 2859c33
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/background-process/web-apis/dat-archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ export default {
},

async resolveName (name) {
if (DAT_HASH_REGEX.test(name)) return name
return datDns.resolveName(name)
},

Expand Down
34 changes: 23 additions & 11 deletions app/shell-window/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export function setup () {
page.siteInfo.peers = details.peerCount
navbar.update(page)
}
// refresh if this was a 503ed site
if (page.siteWasADatTimeout && page.url.startsWith(details.url)) {
page.reload()
}
})
})
}
Expand Down Expand Up @@ -112,6 +116,7 @@ export function create (opts) {
sitePerms: null, // saved permissions for the current page
siteInfoOverride: null, // explicit overrides on the siteinfo, used by beaker: pages
siteHasDatAlternative: false, // is there a dat:// version we can redirect to?
siteWasADatTimeout: false, // did we timeout trying to find this site on the dat network?

// history
lastVisitedAt: 0, // when is last time url updated?
Expand Down Expand Up @@ -575,6 +580,7 @@ function onDidStartLoading (e) {
if (page) {
// update state
page.manuallyTrackedIsLoading = true
page.siteWasADatTimeout = false
navbar.update(page)
navbar.hideInpageFind(page)
if (page.isActive) {
Expand Down Expand Up @@ -606,17 +612,19 @@ function onDidStopLoading (e) {
page.checkForDatAlternative(hostname)
}
if (protocol === 'dat:') {
DatArchive.resolveName(hostname).then(key => {
beaker.archives.get(key).then(info => {
page.siteInfo = info
navbar.update(page)

// fallback the tab title to the site title, if needed
if (isEqualURL(page.getTitle(), page.getURL()) && info.title) {
page.title = info.title
events.emit('page-title-updated', page)
}
})
DatArchive.resolveName(hostname)
.catch(err => hostname) // try the hostname as-is, might be a hash
.then(key => {
beaker.archives.get(key).then(info => {
page.siteInfo = info
navbar.update(page)

// fallback the tab title to the site title, if needed
if (isEqualURL(page.getTitle(), page.getURL()) && info.title) {
page.title = info.title
events.emit('page-title-updated', page)
}
})
})
}
if (protocol !== 'beaker:') {
Expand Down Expand Up @@ -728,6 +736,10 @@ function onDidGetResponseDetails (e) {
page.loadingURL = e.newURL
page.siteInfoOverride = null
navbar.updateLocation(page)
// if it's a failed dat discovery...
if (e.httpResponseCode === 504 && e.newURL.startsWith('dat://')) {
page.siteWasADatTimeout = true
}
}
}

Expand Down

0 comments on commit 2859c33

Please sign in to comment.