Drop the log.Printf/fmt.Printf traces that fired on every config/input/ click/scroll/open/worker-result during IME and tap debugging. These were noise (and some were commented out). Error, limit, and recovery logs are kept; the default-off profiler and gated IME debug remain untouched.
89 lines
1.9 KiB
Go
89 lines
1.9 KiB
Go
//+build !darwin !linux
|
|
|
|
package main
|
|
|
|
/*
|
|
#cgo LDFLAGS: -landroid -llog
|
|
|
|
#include <stdlib.h>
|
|
#include "jni_android.h"
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"runtime"
|
|
"unsafe"
|
|
|
|
"gioui.org/app"
|
|
"gioui.org/io/event"
|
|
_ "gioui.org/app/permission/storage"
|
|
)
|
|
|
|
type JNIEnv = C.JNIEnv
|
|
var (
|
|
startpath="/storage/emulated/0/Notes"
|
|
jvm uintptr
|
|
theJVM *C.JavaVM
|
|
)
|
|
|
|
func impl_start() { }
|
|
|
|
func handleEvent(e event.Event) {
|
|
switch e := e.(type) {
|
|
case app.AndroidViewEvent:
|
|
theJVM = (*C.JavaVM)(unsafe.Pointer(app.JavaVM()))
|
|
RunInJVM(func(env *JNIEnv) {
|
|
C.registerFragment(env, (C.jobject)(unsafe.Pointer(e.View)))
|
|
})
|
|
}
|
|
}
|
|
|
|
func RunInJVM(f func(env *C.JNIEnv)) {
|
|
runtime.LockOSThread()
|
|
defer runtime.UnlockOSThread()
|
|
var env *C.JNIEnv
|
|
var detach bool
|
|
if res := C.GetEnv(theJVM, &env, C.JNI_VERSION_1_6); res != C.JNI_OK {
|
|
if res != C.JNI_EDETACHED {
|
|
panic(fmt.Errorf("JNI GetEnv failed with error %d", res))
|
|
}
|
|
if C.AttachCurrentThread(theJVM, &env, nil) != C.JNI_OK {
|
|
panic(errors.New("runInJVM: AttachCurrentThread failed"))
|
|
}
|
|
detach = true
|
|
}
|
|
|
|
if detach {
|
|
defer func() {
|
|
C.DetachCurrentThread(theJVM)
|
|
}()
|
|
}
|
|
f(env)
|
|
}
|
|
|
|
func OpenFile(path string) {
|
|
var env *C.JNIEnv
|
|
var detach bool
|
|
if res := C.GetEnv(theJVM, &env, C.JNI_VERSION_1_6); res != C.JNI_OK {
|
|
if res != C.JNI_EDETACHED {
|
|
panic(fmt.Errorf("JNI GetEnv failed with error %d", res))
|
|
}
|
|
if C.AttachCurrentThread(theJVM, &env, nil) != C.JNI_OK {
|
|
panic(errors.New("OpenFile: AttachCurrentThread failed"))
|
|
}
|
|
detach = true
|
|
}
|
|
|
|
if detach {
|
|
defer func() {
|
|
C.DetachCurrentThread(theJVM)
|
|
}()
|
|
}
|
|
cpath := C.CString(path)
|
|
C.open_file_in_termux(env, cpath)
|
|
C.free(unsafe.Pointer(cpath))
|
|
}
|
|
|