@@ -2,6 +2,7 @@ package browser
22
33import (
44 "os"
5+ "path/filepath"
56 "strings"
67
78 "hack-browser-data/internal/browingdata"
@@ -42,32 +43,30 @@ func pickChromium(name, profile string) []Browser {
4243 // TODO: add support for 「all」 flag and set profilePath
4344 if name == "all" {
4445 for _ , v := range chromiumList {
46+ if ! fileutil .FolderExists (filepath .Clean (v .profilePath )) {
47+ log .Noticef ("find browser %s failed, profile folder is not exist" , v .name )
48+ continue
49+ }
4550 if b , err := chromium .New (v .name , v .storage , v .profilePath , v .items ); err == nil {
4651 log .Noticef ("find browser %s success" , b .Name ())
4752 browsers = append (browsers , b )
4853 } else {
49- if err == chromium .ErrProfilePathNotFound {
50- log .Errorf ("find browser %s failed, profile folder is not exist, maybe not installed" , v .name )
51- continue
52- } else {
53- log .Errorf ("new chromium error: %s" , err .Error ())
54- }
54+ log .Errorf ("new chromium error: %s" , err .Error ())
5555 }
5656 }
5757 }
5858 if c , ok := chromiumList [name ]; ok {
5959 if profile == "" {
6060 profile = c .profilePath
6161 }
62+ if ! fileutil .FolderExists (filepath .Clean (profile )) {
63+ log .Fatalf ("find browser %s failed, profile folder is not exist" , c .name )
64+ }
6265 b , err := chromium .New (c .name , c .storage , profile , c .items )
6366 if err != nil {
64- if err == chromium .ErrProfilePathNotFound {
65- log .Fatalf ("find browser %s failed, profile folder is not exist, maybe not installed" , c .name )
66- } else {
67- log .Fatalf ("new chromium error:" , err )
68- return nil
69- }
67+ log .Fatalf ("new chromium error:" , err )
7068 }
69+ log .Noticef ("find browser %s success" , b .Name ())
7170 browsers = append (browsers , b )
7271 }
7372 return browsers
@@ -83,17 +82,17 @@ func pickFirefox(name, profile string) []Browser {
8382 } else {
8483 profile = fileutil .ParentDir (profile )
8584 }
85+ if ! fileutil .FolderExists (filepath .Clean (profile )) {
86+ log .Noticef ("find browser firefox %s failed, profile folder is not exist" , v .name )
87+ continue
88+ }
8689 if multiFirefox , err := firefox .New (v .name , v .storage , profile , v .items ); err == nil {
8790 for _ , b := range multiFirefox {
8891 log .Noticef ("find browser firefox %s success" , b .Name ())
8992 browsers = append (browsers , b )
9093 }
9194 } else {
92- if err == firefox .ErrProfilePathNotFound {
93- log .Errorf ("find browser firefox %s failed, profile folder is not exist" , v .name )
94- } else {
95- log .Error (err )
96- }
95+ log .Error (err )
9796 }
9897 }
9998 return browsers
0 commit comments