Adobe-Runtime-Support icon indicating copy to clipboard operation
Adobe-Runtime-Support copied to clipboard

[Windows] NativeApplication.nativeApplication.activate() doesn't work at OS user logon if 2 or more screens connected to device

Open itlancer opened this issue 1 year ago • 0 comments

Problem Description

NativeApplication.nativeApplication.activate() doesn't work at Windows OS user logon if 2 or more screens connected to device. This issue cause that AIR application cannot activate window after OS loaded at user logon. May be it happens only with high performance devices and "fast" screens initialization or something like that.

It has been tested with multiple AIR versions, even with latest AIR 33.1.1.929 with multiple Windows 10 devices with different AIR applications. Same problem with most of devices (almost all of it high performance). There is no such issues with only 1 connected screen. Some of tested devices:

  • Windows 10.0.19044 64-bit IoT Enterprise Edition, Intel(R) Core(TM) i7-1165G7 @ 2.80GHz, 8 GB RAM, Intel(R) Iris(R) Xe Graphics with 2-4 Prestigio PDSIN55WNN0L professional TV panels

There is no such issues with other (non-AIR) applications.

Adding

<windows>
	<maxD3D>9</maxD3D>
</windows>

to application manifest didn't help.

Related issues (not the same): https://github.com/airsdk/Adobe-Runtime-Support/issues/861 https://github.com/airsdk/Adobe-Runtime-Support/issues/365

Steps to Reproduce

  1. Package AIR application with code below. It just call NativeApplication.nativeApplication.activate() to make AIR application window visible and active. Note: application should have initial window setting in manifest <visible>false</visible>.
  2. Set up AIR application autostart at user logon. Use Windows device with 2 or more connected screens (monitors). NativeApplication::startAtLogin doesn't work (https://github.com/airsdk/Adobe-Runtime-Support/issues/861) right now, so you can open Windows Task Scheduler. Create new task: Screenshot_39 Set up user logon trigger: Screenshot_40 And choose our AIR application to launch: Screenshot_41
  3. Reboot Windows device.

Application example with sources attached. windows_autostart_nativeapplication_activate_bug.zip

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.display.NativeWindow;
	import flash.desktop.NativeApplication;
	import flash.filesystem.FileStream;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	
	public class WindowsAutoStartNativeApplicationActivateBug extends Sprite {
		private var window:NativeWindow;
		
		public function WindowsAutoStartNativeApplicationActivateBug() {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			window = stage.nativeWindow;
			stage.addEventListener(Event.ENTER_FRAME, firstFrameRendered);
		}
	
		private function firstFrameRendered(e:Event):void {
			trace("firstFrameRendered");
			stage.removeEventListener(Event.ENTER_FRAME, firstFrameRendered);
			
			window.addEventListener(Event.ACTIVATE, windowActivated);//This event not dispatch
			if (window.active){
				window.removeEventListener(Event.ACTIVATE, windowActivated);
				window.visible = true;
				trace("window already active");
				
				var fs:FileStream = new FileStream();
				fs.open(new File(File.applicationDirectory.resolvePath("test.txt").nativePath), FileMode.WRITE);
				fs.writeUTFBytes("window already active");
				fs.close();
				return;
			}
			
			try {
				NativeApplication.nativeApplication.activate(window);//This function do nothing when application launches at OS logon
			} catch (err:Error){
				var fs2:FileStream = new FileStream();
				fs2.open(new File(File.applicationDirectory.resolvePath("test.txt").nativePath), FileMode.WRITE);
				fs2.writeUTFBytes("error " + err.errorID + " " + err.message);
				fs2.close();
			}
		}
		
		private function windowActivated(e:Event):void {
			window.removeEventListener(Event.ACTIVATE, windowActivated);
			window.visible = true;
			trace("windowActivated");
			
			var fs:FileStream = new FileStream();
			fs.open(new File(File.applicationDirectory.resolvePath("test.txt").nativePath), FileMode.WRITE);
			fs.writeUTFBytes("windowActivated");
			fs.close();
		}
		
	}
}

Actual Result: AIR application launches but no window will be activated or visible. Just application process in background. No any exceptions occurred. NativeApplication.nativeApplication.activate(window) doesn't work.

Expected Result: AIR application launches and it window will be activated (and visible). Or exception should be thrown if something goes wrong.

Known Workarounds

Create Timer (~10 seconds) after NativeApplication.nativeApplication.activate(window), check if NativeWindow::visible==true and try again to activate window. After some timeout (or autostart delay) or after subsequence NativeApplication::activate() calls application window will be activated and shown.

itlancer avatar Oct 09 '22 19:10 itlancer