83 lines
1.5 KiB
Go
83 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"kvmote/internal/input"
|
|
"kvmote/internal/kvm"
|
|
"kvmote/internal/transport"
|
|
)
|
|
|
|
// App struct
|
|
type App struct {
|
|
ctx context.Context
|
|
engine *kvm.Engine
|
|
}
|
|
|
|
// NewApp creates a new App application struct
|
|
func NewApp() *App {
|
|
t := transport.NewBleTransport()
|
|
h := input.NewInputHandler()
|
|
e := kvm.NewEngine(t, h)
|
|
return &App{
|
|
engine: e,
|
|
}
|
|
}
|
|
|
|
// startup is called when the app starts. The context is saved
|
|
// so we can call the runtime methods
|
|
func (a *App) startup(ctx context.Context) {
|
|
a.ctx = ctx
|
|
err := a.engine.Start(ctx)
|
|
if err != nil {
|
|
fmt.Printf("Error starting engine: %v\n", err)
|
|
}
|
|
}
|
|
|
|
func (a *App) Connect() string {
|
|
err := a.engine.Start(a.ctx)
|
|
if err != nil {
|
|
return fmt.Sprintf("Erro Hook: %v", err)
|
|
}
|
|
|
|
// Lógica real de conexão Bluetooth
|
|
ctx, cancel := context.WithTimeout(a.ctx, 10*time.Second)
|
|
defer cancel()
|
|
|
|
ok, err := a.engine.Transport().Detect(ctx)
|
|
if err != nil || !ok {
|
|
return "Erro: KVMote não encontrado"
|
|
}
|
|
|
|
err = a.engine.Transport().Connect(ctx)
|
|
if err != nil {
|
|
return fmt.Sprintf("Erro Conexão: %v", err)
|
|
}
|
|
|
|
return "Conectado"
|
|
}
|
|
|
|
func (a *App) Disconnect() string {
|
|
a.engine.Transport().Disconnect()
|
|
return "Desconectado"
|
|
}
|
|
|
|
func (a *App) SendCtrlAltDel() {
|
|
kvm.LogDebug("App: Chamando SendCtrlAltDel")
|
|
a.engine.SendCtrlAltDel()
|
|
}
|
|
|
|
func (a *App) ChangeLayout(layout int) {
|
|
a.engine.SetLayout(layout)
|
|
}
|
|
|
|
func (a *App) SetPosition(pos int) {
|
|
a.engine.SetPosition(pos)
|
|
}
|
|
|
|
func (a *App) HandleScroll(delta int) {
|
|
a.engine.HandleManualScroll(delta)
|
|
}
|