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 (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/historyposter/process"
|
"git.eeqj.de/sneak/historyposter/hp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// these are filled in at link-time by the build scripts
|
// these are filled in at link-time by the build scripts
|
||||||
@ -15,5 +15,5 @@ var Version string
|
|||||||
var Buildarch string
|
var Buildarch string
|
||||||
|
|
||||||
func main() {
|
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"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/k0kubun/pp"
|
"github.com/k0kubun/pp"
|
||||||
@ -19,27 +21,33 @@ func CLIEntry(version, buildarch string) int {
|
|||||||
hp.version = version
|
hp.version = version
|
||||||
hp.buildarch = buildarch
|
hp.buildarch = buildarch
|
||||||
hp.startup = time.Now()
|
hp.startup = time.Now()
|
||||||
|
hp.newUrlChan = make(chan string)
|
||||||
|
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal)
|
||||||
signal.Notify(c, os.Interrupt)
|
signal.Ignore(syscall.SIGPIPE)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
hp.configure()
|
hp.configure()
|
||||||
hp.setupLogging()
|
hp.setupLogging()
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
hp.appCtx, hp.shutdownFunc = context.WithCancel(context.Background())
|
||||||
go func() {
|
go func() {
|
||||||
// this sits and waits for an interrupt to be received
|
// this sits and waits for an interrupt to be received
|
||||||
sig := <-c
|
sig := <-c
|
||||||
log.Info().Msgf("signal received: %+v", sig)
|
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 {
|
type HistoryPoster struct {
|
||||||
version string
|
version string
|
||||||
buildarch string
|
buildarch string
|
||||||
startup time.Time
|
startup time.Time
|
||||||
|
appCtx context.Context
|
||||||
|
shutdownFunc context.CancelFunc
|
||||||
|
newUrlChan chan string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hp *HistoryPoster) configure() {
|
func (hp *HistoryPoster) configure() {
|
||||||
@ -70,6 +78,11 @@ func (hp *HistoryPoster) configure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (hp *HistoryPoster) runForever(ctx context.Context) int {
|
func (hp *HistoryPoster) runForever(ctx context.Context) int {
|
||||||
|
|
||||||
|
log.Info().Msg("this is where i do stuff")
|
||||||
|
|
||||||
|
_ = findHistoryFiles()
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
log.Info().Msgf("shutting down")
|
log.Info().Msgf("shutting down")
|
||||||
return 0
|
return 0
|
||||||
@ -107,5 +120,6 @@ func (hp *HistoryPoster) identify() {
|
|||||||
log.Info().
|
log.Info().
|
||||||
Str("version", hp.version).
|
Str("version", hp.version).
|
||||||
Str("buildarch", hp.buildarch).
|
Str("buildarch", hp.buildarch).
|
||||||
|
Str("os", runtime.GOOS).
|
||||||
Msg("starting")
|
Msg("starting")
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user