~adnano/astronaut

5281cd60d05ca390729b78987fb375324232261c — adnano a month ago a4363f9
Drop go-xdg dependency
4 files changed, 23 insertions(+), 9 deletions(-)

M browser.go
M main.go
M tab.go
A xdg.go
M browser.go => browser.go +3 -4
@@ 17,7 17,6 @@ import (
	"git.sr.ht/~adnano/go-gemini"
	"git.sr.ht/~adnano/go-gemini/certificate"
	"git.sr.ht/~adnano/go-gemini/tofu"
	"git.sr.ht/~adnano/go-xdg"
	"github.com/gdamore/tcell/v2"
	"github.com/mattn/go-runewidth"
)


@@ 89,7 88,7 @@ func NewBrowser(ui *ui.UI, config *Config) *Browser {
	b.input.SetView(b.inputView)

	// Load known hosts
	knownHostsPath := filepath.Join(xdg.DataHome(), "astronaut", "known_hosts")
	knownHostsPath := filepath.Join(xdgDataHome(), "astronaut", "known_hosts")
	os.MkdirAll(filepath.Dir(knownHostsPath), 0700)
	if err := b.hosts.Load(knownHostsPath); err != nil {
		log.Print(err)


@@ 101,14 100,14 @@ func NewBrowser(ui *ui.UI, config *Config) *Browser {
	}

	// Load client certificates
	certsDir := filepath.Join(xdg.DataHome(), "astronaut", "certificates")
	certsDir := filepath.Join(xdgDataHome(), "astronaut", "certificates")
	os.MkdirAll(certsDir, 0700)
	if err := b.certs.Load(certsDir); err != nil {
		log.Print(err)
	}

	// Load bookmarks
	bookmarks := filepath.Join(xdg.DataHome(), "astronaut", "bookmarks.gmi")
	bookmarks := filepath.Join(xdgDataHome(), "astronaut", "bookmarks.gmi")
	if err := b.bookmarks.Open(bookmarks); err != nil {
		log.Print(err)
	}

M main.go => main.go +6 -3
@@ 15,7 15,6 @@ import (
	"path/filepath"
	"time"

	"git.sr.ht/~adnano/go-xdg"
	"git.sr.ht/~emersion/go-scfg"
)



@@ 40,8 39,12 @@ func main() {
}

func run(url string) error {
	os.MkdirAll(filepath.Join(xdg.DataHome(), "astronaut"), 0700)
	configHome := filepath.Join(xdg.ConfigHome(), "astronaut")
	configDir, err := os.UserConfigDir()
	if err != nil {
		return err
	}
	os.MkdirAll(filepath.Join(xdgDataHome(), "astronaut"), 0700)
	configHome := filepath.Join(configDir, "astronaut")

	config := &Config{Binds: Binds{}}
	if err := parseConfig(configHome, "astronaut.conf", config.Parse); err != nil {

M tab.go => tab.go +1 -2
@@ 25,7 25,6 @@ import (
	"git.sr.ht/~adnano/go-gemini"
	"git.sr.ht/~adnano/go-gemini/certificate"
	"git.sr.ht/~adnano/go-gemini/tofu"
	"git.sr.ht/~adnano/go-xdg"
	"github.com/gdamore/tcell/v2"
	"github.com/mattn/go-runewidth"
)


@@ 461,7 460,7 @@ func (t *Tab) handleAbout(w gemini.ResponseWriter, r *gemini.Request) {
	case "about":
		templates.ExecuteTemplate(w, "about.tmpl", nil)
	case "bookmarks":
		path := filepath.Join(xdg.DataHome(), "astronaut", "bookmarks.gmi")
		path := filepath.Join(xdgDataHome(), "astronaut", "bookmarks.gmi")
		gemini.ServeFile(w, os.DirFS(""), path)
	case "certificates":
		templates.ExecuteTemplate(w, "certificates.tmpl", t.browser.certs.Entries())

A xdg.go => xdg.go +13 -0
@@ 0,0 1,13 @@
package main

import (
	"os"
	"path/filepath"
)

func xdgDataHome() string {
	if s, ok := os.LookupEnv("XDG_DATA_HOME"); ok {
		return s
	}
	return filepath.Join(os.Getenv("HOME"), ".local", "share")
}