Enable to get data directory in iOS
This commit is contained in:
parent
64aa5f2353
commit
6fe8c2bf61
4 changed files with 22 additions and 14 deletions
|
@ -44,9 +44,9 @@ jni = "0.21.1"
|
||||||
ndk = "0.9.0"
|
ndk = "0.9.0"
|
||||||
|
|
||||||
[target.'cfg(target_os="ios")'.dependencies]
|
[target.'cfg(target_os="ios")'.dependencies]
|
||||||
objc = "0.2.7"
|
objc2 = "0.6.2"
|
||||||
objc-foundation = "0.1.1"
|
objc2-foundation = "0.3.1"
|
||||||
objc_id = "0.1.1"
|
objc2-app-kit = "0.3.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3.20.0"
|
tempfile = "3.20.0"
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl PartialStorageConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(target_os="android")]
|
#[cfg(target_os="android")]
|
||||||
fn default_android() -> Self{
|
pub fn default_android() -> Self{
|
||||||
let ctx = ndk_context::android_context();
|
let ctx = ndk_context::android_context();
|
||||||
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
|
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
|
||||||
let mut env = vm.attach_current_thread()?;
|
let mut env = vm.attach_current_thread()?;
|
||||||
|
@ -66,15 +66,22 @@ impl PartialStorageConfig {
|
||||||
Ok(cache_dir.to_string())
|
Ok(cache_dir.to_string())
|
||||||
|
|
||||||
}
|
}
|
||||||
#[cfg(false)]
|
#[cfg(target_os="ios")]
|
||||||
fn default_ios(){
|
pub fn default() -> Self{
|
||||||
unsafe {
|
|
||||||
let file_manager: *mut Object = msg_send![Class::get("NSFileManager").unwrap(), defaultManager];
|
use objc2::rc::Retained;
|
||||||
let paths: Id<Object> = msg_send![file_manager, URLsForDirectory:1 inDomains:1];
|
use objc2::msg_send;
|
||||||
let first_path: *mut Object = msg_send![paths, firstObject];
|
use objc2_foundation::*;
|
||||||
let path: Id<NSString> = Id::from_ptr(msg_send![first_path, path]);
|
|
||||||
Some(path.as_str().to_string())
|
let home_dir: Retained<NSString> = unsafe {NSHomeDirectory()};
|
||||||
|
|
||||||
|
let path = PathBuf::from(home_dir.to_string());
|
||||||
|
Self {
|
||||||
|
data_directory: Some(path.clone()),
|
||||||
|
cache_directory: Some(path.clone()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
pub mod global;
|
pub mod global;
|
||||||
pub mod gui;
|
pub mod gui;
|
||||||
pub mod rpc;
|
pub mod rpc;
|
||||||
pub mod server;
|
pub mod server;
|
|
@ -6,6 +6,7 @@ use bevy::{
|
||||||
window::{AppLifecycle, ScreenEdge, WindowMode},
|
window::{AppLifecycle, ScreenEdge, WindowMode},
|
||||||
winit::WinitSettings,
|
winit::WinitSettings,
|
||||||
};
|
};
|
||||||
|
use caretta_sync::config::PartialStorageConfig;
|
||||||
|
|
||||||
#[bevy_main]
|
#[bevy_main]
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
@ -59,7 +60,7 @@ fn setup_scene(
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
.with_child((
|
.with_child((
|
||||||
Text::new(format!( "{:?}", std::fs::read_dir(std::env::current_dir().unwrap()).unwrap().map(|x| x.unwrap().path()).collect::<Vec<std::path::PathBuf>>())),
|
Text::new(format!("{:?}", PartialStorageConfig::default())),
|
||||||
TextFont {
|
TextFont {
|
||||||
font_size: 16.0,
|
font_size: 16.0,
|
||||||
..default()
|
..default()
|
||||||
|
|
Loading…
Add table
Reference in a new issue