From da09de029384660e5427247155599459311d3b1b Mon Sep 17 00:00:00 2001 From: sneak Date: Mon, 21 Sep 2020 14:44:29 -0700 Subject: [PATCH] little bit of progress --- .gitignore | 2 ++ cmd/historyposter/main.go | 4 ++-- hp/detector.go | 23 +++++++++++++++++++++++ {process => hp}/historyposter.go | 30 ++++++++++++++++++++++-------- 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 .gitignore create mode 100644 hp/detector.go rename {process => hp}/historyposter.go (78%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3330b02 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +debug.log +historyposter diff --git a/cmd/historyposter/main.go b/cmd/historyposter/main.go index cdaa758..94df5ec 100644 --- a/cmd/historyposter/main.go +++ b/cmd/historyposter/main.go @@ -3,7 +3,7 @@ package main import ( "os" - "git.eeqj.de/sneak/historyposter/process" + "git.eeqj.de/sneak/historyposter/hp" ) // these are filled in at link-time by the build scripts @@ -15,5 +15,5 @@ var Version string var Buildarch string func main() { - os.Exit(process.CLIEntry(Version, Buildarch)) + os.Exit(hp.CLIEntry(Version, Buildarch)) } diff --git a/hp/detector.go b/hp/detector.go new file mode 100644 index 0000000..2e0c4b6 --- /dev/null +++ b/hp/detector.go @@ -0,0 +1,23 @@ +package process + +import ( + "os" + "path/filepath" +) + +func findHistoryFiles() []string { + //FIXME make this support safari one day + home := os.Getenv("HOME") + chromeDir := home + "/Library/Application Support/Google/Chrome" + defaultProfileDir := chromeDir + "/Default" + output := make([]string, 0) + output = append(output, defaultProfileDir+"/History") + otherProfiles, err := filepath.Glob(chromeDir + "/Profile *") + if err != nil { + return output + } + for _, v := range otherProfiles { + output = append(output, v+"/History") + } + return output +} diff --git a/process/historyposter.go b/hp/historyposter.go similarity index 78% rename from process/historyposter.go rename to hp/historyposter.go index 5912557..2f2fae6 100644 --- a/process/historyposter.go +++ b/hp/historyposter.go @@ -4,6 +4,8 @@ import ( "context" "os" "os/signal" + "runtime" + "syscall" "time" "github.com/k0kubun/pp" @@ -19,27 +21,33 @@ func CLIEntry(version, buildarch string) int { hp.version = version hp.buildarch = buildarch hp.startup = time.Now() + hp.newUrlChan = make(chan string) - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) + c := make(chan os.Signal) + signal.Ignore(syscall.SIGPIPE) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) hp.configure() hp.setupLogging() - ctx, cancel := context.WithCancel(context.Background()) + hp.appCtx, hp.shutdownFunc = context.WithCancel(context.Background()) go func() { // this sits and waits for an interrupt to be received sig := <-c log.Info().Msgf("signal received: %+v", sig) - cancel() + hp.shutdownFunc() }() - return hp.runForever(ctx) + return hp.runForever(hp.appCtx) } +// HistoryPoster is the main app framework object type HistoryPoster struct { - version string - buildarch string - startup time.Time + version string + buildarch string + startup time.Time + appCtx context.Context + shutdownFunc context.CancelFunc + newUrlChan chan string } func (hp *HistoryPoster) configure() { @@ -70,6 +78,11 @@ func (hp *HistoryPoster) configure() { } func (hp *HistoryPoster) runForever(ctx context.Context) int { + + log.Info().Msg("this is where i do stuff") + + _ = findHistoryFiles() + <-ctx.Done() log.Info().Msgf("shutting down") return 0 @@ -107,5 +120,6 @@ func (hp *HistoryPoster) identify() { log.Info(). Str("version", hp.version). Str("buildarch", hp.buildarch). + Str("os", runtime.GOOS). Msg("starting") }