Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avm2: For AIR report the correct OS in flash.system.Capabilities #17590

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
evilpie marked this conversation as resolved.
Show resolved Hide resolved
} 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