Skip to content

Commit bbaeb8d

Browse files
committed
Do followLink in a new goroutine, update its doc [#281]
1 parent 08c1d65 commit bbaeb8d

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

display/display.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func Init(version, commit, builtBy string) {
241241
}
242242
if i <= len(tabs[tab].page.Links) && i > 0 {
243243
// It's a valid link number
244-
followLink(tabs[tab], tabs[tab].page.URL, tabs[tab].page.Links[i-1])
244+
go followLink(tabs[tab], tabs[tab].page.URL, tabs[tab].page.Links[i-1])
245245
return
246246
}
247247
// Invalid link number, don't do anything

display/private.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package display
22

3+
// This file contains the functions that aren't part of the public API.
4+
// The funcs are for network and displaying.
5+
36
import (
47
"net/url"
58
"strconv"
@@ -9,17 +12,20 @@ import (
912
"github.com/makeworld-the-better-one/amfora/structs"
1013
)
1114

12-
// This file contains the functions that aren't part of the public API.
13-
// The funcs are for network and displaying.
14-
15-
// followLink should be used when the user "clicks" a link on a page.
16-
// Not when a URL is opened on a new tab for the first time.
17-
// It will handle setting the bottomBar.
15+
// followLink should be used when the user "clicks" a link on a page,
16+
// but not when a URL is opened on a new tab for the first time.
17+
//
18+
// It will handle updating the bottomBar.
19+
//
20+
// It should be called with the `go` keyword to spawn a new goroutine if
21+
// it would otherwise block the UI loop, such as when called from an input
22+
// handler.
23+
//
24+
// It blocks until navigation is finished, and we've completed any user
25+
// interaction related to loading the URL (such as info, error modals)
1826
func followLink(t *tab, prev, next string) {
1927
if strings.HasPrefix(next, "about:") {
20-
if final, ok := handleAbout(t, next); ok {
21-
t.addToHistory(final)
22-
}
28+
goURL(t, next)
2329
return
2430
}
2531

@@ -29,7 +35,7 @@ func followLink(t *tab, prev, next string) {
2935
Error("URL Error", err.Error())
3036
return
3137
}
32-
go goURL(t, nextURL)
38+
goURL(t, nextURL)
3339
return
3440
}
3541
// No content on current tab, so the "prev" URL is not valid.
@@ -39,7 +45,7 @@ func followLink(t *tab, prev, next string) {
3945
Error("URL Error", "Link URL could not be parsed")
4046
return
4147
}
42-
go goURL(t, next)
48+
goURL(t, next)
4349
}
4450

4551
// reformatPage will take the raw page content and reformat it according to the current terminal dimensions.

display/tab.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func makeNewTab() *tab {
8686
linkN, _ := strconv.Atoi(currentSelection[0])
8787
tabs[tab].page.Selected = tabs[tab].page.Links[linkN]
8888
tabs[tab].page.SelectedID = currentSelection[0]
89-
followLink(tabs[tab], tabs[tab].page.URL, tabs[tab].page.Links[linkN])
89+
go followLink(tabs[tab], tabs[tab].page.URL, tabs[tab].page.Links[linkN])
9090
return
9191
}
9292
if len(currentSelection) == 0 && (key == tcell.KeyEnter || key == tcell.KeyTab) {
@@ -209,7 +209,7 @@ func makeNewTab() *tab {
209209
if cmd >= config.CmdLink1 && cmd <= config.CmdLink0 {
210210
if int(cmd) <= len(t.page.Links) {
211211
// It's a valid link number
212-
followLink(&t, t.page.URL, t.page.Links[cmd-1])
212+
go followLink(&t, t.page.URL, t.page.Links[cmd-1])
213213
return nil
214214
}
215215
}

0 commit comments

Comments
 (0)