setup project with daemon, socket, cmd, air, notifying, state

This commit is contained in:
LeonardoTrapani
2025-08-07 00:01:49 +02:00
parent d3fc5ee3a4
commit f7936610c9
11 changed files with 457 additions and 25 deletions
+98
View File
@@ -0,0 +1,98 @@
package main
import (
"fmt"
"github.com/leonardotrapani/hyprvoice/internal/bus"
"github.com/leonardotrapani/hyprvoice/internal/hotkeydaemon"
"github.com/spf13/cobra"
)
func main() {
_ = rootCmd.Execute()
}
var rootCmd = &cobra.Command{
Use: "hyprvoice",
Short: "Voice-powered typing for Wayland/Hyprland",
}
func init() {
rootCmd.AddCommand(
serveCmd(),
toggleCmd(),
statusCmd(),
versionCmd(),
stopCmd(),
)
}
func serveCmd() *cobra.Command {
return &cobra.Command{
Use: "serve",
Short: "Run the hotkey daemon",
RunE: func(cmd *cobra.Command, args []string) error {
return (hotkeydaemon.New(nil)).Run()
},
}
}
func toggleCmd() *cobra.Command {
return &cobra.Command{
Use: "toggle",
Short: "Toggle recording on/off",
RunE: func(cmd *cobra.Command, args []string) error {
resp, err := bus.SendCommand('t')
if err != nil {
return fmt.Errorf("failed to toggle: %w", err)
}
fmt.Print(resp) // print STATUS line
return nil
},
}
}
func statusCmd() *cobra.Command {
return &cobra.Command{
Use: "status",
Short: "Get current recording status",
RunE: func(cmd *cobra.Command, args []string) error {
resp, err := bus.SendCommand('s')
if err != nil {
return fmt.Errorf("failed to get status: %w", err)
}
fmt.Print(resp) // print STATUS line
return nil
},
}
}
func versionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Get protocol version",
RunE: func(cmd *cobra.Command, args []string) error {
resp, err := bus.SendCommand('v')
if err != nil {
return fmt.Errorf("failed to get version: %w", err)
}
fmt.Print(resp) // print STATUS proto= line
return nil
},
}
}
func stopCmd() *cobra.Command {
return &cobra.Command{
Use: "stop",
Short: "Stop the hotkey daemon",
RunE: func(cmd *cobra.Command, args []string) error {
resp, err := bus.SendCommand('q')
if err != nil {
return fmt.Errorf("failed to stop daemon: %w", err)
}
fmt.Print(resp) // print OK quitting
return nil
},
}
}