diff --git a/cmd/tailscale/main.go b/cmd/tailscale/main.go index 934b250..f10ad84 100644 --- a/cmd/tailscale/main.go +++ b/cmd/tailscale/main.go @@ -468,10 +468,7 @@ func (a *App) notify(state BackendState) { case a.updates <- struct{}{}: default: } - ready := jni.False - if state.State >= ipn.Stopped { - ready = jni.True - } + ready := jni.Bool(state.State >= ipn.Stopped) if err := a.callVoidMethod(a.appCtx, "setTileReady", "(Z)V", jni.Value(ready)); err != nil { fatalErr(err) } @@ -480,10 +477,7 @@ func (a *App) notify(state BackendState) { func (a *App) setPrefs(prefs *ipn.Prefs) { a.mu.Lock() a.prefs = prefs - wantRunning := jni.True - if !prefs.WantRunning { - wantRunning = jni.False - } + wantRunning := jni.Bool(prefs.WantRunning) a.mu.Unlock() if err := a.callVoidMethod(a.appCtx, "setTileStatus", "(Z)V", jni.Value(wantRunning)); err != nil { fatalErr(err) diff --git a/jni/jni.go b/jni/jni.go index 4ed1fbc..80170bc 100644 --- a/jni/jni.go +++ b/jni/jni.go @@ -64,11 +64,6 @@ type ( Value uint64 // All JNI types fit into 64-bits. ) -const ( - True Boolean = C.JNI_TRUE - False Boolean = C.JNI_FALSE -) - func env(e *Env) *C.JNIEnv { return (*C.JNIEnv)(unsafe.Pointer(e)) } @@ -96,6 +91,13 @@ func Do(vm *JVM, f func(env *Env) error) error { return f((*Env)(unsafe.Pointer(env))) } +func Bool(b bool) Boolean { + if b { + return C.JNI_TRUE + } + return C.JNI_FALSE +} + func varArgs(args []Value) *C.jvalue { if len(args) == 0 { return nil