10000 chore: clean up · NativeScript/NativeScript@e4a5032 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4a5032

Browse files
committed
chore: clean up
1 parent ec908bc commit e4a5032

35 files changed

+1054
-788
lines changed

packages/ui-mobile-base/nativescript_common/Cargo.toml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cargo-features = ["strip"]
2-
31
[package]
42
name = "nativescript_common"
53
version = "0.1.0"
@@ -20,30 +18,28 @@ lto = true
2018
opt-level = "z"
2119
debug = false
2220
incremental = false
23-
strip = true
21+
strip = "debuginfo"
2422

2523
[build-dependencies]
2624
cbindgen = "0.20.0"
2725

2826

2927
[dependencies]
30-
parking_lot = "0.11.2"
28+
parking_lot = "0.12.0"
3129
once_cell = "1.8.0"
3230
filetime = "0.2"
33-
libc = "0.2.107"
34-
bitflags = "1.3.2"
35-
rand = "0.8.4"
31+
libc = "0.2.119"
3632
faccess = { git = "https://github.com/MightyPork/faccess", rev = "0c94ef6d4b08a650ecaa31d4dcbd1b769f8cb56b" }
3733
notify = "4.0.17"
3834
backoff = { git = "https://github.com/ihrwein/backoff", rev = "08f4e2111ea4b856b24556555d5c6ecf14cfa69d" }
3935
num_cpus = "1.0"
4036
tokio = { version = "1.14.0", features = ["rt-multi-thread"] }
4137
log = "0.4.8"
42-
38+
rand = "0.8.5"
4339

4440
[target.'cfg(target_os="android")'.dependencies]
4541
jni = "0.19.0"
46-
android_logger = "0.9.0"
42+
android_logger = "0.10.1"
4743

4844
[target.'cfg(target_os="macos")'.dependencies]
4945
objc = { version = "0.2.4" }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### prerequisites
2+
rustlang
3+
4+
5+
rustup toolchain install nightly
6+
rustup component add rust-src --toolchain nightly
7+
8+
9+
#### iOS
10+
11+
#### Android

packages/ui-mobile-base/nativescript_common/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::HashMap;
21
extern crate cbindgen;
32

43
use cbindgen::{Config, Language};

packages/ui-mobile-base/nativescript_common/src/android/fs/a_sync.rs

Lines changed: 139 additions & 136 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
use std::sync::Arc;
22

3-
use jni::JNIEnv;
43
use jni::objects::{JClass, JObject, JValue};
54
use jni::sys::jlong;
5+
use jni::JNIEnv;
66

77
use crate::android::fs::a_sync::AsyncCallback;
88

99
#[no_mangle]
10-
pub extern "system" fn Java_org_nativescript_widgets_filesystem_AsyncCallback_createAsyncCallback(env: JNIEnv, _: JClass, callback: JObject) -> jlong {
11-
let cb = AsyncCallback::new(
12-
env.new_global_ref(callback).unwrap()
13-
).into_arc();
10+
pub extern "system" fn Java_org_nativescript_widgets_filesystem_AsyncCallback_createAsyncCallback(
11+
env: JNIEnv,
12+
_: JClass,
13+
callback: JObject,
14+
) -> jlong {
15+
let cb = AsyncCallback::new(env.new_global_ref(callback).unwrap()).into_arc();
1416
return Arc::into_raw(cb) as jlong;
1517
}
1618

1719
#[no_mangle]
18-
pub extern "system" fn Java_org_nativescript_widgets_filesystem_AsyncCallback_disposeAsyncCallback(_: JNIEnv, _: JClass, callback: jlong) {
20+
pub extern "system" fn Java_org_nativescript_widgets_filesystem_AsyncCallback_disposeAsyncCallback(
21+
_: JNIEnv,
22+
_: JClass,
23+
callback: jlong,
24+
) {
1925
let callback = unsafe { callback as *const AsyncCallback };
2026
let _ = unsafe { Arc::from_raw(callback) };
2127
}

packages/ui-mobile-base/nativescript_common/src/android/fs/file_dir.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
use jni::{
2-
JNIEnv,
3-
sys::jobject,
4-
};
51
use jni::objects::{JClass, JObject};
62
use jni::sys::jlong;
3+
use jni::{sys::jobject, JNIEnv};
74

5+
use crate::android::prelude::*;
86
use crate::android::FILE_DIR_CLASS;
97
use crate::android::JVM;
10-
use crate::android::prelude::*;
118
use crate::common::fs::file_dir::FileDir;
129

1310
use super::a_sync::AsyncCallback;
@@ -16,9 +13,8 @@ use super::file_dirent::build_dirent;
1613
pub(crate) fn build_dir<'a>(env: &JNIEnv<'a>, dir: FileDir) -> JObject<'a> {
1714
let clazz = find_class(FILE_DIR_CLASS).unwrap();
1815
let dir = Box::into_raw(Box::new(dir));
19-
env.new_object(clazz, "(J)V", &[
20-
(dir as i64).into()
21-
]).unwrap()
16+
env.new_object(clazz, "(J)V", &[(dir as i64).into()])
17+
.unwrap()
2218
}
2319

