feat(linux): the Go half of OpsLog builds for Linux

Measured rather than guessed: the whole repository was cross-compiled for
linux/amd64 and the gaps closed one by one. There were fewer than expected.

Flex and TCI were never Windows-specific — they carried //go:build windows by
inheritance and import nothing but net and gorilla/websocket. Untagged, no code
change. The two backends a Linux operator is most likely to own were already
portable.

Audio was 560 lines, not 2287: only devices.go and engine.go touch WASAPI, while
manager.go, recorder.go, wav.go and mp3.go were pure Go wearing the tag by
association. The whole platform surface is seven functions, now implemented a
second time on PulseAudio through github.com/jfreymuth/pulse — pure Go over the
server socket, so the no-cgo rule survives, and PipeWire answers the same
protocol. The fixed 16 kHz mono format and the server-side resampling mirror
what AUTOCONVERTPCM does on Windows, for the same reason.

OmniRig is the only real loss, and its backend still EXISTS off Windows rather
than being compiled out of app.go: a settings database is portable, so an
operator moving a profile across keeps "omnirig" saved and must be told to pick
a native backend instead of meeting a nil one.

The parts where Linux is not Windows, and where a compile-only stub would have
been a silent bug:

  - data dir: still beside the binary, but ~/.local/share/OpsLog/data when that
    folder belongs to the system — decided by trying the write, because /opt and
    /usr/local are writable on some stations and not others.
  - single instance: an flock, not a pid file. The kernel drops it however the
    process dies, so a crash leaves nothing to delete by hand. This is the guard
    that stops two instances fighting over the rig frequency.
  - update: simpler here. Unix renames over a running binary, so the deferred
    swap the Windows path needs a detached helper for is unreachable.
  - tasklist/taskkill become /proc and SIGTERM; the boot log moves out of /tmp,
    which is wiped exactly when the evidence is wanted.
  - serial ports sorted naturally: /dev/ttyUSB10 was landing between USB1 and
    USB2, the same trap COM10 fell into.

release.ps1 now cross-builds and vets for linux before it builds the exe, and
refuses the release if that fails — a port rots one unguarded x/sys/windows call
at a time.

Nothing has been executed on Linux yet: Wails needs webkit2gtk and cgo there, so
the binary must be built on Linux. scripts/linux-setup.sh checks the machine and
does it; BUILDING-LINUX.md is the manual version.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
2026-09-09 10:21:27 +02:00
co-authored by Claude Opus 5
parent f05e6290df
commit 8b1dff581b
48 changed files with 1456 additions and 251 deletions
-2
View File
@@ -1,5 +1,3 @@
//go:build windows
package cat
import (
+1 -5
View File
@@ -1,5 +1,3 @@
//go:build windows
package cat
import (
@@ -9,8 +7,6 @@ import (
"strconv"
"syscall"
"time"
"golang.org/x/sys/windows"
)
// FlexRadio is one radio found by discovery.
@@ -38,7 +34,7 @@ func DiscoverFlex(timeout time.Duration) ([]FlexRadio, error) {
Control: func(_, _ string, c syscall.RawConn) error {
var serr error
_ = c.Control(func(fd uintptr) {
serr = windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_REUSEADDR, 1)
serr = setSocketReuse(fd)
})
return serr
},
+2
View File
@@ -1,3 +1,5 @@
//go:build windows
package cat
import (
+2
View File
@@ -1,3 +1,5 @@
//go:build windows
package cat
import (
+2
View File
@@ -1,3 +1,5 @@
//go:build windows
package cat
import (
+34
View File
@@ -0,0 +1,34 @@
//go:build !windows
package cat
import "errors"
// OmniRig is COM automation against a Windows-only application, so off Windows
// there is nothing to talk to. The backend still EXISTS here rather than being
// compiled out of app.go, because a settings database is portable: an operator
// who moves a profile from Windows to Linux keeps "omnirig" as their saved CAT
// backend, and OpsLog must start and say why the rig is silent instead of
// failing to build or panicking on a nil backend.
//
// The fix for those operators is a native backend (Icom, Yaesu, Kenwood/
// Elecraft, Flex, TCI, Xiegu all speak to the radio directly) or Hamlib.
type OmniRig struct{ CWLower bool }
var errOmniRigWindowsOnly = errors.New("OmniRig runs only on Windows — pick a native CAT backend (Icom, Yaesu, Kenwood/Elecraft, FlexRadio, TCI, Xiegu) in Settings ▸ CAT")
func NewOmniRig(rigNum int, forceVFO string, cwLower bool) *OmniRig {
return &OmniRig{CWLower: cwLower}
}
func (o *OmniRig) Name() string { return "omnirig" }
func (o *OmniRig) Connect() error { return errOmniRigWindowsOnly }
func (o *OmniRig) Disconnect() {}
func (o *OmniRig) ReadState() (RigState, error) { return RigState{}, errOmniRigWindowsOnly }
func (o *OmniRig) SetFrequency(hz int64) error { return errOmniRigWindowsOnly }
func (o *OmniRig) SetMode(mode string) error { return errOmniRigWindowsOnly }
func (o *OmniRig) SetPTT(on bool) error { return errOmniRigWindowsOnly }
// SetCWLower satisfies OmniRigController so the preference push at startup is a
// no-op here rather than a "backend does not support this" error in the log.
func (o *OmniRig) SetCWLower(on bool) { o.CWLower = on }
+2
View File
@@ -1,3 +1,5 @@
//go:build windows
package cat
import "testing"
+16
View File
@@ -0,0 +1,16 @@
//go:build !windows
package cat
import "golang.org/x/sys/unix"
// setSocketReuse is the Unix half of the Windows SO_REUSEADDR above. Linux
// wants SO_REUSEPORT as well before two processes may share a bound UDP port;
// it is not defined on every Unix, so a refusal there is ignored.
func setSocketReuse(fd uintptr) error {
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); err != nil {
return err
}
_ = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
return nil
}
+14
View File
@@ -0,0 +1,14 @@
//go:build windows
package cat
import "golang.org/x/sys/windows"
// setSocketReuse enables SO_REUSEADDR before bind, so discovery can listen on
// :4992 while SmartSDR is already listening for the same radio broadcast.
// Without it the second bind fails with WSAEADDRINUSE and the operator has to
// type the radio's IP by hand.
func setSocketReuse(fd uintptr) error {
return windows.SetsockoptInt(windows.Handle(fd),
windows.SOL_SOCKET, windows.SO_REUSEADDR, 1)
}
-2
View File
@@ -1,5 +1,3 @@
//go:build windows
package cat
import (
-2
View File
@@ -1,5 +1,3 @@
//go:build windows
package cat
// TCI audio — receiving the radio's audio over the same WebSocket that carries
-2
View File
@@ -1,5 +1,3 @@
//go:build windows
package cat
import "fmt"
-2
View File
@@ -1,5 +1,3 @@
//go:build windows
package cat
// The TCI control panel: what the radio already tells us, gathered up.
-2
View File
@@ -1,5 +1,3 @@
//go:build windows
package cat
import "testing"
-2
View File
@@ -1,5 +1,3 @@
//go:build windows
package cat
import "testing"