1 Star 0 Fork 0

wengo/kooky

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
find.go 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
wengooooo 提交于 2021-10-20 18:14 . fix
//+build !windows
package uzbl
import (
"os"
"path/filepath"
"gitee.com/wengo/kooky"
"gitee.com/wengo/kooky/internal"
"gitee.com/wengo/kooky/internal/netscape"
)
type uzblFinder struct{}
var _ kooky.CookieStoreFinder = (*uzblFinder)(nil)
func init() {
kooky.RegisterFinder(`uzbl`, &uzblFinder{})
}
func (s *uzblFinder) FindCookieStores() ([]kooky.CookieStore, error) {
roots, err := uzblRoots()
if err != nil {
return nil, err
}
var ret []kooky.CookieStore
for _, root := range roots {
for _, filename := range []string{`session-cookies.txt`, `cookies.txt`} {
ret = append(
ret,
&netscape.CookieStore{
DefaultCookieStore: internal.DefaultCookieStore{
BrowserStr: `uzbl`,
FileNameStr: filepath.Join(root, `uzbl`, filename),
},
},
)
}
}
if len(ret) > 0 {
if cookieStore, ok := ret[len(ret)-1].(*netscape.CookieStore); ok {
cookieStore.IsDefaultProfileBool = true
}
}
return ret, nil
}
func uzblRoots() ([]string, error) {
var ret []string
home, errHome := os.UserHomeDir()
// old location
// fallback
if errHome == nil {
ret = append(ret, filepath.Join(home, `.config`))
}
if dir, ok := os.LookupEnv(`XDG_CONFIG_HOME`); ok {
ret = append(ret, dir)
}
// new location
if errHome == nil {
ret = append(ret, filepath.Join(home, `.local`, `share`))
}
if dataDir, ok := os.LookupEnv(`XDG_DATA_HOME`); ok {
ret = append(ret, dataDir)
}
return ret, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wengo/kooky.git
git@gitee.com:wengo/kooky.git
wengo
kooky
kooky
dc41c5585b72

搜索帮助