This commit is contained in:
parent
699dc378a9
commit
da09de0293
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
debug.log
|
||||
historyposter
|
@ -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))
|
||||
}
|
||||
|
23
hp/detector.go
Normal file
23
hp/detector.go
Normal file
@ -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
|
||||
}
|
@ -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")
|
||||
}
|
Loading…
Reference in New Issue
Block a user