mirror of
https://github.com/Mikescher/kpsync.git
synced 2025-10-14 08:45:08 +02:00
non-functional wip state
This commit is contained in:
73
app/application.go
Normal file
73
app/application.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"fyne.io/systray"
|
||||
"mikescher.com/kpsync"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
config kpsync.Config
|
||||
|
||||
trayReady bool
|
||||
sigStopChan chan bool
|
||||
sigErrChan chan error
|
||||
|
||||
dbFile string
|
||||
stateFile string
|
||||
}
|
||||
|
||||
func NewApplication() *Application {
|
||||
|
||||
cfg := kpsync.LoadConfig()
|
||||
|
||||
return &Application{
|
||||
config: cfg,
|
||||
trayReady: false,
|
||||
sigStopChan: make(chan bool, 128),
|
||||
sigErrChan: make(chan error, 128),
|
||||
}
|
||||
}
|
||||
|
||||
func (app *Application) Run() {
|
||||
|
||||
go func() { app.initTray() }()
|
||||
|
||||
go func() {
|
||||
err := app.initSync()
|
||||
if err != nil {
|
||||
app.sigErrChan <- err
|
||||
return
|
||||
}
|
||||
err = app.runSyncLoop()
|
||||
if err != nil {
|
||||
app.sigErrChan <- err
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
sigTerm := make(chan os.Signal, 1)
|
||||
signal.Notify(sigTerm, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
select {
|
||||
case <-sigTerm:
|
||||
|
||||
// TODO term
|
||||
|
||||
case _ = <-app.sigErrChan:
|
||||
|
||||
// TODO stop
|
||||
|
||||
case _ = <-app.sigStopChan:
|
||||
|
||||
// TODO stop
|
||||
}
|
||||
|
||||
if app.trayReady {
|
||||
systray.Quit()
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user