diff --git a/ports/servoshell/egl/ohos/simpleservo.rs b/ports/servoshell/egl/ohos/simpleservo.rs index 5ba9ab9d6cf..77719eaa5f8 100644 --- a/ports/servoshell/egl/ohos/simpleservo.rs +++ b/ports/servoshell/egl/ohos/simpleservo.rs @@ -8,7 +8,7 @@ use std::ptr::NonNull; use std::rc::Rc; use dpi::PhysicalSize; -use log::{debug, info}; +use log::{debug, info, warn}; use raw_window_handle::{ DisplayHandle, OhosDisplayHandle, OhosNdkWindowHandle, RawDisplayHandle, RawWindowHandle, WindowHandle, @@ -40,7 +40,7 @@ pub fn init( info!("Entered simpleservo init function"); crate::init_crypto(); let resource_dir = PathBuf::from(&options.resource_dir).join("servo"); - resources::set(Box::new(ResourceReaderInstance::new(resource_dir))); + resources::set(Box::new(ResourceReaderInstance::new(resource_dir.clone()))); // It would be nice if `from_cmdline_args()` could accept str slices, to avoid allocations here. // Then again, this code could and maybe even should be disabled in production builds. @@ -53,6 +53,15 @@ pub fn init( ); debug!("Servo commandline args: {:?}", args); + let _ = crate::prefs::DEFAULT_CONFIG_DIR + .set(resource_dir) + .inspect_err(|e| { + warn!( + "Default Prefs Dir already previously filled. Got error {}", + e.display() + ); + }); + let (opts, preferences, servoshell_preferences) = match parse_command_line_arguments(args) { ArgumentParsingResult::ContentProcess(..) => { unreachable!("OHOS does not have support for multiprocess yet.") diff --git a/ports/servoshell/prefs.rs b/ports/servoshell/prefs.rs index afd82de1be3..ef5506614ec 100644 --- a/ports/servoshell/prefs.rs +++ b/ports/servoshell/prefs.rs @@ -6,6 +6,8 @@ use std::collections::HashMap; use std::fs::{read_to_string, File}; use std::io::Read; use std::path::{Path, PathBuf}; +#[cfg(any(target_os = "android", target_env = "ohos"))] +use std::sync::OnceLock; use std::{env, fs, process}; use euclid::Size2D; @@ -90,9 +92,12 @@ pub fn default_config_dir() -> Option { Some(config_dir) } +/// Overrides the default preference dir +#[cfg(any(target_os = "android", target_env = "ohos"))] +pub(crate) static DEFAULT_CONFIG_DIR: OnceLock = OnceLock::new(); #[cfg(any(target_os = "android", target_env = "ohos"))] pub fn default_config_dir() -> Option { - None + DEFAULT_CONFIG_DIR.get().cloned() } #[cfg(target_os = "macos")]