diff --git a/Cargo.lock b/Cargo.lock index f3ab55fb0510..6f692aad301b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4825,7 +4825,7 @@ dependencies = [ name = "ruffle_web_safari" version = "0.1.0" dependencies = [ - "objc", + "objc2 0.6.3", ] [[package]] diff --git a/tests/Cargo.toml b/tests/Cargo.toml index f82943465558..0ae4c94344d3 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tests" authors = ["Aaron Hill "] -edition.workspace = true +edition = "2024" homepage.workspace = true license.workspace = true repository.workspace = true diff --git a/tests/framework/Cargo.toml b/tests/framework/Cargo.toml index ef06430350e6..44b431b7b12f 100644 --- a/tests/framework/Cargo.toml +++ b/tests/framework/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ruffle_test_framework" authors.workspace = true -edition.workspace = true +edition = "2024" homepage.workspace = true license.workspace = true repository.workspace = true diff --git a/tests/framework/src/backends/audio.rs b/tests/framework/src/backends/audio.rs index b473833ecfe0..3e4224282762 100644 --- a/tests/framework/src/backends/audio.rs +++ b/tests/framework/src/backends/audio.rs @@ -1,6 +1,6 @@ use ruffle_core::backend::audio::{ - swf, AudioBackend, AudioMixer, DecodeError, RegisterError, SoundHandle, SoundInstanceHandle, - SoundStreamInfo, SoundTransform, + AudioBackend, AudioMixer, DecodeError, RegisterError, SoundHandle, SoundInstanceHandle, + SoundStreamInfo, SoundTransform, swf, }; use ruffle_core::impl_audio_mixer_backend; diff --git a/tests/framework/src/backends/navigator.rs b/tests/framework/src/backends/navigator.rs index a1108b2fd0a9..f19368389b8c 100644 --- a/tests/framework/src/backends/navigator.rs +++ b/tests/framework/src/backends/navigator.rs @@ -4,8 +4,8 @@ use async_channel::{Receiver, Sender}; use percent_encoding::percent_decode_str; use ruffle_core::backend::log::LogBackend; use ruffle_core::backend::navigator::{ - async_return, create_fetch_error, ErrorResponse, NavigationMethod, NavigatorBackend, - NullExecutor, NullSpawner, OwnedFuture, Request, SuccessResponse, + ErrorResponse, NavigationMethod, NavigatorBackend, NullExecutor, NullSpawner, OwnedFuture, + Request, SuccessResponse, async_return, create_fetch_error, }; use ruffle_core::indexmap::IndexMap; use ruffle_core::loader::Error; diff --git a/tests/framework/src/backends/ui.rs b/tests/framework/src/backends/ui.rs index c7ab443384b8..75815f84235d 100644 --- a/tests/framework/src/backends/ui.rs +++ b/tests/framework/src/backends/ui.rs @@ -3,11 +3,11 @@ use std::collections::HashMap; use crate::test::Font; use chrono::{DateTime, Utc}; use ruffle_core::{ + FontFileData, FontQuery, backend::ui::{ DialogLoaderError, DialogResultFuture, FileDialogResult, FileFilter, FontDefinition, - FullscreenError, LanguageIdentifier, MouseCursor, UiBackend, US_ENGLISH, + FullscreenError, LanguageIdentifier, MouseCursor, US_ENGLISH, UiBackend, }, - FontFileData, FontQuery, }; use url::Url; diff --git a/tests/framework/src/options.rs b/tests/framework/src/options.rs index 5d42f21cb1ad..f4fb1d7fffb2 100644 --- a/tests/framework/src/options.rs +++ b/tests/framework/src/options.rs @@ -9,11 +9,11 @@ use crate::options::approximations::Approximations; use crate::options::font::{DefaultFontsOptions, FontOptions, FontSortOptions}; use crate::options::image_comparison::ImageComparison; use crate::options::player::PlayerOptions; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use serde::Deserialize; use std::collections::{HashMap, HashSet}; -use toml::de::{DeTable, DeValue}; use toml::Spanned; +use toml::de::{DeTable, DeValue}; use vfs::VfsPath; fn merge_into_subtest<'a>( diff --git a/tests/framework/src/runner.rs b/tests/framework/src/runner.rs index b194d316535b..85c0c463f400 100644 --- a/tests/framework/src/runner.rs +++ b/tests/framework/src/runner.rs @@ -6,13 +6,13 @@ use crate::backends::{TestLogBackend, TestNavigatorBackend, TestUiBackend}; use crate::environment::RenderInterface; use crate::fs_commands::{FsCommand, TestFsCommandProvider}; use crate::image_trigger::ImageTrigger; -use crate::options::image_comparison::ImageComparison; use crate::options::TestOptions; +use crate::options::image_comparison::ImageComparison; use crate::runner::automation::perform_automated_event; use crate::runner::image_test::capture_and_compare_image; use crate::runner::trace::compare_trace_output; use crate::test::Test; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use ruffle_core::backend::navigator::NullExecutor; use ruffle_core::limits::ExecutionLimit; use ruffle_core::tag_utils::SwfMovie; @@ -21,7 +21,7 @@ use ruffle_input_format::InputInjector; use ruffle_render::backend::{RenderBackend, ViewportDimensions}; use ruffle_socket_format::SocketEvent; use std::collections::HashMap; -use std::sync::{mpsc, Arc, Mutex}; +use std::sync::{Arc, Mutex, mpsc}; use std::time::Duration; use vfs::VfsPath; @@ -196,7 +196,10 @@ impl TestRunner { FsCommand::CaptureImage(name) => { if let Some(image_comparison) = self.images.remove(&name) { if image_comparison.trigger != ImageTrigger::FsCommand { - return Err(anyhow!("Encountered fscommand to capture and compare image '{name}', but the trigger was expected to be {:?}", image_comparison.trigger)); + return Err(anyhow!( + "Encountered fscommand to capture and compare image '{name}', but the trigger was expected to be {:?}", + image_comparison.trigger + )); } capture_and_compare_image( &self.root_path, @@ -207,7 +210,9 @@ impl TestRunner { self.render_interface.as_deref(), )?; } else { - return Err(anyhow!("Encountered fscommand to capture and compare image '{name}', but no [image_comparison] was set up for this.")); + return Err(anyhow!( + "Encountered fscommand to capture and compare image '{name}', but no [image_comparison] was set up for this." + )); } } } diff --git a/tests/framework/src/runner/image_test.rs b/tests/framework/src/runner/image_test.rs index ffecbad44c0c..8374d24b5c85 100644 --- a/tests/framework/src/runner/image_test.rs +++ b/tests/framework/src/runner/image_test.rs @@ -125,7 +125,9 @@ pub fn test( any_check_executed = true; if outliers <= max_outliers { - println!("{check_name} succeeded: {outliers} outliers found, max difference {max_difference}"); + println!( + "{check_name} succeeded: {outliers} outliers found, max difference {max_difference}" + ); continue; } diff --git a/tests/framework/src/runner/trace.rs b/tests/framework/src/runner/trace.rs index d4a6b5a0dafa..930ee8f0e578 100644 --- a/tests/framework/src/runner/trace.rs +++ b/tests/framework/src/runner/trace.rs @@ -1,5 +1,5 @@ use crate::options::TestOptions; -use anyhow::{anyhow, Error}; +use anyhow::{Error, anyhow}; use pretty_assertions::Comparison; use vfs::VfsPath; diff --git a/tests/framework/src/test.rs b/tests/framework/src/test.rs index e765cbff1c69..08acd6f7a04c 100644 --- a/tests/framework/src/test.rs +++ b/tests/framework/src/test.rs @@ -4,8 +4,8 @@ use crate::environment::Environment; use crate::options::TestOptions; use crate::runner::TestRunner; use crate::util::read_bytes; -use anyhow::{anyhow, Result}; -use ruffle_core::{tag_utils::SwfMovie, FontQuery, FontType}; +use anyhow::{Result, anyhow}; +use ruffle_core::{FontQuery, FontType, tag_utils::SwfMovie}; use ruffle_input_format::InputInjector; use ruffle_socket_format::SocketEvent; use vfs::VfsPath; diff --git a/tests/fs-tests-runner/Cargo.toml b/tests/fs-tests-runner/Cargo.toml index c6af4bc4fe0a..258a5b761c35 100644 --- a/tests/fs-tests-runner/Cargo.toml +++ b/tests/fs-tests-runner/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ruffle_fs_tests_runner" authors.workspace = true -edition.workspace = true +edition = "2024" homepage.workspace = true license.workspace = true repository.workspace = true diff --git a/tests/input-format/Cargo.toml b/tests/input-format/Cargo.toml index 1adbc916a8c6..e806cba77430 100644 --- a/tests/input-format/Cargo.toml +++ b/tests/input-format/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ruffle_input_format" authors.workspace = true -edition.workspace = true +edition = "2024" homepage.workspace = true license.workspace = true repository.workspace = true diff --git a/tests/mocket/Cargo.toml b/tests/mocket/Cargo.toml index f8922e93b27d..7ddbf9b4b459 100644 --- a/tests/mocket/Cargo.toml +++ b/tests/mocket/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "mocket" authors.workspace = true -edition.workspace = true +edition = "2024" homepage.workspace = true license.workspace = true repository.workspace = true diff --git a/tests/socket-format/Cargo.toml b/tests/socket-format/Cargo.toml index a5577c7fccf9..08b32366e992 100644 --- a/tests/socket-format/Cargo.toml +++ b/tests/socket-format/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ruffle_socket_format" authors.workspace = true -edition.workspace = true +edition = "2024" homepage.workspace = true license.workspace = true repository.workspace = true diff --git a/tests/tests/environment.rs b/tests/tests/environment.rs index 12a65ee9cbef..6acdfc5737b7 100644 --- a/tests/tests/environment.rs +++ b/tests/tests/environment.rs @@ -27,7 +27,7 @@ impl Environment for NativeEnvironment { #[cfg(feature = "imgtests")] mod renderer { use image::RgbaImage; - use ruffle_render_wgpu::backend::{request_adapter_and_device, WgpuRenderBackend}; + use ruffle_render_wgpu::backend::{WgpuRenderBackend, request_adapter_and_device}; use ruffle_render_wgpu::descriptors::Descriptors; use ruffle_render_wgpu::target::TextureTarget; use ruffle_render_wgpu::wgpu; diff --git a/tests/tests/regression_tests.rs b/tests/tests/regression_tests.rs index afadac1aec65..3676750b5d00 100644 --- a/tests/tests/regression_tests.rs +++ b/tests/tests/regression_tests.rs @@ -15,7 +15,7 @@ use ruffle_test_framework::runner::TestStatus; use ruffle_test_framework::test::Test; use ruffle_test_framework::vfs::VfsPath; use std::borrow::Cow; -use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe}; +use std::panic::{AssertUnwindSafe, catch_unwind, resume_unwind}; use std::path::PathBuf; use std::thread::sleep; diff --git a/web/Cargo.toml b/web/Cargo.toml index 57d8eb4d9682..cb919e0b67fd 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -2,7 +2,7 @@ name = "ruffle_web" description = "Web (WASM) bindings to the Ruffle Flash player" authors.workspace = true -edition.workspace = true +edition = "2024" homepage.workspace = true license.workspace = true repository.workspace = true diff --git a/web/common/Cargo.toml b/web/common/Cargo.toml index d04c072cf743..1a9f5f6dc335 100644 --- a/web/common/Cargo.toml +++ b/web/common/Cargo.toml @@ -2,7 +2,7 @@ name = "ruffle_web_common" version.workspace = true authors.workspace = true -edition.workspace = true +edition = "2024" license.workspace = true [lints] diff --git a/web/packages/extension/safari/Cargo.toml b/web/packages/extension/safari/Cargo.toml index c988d7764ee7..41f2fc9343cb 100644 --- a/web/packages/extension/safari/Cargo.toml +++ b/web/packages/extension/safari/Cargo.toml @@ -2,7 +2,7 @@ name = "ruffle_web_safari" description = "Native binary for the Safari Web Extension" authors.workspace = true -edition.workspace = true +edition = "2024" homepage.workspace = true license.workspace = true repository.workspace = true @@ -12,5 +12,5 @@ publish = false # This crate is useless unless packaged into an appex bundle [lints] workspace = true -[dependencies] -objc = "0.2.7" +[target.'cfg(target_os = "macos")'.dependencies] +objc2 = "0.6.3" diff --git a/web/packages/extension/safari/src/main.rs b/web/packages/extension/safari/src/main.rs index 604e6563075c..349c6c15363b 100644 --- a/web/packages/extension/safari/src/main.rs +++ b/web/packages/extension/safari/src/main.rs @@ -1,15 +1,14 @@ #[cfg(target_os = "macos")] mod macos { - use objc::class; - use objc::declare::ClassDecl; - use objc::runtime::Protocol; + use objc2::class; + use objc2::runtime::{AnyProtocol, ClassBuilder}; pub fn extension_class() { - let mut ruffle = ClassDecl::new("RuffleWebExtension", class!(NSObject)) - .expect("Couldn't allocate new ClassDecl"); + let mut ruffle = ClassBuilder::new(c"RuffleWebExtension", class!(NSObject)) + .expect("Couldn't allocate new class"); ruffle.add_protocol( - Protocol::get("NSExtensionRequestHandling") + AnyProtocol::get(c"NSExtensionRequestHandling") .expect("Couldn't find NSExtensionRequestHandling"), ); @@ -17,7 +16,7 @@ mod macos { } #[link(name = "Foundation", kind = "framework")] - extern "C" { + unsafe extern "C" { /// Private function used as the entry point of all app extensions. /// /// In Obj-C/Swift apps, a linker flag is used to set this as the entry diff --git a/web/src/audio.rs b/web/src/audio.rs index e803827161ae..6db28e05ff4a 100644 --- a/web/src/audio.rs +++ b/web/src/audio.rs @@ -1,6 +1,6 @@ use ruffle_core::backend::audio::{ - swf, AudioBackend, AudioMixer, AudioMixerProxy, DecodeError, RegisterError, SoundHandle, - SoundInstanceHandle, SoundStreamInfo, SoundTransform, + AudioBackend, AudioMixer, AudioMixerProxy, DecodeError, RegisterError, SoundHandle, + SoundInstanceHandle, SoundStreamInfo, SoundTransform, swf, }; use ruffle_core::impl_audio_mixer_backend; use ruffle_web_common::JsResult; @@ -8,8 +8,8 @@ use std::cell::{Cell, RefCell}; use std::rc::Rc; use std::sync::Arc; use std::time::Duration; -use tracing_subscriber::layer::Layered; use tracing_subscriber::Registry; +use tracing_subscriber::layer::Layered; use tracing_wasm::WASMLayer; use wasm_bindgen::prelude::*; use web_sys::{AudioContext, AudioScheduledSourceNode}; @@ -257,7 +257,7 @@ impl Drop for Buffer { } #[wasm_bindgen(raw_module = "./ruffle-imports")] -extern "C" { +unsafe extern "C" { // Imported JS method to copy interleaved audio data into an `AudioBuffer`. #[wasm_bindgen(js_name = "copyToAudioBufferInterleaved")] fn copy_to_audio_buffer_interleaved( diff --git a/web/src/builder.rs b/web/src/builder.rs index 998f46233ed5..46dc1ff813ac 100644 --- a/web/src/builder.rs +++ b/web/src/builder.rs @@ -1,8 +1,8 @@ use crate::external_interface::JavascriptInterface; use crate::navigator::{OpenUrlMode, WebNavigatorBackend}; use crate::{ - audio, log_adapter, storage, ui, JavascriptPlayer, RuffleHandle, ScrollingBehavior, - SocketProxy, RUFFLE_GLOBAL_PANIC, + JavascriptPlayer, RUFFLE_GLOBAL_PANIC, RuffleHandle, ScrollingBehavior, SocketProxy, audio, + log_adapter, storage, ui, }; use js_sys::{Promise, RegExp}; use ruffle_core::backend::audio::{AudioBackend, NullAudioBackend}; @@ -12,9 +12,9 @@ use ruffle_core::compatibility_rules::CompatibilityRules; use ruffle_core::config::{Letterbox, NetworkingAccessMode}; use ruffle_core::events::{GamepadButton, KeyCode}; use ruffle_core::{ - swf, Color, DefaultFont, Player, PlayerBuilder, PlayerRuntime, StageAlign, StageScaleMode, + Color, DefaultFont, Player, PlayerBuilder, PlayerRuntime, StageAlign, StageScaleMode, swf, }; -use ruffle_core::{ttf_parser, FontFileData}; +use ruffle_core::{FontFileData, ttf_parser}; use ruffle_render::backend::RenderBackend; use ruffle_render::quality::StageQuality; use ruffle_video_external::backend::ExternalVideoBackend; @@ -27,8 +27,8 @@ use std::rc::Rc; use std::str::FromStr; use std::sync::{Arc, Mutex}; use std::time::Duration; -use tracing_subscriber::layer::{Layered, SubscriberExt}; use tracing_subscriber::Registry; +use tracing_subscriber::layer::{Layered, SubscriberExt}; use tracing_wasm::{WASMLayer, WASMLayerConfigBuilder}; use wasm_bindgen::prelude::*; use web_sys::{HtmlCanvasElement, HtmlElement}; @@ -391,49 +391,48 @@ impl RuffleInstanceBuilder { } } else { tracing::debug!("Loading font {font_name} as SWF font"); - if let Ok(swf_stream) = swf::decompress_swf(&bytes[..]) { - if let Ok(swf) = swf::parse_swf(&swf_stream) { - let encoding = swf::SwfStr::encoding_for_version(swf.header.version()); - for tag in swf.tags { - match tag { - swf::Tag::DefineFont(_font) => { - tracing::warn!("DefineFont1 tag is not yet supported by Ruffle, inside font swf {font_name}"); - } - swf::Tag::DefineFont2(font) => { - tracing::debug!( - "Loaded font {} from font swf {font_name}", - font.name.to_str_lossy(encoding) + if let Ok(swf_stream) = swf::decompress_swf(&bytes[..]) + && let Ok(swf) = swf::parse_swf(&swf_stream) + { + let encoding = swf::SwfStr::encoding_for_version(swf.header.version()); + for tag in swf.tags { + match tag { + swf::Tag::DefineFont(_font) => { + tracing::warn!( + "DefineFont1 tag is not yet supported by Ruffle, inside font swf {font_name}" + ); + } + swf::Tag::DefineFont2(font) => { + tracing::debug!( + "Loaded font {} from font swf {font_name}", + font.name.to_str_lossy(encoding) + ); + player + .register_device_font(FontDefinition::SwfTag(*font, encoding)); + } + swf::Tag::DefineFont4(font) => { + let name = font.name.to_str_lossy(encoding); + if let Some(data) = font.data { + tracing::debug!("Loaded font {name} from font swf {font_name}"); + player.register_device_font(FontDefinition::FontFile { + name: name.to_string(), + is_bold: font.is_bold, + is_italic: font.is_italic, + // TODO remove when https://github.com/rust-lang/rust-clippy/issues/15252 is fixed + #[expect(clippy::unnecessary_to_owned)] + data: FontFileData::new(data.to_vec()), + index: 0, + }) + } else { + tracing::warn!( + "Font {name} from font swf {font_name} contains no data" ); - player.register_device_font(FontDefinition::SwfTag( - *font, encoding, - )); - } - swf::Tag::DefineFont4(font) => { - let name = font.name.to_str_lossy(encoding); - if let Some(data) = font.data { - tracing::debug!( - "Loaded font {name} from font swf {font_name}" - ); - player.register_device_font(FontDefinition::FontFile { - name: name.to_string(), - is_bold: font.is_bold, - is_italic: font.is_italic, - // TODO remove when https://github.com/rust-lang/rust-clippy/issues/15252 is fixed - #[expect(clippy::unnecessary_to_owned)] - data: FontFileData::new(data.to_vec()), - index: 0, - }) - } else { - tracing::warn!( - "Font {name} from font swf {font_name} contains no data" - ); - } } - _ => {} } + _ => {} } - continue; } + continue; } tracing::warn!("Font source {font_name} was not recognised (not a valid SWF?)"); } diff --git a/web/src/external_interface.rs b/web/src/external_interface.rs index c473ae902979..c4a54ef8af32 100644 --- a/web/src/external_interface.rs +++ b/web/src/external_interface.rs @@ -1,4 +1,4 @@ -use crate::{JavascriptPlayer, CURRENT_CONTEXT}; +use crate::{CURRENT_CONTEXT, JavascriptPlayer}; use js_sys::{Array, Object}; use ruffle_core::context::UpdateContext; use ruffle_core::external::{ @@ -89,10 +89,10 @@ pub fn js_to_external_value(js: &JsValue) -> ExternalValue { } else { let mut values = BTreeMap::new(); for entry in Object::entries(&Object::from(js.to_owned())).values() { - if let Ok(entry) = entry.and_then(|v| v.dyn_into::()) { - if let Some(key) = entry.get(0).as_string() { - values.insert(key, js_to_external_value(&entry.get(1))); - } + if let Ok(entry) = entry.and_then(|v| v.dyn_into::()) + && let Some(key) = entry.get(0).as_string() + { + values.insert(key, js_to_external_value(&entry.get(1))); } } ExternalValue::Object(values) diff --git a/web/src/lib.rs b/web/src/lib.rs index 03f4a7fbf9c6..4b14a01b27e6 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -22,7 +22,7 @@ use ruffle_core::tag_utils::SwfMovie; use ruffle_core::{Player, PlayerEvent, StaticCallstack, ViewportDimensions}; use ruffle_web_common::JsResult; use serde::Serialize; -use slotmap::{new_key_type, SlotMap}; +use slotmap::{SlotMap, new_key_type}; use std::any::Any; use std::rc::Rc; use std::str::FromStr; @@ -147,7 +147,7 @@ struct RuffleInstance { } #[wasm_bindgen(raw_module = "./internal/player/inner")] -extern "C" { +unsafe extern "C" { #[derive(Clone)] pub type JavascriptPlayer; @@ -159,7 +159,7 @@ extern "C" { #[wasm_bindgen(method, catch, js_name = "callFSCommand")] fn call_fs_command(this: &JavascriptPlayer, command: &str, args: &str) - -> Result; + -> Result; #[wasm_bindgen(method)] fn panic(this: &JavascriptPlayer, error: &JsError); @@ -1110,57 +1110,54 @@ impl RuffleHandle { )); } - if let Ok(gamepads) = instance.window.navigator().get_gamepads() { - if let Some(gamepad) = gamepads - .into_iter() - .next() - .and_then(|gamepad| gamepad.dyn_into::().ok()) - { - let mut pressed_buttons = Vec::new(); - - let buttons = gamepad.buttons(); - for (index, button) in buttons.into_iter().enumerate() { - let Ok(button) = button.dyn_into::() else { - continue; - }; + if let Ok(gamepads) = instance.window.navigator().get_gamepads() + && let Some(gamepad) = gamepads.into_iter().next() + && let Ok(gamepad) = gamepad.dyn_into::() + { + let mut pressed_buttons = Vec::new(); - if !button.pressed() { - continue; - } + let buttons = gamepad.buttons(); + for (index, button) in buttons.into_iter().enumerate() { + let Ok(button) = button.dyn_into::() else { + continue; + }; - // See https://w3c.github.io/gamepad/#remapping - let gamepad_button = match index { - 0 => GamepadButton::South, - 1 => GamepadButton::East, - 2 => GamepadButton::West, - 3 => GamepadButton::North, - 12 => GamepadButton::DPadUp, - 13 => GamepadButton::DPadDown, - 14 => GamepadButton::DPadLeft, - 15 => GamepadButton::DPadRight, - _ => continue, - }; - - pressed_buttons.push(gamepad_button); + if !button.pressed() { + continue; } - if pressed_buttons != instance.pressed_buttons { - for button in pressed_buttons.iter() { - if !instance.pressed_buttons.contains(button) { - gamepad_button_events - .push(PlayerEvent::GamepadButtonDown { button: *button }); - } - } + // See https://w3c.github.io/gamepad/#remapping + let gamepad_button = match index { + 0 => GamepadButton::South, + 1 => GamepadButton::East, + 2 => GamepadButton::West, + 3 => GamepadButton::North, + 12 => GamepadButton::DPadUp, + 13 => GamepadButton::DPadDown, + 14 => GamepadButton::DPadLeft, + 15 => GamepadButton::DPadRight, + _ => continue, + }; + + pressed_buttons.push(gamepad_button); + } - for button in instance.pressed_buttons.iter() { - if !pressed_buttons.contains(button) { - gamepad_button_events - .push(PlayerEvent::GamepadButtonUp { button: *button }); - } + if pressed_buttons != instance.pressed_buttons { + for button in pressed_buttons.iter() { + if !instance.pressed_buttons.contains(button) { + gamepad_button_events + .push(PlayerEvent::GamepadButtonDown { button: *button }); } + } - instance.pressed_buttons = pressed_buttons; + for button in instance.pressed_buttons.iter() { + if !pressed_buttons.contains(button) { + gamepad_button_events + .push(PlayerEvent::GamepadButtonUp { button: *button }); + } } + + instance.pressed_buttons = pressed_buttons; } } @@ -1306,10 +1303,10 @@ fn parse_movie_parameters(input: &JsValue) -> Vec<(String, String)> { let mut params = Vec::new(); if let Ok(keys) = js_sys::Reflect::own_keys(input) { for key in keys.values().into_iter().flatten() { - if let Ok(value) = js_sys::Reflect::get(input, &key) { - if let (Some(key), Some(value)) = (key.as_string(), value.as_string()) { - params.push((key, value)) - } + if let Ok(value) = js_sys::Reflect::get(input, &key) + && let (Some(key), Some(value)) = (key.as_string(), value.as_string()) + { + params.push((key, value)) } } } diff --git a/web/src/navigator.rs b/web/src/navigator.rs index a887c3ad1892..863adefe3165 100644 --- a/web/src/navigator.rs +++ b/web/src/navigator.rs @@ -2,34 +2,34 @@ use crate::SocketProxy; use async_channel::{Receiver, Sender}; use futures_util::future::Either; -use futures_util::{future, SinkExt, StreamExt}; -use gloo_net::websocket::{futures::WebSocket, Message}; +use futures_util::{SinkExt, StreamExt, future}; +use gloo_net::websocket::{Message, futures::WebSocket}; use js_sys::{Array, Promise, RegExp, Uint8Array}; +use ruffle_core::Player; use ruffle_core::backend::navigator::{ - async_return, create_fetch_error, create_specific_fetch_error, get_encoding, ErrorResponse, - NavigationMethod, NavigatorBackend, OwnedFuture, Request, SuccessResponse, + ErrorResponse, NavigationMethod, NavigatorBackend, OwnedFuture, Request, SuccessResponse, + async_return, create_fetch_error, create_specific_fetch_error, get_encoding, }; use ruffle_core::config::NetworkingAccessMode; use ruffle_core::indexmap::IndexMap; use ruffle_core::loader::Error; use ruffle_core::socket::{ConnectionState, SocketAction, SocketHandle}; use ruffle_core::swf::Encoding; -use ruffle_core::Player; use std::borrow::Cow; use std::cell::RefCell; use std::rc::Rc; use std::sync::{Arc, Mutex, Weak}; use std::time::Duration; -use tracing_subscriber::layer::Layered; use tracing_subscriber::Registry; +use tracing_subscriber::layer::Layered; use tracing_wasm::WASMLayer; use url::{ParseError, Url}; use wasm_bindgen::{JsCast, JsValue}; -use wasm_bindgen_futures::{spawn_local, JsFuture}; +use wasm_bindgen_futures::{JsFuture, spawn_local}; use wasm_streams::readable::ReadableStream; use web_sys::{ - window, Blob, BlobPropertyBag, HtmlFormElement, HtmlInputElement, Request as WebRequest, - RequestCredentials, RequestInit, Response as WebResponse, + Blob, BlobPropertyBag, HtmlFormElement, HtmlInputElement, Request as WebRequest, + RequestCredentials, RequestInit, Response as WebResponse, window, }; /// The handling mode of links opening a new website. @@ -216,7 +216,9 @@ impl NavigatorBackend for WebNavigatorBackend { } else { match target.to_lowercase().as_str() { "_parent" | "_self" | "_top" | "" => { - tracing::warn!("SWF tried to open a URL, but opening URLs in the current tab is prevented by script access"); + tracing::warn!( + "SWF tried to open a URL, but opening URLs in the current tab is prevented by script access" + ); return; } _ => (), diff --git a/web/src/storage.rs b/web/src/storage.rs index fdb8e8a5f2e5..76de527ff738 100644 --- a/web/src/storage.rs +++ b/web/src/storage.rs @@ -1,5 +1,5 @@ -use base64::prelude::BASE64_STANDARD; use base64::Engine; +use base64::prelude::BASE64_STANDARD; use ruffle_core::backend::storage::StorageBackend; use web_sys::Storage; @@ -15,13 +15,13 @@ impl LocalStorageBackend { impl StorageBackend for LocalStorageBackend { fn get(&self, name: &str) -> Option> { - if let Ok(Some(data)) = self.storage.get(name) { - if let Ok(data) = BASE64_STANDARD.decode(data) { - return Some(data); - } + if let Ok(Some(data)) = self.storage.get(name) + && let Ok(data) = BASE64_STANDARD.decode(data) + { + Some(data) + } else { + None } - - None } fn put(&mut self, name: &str, value: &[u8]) -> bool { diff --git a/web/src/ui.rs b/web/src/ui.rs index 85dd9952d3c2..576529413d81 100644 --- a/web/src/ui.rs +++ b/web/src/ui.rs @@ -1,12 +1,12 @@ use super::JavascriptPlayer; use rfd::{AsyncFileDialog, FileHandle}; +use ruffle_core::FontQuery; use ruffle_core::backend::ui::{ DialogLoaderError, DialogResultFuture, FileDialogResult, FileFilter, }; use ruffle_core::backend::ui::{ - FontDefinition, FullscreenError, LanguageIdentifier, MouseCursor, UiBackend, US_ENGLISH, + FontDefinition, FullscreenError, LanguageIdentifier, MouseCursor, US_ENGLISH, UiBackend, }; -use ruffle_core::FontQuery; use ruffle_web_common::JsResult; use std::borrow::Cow; use url::Url; diff --git a/web/src/zip.rs b/web/src/zip.rs index 0ae4b934aa4f..87095bcd471b 100644 --- a/web/src/zip.rs +++ b/web/src/zip.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::io::Write; -use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; use zip::write::SimpleFileOptions; #[wasm_bindgen]