mirror of
https://github.com/onyx-and-iris/voicemeeter.git
synced 2024-11-15 17:40:51 +00:00
return err from NewRemote\
pass Kind.Name to logout update examples/tests to reflect changes
This commit is contained in:
parent
3fd08ff606
commit
6fabc43998
6
base.go
6
base.go
@ -54,14 +54,14 @@ func login(kindId string) {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Println("Logged into API")
|
fmt.Printf("Logged into Voicemeeter %s\n", kindId)
|
||||||
for pdirty() || mdirty() {
|
for pdirty() || mdirty() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// logout logs out of the API,
|
// logout logs out of the API,
|
||||||
// delayed for 100ms to allow final operation to complete.
|
// delayed for 100ms to allow final operation to complete.
|
||||||
func logout() {
|
func logout(kindId string) {
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
res, _, _ := vmLogout.Call()
|
res, _, _ := vmLogout.Call()
|
||||||
if res != 0 {
|
if res != 0 {
|
||||||
@ -69,7 +69,7 @@ func logout() {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Println("Logged out of API")
|
fmt.Printf("Logged out of Voicemeeter %s\n", kindId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// runVoicemeeter attempts to launch a Voicemeeter GUI of a kind.
|
// runVoicemeeter attempts to launch a Voicemeeter GUI of a kind.
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/voicemeeter-api-go"
|
"github.com/onyx-and-iris/voicemeeter-api-go"
|
||||||
@ -46,7 +47,13 @@ func (o observer) OnUpdate(subject string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
vm := voicemeeter.NewRemote("potato")
|
vm, err := voicemeeter.NewRemote("potato")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer vm.Logout()
|
||||||
|
|
||||||
vm.Login()
|
vm.Login()
|
||||||
// enable level updates (disabled by default)
|
// enable level updates (disabled by default)
|
||||||
vm.EventAdd("ldirty")
|
vm.EventAdd("ldirty")
|
||||||
@ -55,6 +62,4 @@ func main() {
|
|||||||
o.Register()
|
o.Register()
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
o.Deregister()
|
o.Deregister()
|
||||||
|
|
||||||
vm.Logout()
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
package voicemeeter
|
package voicemeeter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
vm = NewRemote("potato")
|
vm, err = NewRemote("potato")
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
vm.Login()
|
vm.Login()
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
vm.Logout()
|
vm.Logout()
|
||||||
|
10
remote.go
10
remote.go
@ -2,7 +2,6 @@ package voicemeeter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Remote type represents the API for a kind
|
// A Remote type represents the API for a kind
|
||||||
@ -36,7 +35,7 @@ func (r *Remote) Login() {
|
|||||||
// it also terminates the pooler
|
// it also terminates the pooler
|
||||||
func (r *Remote) Logout() {
|
func (r *Remote) Logout() {
|
||||||
r.pooler.run = false
|
r.pooler.run = false
|
||||||
logout()
|
logout(r.Kind.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type returns the type of Voicemeeter (basic, banana, potato)
|
// Type returns the type of Voicemeeter (basic, banana, potato)
|
||||||
@ -289,12 +288,11 @@ func (potb *potatoBuilder) Build() remoteBuilder {
|
|||||||
|
|
||||||
// NewRemote returns a Remote type for a kind
|
// NewRemote returns a Remote type for a kind
|
||||||
// this is the interface entry point
|
// this is the interface entry point
|
||||||
func NewRemote(kindId string) *Remote {
|
func NewRemote(kindId string) (*Remote, error) {
|
||||||
_kind, ok := kindMap[kindId]
|
_kind, ok := kindMap[kindId]
|
||||||
if !ok {
|
if !ok {
|
||||||
err := fmt.Errorf("unknown Voicemeeter kind '%s'", kindId)
|
err := fmt.Errorf("unknown Voicemeeter kind '%s'", kindId)
|
||||||
fmt.Println(err)
|
return nil, err
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
director := director{}
|
director := director{}
|
||||||
@ -307,5 +305,5 @@ func NewRemote(kindId string) *Remote {
|
|||||||
director.SetBuilder(&potatoBuilder{genericBuilder{_kind, Remote{}}})
|
director.SetBuilder(&potatoBuilder{genericBuilder{_kind, Remote{}}})
|
||||||
}
|
}
|
||||||
director.Construct()
|
director.Construct()
|
||||||
return director.Get()
|
return director.Get(), nil
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func TestGetBasicRemote(t *testing.T) {
|
func TestGetBasicRemote(t *testing.T) {
|
||||||
//t.Skip("skipping test")
|
//t.Skip("skipping test")
|
||||||
__rem := NewRemote("basic")
|
__rem, _ := NewRemote("basic")
|
||||||
t.Run("Should return a remote basic type", func(t *testing.T) {
|
t.Run("Should return a remote basic type", func(t *testing.T) {
|
||||||
assert.NotNil(t, __rem)
|
assert.NotNil(t, __rem)
|
||||||
})
|
})
|
||||||
@ -34,7 +34,7 @@ func TestGetBasicRemote(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetBananaRemote(t *testing.T) {
|
func TestGetBananaRemote(t *testing.T) {
|
||||||
//t.Skip("skipping test")
|
//t.Skip("skipping test")
|
||||||
__rem := NewRemote("banana")
|
__rem, _ := NewRemote("banana")
|
||||||
t.Run("Should return a remote banana type", func(t *testing.T) {
|
t.Run("Should return a remote banana type", func(t *testing.T) {
|
||||||
assert.NotNil(t, __rem)
|
assert.NotNil(t, __rem)
|
||||||
})
|
})
|
||||||
@ -60,7 +60,7 @@ func TestGetBananaRemote(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetPotatoRemote(t *testing.T) {
|
func TestGetPotatoRemote(t *testing.T) {
|
||||||
//t.Skip("skipping test")
|
//t.Skip("skipping test")
|
||||||
__rem := NewRemote("potato")
|
__rem, _ := NewRemote("potato")
|
||||||
t.Run("Should return a remote basic type", func(t *testing.T) {
|
t.Run("Should return a remote basic type", func(t *testing.T) {
|
||||||
assert.NotNil(t, __rem)
|
assert.NotNil(t, __rem)
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package voicemeeter_test
|
package voicemeeter_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -9,10 +10,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
vm = voicemeeter.NewRemote("potato")
|
vm, err = voicemeeter.NewRemote("potato")
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer vm.Logout()
|
||||||
|
|
||||||
vm.Login()
|
vm.Login()
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
vm.Logout()
|
vm.Logout()
|
||||||
|
Loading…
Reference in New Issue
Block a user