Skip to content

Commit 242f6a5

Browse files
committed
chore: migrate web/* crates to edition 2024
The `obj2` crate now causes a warning ("unexpected `cfg` condition value: `cargo-clippy`") and is unmaintained, so this switches to the better-maintained `objc2` fork (https://github.com/madsmtm/objc2).
1 parent 7e7fce6 commit 242f6a5

File tree

13 files changed

+132
-135
lines changed

13 files changed

+132
-135
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "ruffle_web"
33
description = "Web (WASM) bindings to the Ruffle Flash player"
44
authors.workspace = true
5-
edition.workspace = true
5+
edition = "2024"
66
homepage.workspace = true
77
license.workspace = true
88
repository.workspace = true

web/common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "ruffle_web_common"
33
version.workspace = true
44
authors.workspace = true
5-
edition.workspace = true
5+
edition = "2024"
66
license.workspace = true
77

88
[lints]

web/packages/extension/safari/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "ruffle_web_safari"
33
description = "Native binary for the Safari Web Extension"
44
authors.workspace = true
5-
edition.workspace = true
5+
edition = "2024"
66
homepage.workspace = true
77
license.workspace = true
88
repository.workspace = true
@@ -12,5 +12,5 @@ publish = false # This crate is useless unless packaged into an appex bundle
1212
[lints]
1313
workspace = true
1414

15-
[dependencies]
16-
objc = "0.2.7"
15+
[target.'cfg(target_os = "macos")'.dependencies]
16+
objc2 = "0.6.3"

web/packages/extension/safari/src/main.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
#[cfg(target_os = "macos")]
22
mod macos {
3-
use objc::class;
4-
use objc::declare::ClassDecl;
5-
use objc::runtime::Protocol;
3+
use objc2::class;
4+
use objc2::runtime::{AnyProtocol, ClassBuilder};
65

76
pub fn extension_class() {
8-
let mut ruffle = ClassDecl::new("RuffleWebExtension", class!(NSObject))
9-
.expect("Couldn't allocate new ClassDecl");
7+
let mut ruffle = ClassBuilder::new(c"RuffleWebExtension", class!(NSObject))
8+
.expect("Couldn't allocate new class");
109

1110
ruffle.add_protocol(
12-
Protocol::get("NSExtensionRequestHandling")
11+
AnyProtocol::get(c"NSExtensionRequestHandling")
1312
.expect("Couldn't find NSExtensionRequestHandling"),
1413
);
1514

1615
ruffle.register();
1716
}
1817

1918
#[link(name = "Foundation", kind = "framework")]
20-
extern "C" {
19+
unsafe extern "C" {
2120
/// Private function used as the entry point of all app extensions.
2221
///
2322
/// In Obj-C/Swift apps, a linker flag is used to set this as the entry

web/src/audio.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use ruffle_core::backend::audio::{
2-
swf, AudioBackend, AudioMixer, AudioMixerProxy, DecodeError, RegisterError, SoundHandle,
3-
SoundInstanceHandle, SoundStreamInfo, SoundTransform,
2+
AudioBackend, AudioMixer, AudioMixerProxy, DecodeError, RegisterError, SoundHandle,
3+
SoundInstanceHandle, SoundStreamInfo, SoundTransform, swf,
44
};
55
use ruffle_core::impl_audio_mixer_backend;
66
use ruffle_web_common::JsResult;
77
use std::cell::{Cell, RefCell};
88
use std::rc::Rc;
99
use std::sync::Arc;
1010
use std::time::Duration;
11-
use tracing_subscriber::layer::Layered;
1211
use tracing_subscriber::Registry;
12+
use tracing_subscriber::layer::Layered;
1313
use tracing_wasm::WASMLayer;
1414
use wasm_bindgen::prelude::*;
1515
use web_sys::{AudioContext, AudioScheduledSourceNode};
@@ -257,7 +257,7 @@ impl Drop for Buffer {
257257
}
258258

259259
#[wasm_bindgen(raw_module = "./ruffle-imports")]
260-
extern "C" {
260+
unsafe extern "C" {
261261
// Imported JS method to copy interleaved audio data into an `AudioBuffer`.
262262
#[wasm_bindgen(js_name = "copyToAudioBufferInterleaved")]
263263
fn copy_to_audio_buffer_interleaved(

web/src/builder.rs

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::external_interface::JavascriptInterface;
22
use crate::navigator::{OpenUrlMode, WebNavigatorBackend};
33
use crate::{
4-
audio, log_adapter, storage, ui, JavascriptPlayer, RuffleHandle, ScrollingBehavior,
5-
SocketProxy, RUFFLE_GLOBAL_PANIC,
4+
JavascriptPlayer, RUFFLE_GLOBAL_PANIC, RuffleHandle, ScrollingBehavior, SocketProxy, audio,
5+
log_adapter, storage, ui,
66
};
77
use js_sys::{Promise, RegExp};
88
use ruffle_core::backend::audio::{AudioBackend, NullAudioBackend};
@@ -12,9 +12,9 @@ use ruffle_core::compatibility_rules::CompatibilityRules;
1212
use ruffle_core::config::{Letterbox, NetworkingAccessMode};
1313
use ruffle_core::events::{GamepadButton, KeyCode};
1414
use ruffle_core::{
15-
swf, Color, DefaultFont, Player, PlayerBuilder, PlayerRuntime, StageAlign, StageScaleMode,
15+
Color, DefaultFont, Player, PlayerBuilder, PlayerRuntime, StageAlign, StageScaleMode, swf,
1616
};
17-
use ruffle_core::{ttf_parser, FontFileData};
17+
use ruffle_core::{FontFileData, ttf_parser};
1818
use ruffle_render::backend::RenderBackend;
1919
use ruffle_render::quality::StageQuality;
2020
use ruffle_video_external::backend::ExternalVideoBackend;
@@ -27,8 +27,8 @@ use std::rc::Rc;
2727
use std::str::FromStr;
2828
use std::sync::{Arc, Mutex};
2929
use std::time::Duration;
30-
use tracing_subscriber::layer::{Layered, SubscriberExt};
3130
use tracing_subscriber::Registry;
31+
use tracing_subscriber::layer::{Layered, SubscriberExt};
3232
use tracing_wasm::{WASMLayer, WASMLayerConfigBuilder};
3333
use wasm_bindgen::prelude::*;
3434
use web_sys::{HtmlCanvasElement, HtmlElement};
@@ -391,49 +391,48 @@ impl RuffleInstanceBuilder {
391391
}
392392
} else {
393393
tracing::debug!("Loading font {font_name} as SWF font");
394-
if let Ok(swf_stream) = swf::decompress_swf(&bytes[..]) {
395-
if let Ok(swf) = swf::parse_swf(&swf_stream) {
396-
let encoding = swf::SwfStr::encoding_for_version(swf.header.version());
397-
for tag in swf.tags {
398-
match tag {
399-
swf::Tag::DefineFont(_font) => {
400-
tracing::warn!("DefineFont1 tag is not yet supported by Ruffle, inside font swf {font_name}");
401-
}
402-
swf::Tag::DefineFont2(font) => {
403-
tracing::debug!(
404-
"Loaded font {} from font swf {font_name}",
405-
font.name.to_str_lossy(encoding)
394+
if let Ok(swf_stream) = swf::decompress_swf(&bytes[..])
395+
&& let Ok(swf) = swf::parse_swf(&swf_stream)
396+
{
397+
let encoding = swf::SwfStr::encoding_for_version(swf.header.version());
398+
for tag in swf.tags {
399+
match tag {
400+
swf::Tag::DefineFont(_font) => {
401+
tracing::warn!(
402+
"DefineFont1 tag is not yet supported by Ruffle, inside font swf {font_name}"
403+
);
404+
}
405+
swf::Tag::DefineFont2(font) => {
406+
tracing::debug!(
407+
"Loaded font {} from font swf {font_name}",
408+
font.name.to_str_lossy(encoding)
409+
);
410+
player
411+
.register_device_font(FontDefinition::SwfTag(*font, encoding));
412+
}
413+
swf::Tag::DefineFont4(font) => {
414+
let name = font.name.to_str_lossy(encoding);
415+
if let Some(data) = font.data {
416+
tracing::debug!("Loaded font {name} from font swf {font_name}");
417+
player.register_device_font(FontDefinition::FontFile {
418+
name: name.to_string(),
419+
is_bold: font.is_bold,
420+
is_italic: font.is_italic,
421+
// TODO remove when https://github.com/rust-lang/rust-clippy/issues/15252 is fixed
422+
#[expect(clippy::unnecessary_to_owned)]
423+
data: FontFileData::new(data.to_vec()),
424+
index: 0,
425+
})
426+
} else {
427+
tracing::warn!(
428+
"Font {name} from font swf {font_name} contains no data"
406429
);
407-
player.register_device_font(FontDefinition::SwfTag(
408-
*font, encoding,
409-
));
410-
}
411-
swf::Tag::DefineFont4(font) => {
412-
let name = font.name.to_str_lossy(encoding);
413-
if let Some(data) = font.data {
414-
tracing::debug!(
415-
"Loaded font {name} from font swf {font_name}"
416-
);
417-
player.register_device_font(FontDefinition::FontFile {
418-
name: name.to_string(),
419-
is_bold: font.is_bold,
420-
is_italic: font.is_italic,
421-
// TODO remove when https://github.com/rust-lang/rust-clippy/issues/15252 is fixed
422-
#[expect(clippy::unnecessary_to_owned)]
423-
data: FontFileData::new(data.to_vec()),
424-
index: 0,
425-
})
426-
} else {
427-
tracing::warn!(
428-
"Font {name} from font swf {font_name} contains no data"
429-
);
430-
}
431430
}
432-
_ => {}
433431
}
432+
_ => {}
434433
}
435-
continue;
436434
}
435+
continue;
437436
}
438437
tracing::warn!("Font source {font_name} was not recognised (not a valid SWF?)");
439438
}

web/src/external_interface.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{JavascriptPlayer, CURRENT_CONTEXT};
1+
use crate::{CURRENT_CONTEXT, JavascriptPlayer};
22
use js_sys::{Array, Object};
33
use ruffle_core::context::UpdateContext;
44
use ruffle_core::external::{
@@ -89,10 +89,10 @@ pub fn js_to_external_value(js: &JsValue) -> ExternalValue {
8989
} else {
9090
let mut values = BTreeMap::new();
9191
for entry in Object::entries(&Object::from(js.to_owned())).values() {
92-
if let Ok(entry) = entry.and_then(|v| v.dyn_into::<Array>()) {
93-
if let Some(key) = entry.get(0).as_string() {
94-
values.insert(key, js_to_external_value(&entry.get(1)));
95-
}
92+
if let Ok(entry) = entry.and_then(|v| v.dyn_into::<Array>())
93+
&& let Some(key) = entry.get(0).as_string()
94+
{
95+
values.insert(key, js_to_external_value(&entry.get(1)));
9696
}
9797
}
9898
ExternalValue::Object(values)

web/src/lib.rs

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ruffle_core::tag_utils::SwfMovie;
2222
use ruffle_core::{Player, PlayerEvent, StaticCallstack, ViewportDimensions};
2323
use ruffle_web_common::JsResult;
2424
use serde::Serialize;
25-
use slotmap::{new_key_type, SlotMap};
25+
use slotmap::{SlotMap, new_key_type};
2626
use std::any::Any;
2727
use std::rc::Rc;
2828
use std::str::FromStr;
@@ -147,7 +147,7 @@ struct RuffleInstance {
147147
}
148148

149149
#[wasm_bindgen(raw_module = "./internal/player/inner")]
150-
extern "C" {
150+
unsafe extern "C" {
151151
#[derive(Clone)]
152152
pub type JavascriptPlayer;
153153

@@ -159,7 +159,7 @@ extern "C" {
159159

160160
#[wasm_bindgen(method, catch, js_name = "callFSCommand")]
161161
fn call_fs_command(this: &JavascriptPlayer, command: &str, args: &str)
162-
-> Result<bool, JsValue>;
162+
-> Result<bool, JsValue>;
163163

164164
#[wasm_bindgen(method)]
165165
fn panic(this: &JavascriptPlayer, error: &JsError);
@@ -1110,57 +1110,54 @@ impl RuffleHandle {
11101110
));
11111111
}
11121112

1113-
if let Ok(gamepads) = instance.window.navigator().get_gamepads() {
1114-
if let Some(gamepad) = gamepads
1115-
.into_iter()
1116-
.next()
1117-
.and_then(|gamepad| gamepad.dyn_into::<WebGamepad>().ok())
1118-
{
1119-
let mut pressed_buttons = Vec::new();
1120-
1121-
let buttons = gamepad.buttons();
1122-
for (index, button) in buttons.into_iter().enumerate() {
1123-
let Ok(button) = button.dyn_into::<WebGamepadButton>() else {
1124-
continue;
1125-
};
1113+
if let Ok(gamepads) = instance.window.navigator().get_gamepads()
1114+
&& let Some(gamepad) = gamepads.into_iter().next()
1115+
&& let Ok(gamepad) = gamepad.dyn_into::<WebGamepad>()
1116+
{
1117+
let mut pressed_buttons = Vec::new();
11261118

1127-
if !button.pressed() {
1128-
continue;
1129-
}
1119+
let buttons = gamepad.buttons();
1120+
for (index, button) in buttons.into_iter().enumerate() {
1121+
let Ok(button) = button.dyn_into::<WebGamepadButton>() else {
1122+
continue;
1123+
};
11301124

1131-
// See https://w3c.github.io/gamepad/#remapping
1132-
let gamepad_button = match index {
1133-
0 => GamepadButton::South,
1134-
1 => GamepadButton::East,
1135-
2 => GamepadButton::West,
1136-
3 => GamepadButton::North,
1137-
12 => GamepadButton::DPadUp,
1138-
13 => GamepadButton::DPadDown,
1139-
14 => GamepadButton::DPadLeft,
1140-
15 => GamepadButton::DPadRight,
1141-
_ => continue,
1142-
};
1143-
1144-
pressed_buttons.push(gamepad_button);
1125+
if !button.pressed() {
1126+
continue;
11451127
}
11461128

1147-
if pressed_buttons != instance.pressed_buttons {
1148-
for button in pressed_buttons.iter() {
1149-
if !instance.pressed_buttons.contains(button) {
1150-
gamepad_button_events
1151-
.push(PlayerEvent::GamepadButtonDown { button: *button });
1152-
}
1153-
}
1129+
// See https://w3c.github.io/gamepad/#remapping
1130+
let gamepad_button = match index {
1131+
0 => GamepadButton::South,
1132+
1 => GamepadButton::East,
1133+
2 => GamepadButton::West,
1134+
3 => GamepadButton::North,
1135+
12 => GamepadButton::DPadUp,
1136+
13 => GamepadButton::DPadDown,
1137+
14 => GamepadButton::DPadLeft,
1138+
15 => GamepadButton::DPadRight,
1139+
_ => continue,
1140+
};
1141+
1142+
pressed_buttons.push(gamepad_button);
1143+
}
11541144

1155-
for button in instance.pressed_buttons.iter() {
1156-
if !pressed_buttons.contains(button) {
1157-
gamepad_button_events
1158-
.push(PlayerEvent::GamepadButtonUp { button: *button });
1159-
}
1145+
if pressed_buttons != instance.pressed_buttons {
1146+
for button in pressed_buttons.iter() {
1147+
if !instance.pressed_buttons.contains(button) {
1148+
gamepad_button_events
1149+
.push(PlayerEvent::GamepadButtonDown { button: *button });
11601150
}
1151+
}
11611152

1162-
instance.pressed_buttons = pressed_buttons;
1153+
for button in instance.pressed_buttons.iter() {
1154+
if !pressed_buttons.contains(button) {
1155+
gamepad_button_events
1156+
.push(PlayerEvent::GamepadButtonUp { button: *button });
1157+
}
11631158
}
1159+
1160+
instance.pressed_buttons = pressed_buttons;
11641161
}
11651162
}
11661163

@@ -1306,10 +1303,10 @@ fn parse_movie_parameters(input: &JsValue) -> Vec<(String, String)> {
13061303
let mut params = Vec::new();
13071304
if let Ok(keys) = js_sys::Reflect::own_keys(input) {
13081305
for key in keys.values().into_iter().flatten() {
1309-
if let Ok(value) = js_sys::Reflect::get(input, &key) {
1310-
if let (Some(key), Some(value)) = (key.as_string(), value.as_string()) {
1311-
params.push((key, value))
1312-
}
1306+
if let Ok(value) = js_sys::Reflect::get(input, &key)
1307+
&& let (Some(key), Some(value)) = (key.as_string(), value.as_string())
1308+
{
1309+
params.push((key, value))
13131310
}
13141311
}
13151312
}

0 commit comments

Comments
 (0)