gpui-component/crates/wef/src/framework_loader.rs
Sunli b70b229370
wef: Added a new WebView component named "Wef" based on CEF. (#877)
Wef is a Rust library for embedding WebView functionality using Chromium
Embedded Framework (CEF3) with offscreen rendering support.
2025-06-17 18:57:44 +08:00

38 lines
1 KiB
Rust

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)
}
}