2420
#[no_mangle]
@@ -32,7 +28,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeCl
3228
let mut dir = unsafe { Box::from_raw(dir) };
3329
let result = dir.close();
3430
if let Err(error) = result {
35-
env.throw(error.to_string());
31+
let _ = env.throw(error.to_string());
3632
}
3733
}
3834
}
@@ -50,18 +46,17 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeCl
5046
if !dir.is_null() {
5147
let mut dir = unsafe { Box::from_raw(dir) };
5248
dir.close_async(Box::new(move |error| {
53-
if error.is_some() {
54-
on_success.on_error(
55-
jni::objects::JValue::Object(error_to_jstring(error.unwrap()).as_obj())
56-
)
49+
if let Some(error) = error {
50+
on_success.on_error(jni::objects::JValue::Object(
51+
error_to_jstring(error).as_obj(),
52+
))
5753
} else {
5854
on_success.on_success(jni::objects::JObject::null().into())
5955
}
6056
}));
6157
}
6258
}
6359

64-
6560
#[no_mangle]
6661
pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativePath(
6762
env: JNIEnv,
@@ -76,7 +71,6 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativePa
7671
JObject::null().into_inner()
7772
}
7873

79-
8074
#[no_mangle]
8175
pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeDispose(
8276
_env: JNIEnv,
@@ -89,7 +83,6 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeDi
8983
}
9084
}
9185

92-
9386
#[no_mangle]
9487
pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeReadSync(
9588
env: JNIEnv,
@@ -104,14 +97,13 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeRe
10497
return build_dirent(&env, dirent).into_inner();
10598
}
10699
Err(error) => {
107-
env.throw(error.to_string());
100+
let _ = env.throw(error.to_string());
108101
}
109102
}
110103
}
111104
return JObject::null().into_inner();
112105
}
113106

114-
115107
#[no_mangle]
116108
pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeRead(
117109
_: JNIEnv,
@@ -126,16 +118,14 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeRe
126118
let mut dir = unsafe { Box::from_raw(dir) };
127119
dir.read_async(Box::new(move |dirent, error| {
128120
if error.is_some() {
129-
on_success.on_error(
130-
jni::objects::JValue::Object(error_to_jstring(error.unwrap()).as_obj())
131-
)
121+
on_success.on_error(jni::objects::JValue::Object(
122+
error_to_jstring(error.unwrap()).as_obj(),
123+
))
132124
} else {
133125
let jvm = JVM.get().unwrap();
134126
let env = jvm.attach_current_thread().unwrap();
135-
on_success.on_success(
136-
build_dirent(&env, dirent.unwrap()).into()
137-
)
127+
on_success.on_success(build_dirent(&env, dirent.unwrap()).into())
138128
}
139129
}));
140130
}
141-
}
131+
}

packages/ui-mobile-base/nativescript_common/src/android/fs/file_dirent.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
use std::ffi::OsString;
22
use std::sync::Arc;
33

4-
use jni::{
5-
JNIEnv,
6-
sys::jobject,
7-
};
84
use jni::objects::{JClass, JObject, JValue};
9-
use jni::sys::{jboolean, jlong, JNI_FALSE, jobjectArray};
5+
use jni::sys::{jboolean, jlong, jobjectArray, JNI_FALSE};
6+
use jni::{sys::jobject, JNIEnv};
107

11-
use crate::android::{FILE_DIRENT_CLASS, OBJECT_CLASS, STRING_CLASS};
128
use crate::android::prelude::*;
9+
use crate::android::{FILE_DIRENT_CLASS, OBJECT_CLASS, STRING_CLASS};
1310
use crate::common::fs::file_dirent::FileDirent;
1411

1512
use super::a_sync::AsyncCallback;
1613

