Skip to content

Commit a0c3b49

Browse files
committed
Add Dia browser support on macOS
1 parent b9760f9 commit a0c3b49

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed

browser/all/import.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
_ "github.com/browserutils/kooky/browser/browsh"
88
_ "github.com/browserutils/kooky/browser/chrome"
99
_ "github.com/browserutils/kooky/browser/chromium"
10+
_ "github.com/browserutils/kooky/browser/dia"
1011
_ "github.com/browserutils/kooky/browser/dillo"
1112
_ "github.com/browserutils/kooky/browser/edge"
1213
_ "github.com/browserutils/kooky/browser/elinks"

browser/dia/dia.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dia
2+
3+
import (
4+
"context"
5+
6+
"github.com/browserutils/kooky"
7+
"github.com/browserutils/kooky/internal/chrome"
8+
"github.com/browserutils/kooky/internal/cookies"
9+
)
10+
11+
func ReadCookies(ctx context.Context, filename string, filters ...kooky.Filter) ([]*kooky.Cookie, error) {
12+
return cookies.SingleRead(cookieStore, filename, filters...).ReadAllCookies(ctx)
13+
}
14+
15+
func TraverseCookies(filename string, filters ...kooky.Filter) kooky.CookieSeq {
16+
return cookies.SingleRead(cookieStore, filename, filters...)
17+
}
18+
19+
// CookieStore has to be closed with CookieStore.Close() after use.
20+
func CookieStore(filename string, filters ...kooky.Filter) (kooky.CookieStore, error) {
21+
return cookieStore(filename, filters...)
22+
}
23+
24+
func cookieStore(filename string, filters ...kooky.Filter) (*cookies.CookieJar, error) {
25+
s := &chrome.CookieStore{}
26+
s.FileNameStr = filename
27+
s.BrowserStr = `dia`
28+
s.SetSafeStorage(`Dia`, ``, ``)
29+
30+
return cookies.NewCookieJar(s, filters...), nil
31+
}

browser/dia/find.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//go:build darwin && !ios
2+
3+
package dia
4+
5+
import (
6+
"github.com/browserutils/kooky"
7+
"github.com/browserutils/kooky/internal/chrome"
8+
chromefind "github.com/browserutils/kooky/internal/chrome/find"
9+
"github.com/browserutils/kooky/internal/cookies"
10+
)
11+
12+
type diaFinder struct{}
13+
14+
var _ kooky.CookieStoreFinder = (*diaFinder)(nil)
15+
16+
func init() {
17+
kooky.RegisterFinder(`dia`, &diaFinder{})
18+
}
19+
20+
func (f *diaFinder) FindCookieStores() kooky.CookieStoreSeq {
21+
return func(yield func(kooky.CookieStore, error) bool) {
22+
for file, err := range chromefind.FindCookieStoreFiles(diaChromiumRoots, `dia`) {
23+
if err != nil {
24+
if !yield(nil, err) {
25+
return
26+
}
27+
continue
28+
}
29+
if file == nil {
30+
continue
31+
}
32+
cookieStore := &chrome.CookieStore{
33+
DefaultCookieStore: cookies.DefaultCookieStore{
34+
BrowserStr: file.Browser,
35+
ProfileStr: file.Profile,
36+
OSStr: file.OS,
37+
IsDefaultProfileBool: file.IsDefaultProfile,
38+
FileNameStr: file.Path,
39+
},
40+
}
41+
cookieStore.SetSafeStorage(`Dia`, ``, ``)
42+
if !yield(&cookies.CookieJar{CookieStore: cookieStore}, nil) {
43+
return
44+
}
45+
}
46+
}
47+
}

browser/dia/find_darwin.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//go:build darwin && !ios
2+
3+
package dia
4+
5+
import (
6+
"os"
7+
"path/filepath"
8+
)
9+
10+
func diaChromiumRoots(yield func(string, error) bool) {
11+
cfgDir, err := os.UserConfigDir()
12+
if err != nil {
13+
_ = yield(``, err)
14+
return
15+
}
16+
_ = yield(filepath.Join(cfgDir, `Dia`, `User Data`), nil)
17+
}

internal/chrome/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
|----------------|-----------------------------|-------------------|-----------------------|
77
| Chrome | Chrome Safe Storage | chrome | com.google.Chrome |
88
| Chromium | Chromium Safe Storage | chromium | org.chromium.Chromium |
9+
| Dia | Dia Safe Storage | dia | |
910
| Brave | Brave Safe Storage | brave | |
1011
| Microsoft Edge | Microsoft Edge Safe Storage | chromium (shared) | |
1112
| Opera | uses Chromium Safe Storage | chromium (shared) | |

0 commit comments

Comments
 (0)