#![cfg_attr(target_os = "windows", allow(dead_code))]
#[cfg(feature = "browser-runtime")]
pub(crate) const APP_ID: &str = lingxia_browser::BUILTIN_BROWSER_APPID;
#[cfg(not(feature = "browser-runtime"))]
pub(crate) const APP_ID: &str = "";
#[cfg(not(feature = "browser-runtime"))]
fn unavailable<T>() -> Result<T, lxapp::LxAppError> {
Err(lxapp::LxAppError::UnsupportedOperation(
"browser not available (browser feature disabled)".to_string(),
))
}
pub(crate) fn register_bundled_app() {
#[cfg(feature = "browser-runtime")]
lingxia_browser::register_bundled_app();
}
#[cfg(all(feature = "browser-runtime", not(feature = "browser-shell")))]
pub(crate) fn install_runtime_once() {
use std::sync::OnceLock;
static REGISTERED: OnceLock<()> = OnceLock::new();
REGISTERED.get_or_init(lingxia_browser::install_runtime);
}
#[cfg(all(feature = "browser-runtime", not(feature = "browser-shell")))]
pub(crate) fn register_bundled_app_once() {
use std::sync::OnceLock;
static REGISTERED: OnceLock<()> = OnceLock::new();
REGISTERED.get_or_init(lingxia_browser::register_bundled_app);
}
#[cfg(all(feature = "browser-runtime", not(feature = "browser-shell")))]
pub(crate) fn warmup() {
lingxia_browser::warmup();
}
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub(crate) fn open(url: &str, tab_id: Option<&str>) -> Result<String, lxapp::LxAppError> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::open(url, tab_id);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = (url, tab_id);
unavailable()
}
}
pub(crate) fn open_for_app(
appid: &str,
session_id: u64,
url: &str,
tab_id: Option<&str>,
) -> Result<String, lxapp::LxAppError> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::open_for_app(appid, session_id, url, tab_id);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = (appid, session_id, url, tab_id);
unavailable()
}
}
pub(crate) fn open_aside_for_app(
appid: &str,
session_id: u64,
url: &str,
tab_id: Option<&str>,
) -> Result<String, lxapp::LxAppError> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::open_aside_for_app(appid, session_id, url, tab_id);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = (appid, session_id, url, tab_id);
unavailable()
}
}
pub(crate) fn tab_is_aside(tab_id: &str) -> bool {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::tab_is_aside(tab_id);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = tab_id;
false
}
}
pub(crate) fn open_standalone_for_app(
appid: &str,
session_id: u64,
url: &str,
tab_id: Option<&str>,
data_mode: lingxia_webview::WebViewDataMode,
url_callback: bool,
) -> Result<String, lxapp::LxAppError> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::open_standalone_for_app(
appid,
session_id,
url,
tab_id,
data_mode,
url_callback,
);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = (appid, session_id, url, tab_id, data_mode, url_callback);
unavailable()
}
}
#[cfg(target_os = "windows")]
pub(crate) fn runtime_enabled() -> bool {
cfg!(feature = "browser-runtime")
}
#[cfg(target_os = "windows")]
#[derive(Debug, Clone)]
pub(crate) struct BrowserTabSummary {
pub(crate) tab_id: String,
pub(crate) path: String,
pub(crate) session_id: u64,
pub(crate) title: Option<String>,
pub(crate) current_url: Option<String>,
pub(crate) favicon_png: Option<std::sync::Arc<Vec<u8>>>,
}
#[cfg(all(target_os = "windows", feature = "browser-runtime"))]
fn tab_summary_from_info(info: lingxia_browser::BrowserTabInfo) -> BrowserTabSummary {
let favicon_png = lingxia_browser::tab_favicon(&info.tab_id);
BrowserTabSummary {
tab_id: info.tab_id,
path: info.path,
session_id: info.session_id,
title: info.title,
current_url: info.current_url,
favicon_png,
}
}
#[cfg(target_os = "windows")]
pub(crate) fn tabs() -> Vec<BrowserTabSummary> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::tabs()
.into_iter()
.map(tab_summary_from_info)
.collect();
#[cfg(not(feature = "browser-runtime"))]
Vec::new()
}
#[cfg(target_os = "windows")]
pub(crate) fn tab_summary(tab_id: &str) -> Option<BrowserTabSummary> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::tabs()
.into_iter()
.find(|tab| tab.tab_id == tab_id)
.map(tab_summary_from_info);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = tab_id;
None
}
}
#[cfg(target_os = "windows")]
pub(crate) fn activate(tab_id: &str) -> bool {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::activate(tab_id).is_ok();
#[cfg(not(feature = "browser-runtime"))]
{
let _ = tab_id;
false
}
}
#[cfg(target_os = "windows")]
pub(crate) fn set_tabs_changed_handler(handler: std::sync::Arc<dyn Fn() + Send + Sync>) {
#[cfg(feature = "browser-runtime")]
lingxia_browser::set_tabs_changed_handler(handler);
#[cfg(not(feature = "browser-runtime"))]
let _ = handler;
}
#[cfg(any(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "android",
target_env = "ohos"
))]
pub(crate) fn navigate(tab_id: &str, url: &str) -> Result<(), lxapp::LxAppError> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::open(url, Some(tab_id)).map(|_| ());
#[cfg(not(feature = "browser-runtime"))]
{
let _ = (tab_id, url);
unavailable()
}
}
#[cfg(target_os = "windows")]
pub(crate) fn go_back(tab_id: &str) -> bool {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::go_back(tab_id).is_ok();
#[cfg(not(feature = "browser-runtime"))]
{
let _ = tab_id;
false
}
}
#[cfg(target_os = "windows")]
pub(crate) fn go_forward(tab_id: &str) -> bool {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::go_forward(tab_id).is_ok();
#[cfg(not(feature = "browser-runtime"))]
{
let _ = tab_id;
false
}
}
#[cfg(target_os = "windows")]
pub(crate) fn reload(tab_id: &str) -> bool {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::reload(tab_id).is_ok();
#[cfg(not(feature = "browser-runtime"))]
{
let _ = tab_id;
false
}
}
pub(crate) fn close(tab_id: &str) -> Result<(), lxapp::LxAppError> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::close(tab_id);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = tab_id;
unavailable()
}
}
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub(crate) fn discard(tab_id: &str) -> Result<(), lxapp::LxAppError> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::discard(tab_id);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = tab_id;
unavailable()
}
}
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub(crate) fn reactivate(tab_id: &str) -> Result<(), lxapp::LxAppError> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::reactivate(tab_id);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = tab_id;
unavailable()
}
}
pub(crate) fn mark_active(tab_id: &str) {
#[cfg(feature = "browser-runtime")]
lingxia_browser::mark_active(tab_id);
#[cfg(not(feature = "browser-runtime"))]
let _ = tab_id;
}
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub(crate) fn clear_active() {
#[cfg(feature = "browser-runtime")]
lingxia_browser::clear_active();
}
pub(crate) fn tab_path(tab_id: &str) -> String {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::tab_path(tab_id);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = tab_id;
String::new()
}
}
#[cfg_attr(not(any(target_os = "ios", target_os = "macos")), allow(dead_code))]
pub(crate) fn update_tab(tab_id: &str, current_url: Option<&str>, title: Option<&str>) -> bool {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::update_tab(tab_id, current_url, title);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = (tab_id, current_url, title);
false
}
}
#[cfg_attr(not(any(target_os = "ios", target_os = "macos")), allow(dead_code))]
pub(crate) fn download(
tab_id: &str,
url: &str,
user_agent: Option<&str>,
suggested_filename: Option<&str>,
source_page_url: Option<&str>,
cookie: Option<&str>,
) -> Result<(), lxapp::LxAppError> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::start_download(
tab_id,
url,
user_agent,
suggested_filename,
source_page_url,
cookie,
);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = (
tab_id,
url,
user_agent,
suggested_filename,
source_page_url,
cookie,
);
unavailable()
}
}
#[cfg_attr(not(any(target_os = "android", target_env = "ohos")), allow(dead_code))]
pub(crate) fn classify_navigation_json(request_json: &str) -> Option<String> {
#[cfg(feature = "browser-runtime")]
return lingxia_browser::classify_navigation_json(request_json);
#[cfg(not(feature = "browser-runtime"))]
{
let _ = request_json;
None
}
}