Compare commits
No commits in common. "312b91fedb87e1bf6e636e10bdbca4d7ca639dda" and "64aa5f2353846c3f55a6333390fd5111b3f419c0" have entirely different histories.
312b91fedb
...
64aa5f2353
9 changed files with 17 additions and 64 deletions
|
|
@ -36,7 +36,7 @@ impl ConfigArgs {
|
|||
}).await.clone()
|
||||
}
|
||||
pub async fn to_partial_config_with_default(&self, app_name: &'static str) -> PartialConfig {
|
||||
let mut default = PartialConfig::default(app_name);
|
||||
let mut default = PartialConfig::default_desktop(app_name);
|
||||
default.merge(self.to_partial_config_without_default(app_name).await);
|
||||
default
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ jni = "0.21.1"
|
|||
ndk = "0.9.0"
|
||||
|
||||
[target.'cfg(target_os="ios")'.dependencies]
|
||||
objc2 = "0.6.2"
|
||||
objc2-foundation = "0.3.1"
|
||||
objc2-app-kit = "0.3.1"
|
||||
objc = "0.2.7"
|
||||
objc-foundation = "0.1.1"
|
||||
objc_id = "0.1.1"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.20.0"
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@ impl PartialConfig {
|
|||
file.write_all(toml::to_string(self)?.as_bytes()).await?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn default(app_name: &'static str) -> Self {
|
||||
#[cfg(not(any(target_os="android", target_os="ios")))]
|
||||
pub fn default_desktop(app_name: &'static str) -> Self {
|
||||
Self {
|
||||
p2p: Some(PartialP2pConfig::default()),
|
||||
rpc: Some(PartialRpcConfig::default(app_name)),
|
||||
|
|
|
|||
|
|
@ -31,19 +31,12 @@ pub struct PartialRpcConfig {
|
|||
}
|
||||
|
||||
impl PartialRpcConfig {
|
||||
#[cfg(not(target_os="ios"))]
|
||||
pub fn default(app_name: &'static str) -> Self {
|
||||
let username = whoami::username();
|
||||
Self{
|
||||
socket_path: Some(std::env::temp_dir().join(username).join(String::from(app_name) + ".sock")),
|
||||
}
|
||||
}
|
||||
#[cfg(target_os="ios")]
|
||||
pub fn default(app_name: &'static str) -> Self {
|
||||
Self{
|
||||
socket_path: Some(std::env::temp_dir().join(String::from(app_name) + ".sock")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Emptiable for PartialRpcConfig {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ impl PartialStorageConfig {
|
|||
}
|
||||
}
|
||||
#[cfg(target_os="android")]
|
||||
pub fn default_android() -> Self{
|
||||
fn default_android() -> Self{
|
||||
let ctx = ndk_context::android_context();
|
||||
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
|
||||
let mut env = vm.attach_current_thread()?;
|
||||
|
|
@ -66,22 +66,15 @@ impl PartialStorageConfig {
|
|||
Ok(cache_dir.to_string())
|
||||
|
||||
}
|
||||
#[cfg(target_os="ios")]
|
||||
pub fn default(_: &'static str) -> Self{
|
||||
|
||||
use objc2::rc::Retained;
|
||||
use objc2::msg_send;
|
||||
use objc2_foundation::*;
|
||||
|
||||
let home_dir: Retained<NSString> = unsafe {NSHomeDirectory()};
|
||||
|
||||
let path = PathBuf::from(home_dir.to_string());
|
||||
Self {
|
||||
data_directory: Some(path.join("Library")),
|
||||
cache_directory: Some(path.join("Library").join("Cache")),
|
||||
#[cfg(false)]
|
||||
fn default_ios(){
|
||||
unsafe {
|
||||
let file_manager: *mut Object = msg_send![Class::get("NSFileManager").unwrap(), defaultManager];
|
||||
let paths: Id<Object> = msg_send![file_manager, URLsForDirectory:1 inDomains:1];
|
||||
let first_path: *mut Object = msg_send![paths, firstObject];
|
||||
let path: Id<NSString> = Id::from_ptr(msg_send![first_path, path]);
|
||||
Some(path.as_str().to_string())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
pub mod global;
|
||||
pub mod gui;
|
||||
pub mod rpc;
|
||||
pub mod server;
|
||||
pub mod server;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
mod cli;
|
||||
use caretta_sync::utils::Runnable;
|
||||
use caretta_sync_example_core::global::APP_NAME;
|
||||
use clap::Parser;
|
||||
|
|
|
|||
|
|
@ -18,4 +18,3 @@ crate-type = ["lib", "cdylib"]
|
|||
bevy.workspace = true
|
||||
caretta-sync-example-core.path = "../core"
|
||||
caretta-sync.path = "../.."
|
||||
tokio.workspace = true
|
||||
|
|
|
|||
|
|
@ -6,41 +6,9 @@ use bevy::{
|
|||
window::{AppLifecycle, ScreenEdge, WindowMode},
|
||||
winit::WinitSettings,
|
||||
};
|
||||
use caretta_sync::{config::{Config, PartialConfig, PartialP2pConfig, PartialStorageConfig, StorageConfig}, server::ServerTrait, utils::{Emptiable, Mergeable}};
|
||||
use caretta_sync_example_core::{global::APP_NAME, server::Server};
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn init_config() {
|
||||
let storage_config: StorageConfig = PartialStorageConfig::default(APP_NAME).try_into().unwrap();
|
||||
let config_path = storage_config.data_directory.join("config.toml");
|
||||
let mut config = PartialConfig::read_from(&config_path).await.unwrap();
|
||||
if let Some(x) = if let Some(y) = config.p2p.as_mut() {
|
||||
if y.private_key.is_none() {
|
||||
Some(y.clone().with_new_private_key())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
} else {
|
||||
Some(PartialP2pConfig::empty().with_new_private_key())
|
||||
} {
|
||||
config.p2p = Some(x);
|
||||
config.write_to(&config_path).await.unwrap()
|
||||
}
|
||||
let mut default = PartialConfig::default(APP_NAME);
|
||||
default.merge(config);
|
||||
let config2 : Config = default.try_into().unwrap();
|
||||
Server::serve_all(&config2).await;
|
||||
|
||||
}
|
||||
|
||||
#[bevy_main]
|
||||
pub fn main() {
|
||||
|
||||
//init_config();
|
||||
|
||||
|
||||
|
||||
let mut app = App::new();
|
||||
app.add_plugins(
|
||||
DefaultPlugins.set(LogPlugin {
|
||||
|
|
@ -91,7 +59,7 @@ fn setup_scene(
|
|||
}
|
||||
))
|
||||
.with_child((
|
||||
Text::new(format!("{:?}", PartialConfig::default(APP_NAME))),
|
||||
Text::new(format!( "{:?}", std::fs::read_dir(std::env::current_dir().unwrap()).unwrap().map(|x| x.unwrap().path()).collect::<Vec<std::path::PathBuf>>())),
|
||||
TextFont {
|
||||
font_size: 16.0,
|
||||
..default()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue