|
3 | 3 | use crate::avm2::{Activation, AvmString, Error, Object, Value};
|
4 | 4 | use crate::player::PlayerRuntime;
|
5 | 5 |
|
| 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 | + |
6 | 29 | /// Implements `flash.system.Capabilities.version`
|
7 | 30 | pub fn get_version<'gc>(
|
8 | 31 | activation: &mut Activation<'_, 'gc>,
|
9 | 32 | _this: Object<'gc>,
|
10 | 33 | _args: &[Value<'gc>],
|
11 | 34 | ) -> 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 | + }; |
13 | 47 | 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), |
16 | 50 | )
|
17 | 51 | .into())
|
18 | 52 | }
|
|
0 commit comments