jni: replace True and False with more convenient Bool function

Signed-off-by: Elias Naur <mail@eliasnaur.com>
pull/7/head
Elias Naur 4 years ago
parent 07b2373e6b
commit 33cf7c0aa1

@ -468,10 +468,7 @@ func (a *App) notify(state BackendState) {
case a.updates <- struct{}{}: case a.updates <- struct{}{}:
default: default:
} }
ready := jni.False ready := jni.Bool(state.State >= ipn.Stopped)
if state.State >= ipn.Stopped {
ready = jni.True
}
if err := a.callVoidMethod(a.appCtx, "setTileReady", "(Z)V", jni.Value(ready)); err != nil { if err := a.callVoidMethod(a.appCtx, "setTileReady", "(Z)V", jni.Value(ready)); err != nil {
fatalErr(err) fatalErr(err)
} }
@ -480,10 +477,7 @@ func (a *App) notify(state BackendState) {
func (a *App) setPrefs(prefs *ipn.Prefs) { func (a *App) setPrefs(prefs *ipn.Prefs) {
a.mu.Lock() a.mu.Lock()
a.prefs = prefs a.prefs = prefs
wantRunning := jni.True wantRunning := jni.Bool(prefs.WantRunning)
if !prefs.WantRunning {
wantRunning = jni.False
}
a.mu.Unlock() a.mu.Unlock()
if err := a.callVoidMethod(a.appCtx, "setTileStatus", "(Z)V", jni.Value(wantRunning)); err != nil { if err := a.callVoidMethod(a.appCtx, "setTileStatus", "(Z)V", jni.Value(wantRunning)); err != nil {
fatalErr(err) fatalErr(err)

@ -64,11 +64,6 @@ type (
Value uint64 // All JNI types fit into 64-bits. 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 { func env(e *Env) *C.JNIEnv {
return (*C.JNIEnv)(unsafe.Pointer(e)) 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))) 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 { func varArgs(args []Value) *C.jvalue {
if len(args) == 0 { if len(args) == 0 {
return nil return nil

Loading…
Cancel
Save