feat: implement darwin launch agent (#192)
* feat: sketch out periodic command * feat: sketch out periodic command for macOS * feat: implement darwin's launch agent * refactor: better way to run on darwin Make sure we have code that builds on all platforms. * fix(run): max 10 URLs with darwin in unattended mode * feat: add support for seeing/streaming logs * feat: implement the status command and add usage hints * feat(periodic): run onboarding if needed * fix: no too confusing function names * fix: s/periodic/autorun/ Discussed earlier this morning with @hellais. * fix: we cannot show logs before Big Sur Bug reported by @hellais.
This commit is contained in:
parent
6fbad8555f
commit
504a4e79d4
7 changed files with 334 additions and 0 deletions
49
internal/autorun/autorun.go
Normal file
49
internal/autorun/autorun.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// Package autorun contains code to manage automatic runs
|
||||
package autorun
|
||||
|
||||
import "sync"
|
||||
|
||||
const (
|
||||
// StatusScheduled indicates that OONI is scheduled to run
|
||||
// periodically in the background.
|
||||
StatusScheduled = "scheduled"
|
||||
|
||||
// StatusStopped indicates that OONI is not scheduled to
|
||||
// run periodically in the background.
|
||||
StatusStopped = "stopped"
|
||||
|
||||
// StatusRunning indicates that OONI is currently
|
||||
// running in the background.
|
||||
StatusRunning = "running"
|
||||
)
|
||||
|
||||
// Manager manages automatic runs
|
||||
type Manager interface {
|
||||
LogShow() error
|
||||
LogStream() error
|
||||
Start() error
|
||||
Status() (string, error)
|
||||
Stop() error
|
||||
}
|
||||
|
||||
var (
|
||||
registry map[string]Manager
|
||||
mtx sync.Mutex
|
||||
)
|
||||
|
||||
func register(platform string, manager Manager) {
|
||||
defer mtx.Unlock()
|
||||
mtx.Lock()
|
||||
if registry == nil {
|
||||
registry = make(map[string]Manager)
|
||||
}
|
||||
registry[platform] = manager
|
||||
}
|
||||
|
||||
// Get gets the specified autorun manager. This function
|
||||
// returns nil if no autorun manager exists.
|
||||
func Get(platform string) Manager {
|
||||
defer mtx.Unlock()
|
||||
mtx.Lock()
|
||||
return registry[platform]
|
||||
}
|
||||
Loading…
Reference in a new issue