feat: Added --profile argument to start OpsLog on specific profile

This commit is contained in:
2026-06-20 19:47:22 +02:00
parent 4b5e2e0b72
commit 260172cd6d
2 changed files with 42 additions and 0 deletions
+17
View File
@@ -383,6 +383,7 @@ type App struct {
cwStop chan struct{} // stops the CW decoder capture loop; nil when off cwStop chan struct{} // stops the CW decoder capture loop; nil when off
cwDecoder *cwdecode.Decoder // live decoder (for retargeting the pitch) cwDecoder *cwdecode.Decoder // live decoder (for retargeting the pitch)
cwPitchHz int // manual pitch override (0 = auto / follow Flex) cwPitchHz int // manual pitch override (0 = auto / follow Flex)
startupProfile string // --profile <name> from the command line (activate at startup)
dvkRecSlot int // slot currently being recorded (DVKStartRecord → DVKStopRecord) dvkRecSlot int // slot currently being recorded (DVKStartRecord → DVKStopRecord)
dvkPttKeyed bool // we keyed PTT for a voice message; unkey when it ends dvkPttKeyed bool // we keyed PTT for a voice message; unkey when it ends
pttMu sync.Mutex pttMu sync.Mutex
@@ -613,6 +614,22 @@ func (a *App) startup(ctx context.Context) {
if err != nil { if err != nil {
fmt.Println("OpsLog: EnsureDefault profile:", err) fmt.Println("OpsLog: EnsureDefault profile:", err)
} }
// A "--profile <name>" command-line argument selects which profile to start
// on (so a desktop shortcut can launch OpsLog straight into F4BPO or TM2Q).
// Match by name, case-insensitive; activate it before any per-profile wiring.
if want := strings.TrimSpace(a.startupProfile); want != "" {
if list, lerr := a.profiles.List(a.ctx); lerr == nil {
for _, p := range list {
if strings.EqualFold(p.Name, want) {
if serr := a.profiles.SetActive(a.ctx, p.ID); serr == nil {
active = p
fmt.Printf("OpsLog: started on profile %q (from --profile)\n", p.Name)
}
break
}
}
}
}
a.settings.SetProfile(active.ID) a.settings.SetProfile(active.ID)
a.awardRefs = awardref.NewRepo(conn) a.awardRefs = awardref.NewRepo(conn)
a.qslTemplates = qslcard.NewRepo(conn) a.qslTemplates = qslcard.NewRepo(conn)
+25
View File
@@ -2,6 +2,8 @@ package main
import ( import (
"embed" "embed"
"os"
"strings"
"github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options" "github.com/wailsapp/wails/v2/pkg/options"
@@ -11,9 +13,32 @@ import (
//go:embed all:frontend/dist //go:embed all:frontend/dist
var assets embed.FS var assets embed.FS
// profileArg extracts a profile name from the command line. Accepts
// "--profile NAME", "--profile=NAME", "-profile NAME", "-p NAME" so a desktop
// shortcut can launch OpsLog straight into a given profile (e.g. F4BPO / TM2Q).
func profileArg(args []string) string {
for i := 0; i < len(args); i++ {
a := args[i]
switch {
case a == "--profile" || a == "-profile" || a == "-p":
if i+1 < len(args) {
return strings.TrimSpace(args[i+1])
}
case strings.HasPrefix(a, "--profile="):
return strings.TrimSpace(strings.TrimPrefix(a, "--profile="))
case strings.HasPrefix(a, "-profile="):
return strings.TrimSpace(strings.TrimPrefix(a, "-profile="))
case strings.HasPrefix(a, "-p="):
return strings.TrimSpace(strings.TrimPrefix(a, "-p="))
}
}
return ""
}
func main() { func main() {
// Create an instance of the app structure // Create an instance of the app structure
app := NewApp() app := NewApp()
app.startupProfile = profileArg(os.Args[1:])
// Create application with options // Create application with options
err := wails.Run(&options.App{ err := wails.Run(&options.App{