Skip to content

Commit

Permalink
avm2: Add some AIR desktop/display APIs stub
Browse files Browse the repository at this point in the history
Co-authored-by: Fancy2209 <[email protected]>
  • Loading branch information
Mesteery and Fancy2209 committed Aug 5, 2024
1 parent 4d85307 commit 69a75a5
Show file tree
Hide file tree
Showing 41 changed files with 1,309 additions and 26 deletions.
1 change: 1 addition & 0 deletions core/src/avm2/globals/flash.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! `flash` namespace
pub mod crypto;
pub mod desktop;
pub mod display;
#[allow(non_snake_case)]
pub mod display3D;
Expand Down
1 change: 1 addition & 0 deletions core/src/avm2/globals/flash/desktop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod native_application;
21 changes: 21 additions & 0 deletions core/src/avm2/globals/flash/desktop/Icon.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// The initial version of this file was autogenerated from the official AS3 reference at
// https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/Icon.html
// by https://github.com/golfinq/ActionScript_Event_Builder
// It won't be regenerated in the future, so feel free to edit and/or fix

package flash.desktop
{
import flash.events.EventDispatcher;
[API("661")]
public class Icon extends EventDispatcher
{

// The icon image as an array of BitmapData objects of different sizes.
public var bitmaps:Array;

function Icon(bitmaps:Array)
{
this.bitmaps = bitmaps;
}
}
}
27 changes: 27 additions & 0 deletions core/src/avm2/globals/flash/desktop/InteractiveIcon.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// The initial version of this file was autogenerated from the official AS3 reference at
// https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/InteractiveIcon.html
// by https://github.com/golfinq/ActionScript_Event_Builder
// It won't be regenerated in the future, so feel free to edit and/or fix

