more nil pointer checks, fix firefox hook calling
This commit is contained in:
parent
535b287842
commit
27e8e28920
@ -154,6 +154,7 @@ func (f *Firefox) loadBookmarksToTree(bookmarks []*MozBookmark) {
|
|||||||
if fOk {
|
if fOk {
|
||||||
tree.AddChild(folderNode, urlNode)
|
tree.AddChild(folderNode, urlNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,9 +432,11 @@ func (f *Firefox) Shutdown() error {
|
|||||||
func (f *Firefox) addURLNode(url, title, desc string) (bool, *tree.Node) {
|
func (f *Firefox) addURLNode(url, title, desc string) (bool, *tree.Node) {
|
||||||
|
|
||||||
var urlNode *tree.Node
|
var urlNode *tree.Node
|
||||||
iUrlNode, exists := f.URLIndex.Get(url)
|
var created bool
|
||||||
|
|
||||||
|
iURLNode, exists := f.URLIndex.Get(url)
|
||||||
if !exists {
|
if !exists {
|
||||||
urlNode := &tree.Node{
|
urlNode = &tree.Node{
|
||||||
Name: title,
|
Name: title,
|
||||||
Type: tree.URLNode,
|
Type: tree.URLNode,
|
||||||
URL: url,
|
URL: url,
|
||||||
@ -445,20 +448,23 @@ func (f *Firefox) addURLNode(url, title, desc string) (bool, *tree.Node) {
|
|||||||
f.URLIndexList = append(f.URLIndexList, url)
|
f.URLIndexList = append(f.URLIndexList, url)
|
||||||
f.CurrentNodeCount++
|
f.CurrentNodeCount++
|
||||||
|
|
||||||
// Call hooks
|
created = true
|
||||||
//TEST:
|
|
||||||
err := f.CallHooks(urlNode)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("error calling hooks for <%s>: %s", url, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return true, urlNode
|
|
||||||
} else {
|
} else {
|
||||||
urlNode = iUrlNode.(*tree.Node)
|
urlNode = iURLNode.(*tree.Node)
|
||||||
|
//TEST:
|
||||||
|
// update title and desc
|
||||||
|
urlNode.Name = title
|
||||||
|
urlNode.Desc = desc
|
||||||
}
|
}
|
||||||
|
|
||||||
return false, urlNode
|
// Call hooks
|
||||||
|
err := f.CallHooks(urlNode)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("error calling hooks for <%s>: %s", url, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return created, urlNode
|
||||||
}
|
}
|
||||||
|
|
||||||
// adds a new tagNode if it is not yet in the tagMap
|
// adds a new tagNode if it is not yet in the tagMap
|
||||||
@ -603,9 +609,9 @@ func loadBookmarks(f *Firefox) {
|
|||||||
*/
|
*/
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var url, title, tagTitle, desc string
|
var url, title, tagTitle, desc string
|
||||||
var tagId sqlid
|
var tagID sqlid
|
||||||
|
|
||||||
err = rows.Scan(&url, &title, &desc, &tagId, &tagTitle)
|
err = rows.Scan(&url, &title, &desc, &tagID, &tagTitle)
|
||||||
// log.Debugf("%s|%s|%s|%d|%s", url, title, desc, tagId, tagTitle)
|
// log.Debugf("%s|%s|%s|%d|%s", url, title, desc, tagId, tagTitle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@ -666,7 +672,7 @@ func (f *Firefox) initPlacesCopy() (mozilla.PlaceCopyJob, error) {
|
|||||||
|
|
||||||
// init is required to register the module as a plugin when it is imported
|
// init is required to register the module as a plugin when it is imported
|
||||||
func init() {
|
func init() {
|
||||||
// modules.RegisterBrowser(Firefox{FirefoxConfig: FFConfig})
|
modules.RegisterBrowser(Firefox{FirefoxConfig: FFConfig})
|
||||||
//TIP: cmd.RegisterModCommand(BrowserName, &cli.Command{
|
//TIP: cmd.RegisterModCommand(BrowserName, &cli.Command{
|
||||||
// Name: "test",
|
// Name: "test",
|
||||||
// })
|
// })
|
||||||
|
@ -114,8 +114,13 @@ func (b BrowserConfig) BookmarkDir() (string, error) {
|
|||||||
// usually done within the parsing logic of a browser module, typically in the
|
// usually done within the parsing logic of a browser module, typically in the
|
||||||
// Run() method.
|
// Run() method.
|
||||||
func (b BrowserConfig) CallHooks(node *tree.Node) error {
|
func (b BrowserConfig) CallHooks(node *tree.Node) error {
|
||||||
|
|
||||||
|
if node == nil {
|
||||||
|
return fmt.Errorf("hook node is nil")
|
||||||
|
}
|
||||||
|
|
||||||
for _, hook := range b.hooks {
|
for _, hook := range b.hooks {
|
||||||
log.Debugf("calling hook <%s> on node", hook.Name)
|
log.Debugf("<%s> calling hook <%s> on node <%s>",b.Name, hook.Name, node.URL)
|
||||||
if err := hook.Func(node); err != nil {
|
if err := hook.Func(node); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,11 @@ func ParseTags(node *Node) error {
|
|||||||
|
|
||||||
matches := regex.FindAllStringSubmatch(node.Name, -1)
|
matches := regex.FindAllStringSubmatch(node.Name, -1)
|
||||||
for _, m := range matches {
|
for _, m := range matches {
|
||||||
node.Tags = append(node.Tags, m[1])
|
if node.Tags == nil {
|
||||||
|
node.Tags = []string{m[1]}
|
||||||
|
} else {
|
||||||
|
node.Tags = append(node.Tags, m[1])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//res := regex.FindAllStringSubmatch(bk.Metadata, -1)
|
//res := regex.FindAllStringSubmatch(bk.Metadata, -1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user