mirror of
https://github.com/makew0rld/amfora.git
synced 2024-12-04 14:46:29 -05:00
When creating a tab with a URL, show a minimal interstitial page (#272)
Co-authored-by: makeworld
This commit is contained in:
parent
e8342ce3fd
commit
fe73359bcd
@ -74,7 +74,6 @@ func main() {
|
|||||||
|
|
||||||
// Initialize Amfora's settings
|
// Initialize Amfora's settings
|
||||||
display.Init(version, commit, builtBy)
|
display.Init(version, commit, builtBy)
|
||||||
display.NewTab()
|
|
||||||
|
|
||||||
// Load a URL, file, or render from stdin
|
// Load a URL, file, or render from stdin
|
||||||
if len(os.Args[1:]) > 0 {
|
if len(os.Args[1:]) > 0 {
|
||||||
@ -93,9 +92,11 @@ func main() {
|
|||||||
url = "file://" + fileName
|
url = "file://" + fileName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
display.URL(url)
|
display.NewTabWithURL(url)
|
||||||
} else if !isStdinEmpty() {
|
} else if !isStdinEmpty() {
|
||||||
renderFromStdin()
|
renderFromStdin()
|
||||||
|
} else {
|
||||||
|
display.NewTab()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start
|
// Start
|
||||||
|
@ -187,7 +187,6 @@ func Init(version, commit, builtBy string) {
|
|||||||
if i <= len(tabs[tab].page.Links) && i > 0 {
|
if i <= len(tabs[tab].page.Links) && i > 0 {
|
||||||
// Open new tab and load link
|
// Open new tab and load link
|
||||||
oldTab := tab
|
oldTab := tab
|
||||||
NewTab()
|
|
||||||
// Resolve and follow link manually
|
// Resolve and follow link manually
|
||||||
prevParsed, _ := url.Parse(tabs[oldTab].page.URL)
|
prevParsed, _ := url.Parse(tabs[oldTab].page.URL)
|
||||||
nextParsed, err := url.Parse(tabs[oldTab].page.Links[i-1])
|
nextParsed, err := url.Parse(tabs[oldTab].page.Links[i-1])
|
||||||
@ -196,7 +195,7 @@ func Init(version, commit, builtBy string) {
|
|||||||
reset()
|
reset()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
URL(prevParsed.ResolveReference(nextParsed).String())
|
NewTabWithURL(prevParsed.ResolveReference(nextParsed).String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -328,8 +327,7 @@ func Init(version, commit, builtBy string) {
|
|||||||
Error("URL Error", err.Error())
|
Error("URL Error", err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
NewTab()
|
NewTabWithURL(next)
|
||||||
URL(next)
|
|
||||||
} else {
|
} else {
|
||||||
NewTab()
|
NewTab()
|
||||||
}
|
}
|
||||||
@ -377,6 +375,17 @@ func Stop() {
|
|||||||
// NewTab opens a new tab and switches to it, displaying the
|
// NewTab opens a new tab and switches to it, displaying the
|
||||||
// the default empty content because there's no URL.
|
// the default empty content because there's no URL.
|
||||||
func NewTab() {
|
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
|
// Create TextView and change curTab
|
||||||
// Set the TextView options, and the changed func to App.Draw()
|
// Set the TextView options, and the changed func to App.Draw()
|
||||||
// SetDoneFunc to do link highlighting
|
// SetDoneFunc to do link highlighting
|
||||||
@ -393,8 +402,16 @@ func NewTab() {
|
|||||||
curTab = NumTabs()
|
curTab = NumTabs()
|
||||||
|
|
||||||
tabs = append(tabs, makeNewTab())
|
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].addToHistory("about:newtab")
|
||||||
tabs[curTab].history.pos = 0 // Manually set as first page
|
tabs[curTab].history.pos = 0 // Manually set as first page
|
||||||
|
|
||||||
@ -406,9 +423,7 @@ func NewTab() {
|
|||||||
browser.SetCurrentTab(strconv.Itoa(curTab))
|
browser.SetCurrentTab(strconv.Itoa(curTab))
|
||||||
App.SetFocus(tabs[curTab].view)
|
App.SetFocus(tabs[curTab].view)
|
||||||
|
|
||||||
bottomBar.SetLabel("")
|
URL(url)
|
||||||
bottomBar.SetText("")
|
|
||||||
tabs[curTab].saveBottomBar()
|
|
||||||
|
|
||||||
// Draw just in case
|
// Draw just in case
|
||||||
App.Draw()
|
App.Draw()
|
||||||
@ -529,11 +544,11 @@ func URL(u string) {
|
|||||||
|
|
||||||
func RenderFromString(str string) {
|
func RenderFromString(str string) {
|
||||||
t := tabs[curTab]
|
t := tabs[curTab]
|
||||||
page, _ := renderPageFromString(str)
|
page := renderPageFromString(str)
|
||||||
setPage(t, page)
|
setPage(t, page)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderPageFromString(str string) (*structs.Page, bool) {
|
func renderPageFromString(str string) *structs.Page {
|
||||||
rendered, links := renderer.RenderGemini(str, textWidth(), false)
|
rendered, links := renderer.RenderGemini(str, textWidth(), false)
|
||||||
page := &structs.Page{
|
page := &structs.Page{
|
||||||
Mediatype: structs.TextGemini,
|
Mediatype: structs.TextGemini,
|
||||||
@ -543,7 +558,7 @@ func renderPageFromString(str string) (*structs.Page, bool) {
|
|||||||
TermWidth: termW,
|
TermWidth: termW,
|
||||||
}
|
}
|
||||||
|
|
||||||
return page, true
|
return page
|
||||||
}
|
}
|
||||||
|
|
||||||
func NumTabs() int {
|
func NumTabs() int {
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
var infoModal = cview.NewModal()
|
var infoModal = cview.NewModal()
|
||||||
|
|
||||||
var errorModal = cview.NewModal()
|
var errorModal = cview.NewModal()
|
||||||
|
var errorModalDone = make(chan struct{})
|
||||||
|
|
||||||
var inputModal = cview.NewModal()
|
var inputModal = cview.NewModal()
|
||||||
var inputCh = make(chan string)
|
var inputCh = make(chan string)
|
||||||
@ -152,6 +153,7 @@ func modalInit() {
|
|||||||
panels.HidePanel("error")
|
panels.HidePanel("error")
|
||||||
App.SetFocus(tabs[curTab].view)
|
App.SetFocus(tabs[curTab].view)
|
||||||
App.Draw()
|
App.Draw()
|
||||||
|
errorModalDone <- struct{}{}
|
||||||
})
|
})
|
||||||
|
|
||||||
inputModal.SetBorder(true)
|
inputModal.SetBorder(true)
|
||||||
@ -200,6 +202,8 @@ func Error(title, text string) {
|
|||||||
panels.SendToFront("error")
|
panels.SendToFront("error")
|
||||||
App.SetFocus(errorModal)
|
App.SetFocus(errorModal)
|
||||||
App.Draw()
|
App.Draw()
|
||||||
|
|
||||||
|
<-errorModalDone
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info displays some info on the screen in a modal.
|
// Info displays some info on the screen in a modal.
|
||||||
|
@ -134,6 +134,9 @@ func goURL(t *tab, u string) {
|
|||||||
final, displayed := handleURL(t, u, 0)
|
final, displayed := handleURL(t, u, 0)
|
||||||
if displayed {
|
if displayed {
|
||||||
t.addToHistory(final)
|
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] {
|
if t == tabs[curTab] {
|
||||||
// Display the bottomBar state that handleURL set
|
// Display the bottomBar state that handleURL set
|
||||||
|
Loading…
Reference in New Issue
Block a user