PolyMeilex / rfd

Rusty File Dialog
MIT License
524 stars 60 forks source link

File dialog freeze when use in JNI #169

Open SudoDios opened 5 months ago

SudoDios commented 5 months ago

Hi. I using this on jni. but when i choose file or cancel it, dialog is freeze. this is my jni fn :

#[allow(non_snake_case)]
#[no_mangle]
pub extern "system" fn Java_my_package_openFilePicker<'local>(env: JNIEnv<'local>, _class: JClass<'local>) -> jstring {
    let path = std::env::current_dir().unwrap();
    let res = rfd::FileDialog::new()
        .add_filter("image", &["jpg", "png"])
        .set_directory(&path)
        .pick_file();
    let result = if res != None {
        res.unwrap().into_os_string().into_string().unwrap()
    } else {
        "".to_string()
    };
    env.new_string(result).unwrap().into_raw()
}