From 7fb1fcce68e756f3e7e5afbb04edcc648449de36 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Mon, 1 Nov 2021 09:19:12 -0700 Subject: [PATCH] Create Init() rather than using init() --- btsetup.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/btsetup.go b/btsetup.go index 8395224..9fce824 100644 --- a/btsetup.go +++ b/btsetup.go @@ -1,27 +1,27 @@ package infinitime import ( - "os/exec" - bt "github.com/muka/go-bluetooth/api" "github.com/muka/go-bluetooth/bluez/profile/adapter" ) var defaultAdapter *adapter.Adapter1 -func init() { +func Init() { // Get bluez default adapter da, err := bt.GetDefaultAdapter() if err != nil { panic(err) } - // Power on command (workaround as go-bluetooth does not have a power on function) - exec.Command("bluetoothctl", "power", "on").Start() + da.SetPowered(true) defaultAdapter = da } func Exit() error { + if defaultAdapter != nil { + defaultAdapter.Close() + } return bt.Exit() }