mod logger;
mod cache;
mod camera;
mod share;
mod clipboard;
mod cloud;
mod haptics;
mod photo_picker;
mod safe_area;
mod notifications;
mod app_support;
use std::env;
use std::sync::mpsc::Sender;
use std::sync::{Arc, Mutex};
pub use cache::Cache;
pub use clipboard::Clipboard;
pub use camera::{Camera, CameraError, CameraSettings};
pub use share::Share;
pub use cloud::CloudStorage;
pub use photo_picker::{PhotoPicker, ImageOrientation};
pub use safe_area::SafeAreaInsets;
pub use haptics::Haptics;
pub use notifications::Notifications;
pub use logger::Logger;
#[derive(Clone)]
pub struct Context {
pub cache: Cache,
pub clipboard: Clipboard,
pub cloud: CloudStorage,
pub share: Share,
pub haptics: Haptics,
pub notifications: Notifications,
}
impl Context {
pub(crate) fn new() -> Self {
env::set_current_dir(&app_support::ApplicationSupport::get().expect("Could not get app suppport dir"));
Logger::start(None);
#[cfg(target_os = "android")]
let vm = {
let vm_ptr = ndk_context::android_context().vm().cast();
unsafe { jni::JavaVM::from_raw(vm_ptr).unwrap() }
};
Self {
cache: Cache::new(
#[cfg(target_os = "android")]
&vm
),
clipboard: Clipboard::new(
#[cfg(target_os = "android")]
&vm
),
cloud: CloudStorage::new(
#[cfg(target_os = "android")]
&vm
),
share: Share::new(),
haptics: Haptics::new(),
notifications: Notifications::new(),
}
}
pub fn camera(&mut self) -> Option<Camera> {
Camera::new().ok()
}
pub fn camera_existing(&mut self) -> Option<Camera> {
Camera::existing()
}
pub fn photo_picker(&self, sender: Sender<(Vec<u8>, ImageOrientation)>) {
PhotoPicker::open(sender)
}
pub fn safe_area_insets(&self) -> (f32, f32, f32, f32) {
SafeAreaInsets::get()
}
pub fn clipboard(&self) -> &Clipboard {
&self.clipboard
}
pub fn cloud(&self) -> &CloudStorage {
&self.cloud
}
pub fn share(&self, data: &str) {
self.share.share(data);
}
pub fn haptic(&self) { self.haptics.vibrate() }
pub fn notifications(&self) -> &Notifications {
&self.notifications
}
}