#![deny(missing_docs)]
#[macro_use]
extern crate cfg_if;
cfg_if! {
if #[cfg(target_os = "windows")] {
} else if #[cfg(target_os = "macos")] {
extern crate cocoa;
extern crate dispatch;
#[macro_use]
extern crate objc;
} else {
extern crate glib;
extern crate gtk;
extern crate webkit2gtk;
}
}
use std::marker::PhantomData;
use std::sync::atomic::{ATOMIC_BOOL_INIT, AtomicBool};
use std::sync::atomic::Ordering::SeqCst;
mod escape;
mod handler;
mod options;
mod platform;
pub use escape::escape;
pub use handler::Handler;
pub use options::Options;
static LOADED: AtomicBool = ATOMIC_BOOL_INIT;
pub fn builder() -> Options<'static, ()> {
Options::new()
}
pub fn dispatch<F: FnOnce(Window) + Send + 'static>(f: F) {
if LOADED.load(SeqCst) {
platform::dispatch(f)
}
}
fn start<H: Handler>(opts: Options<H>) -> ! {
if !LOADED.swap(true, SeqCst) {
platform::start(opts)
} else {
panic!("Tried to initialize the window more than once!")
}
}
#[derive(Clone, Copy)]
pub struct Window(PhantomData<*mut ()>);
impl Window {
pub fn eval(self, js: &str) {
platform::eval(js)
}
pub fn load(self, html: &str) {
platform::load(html)
}
unsafe fn new() -> Window {
Window(PhantomData)
}
}