When creating a tab with a URL, show a minimal interstitial page (#272)

Co-authored-by: makeworld
This commit is contained in:
mooff 2021-12-08 00:54:54 +00:00 committed by GitHub
parent e8342ce3fd
commit fe73359bcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 14 deletions

View File

@ -74,7 +74,6 @@ func main() {
// Initialize Amfora's settings
display.Init(version, commit, builtBy)
display.NewTab()
// Load a URL, file, or render from stdin
if len(os.Args[1:]) > 0 {
@ -93,9 +92,11 @@ func main() {
url = "file://" + fileName
}
}
display.URL(url)
display.NewTabWithURL(url)
} else if !isStdinEmpty() {
renderFromStdin()
} else {
display.NewTab()
}
// Start

View File

@ -187,7 +187,6 @@ func Init(version, commit, builtBy string) {
if i <= len(tabs[tab].page.Links) && i > 0 {
// Open new tab and load link
oldTab := tab
NewTab()
// Resolve and follow link manually
prevParsed, _ := url.Parse(tabs[oldTab].page.URL)
nextParsed, err := url.Parse(tabs[oldTab].page.Links[i-1])
@ -196,7 +195,7 @@ func Init(version, commit, builtBy string) {
reset()
return
}
URL(prevParsed.ResolveReference(nextParsed).String())
NewTabWithURL(prevParsed.ResolveReference(nextParsed).String())
return
}
} else {
@ -328,8 +327,7 @@ func Init(version, commit, builtBy string) {
Error("URL Error", err.Error())
return nil
}
NewTab()
URL(next)
NewTabWithURL(next)
} else {
NewTab()
}
@ -377,6 +375,17 @@ func Stop() {
// NewTab opens a new tab and switches to it, displaying the
// the default empty content because there's no URL.
func NewTab() {
NewTabWithURL("about:newtab")
bottomBar.SetLabel("")
bottomBar.SetText("")
tabs[NumTabs()-1].saveBottomBar()
}
// NewTabWithURL opens a new tab and switches to it, displaying the
// the URL provided.
func NewTabWithURL(url string) {
// Create TextView and change curTab
// Set the TextView options, and the changed func to App.Draw()
// SetDoneFunc to do link highlighting
@ -393,8 +402,16 @@ func NewTab() {
curTab = NumTabs()
tabs = append(tabs, makeNewTab())
temp := newTabPage // Copy
setPage(tabs[curTab], &temp)
var interstitial string
if !strings.HasPrefix(url, "about:") {
interstitial = "Loading " + url + "..."
}
setPage(tabs[curTab], renderPageFromString(interstitial))
// Regardless of the starting URL, about:newtab will
// be the history root.
tabs[curTab].addToHistory("about:newtab")
tabs[curTab].history.pos = 0 // Manually set as first page
@ -406,9 +423,7 @@ func NewTab() {
browser.SetCurrentTab(strconv.Itoa(curTab))
App.SetFocus(tabs[curTab].view)
bottomBar.SetLabel("")
bottomBar.SetText("")
tabs[curTab].saveBottomBar()
URL(url)
// Draw just in case
App.Draw()
@ -529,11 +544,11 @@ func URL(u string) {
func RenderFromString(str string) {
t := tabs[curTab]
page, _ := renderPageFromString(str)
page := renderPageFromString(str)
setPage(t, page)
}
func renderPageFromString(str string) (*structs.Page, bool) {
func renderPageFromString(str string) *structs.Page {
rendered, links := renderer.RenderGemini(str, textWidth(), false)
page := &structs.Page{
Mediatype: structs.TextGemini,
@ -543,7 +558,7 @@ func renderPageFromString(str string) (*structs.Page, bool) {
TermWidth: termW,
}
return page, true
return page
}
func NumTabs() int {

View File

@ -18,6 +18,7 @@ import (
var infoModal = cview.NewModal()
var errorModal = cview.NewModal()
var errorModalDone = make(chan struct{})
var inputModal = cview.NewModal()
var inputCh = make(chan string)
@ -152,6 +153,7 @@ func modalInit() {
panels.HidePanel("error")
App.SetFocus(tabs[curTab].view)
App.Draw()
errorModalDone <- struct{}{}
})
inputModal.SetBorder(true)
@ -200,6 +202,8 @@ func Error(title, text string) {
panels.SendToFront("error")
App.SetFocus(errorModal)
App.Draw()
<-errorModalDone
}
// Info displays some info on the screen in a modal.

View File

@ -134,6 +134,9 @@ func goURL(t *tab, u string) {
final, displayed := handleURL(t, u, 0)
if displayed {
t.addToHistory(final)
} else if t.page.URL == "" {
// The tab is showing interstitial or no content. Let's go to about:newtab.
handleAbout(t, "about:newtab")
}
if t == tabs[curTab] {
// Display the bottomBar state that handleURL set