1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::os::raw::c_void;
use crate::{Error, ffi::*};
/// Scoped helper for loading and unloading the CEF framework library at
/// runtime from the expected location in the app bundle.
#[derive(Debug)]
pub struct FrameworkLoader(*mut c_void);
impl Drop for FrameworkLoader {
fn drop(&mut self) {
unsafe { wef_unload_library(self.0) };
}
}
impl FrameworkLoader {
fn load(helper: bool) -> Result<Self, Error> {
unsafe {
let loader = wef_load_library(helper);
if loader.is_null() {
return Err(Error::LoadLibrary);
}
Ok(Self(loader))
}
}
/// Load the CEF framework in the main process from the expected app
/// bundle location relative to the executable.
pub fn load_in_main() -> Result<Self, Error> {
Self::load(false)
}
/// Load the CEF framework in the helper process from the expected app
/// bundle location relative to the executable.
pub fn load_in_helper() -> Result<Self, Error> {
Self::load(true)
}
}