firefox: clean + refactor names

This commit is contained in:
blob42 2023-09-05 22:28:26 +02:00
parent f2dbe0b088
commit 788fef46a0
3 changed files with 29 additions and 30 deletions

View File

@ -120,12 +120,8 @@ func startDaemon(c *cli.Context) error {
log.Criticalf("module <%s> is not a BrowserModule", mod.ID)
}
//WIP: Handle multiple profiles for modules who announce it - here ?
// Check if browser implements ProfileManager
//WIP: global flag for watch all
// Check if watch all profiles is defined
// if defined then spawn a new browser module for each profile
// if the module is a profile manager and is watching all profiles
// call RunModule for each profile
bpm, ok := browser.(profiles.ProfileManager)
if ok {
if bpm.WatchAllProfiles() {

View File

@ -21,7 +21,7 @@ import (
const (
BrowserName = "firefox"
FirefoxConfigDir = "$HOME/.mozilla/firefox"
FirefoxBaseDir = "$HOME/.mozilla/firefox"
DefaultProfile = "default"
)
@ -65,12 +65,6 @@ var (
}
)
func init() {
config.RegisterConfigurator(BrowserName, FFConfig)
//BUG: initFirefoxConfig is is called too early
config.RegisterConfReadyHooks(initFirefoxConfig)
}
// FirefoxConfig implements the Configurator interface
// which allows it to register and set field through the Configurator.
//
@ -139,7 +133,7 @@ func initFirefoxConfig(c *cli.Context) error {
pm := FirefoxProfileManager
// expand path to config dir
pm.ConfigDir = filepath.Join(os.ExpandEnv(FirefoxConfigDir))
pm.ConfigDir = filepath.Join(os.ExpandEnv(FirefoxBaseDir))
// Check if base folder exists
configFolderExists, err := utils.CheckDirExists(pm.ConfigDir)
@ -170,3 +164,10 @@ func initFirefoxConfig(c *cli.Context) error {
log.Debugf("Using profile %s", bookmarkDir)
return nil
}
func init() {
config.RegisterConfigurator(BrowserName, FFConfig)
//BUG: initFirefoxConfig is is called too early
config.RegisterConfReadyHooks(initFirefoxConfig)
}

View File

@ -65,7 +65,7 @@ type Firefox struct {
// internal folder map used for scanning
folderScanMap map[sqlid]*MozFolder
lastRunTime time.Time
lastRunAt time.Time
}
@ -216,16 +216,6 @@ func (f *Firefox) scanModifiedBookmarks(since timestamp) ([]*MozBookmark, error)
return bookmarks, err
}
// init is required to register the module as a plugin when it is imported
func init() {
modules.RegisterBrowser(Firefox{FirefoxConfig: FFConfig})
//TIP: cmd.RegisterModCommand(BrowserName, &cli.Command{
// Name: "test",
// })
// cmd.RegisterModCommand(BrowserName, &cli.Command{
// Name: "test2",
// })
}
func NewFirefox() *Firefox {
return &Firefox{
@ -342,7 +332,7 @@ func (f *Firefox) Load() error {
f.loadBookmarksToTree(bookmarks)
f.LastFullTreeParseTime = time.Since(start)
f.lastRunTime = time.Now().UTC()
f.lastRunAt = time.Now().UTC()
log.Debugf("parsed %d bookmarks and %d nodes in %s",
f.CurrentUrlCount,
@ -392,10 +382,10 @@ func (ff *Firefox) Run() {
defer pc.Clean()
log.Debugf("Checking changes since <%d> %s",
ff.lastRunTime.UTC().UnixNano()/1000,
ff.lastRunTime.Local().Format("Mon Jan 2 15:04:05 MST 2006"))
ff.lastRunAt.UTC().UnixNano()/1000,
ff.lastRunAt.Local().Format("Mon Jan 2 15:04:05 MST 2006"))
scanSince := ff.lastRunTime.UTC().UnixNano() / 1000
scanSince := ff.lastRunAt.UTC().UnixNano() / 1000
bookmarks, err := ff.scanModifiedBookmarks(scanSince)
if err != nil {
@ -408,8 +398,9 @@ func (ff *Firefox) Run() {
ff.BufferDB.SyncTo(database.Cache.DB)
database.Cache.DB.SyncToDisk(database.GetDBFullPath())
//TODO!: is LastWatchRunTime alone enough ?
ff.LastWatchRunTime = time.Since(startRun)
ff.lastRunTime = time.Now().UTC()
ff.lastRunAt = time.Now().UTC()
}
// Implement moduls.Shutdowner
@ -655,3 +646,14 @@ func (f *Firefox) initPlacesCopy() (mozilla.PlaceCopyJob, error) {
return pc, nil
}
// init is required to register the module as a plugin when it is imported
func init() {
modules.RegisterBrowser(Firefox{FirefoxConfig: FFConfig})
//TIP: cmd.RegisterModCommand(BrowserName, &cli.Command{
// Name: "test",
// })
// cmd.RegisterModCommand(BrowserName, &cli.Command{
// Name: "test2",
// })
}