Fix various clippy warnings on OpenHarmony (#34281)

* ohos: Fix more clippy warnings

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* Remove unnecessary `macro_use`

We can use `use` instead. Removes a warning about
unused macro_use on OpenHarmony.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

---------

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender 2024-11-19 06:21:48 +01:00 committed by GitHub
parent caf2467649
commit 09684a3501
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 37 additions and 51 deletions

View file

@ -128,7 +128,7 @@ winit = "0.30.5"
[target.'cfg(any(all(target_os = "linux", not(target_env = "ohos")), target_os = "windows"))'.dependencies]
image = { workspace = true }
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
[target.'cfg(any(all(target_os = "linux", not(target_env = "ohos")), target_os = "macos"))'.dependencies]
sig = "1.0"
[target.'cfg(target_os = "windows")'.dependencies]

View file

@ -11,6 +11,8 @@ pub fn install() {
use std::sync::atomic;
use std::thread;
use sig::signal;
use crate::backtrace;
extern "C" fn handler(sig: i32) {

View file

@ -30,7 +30,6 @@ use ohos_sys::xcomponent::{
use servo::compositing::windowing::EmbedderEvent;
use servo::embedder_traits;
use servo::embedder_traits::{InputMethodType, PromptResult};
use servo::euclid::Point2D;
use servo::style::Zero;
use simpleservo::EventLoopWaker;
use xcomponent_sys::{
@ -82,7 +81,7 @@ unsafe impl Send for XComponentWrapper {}
unsafe impl Send for WindowWrapper {}
#[derive(Clone, Copy, Debug)]
enum TouchEventType {
pub(super) enum TouchEventType {
Down,
Up,
Move,
@ -91,7 +90,7 @@ enum TouchEventType {
}
#[derive(Debug)]
enum ServoAction {
pub(super) enum ServoAction {
WakeUp,
LoadUrl(String),
GoBack,
@ -206,11 +205,9 @@ unsafe extern "C" fn on_vsync_cb(
data: *mut ::core::ffi::c_void,
) {
trace!("Vsync callback at time {timestamp}");
// SAFETY: We require the function registering us as a callback
let (native_vsync, data) = unsafe {
let native = ohos_vsync::NativeVsync::from_raw(data.cast());
(native, 0)
};
// SAFETY: We require the function registering us as a callback provides a valid
// `OH_NativeVSync` object. We do not use `data` after this point.
let native_vsync = unsafe { ohos_vsync::NativeVsync::from_raw(data.cast()) };
call(ServoAction::Vsync).unwrap();
// Todo: Do we have a callback for when the frame finished rendering?
unsafe {
@ -507,7 +504,7 @@ pub fn go_forward() {
#[napi(js_name = "registerURLcallback")]
pub fn register_url_callback(callback: Function<String, ()>) -> napi_ohos::Result<()> {
debug!("register_url_callback called!");
let mut tsfn_builder = callback.build_threadsafe_function();
let tsfn_builder = callback.build_threadsafe_function();
let function = tsfn_builder
.max_queue_size::<UPDATE_URL_QUEUE_SIZE>()
.build()?;
@ -522,7 +519,7 @@ pub fn register_url_callback(callback: Function<String, ()>) -> napi_ohos::Resul
#[napi]
pub fn register_prompt_toast_callback(callback: Function<String, ()>) -> napi_ohos::Result<()> {
debug!("register_prompt_toast_callback called!");
let mut tsfn_builder = callback.build_threadsafe_function();
let tsfn_builder = callback.build_threadsafe_function();
let function = tsfn_builder.max_queue_size::<PROMPT_QUEUE_SIZE>().build()?;
PROMPT_TOAST

View file

@ -82,18 +82,12 @@ pub fn init(
"--prefs-file /path/to/prefs.json",
);
let opts_matches;
let content_process_token;
match opts::from_cmdline_args(opts, &args) {
ArgumentParsingResult::ContentProcess(matches, token) => {
let opts_matches = match opts::from_cmdline_args(opts, &args) {
ArgumentParsingResult::ContentProcess(matches, _token) => {
error!("Content Process mode not supported / tested yet on OpenHarmony!");
opts_matches = matches;
content_process_token = Some(token);
},
ArgumentParsingResult::ChromeProcess(matches) => {
opts_matches = matches;
content_process_token = None;
matches
},
ArgumentParsingResult::ChromeProcess(matches) => matches,
};
crate::prefs::register_user_prefs(&opts_matches);

View file

@ -26,7 +26,6 @@ use servo::script_traits::{
};
use servo::servo_geometry::DeviceIndependentPixel;
use servo::style_traits::DevicePixel;
use servo::webrender_api::units::DeviceIntRect;
use servo::webrender_api::ScrollLocation;
use servo::webrender_traits::RenderingContext;
use servo::{gl, Servo, TopLevelBrowsingContextId};
@ -501,7 +500,8 @@ impl ServoGlue {
let trusted = origin == PromptOrigin::Trusted;
let res = match definition {
PromptDefinition::Alert(message, sender) => {
sender.send(cb.prompt_alert(message, trusted))
cb.prompt_alert(message, trusted);
sender.send(())
},
PromptDefinition::OkCancel(message, sender) => {
sender.send(cb.prompt_ok_cancel(message, trusted))

View file

@ -4,21 +4,18 @@
use cfg_if::cfg_if;
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[macro_use]
extern crate sig;
#[cfg(test)]
mod test;
#[cfg(not(target_os = "android"))]
mod backtrace;
#[cfg(not(target_env = "ohos"))]
mod crash_handler;
#[cfg(not(any(target_os = "android", target_env = "ohos")))]
pub(crate) mod desktop;
#[cfg(any(target_os = "android", target_env = "ohos"))]
mod egl;
#[cfg(not(target_os = "android"))]
#[cfg(not(any(target_os = "android", target_env = "ohos")))]
mod panic_hook;
mod parser;
mod prefs;

View file

@ -2,20 +2,19 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#[cfg(not(any(target_os = "android", target_env = "ohos")))]
use std::path::{Path, PathBuf};
use log::warn;
use servo::net_traits::pub_domains::is_reg_domain;
use servo::servo_config::pref;
use servo::servo_url::ServoUrl;
use url::{self, Url};
#[cfg(not(any(target_os = "android", target_env = "ohos")))]
pub fn parse_url_or_filename(cwd: &Path, input: &str) -> Result<ServoUrl, ()> {
match ServoUrl::parse(input) {
Ok(url) => Ok(url),
Err(url::ParseError::RelativeUrlWithoutBase) => {
Url::from_file_path(&*cwd.join(input)).map(ServoUrl::from_url)
url::Url::from_file_path(&*cwd.join(input)).map(ServoUrl::from_url)
},
Err(_) => Err(()),
}
@ -33,7 +32,7 @@ pub fn get_default_url(
let cmdline_url = url_opt.map(|s| s.to_string()).and_then(|url_string| {
parse_url_or_filename(cwd.as_ref(), &url_string)
.map_err(|error| {
warn!("URL parsing failed ({:?}).", error);
log::warn!("URL parsing failed ({:?}).", error);
error
})
.ok()