Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add provider software folder and check linters
Merge pull request #172 from moonD4rk/fix/golangci-lint
- Loading branch information
Showing
12 changed files
with
143 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package provider | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
"strings" | ||
|
||
"hack-browser-data/internal/browser" | ||
"hack-browser-data/internal/log" | ||
"hack-browser-data/internal/provider/chromium" | ||
"hack-browser-data/internal/provider/firefox" | ||
"hack-browser-data/internal/utils/fileutil" | ||
"hack-browser-data/internal/utils/typeutil" | ||
) | ||
|
||
func PickBrowsers(name, profile string) ([]browser.Browser, error) { | ||
var browsers []browser.Browser | ||
clist := pickChromium(name, profile) | ||
for _, b := range clist { | ||
if b != nil { | ||
browsers = append(browsers, b) | ||
} | ||
} | ||
flist := pickFirefox(name, profile) | ||
for _, b := range flist { | ||
if b != nil { | ||
browsers = append(browsers, b) | ||
} | ||
} | ||
return browsers, nil | ||
} | ||
|
||
func pickChromium(name, profile string) []browser.Browser { | ||
var browsers []browser.Browser | ||
name = strings.ToLower(name) | ||
if name == "all" { | ||
for _, v := range chromiumList { | ||
if !fileutil.FolderExists(filepath.Clean(v.profilePath)) { | ||
log.Noticef("find browser %s failed, profile folder does not exist", v.name) | ||
continue | ||
} | ||
if multiChromium, err := chromium.New(v.name, v.storage, v.profilePath, v.items); err == nil { | ||
log.Noticef("find browser %s success", v.name) | ||
for _, b := range multiChromium { | ||
log.Noticef("find browser %s success", b.Name()) | ||
browsers = append(browsers, b) | ||
} | ||
} else { | ||
log.Errorf("new chromium error: %s", err.Error()) | ||
} | ||
} | ||
} | ||
if c, ok := chromiumList[name]; ok { | ||
if profile == "" { | ||
profile = c.profilePath | ||
} | ||
if !fileutil.FolderExists(filepath.Clean(profile)) { | ||
log.Fatalf("find browser %s failed, profile folder does not exist", c.name) | ||
} | ||
chromiumList, err := chromium.New(c.name, c.storage, profile, c.items) | ||
if err != nil { | ||
log.Fatalf("new chromium error: %s", err) | ||
} | ||
for _, b := range chromiumList { | ||
log.Noticef("find browser %s success", b.Name()) | ||
browsers = append(browsers, b) | ||
} | ||
} | ||
return browsers | ||
} | ||
|
||
func pickFirefox(name, profile string) []browser.Browser { | ||
var browsers []browser.Browser | ||
name = strings.ToLower(name) | ||
if name == "all" || name == "firefox" { | ||
for _, v := range firefoxList { | ||
if profile == "" { | ||
profile = v.profilePath | ||
} else { | ||
profile = fileutil.ParentDir(profile) | ||
} | ||
if !fileutil.FolderExists(filepath.Clean(profile)) { | ||
log.Noticef("find browser firefox %s failed, profile folder does not exist", v.name) | ||
continue | ||
} | ||
if multiFirefox, err := firefox.New(v.name, v.storage, profile, v.items); err == nil { | ||
for _, b := range multiFirefox { | ||
log.Noticef("find browser firefox %s success", b.Name()) | ||
browsers = append(browsers, b) | ||
} | ||
} else { | ||
log.Error(err) | ||
} | ||
} | ||
return browsers | ||
} | ||
return nil | ||
} | ||
|
||
func ListBrowsers() []string { | ||
var l []string | ||
l = append(l, typeutil.Keys(chromiumList)...) | ||
l = append(l, typeutil.Keys(firefoxList)...) | ||
sort.Strings(l) | ||
return l | ||
} | ||
|
||
// home dir path for all platforms | ||
var homeDir, _ = os.UserHomeDir() | ||
|
||
const ( | ||
chromeName = "Chrome" | ||
chromeBetaName = "Chrome Beta" | ||
chromiumName = "Chromium" | ||
edgeName = "Microsoft Edge" | ||
braveName = "Brave" | ||
operaName = "Opera" | ||
operaGXName = "OperaGX" | ||
vivaldiName = "Vivaldi" | ||
coccocName = "CocCoc" | ||
yandexName = "Yandex" | ||
firefoxName = "Firefox" | ||
speed360Name = "360speed" | ||
qqBrowserName = "QQ" | ||
) |
2 changes: 1 addition & 1 deletion
2
internal/browser/browser_darwin.go → internal/provider/provider_darwin.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
//go:build darwin | ||
|
||
package browser | ||
package provider | ||
|
||
import ( | ||
"hack-browser-data/internal/item" | ||
|
Oops, something went wrong.