<commit_before>/*©agpl*************************************************************************
*                                                                              *
* This file is part of FRIEND UNIFYING PLATFORM.                               *
* Copyright (c) Friend Software Labs AS. All rights reserved.                  *
*                                                                              *
* Licensed under the Source EULA. Please refer to the copy of the GNU Affero   *
* General Public License, found in the file license_agpl.txt.                  *
*                                                                              *
*****************************************************************************©*/

var _appNum = 1;

var _executionQueue = {};

function RemoveFromExecutionQueue( app )
{
	try
	{
		var out = {};
		for( var a in _executionQueue )
			if( a != app )
				out[ a ] = true;
		_executionQueue = out;
	}
	// Something went wrong, flush
	catch( e )
	{
		console.log( 'Problem!' );
		mobileDebug( 'Something failed with execution queue.', true );
		_executionQueue = {};
	}
}

// Load a javascript application into a sandbox
function ExecuteApplication( app, args, callback )
{
	var appName = app;
	if( app.indexOf( ':' ) > 0 )
	{
		if( app.indexOf( '/' ) > 0 )
			appName = app.split( '/' ).pop();
		else appName = app.split( ':' ).pop();
	}
	
	// You need to wait with opening apps until they are loaded by app name
	if( _executionQueue[ appName ] )
	{
		callback( false, { response: false, message: 'Already run.', data: 'executed' } );
		return;
	}

	// Register that we are executing
	_executionQueue[ appName ] = true;

	if( isMobile )
	{
		Workspace.goToMobileDesktop();
		if( Workspace.widget )
			Workspace.widget.slideUp();
		if( Workspace.mainDock )
			Workspace.mainDock.closeDesklet();
	}
	
	if( args )
	{ 
		Workspace.lastLaunchedAppArgs = args; 
	}

	// Hide current app
	if( window.FriendVR )
	{
		window.FriendVR.hideCurrentApplication();
	}

	mousePointer.clear();

	// Check if the app called is found in the singleInstanceApps array
	if( Friend.singleInstanceApps[ appName ] )
	{
		// Clean blocker
		RemoveFromExecutionQueue( appName );
		
		var msg = {
			command: 'cliarguments',
			args: args
		};
		if( callback )
		{
			msg.cid = addWrapperCallback( callback );
			msg.type = 'callback';
		}
		// If it is found, send the message directly to the app instead of relaunching
		Friend.singleInstanceApps[ appName ].contentWindow.postMessage( JSON.stringify( msg ), '*' );
		for( var a in Friend.singleInstanceApps[ appName ].windows )
		{
			_ActivateWindow( Friend.singleInstanceApps[ appName ].windows[ a ]._window.parentNode );
			_WindowToFront( Friend.singleInstanceApps[ appName ].windows[ a ]._window.parentNode );
			callback( false, { response: false, message: 'Already run.', data: 'executed' } );
			return;
		}
		callback( false, { response: false, message: 'Already run.', data: 'executed' } );
		return;
	}
	// Only allow one app instance in mobile!
	else if( isMobile )
	{
		for( var a in Workspace.applications )
		{
			if( Workspace.applications[ a ].applicationName == appName )
			{
				var app = Workspace.applications[ a ];
				for( var z in app.windows )
				{
					_ActivateWindow( app.windows[ z ]._window.parentNode );
					_WindowToFront( app.windows[ z ]._window.parentNode );
					
					// Clean blocker
					RemoveFromExecutionQueue( appName );
					
					// Tell that we didn't launch
					if( callback )
						callback( false, { response: false, message: 'Already run.', data: 'executed' } );
					return;
				}
			}
		}
	}
<commit_msg>Sometimes we do not have a callback. Check it.<commit_after>/*©agpl*************************************************************************
*                                                                              *
* This file is part of FRIEND UNIFYING PLATFORM.                               *
* Copyright (c) Friend Software Labs AS. All rights reserved.                  *
*                                                                              *
* Licensed under the Source EULA. Please refer to the copy of the GNU Affero   *
* General Public License, found in the file license_agpl.txt.                  *
*                                                                              *
*****************************************************************************©*/

var _appNum = 1;

var _executionQueue = {};

function RemoveFromExecutionQueue( app )
{
	try
	{
		var out = {};
		for( var a in _executionQueue )
			if( a != app )
				out[ a ] = true;
		_executionQueue = out;
	}
	// Something went wrong, flush
	catch( e )
	{
		console.log( 'Problem!' );
		mobileDebug( 'Something failed with execution queue.', true );
		_executionQueue = {};
	}
}

// Load a javascript application into a sandbox
function ExecuteApplication( app, args, callback )
{
	var appName = app;
	if( app.indexOf( ':' ) > 0 )
	{
		if( app.indexOf( '/' ) > 0 )
			appName = app.split( '/' ).pop();
		else appName = app.split( ':' ).pop();
	}
	
	// You need to wait with opening apps until they are loaded by app name
	if( _executionQueue[ appName ] )
	{
		if( callback )
			callback( false, { response: false, message: 'Already run.', data: 'executed' } );
		return;
	}

	// Register that we are executing
	_executionQueue[ appName ] = true;

	if( isMobile )
	{
		Workspace.goToMobileDesktop();
		if( Workspace.widget )
			Workspace.widget.slideUp();
		if( Workspace.mainDock )
			Workspace.mainDock.closeDesklet();
	}
	
	if( args )
	{ 
		Workspace.lastLaunchedAppArgs = args; 
	}

	// Hide current app
	if( window.FriendVR )
	{
		window.FriendVR.hideCurrentApplication();
	}

	mousePointer.clear();

	// Check if the app called is found in the singleInstanceApps array
	if( Friend.singleInstanceApps[ appName ] )
	{
		// Clean blocker
		RemoveFromExecutionQueue( appName );
		
		var msg = {
			command: 'cliarguments',
			args: args
		};
		if( callback )
		{
			msg.cid = addWrapperCallback( callback );
			msg.type = 'callback';
		}
		// If it is found, send the message directly to the app instead of relaunching
		Friend.singleInstanceApps[ appName ].contentWindow.postMessage( JSON.stringify( msg ), '*' );
		for( var a in Friend.singleInstanceApps[ appName ].windows )
		{
			_ActivateWindow( Friend.singleInstanceApps[ appName ].windows[ a ]._window.parentNode );
			_WindowToFront( Friend.singleInstanceApps[ appName ].windows[ a ]._window.parentNode );
			if( callback )
				callback( false, { response: false, message: 'Already run.', data: 'executed' } );
			return;
		}
		f( callback )
			callback( false, { response: false, message: 'Already run.', data: 'executed' } );
		return;
	}
	// Only allow one app instance in mobile!
	else if( isMobile )
	{
		for( var a in Workspace.applications )
		{
			if( Workspace.applications[ a ].applicationName == appName )
			{
				var app = Workspace.applications[ a ];
				for( var z in app.windows )
				{
					_ActivateWindow( app.windows[ z ]._window.parentNode );
					_WindowToFront( app.windows[ z ]._window.parentNode );
					
					// Clean blocker
					RemoveFromExecutionQueue( appName );
					
					// Tell that we didn't launch
					if( callback )
						callback( false, { response: false, message: 'Already run.', data: 'executed' } );
					return;
				}
			}
		}
	}

{'fraction_non_alphanumeric': 0.15248948582281915, 'fraction_numerical': 0.000814000814000814, 'mean_word_length': 2.4161260426320665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '920418', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2131, 'n_words': 636}