Skip to content

Commit a10b31b

Browse files
evilpieDinnerbone
authored andcommitted
avm2: For AIR report the correct OS in flash.system.Capabilities
1 parent 73919c7 commit a10b31b

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
package flash.system {
22
import __ruffle__.stub_getter;
33
public final class Capabilities {
4-
public static function get os(): String {
5-
stub_getter("flash.system.Capabilities", "os");
6-
return "Windows 8"
7-
}
8-
4+
public native static function get os(): String;
95
public native static function get playerType(): String;
10-
116
public native static function get version(): String;
12-
137
public native static function get screenResolutionX():Number;
14-
158
public native static function get screenResolutionY():Number;
16-
179
public native static function get pixelAspectRatio():Number;
18-
1910
public native static function get screenDPI():Number;
20-
2111
public static function get manufacturer(): String {
2212
stub_getter("flash.system.Capabilities", "manufacturer");
2313
return "Adobe Windows"
@@ -29,6 +19,5 @@ package flash.system {
2919
public static function get isDebugger(): Boolean {
3020
return false
3121
}
32-
3322
}
3423
}

core/src/avm2/globals/flash/system/capabilities.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,50 @@
33
use crate::avm2::{Activation, AvmString, Error, Object, Value};
44
use crate::player::PlayerRuntime;
55

6+
/// Implements `flash.system.Capabilities.os`
7+
pub fn get_os<'gc>(
8+
activation: &mut Activation<'_, 'gc>,
9+
_this: Object<'gc>,
10+
_args: &[Value<'gc>],
11+
) -> Result<Value<'gc>, Error<'gc>> {
12+
let os = match activation.avm2().player_runtime {
13+
// For most normal Flash Player usage, the OS should not matter,
14+
// so let's pretend it's Windows for the broadest possible compatibility.
15+
PlayerRuntime::FlashPlayer => "Windows 8",
16+
PlayerRuntime::AIR => {
17+
if cfg!(windows) {
18+
"Windows 10"
19+
} else if cfg!(target_os = "macos") {
20+
"Mac OS 10.5.2"
21+
} else {
22+
"Linux 5.10.49"
23+
}
24+
}
25+
};
26+
Ok(AvmString::new_utf8(activation.gc(), os).into())
27+
}
28+
629
/// Implements `flash.system.Capabilities.version`
730
pub fn get_version<'gc>(
831
activation: &mut Activation<'_, 'gc>,
932
_this: Object<'gc>,
1033
_args: &[Value<'gc>],
1134
) -> Result<Value<'gc>, Error<'gc>> {
12-
// TODO: Report the correct OS instead of always reporting Windows
35+
let os = match activation.avm2().player_runtime {
36+
PlayerRuntime::FlashPlayer => "WIN",
37+
PlayerRuntime::AIR => {
38+
if cfg!(windows) {
39+
"WIN"
40+
} else if cfg!(target_os = "macos") {
41+
"MAC"
42+
} else {
43+
"LNX"
44+
}
45+
}
46+
};
1347
Ok(AvmString::new_utf8(
14-
activation.context.gc_context,
15-
format!("WIN {},0,0,0", activation.avm2().player_version),
48+
activation.gc(),
49+
format!("{os} {},0,0,0", activation.avm2().player_version),
1650
)
1751
.into())
1852
}

0 commit comments

Comments
 (0)