mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-09-11 14:55:51 +03:00
Custom new tab page (#83)
This commit is contained in:
parent
3dfbeb5bda
commit
9d7c7370e0
@ -19,6 +19,9 @@ var amforaAppData string // Where amfora files are stored on Windows - cached he
|
||||
var configDir string
|
||||
var configPath string
|
||||
|
||||
var NewTabPath string
|
||||
var CustomNewTab bool
|
||||
|
||||
var TofuStore = viper.New()
|
||||
var tofuDBDir string
|
||||
var tofuDBPath string
|
||||
@ -64,6 +67,13 @@ func Init() error {
|
||||
}
|
||||
configPath = filepath.Join(configDir, "config.toml")
|
||||
|
||||
// Search for a custom new tab
|
||||
NewTabPath = filepath.Join(configDir, "newtab.gmi")
|
||||
CustomNewTab = false
|
||||
if _, err := os.Stat(NewTabPath); err == nil {
|
||||
CustomNewTab = true
|
||||
}
|
||||
|
||||
// Store TOFU db directory and file paths
|
||||
if runtime.GOOS == "windows" {
|
||||
// Windows just stores it in APPDATA along with other stuff
|
||||
|
@ -51,8 +51,6 @@ var tabRow = cview.NewTextView().
|
||||
var layout = cview.NewFlex().
|
||||
SetDirection(cview.FlexRow)
|
||||
|
||||
var renderedNewTabContent string
|
||||
var newTabLinks []string
|
||||
var newTabPage structs.Page
|
||||
|
||||
var App = cview.NewApplication().
|
||||
@ -202,7 +200,8 @@ func Init() {
|
||||
})
|
||||
|
||||
// Render the default new tab content ONCE and store it for later
|
||||
renderedNewTabContent, newTabLinks = renderer.RenderGemini(newTabContent, textWidth(), leftMargin())
|
||||
newTabContent := getNewTabContent()
|
||||
renderedNewTabContent, newTabLinks := renderer.RenderGemini(newTabContent, textWidth(), leftMargin())
|
||||
newTabPage = structs.Page{
|
||||
Raw: newTabContent,
|
||||
Content: renderedNewTabContent,
|
||||
@ -519,6 +518,24 @@ func SwitchTab(tab int) {
|
||||
}
|
||||
|
||||
func Reload() {
|
||||
if tabs[curTab].page.URL == "about:newtab" && config.CustomNewTab {
|
||||
// Re-render new tab, similar to Init()
|
||||
newTabContent := getNewTabContent()
|
||||
tmpTermW := termW
|
||||
renderedNewTabContent, newTabLinks := renderer.RenderGemini(newTabContent, textWidth(), leftMargin())
|
||||
newTabPage = structs.Page{
|
||||
Raw: newTabContent,
|
||||
Content: renderedNewTabContent,
|
||||
Links: newTabLinks,
|
||||
URL: "about:newtab",
|
||||
Width: tmpTermW,
|
||||
Mediatype: structs.TextGemini,
|
||||
}
|
||||
temp := newTabPage // Copy
|
||||
setPage(tabs[curTab], &temp)
|
||||
return
|
||||
}
|
||||
|
||||
if !tabs[curTab].hasContent() {
|
||||
return
|
||||
}
|
||||
|
@ -1,12 +1,20 @@
|
||||
//nolint
|
||||
package display
|
||||
|
||||
var newTabContent = `# New Tab
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/makeworld-the-better-one/amfora/config"
|
||||
)
|
||||
|
||||
//nolint
|
||||
var defaultNewTabContent = `# New Tab
|
||||
|
||||
You've opened a new tab. Use the bar at the bottom to browse around. You can start typing in it by pressing the space key.
|
||||
|
||||
Press the ? key at any time to bring up the help, and see other keybindings. Most are what you expect.
|
||||
|
||||
You can customize this page by creating a gemtext file called newtab.gmi, in Amfora's configuration folder.
|
||||
|
||||
Happy browsing!
|
||||
|
||||
=> about:bookmarks Bookmarks
|
||||
@ -14,3 +22,12 @@ Happy browsing!
|
||||
=> //gemini.circumlunar.space Project Gemini
|
||||
=> https://github.com/makeworld-the-better-one/amfora Amfora homepage [HTTPS]
|
||||
`
|
||||
|
||||
// Read the new tab content from a file if it exists or fallback to a default page.
|
||||
func getNewTabContent() string {
|
||||
data, err := ioutil.ReadFile(config.NewTabPath)
|
||||
if err == nil {
|
||||
return string(data)
|
||||
}
|
||||
return defaultNewTabContent
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user