package flash.desktop
{
[API("661")]
public class InteractiveIcon extends Icon
{
// The current display height of the icon in pixels.
private var _height:int;

// The current display width of the icon in pixels.
private var _width:int;

public function get height():int
{
return this._height;
}

public function get width():int
{
return this._width;
}
}
}
261 changes: 261 additions & 0 deletions core/src/avm2/globals/flash/desktop/NativeApplication.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
package flash.desktop
{
import flash.display.NativeWindow;
import flash.events.InvokeEvent;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.EventDispatcher;
import flash.system.Security;
import flash.utils.Timer;
import flash.utils.setTimeout;
import __ruffle__.stub_method;
import __ruffle__.stub_getter;
import __ruffle__.stub_setter;

[API("661")]
public final class NativeApplication extends EventDispatcher
{
private static var _instance:NativeApplication;

public var _openedWindows:Array = [];

private var _idleThreshold:int = 300;

public function NativeApplication()
{
super();
setTimeout(function():void
{
dispatchEvent(new InvokeEvent(InvokeEvent.INVOKE, false, false, null, getArgvInternal()));
}, 500);
}

private static native function getArgvInternal():Array;

public static function get nativeApplication():NativeApplication
{
if (!_instance)
_instance = new NativeApplication();
return _instance;
}

public static function get supportsMenu():Boolean
{
stub_getter("flash.desktop.NativeApplication", "supportsMenu");
return false;
}

public static function get supportsDockIcon():Boolean
{
stub_getter("flash.desktop.NativeApplication", "supportsDockIcon");
return false;
}

public static function get supportsSystemTrayIcon():Boolean
{
stub_getter("flash.desktop.NativeApplication", "supportsSystemTrayIcon");
return false;
}

[API("668")]
public static function get supportsDefaultApplication():Boolean
{
stub_getter("flash.desktop.NativeApplication", "supportsDefaultApplication");
return false;
}

[API("668")]
public static function get supportsStartAtLogin():Boolean
{
stub_getter("flash.desktop.NativeApplication", "supportsStartAtLogin");
return false;
}

public function exit(exitCode:int = 0):void
{
stub_method("flash.desktop.NativeApplication", "exit");
}

public function get runtimeVersion():String
{
stub_method("flash.desktop.NativeApplication", "runtimeVersion");
return "5.0.0";
}

public function get runtimePatchLevel():uint
{
stub_method("flash.desktop.NativeApplication", "runtimePatchLevel");
return 0;
}

public function get applicationID():String
{
stub_method("flash.desktop.NativeApplication", "applicationID");
return "";
}

public function get publisherID():String
{
stub_method("flash.desktop.NativeApplication", "publisherID");
return "";
}

public function get applicationDescriptor():XML
{
stub_method("flash.desktop.NativeApplication", "applicationDescriptor");
return null;
}

public function get autoExit():Boolean
{
stub_getter("flash.desktop.NativeApplication", "autoExit");
return false;
}

public function set autoExit(param1:Boolean):void
{
stub_getter("flash.desktop.NativeApplication", "autoExit");
}

public function get icon():InteractiveIcon
{
stub_getter("flash.desktop.NativeApplication", "icon");
return null;
}

[API("668")]
public function get systemIdleMode():String
{
stub_getter("flash.desktop.NativeApplication", "systemIdleMode");
return "normal";
}

[API("668")]
public function set systemIdleMode(param1:String):void
{
stub_setter("flash.desktop.NativeApplication", "systemIdleMode");
}

public function get startAtLogin():Boolean
{
stub_getter("flash.desktop.NativeApplication", "startAtLogin");
return false;
}

public function set startAtLogin(param1:Boolean):void
{
stub_setter("flash.desktop.NativeApplication", "startAtLogin");
}

public function activate(window:NativeWindow = null):void
{
stub_method("flash.desktop.NativeApplication", "activate");
}

public function get activeWindow():NativeWindow
{
stub_getter("flash.desktop.NativeApplication", "activeWindow");
return _openedWindows[0];
}

public function get openedWindows():Array
{
stub_getter("flash.desktop.NativeApplication", "openedWindows");
return _openedWindows;
}

public function get timeSinceLastUserInput():int
{
stub_getter("flash.desktop.NativeApplication", "timeSinceLastUserInput");
return 100;
}

public function get idleThreshold():int
{
return this._idleThreshold;
}

public function set idleThreshold(value:int):void
{
this._idleThreshold = value;
}

public function copy():Boolean
{
stub_getter("flash.desktop.NativeApplication", "copy");
return false;
}

public function cut():Boolean
{
stub_getter("flash.desktop.NativeApplication", "cut");
return false;
}

public function paste():Boolean
{
stub_getter("flash.desktop.NativeApplication", "paste");
return false;
}

public function clear():Boolean
{
stub_getter("flash.desktop.NativeApplication", "clear");
return false;
}

public function selectAll():Boolean
{
stub_method("flash.desktop.NativeApplication", "selectAll");
return false;
}

public function getDefaultApplication(extension:String):String
{
stub_method("flash.desktop.NativeApplication", "getDefaultApplication");
return null;
}

public function isSetAsDefaultApplication(extension:String):Boolean
{
stub_method("flash.desktop.NativeApplication", "isSetAsDefaultApplication");
return true;
}

public function setAsDefaultApplication(extension:String):void
{
stub_method("flash.desktop.NativeApplication", "setAsDefaultApplication");
}

public function removeAsDefaultApplication(extension:String):void
{
stub_method("flash.desktop.NativeApplication", "removeAsDefaultApplication");
}

[API("681")]
public function get executeInBackground():Boolean
{
stub_getter("flash.desktop.NativeApplication", "executeInBackground");
return false;
}

[API("681")]
public function set executeInBackground(param1:Boolean):void
{
stub_setter("flash.desktop.NativeApplication", "executeInBackground");
}

// [API("721")] Ruffle doesn't support this API Version
public function get isCompiledAOT():Boolean
{
stub_getter("flash.desktop.NativeApplication", "isCompiledAOT");
return true;
}

public function get isActive():Boolean
{
stub_getter("flash.desktop.NativeApplication", "isActive");
return true;
}
}
}
17 changes: 17 additions & 0 deletions core/src/avm2/globals/flash/desktop/native_application.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::avm2::{Activation, ArrayObject, ArrayStorage, Error, Object, Value};
use crate::string::AvmString;

pub fn get_argv_internal<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let values = activation
.context
.air_argv
.iter()
.map(|arg| Some(AvmString::new_utf8(activation.context.gc_context, arg).into()))
.collect::<Vec<Option<Value<'gc>>>>();
let storage = ArrayStorage::from_storage(values);
Ok(ArrayObject::from_storage(activation, storage)?.into())
}
1 change: 1 addition & 0 deletions core/src/avm2/globals/flash/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod loader;
pub mod loader_info;
pub mod morph_shape;
pub mod movie_clip;
pub mod screen;
pub mod shader_data;
pub mod shader_job;
pub mod shader_parameter;
Expand Down
Loading

0 comments on commit 69a75a5

Please sign in to comment.