The station reads ~/.funknetz.json, speaks protocol 2.0, and builds an unsigned funknetz.app. Co-authored-by: Cursor <cursoragent@cursor.com>
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"gitea.neitzel.de/konrad/funknetz/audio"
|
|
"gitea.neitzel.de/konrad/funknetz/station"
|
|
)
|
|
|
|
// App is the window's view of the station.
|
|
type App struct {
|
|
cancel context.CancelFunc
|
|
station *station.Station
|
|
}
|
|
|
|
func (a *App) startup(ctx context.Context) {
|
|
runCtx, cancel := context.WithCancel(ctx)
|
|
a.cancel = cancel
|
|
if err := audio.Start(runCtx, a.station.WriteMicrophone, a.station.TakePlayback); err != nil {
|
|
a.station.Fail("could not open the audio device")
|
|
return
|
|
}
|
|
go func() { _ = a.station.Run(runCtx) }()
|
|
}
|
|
|
|
func (a *App) shutdown(context.Context) {
|
|
if a.cancel != nil {
|
|
a.cancel()
|
|
}
|
|
}
|
|
|
|
// State returns the station state the page renders.
|
|
func (a *App) State() station.State { return a.station.State() }
|
|
|
|
// HoldButton reports that the on-screen button is held.
|
|
func (a *App) HoldButton() { a.station.HoldButton() }
|
|
|
|
// ReleaseButton reports that the on-screen button was released.
|
|
func (a *App) ReleaseButton() { a.station.ReleaseButton() }
|
|
|
|
// HoldSpace reports that Space is held.
|
|
func (a *App) HoldSpace() { a.station.HoldSpace() }
|
|
|
|
// ReleaseSpace reports that Space was released.
|
|
func (a *App) ReleaseSpace() { a.station.ReleaseSpace() }
|
|
|
|
func configPath() (string, error) {
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return filepath.Join(home, ".funknetz.json"), nil
|
|
}
|
|
|
|
func openStation() (*station.Station, error) {
|
|
path, err := configPath()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not be read")
|
|
}
|
|
return station.New(station.Options{ConfigPath: path})
|
|
}
|