1714
pub(crate) fn build_dirent<'a>(env: &JNIEnv<'a>, dirent: FileDirent) -> JObject<'a> {
1815
let clazz = find_class(FILE_DIRENT_CLASS).unwrap();
1916
let dirent = Box::into_raw(Box::new(dirent));
20-
env.new_object(clazz, "(J)V", &[
21-
(dirent as i64).into()
22-
]).unwrap()
17+
env.new_object(clazz, "(J)V", &[(dirent as i64).into()])
18+
.unwrap()
2319
}
2420

2521
pub(crate) fn build_dirents(env: &JNIEnv, dirent: Vec<FileDirent>) -> jobjectArray {
2622
let mut dirent = dirent;
2723
let object_clazz = find_class(OBJECT_CLASS).unwrap();
2824
let clazz = find_class(FILE_DIRENT_CLASS).unwrap();
29-
let mut object_array = env.new_object_array(dirent.len().try_into().unwrap(), object_clazz, JObject::null()).unwrap();
25+
let mut object_array = env
26+
.new_object_array(
27+
dirent.len().try_into().unwrap(),
28+
object_clazz,
29+
JObject::null(),
30+
)
31+
.unwrap();
3032

31-
let mut i = 0;
32-
for dirent in dirent.iter_mut() {
33+
for (i, dirent) in dirent.iter_mut().enumerate() {
3334
let dirent = FileDirent(Arc::clone(&dirent.0));
3435
let dirent = Box::into_raw(Box::new(dirent));
35-
let res = env.new_object(clazz, "(J)V", &[
36-
(dirent as i64).into()
37-
]).unwrap();
38-
env.set_object_array_element(object_array, i.try_into().unwrap(), res);
39-
i += 1;
36+
let res = env
37+
.new_object(clazz, "(J)V", &[(dirent as i64).into()])
38+
.unwrap();
39+
let _ = env.set_object_array_element(object_array, i.try_into().unwrap(), res);
4040
}
4141

4242
object_array
@@ -45,11 +45,13 @@ pub(crate) fn build_dirents(env: &JNIEnv, dirent: Vec<FileDirent>) -> jobjectArr
4545
pub(crate) fn build_dirents_paths(env: &JNIEnv, dirent: Vec<OsString>) -> jobjectArray {
4646
let mut dirent = dirent;
4747
let clazz = find_class(OBJECT_CLASS).unwrap();
48-
let mut object_array = env.new_object_array(dirent.len().try_into().unwrap(), clazz, JObject::null()).unwrap();
48+
let mut object_array = env
49+
.new_object_array(dirent.len().try_into().unwrap(), clazz, JObject::null())
50+
.unwrap();
4951

5052
for (i, dirent) in dirent.iter_mut().enumerate() {
5153
let dirent = env.new_string(dirent.to_string_lossy()).unwrap();
52-
env.set_object_array_element(object_array, i.try_into().unwrap(), dirent);
54+
let _ = env.set_object_array_element(object_array, i.try_into().unwrap(), dirent);
5355
}
5456

5557
object_array
@@ -76,14 +78,11 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativ
7678
let dirent: *mut FileDirent = file_dirent as _;
7779
if !dirent.is_null() {
7880
let dirent = unsafe { &*dirent };
79-
return env.new_string(
80-
dirent.name()
81-
).unwrap().into_inner();
81+
return env.new_string(dirent.name()).unwrap().into_inner();
8282
}
8383
JObject::null().into_inner()
8484
}
8585

86-
8786
#[no_mangle]
8887
pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativeIsBlockDevice(
8988
_: JNIEnv,
@@ -98,7 +97,6 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativ
9897
JNI_FALSE
9998
}
10099

101-
102100
#[no_mangle]
103101
pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativeIsCharacterDevice(
104102
_: JNIEnv,
@@ -141,7 +139,6 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativ
141139
JNI_FALSE
142140
}
143141

144-
145142
#[no_mangle]
146143
pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativeIsFile(
147144
_: JNIEnv,
@@ -156,7 +153,6 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativ
156153
JNI_FALSE
157154
}
158155

159-
160156
#[no_mangle]
161157
pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativeIsSocket(
162158
_: JNIEnv,
@@ -171,7 +167,6 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativ
171167
JNI_FALSE
172168
}
173169

174-
175170
#[no_mangle]
176171
pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativeIsSymbolicLink(
177172
_: JNIEnv,
@@ -184,4 +179,4 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDirent_nativ
184179
return dirent.is_symbolic_link().into();
185180
}
186181
JNI_FALSE
187-
}
182+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)
0