Skip to content

Commit

Permalink
avm2: For AIR report the correct OS in flash.system.Capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie authored and Dinnerbone committed Aug 21, 2024
1 parent 73919c7 commit a10b31b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
13 changes: 1 addition & 12 deletions core/src/avm2/globals/flash/system/Capabilities.as
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
package flash.system {
import __ruffle__.stub_getter;
public final class Capabilities {
public static function get os(): String {
stub_getter("flash.system.Capabilities", "os");
return "Windows 8"
}

public native static function get os(): String;
public native static function get playerType(): String;

public native static function get version(): String;

public native static function get screenResolutionX():Number;

public native static function get screenResolutionY():Number;

public native static function get pixelAspectRatio():Number;

public native static function get screenDPI():Number;

public static function get manufacturer(): String {
stub_getter("flash.system.Capabilities", "manufacturer");
return "Adobe Windows"
Expand All @@ -29,6 +19,5 @@ package flash.system {
public static function get isDebugger(): Boolean {
return false
}

}
}
40 changes: 37 additions & 3 deletions core/src/avm2/globals/flash/system/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,50 @@
use crate::avm2::{Activation, AvmString, Error, Object, Value};
use crate::player::PlayerRuntime;

/// Implements `flash.system.Capabilities.os`
pub fn get_os<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let os = match activation.avm2().player_runtime {
// For most normal Flash Player usage, the OS should not matter,
// so let's pretend it's Windows for the broadest possible compatibility.
PlayerRuntime::FlashPlayer => "Windows 8",
PlayerRuntime::AIR => {
if cfg!(windows) {
"Windows 10"
} else if cfg!(target_os = "macos") {
"Mac OS 10.5.2"
} else {
"Linux 5.10.49"
}
}
};
Ok(AvmString::new_utf8(activation.gc(), os).into())
}

/// Implements `flash.system.Capabilities.version`
pub fn get_version<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
// TODO: Report the correct OS instead of always reporting Windows
let os = match activation.avm2().player_runtime {
PlayerRuntime::FlashPlayer => "WIN",
PlayerRuntime::AIR => {
if cfg!(windows) {
"WIN"
} else if cfg!(target_os = "macos") {
"MAC"
} else {
"LNX"
}
}
};
Ok(AvmString::new_utf8(
activation.context.gc_context,
format!("WIN {},0,0,0", activation.avm2().player_version),
activation.gc(),
format!("{os} {},0,0,0", activation.avm2().player_version),
)
.into())
}
Expand Down

0 comments on commit a10b31b

Please sign in to comment.