﻿using System.Linq;
using System.Windows.Forms;
using Bloom.Api;

namespace Bloom.web.controllers
{
	class KeybordingConfigApi
	{
		public void RegisterWithServer(EnhancedImageServer server)
		{
			server.RegisterEndpointHandler("keyboarding/useLongPress", (ApiRequest request) => 
			{
				//detect if some keyboarding system is active, e.g. KeyMan. If it is, don't enable LongPress
				var form = Application.OpenForms.Cast<Form>().Last();
				request.ReplyWithText(SIL.Windows.Forms.Keyboarding.KeyboardController.IsFormUsingInputProcessor(form)?"false":"true");
			});
		}
	}
}

﻿using System;
using System.Linq;
using System.Windows.Forms;
using Bloom.Api;

namespace Bloom.web.controllers
{
	class KeybordingConfigApi
	{
		public void RegisterWithServer(EnhancedImageServer server)
		{
			server.RegisterEndpointHandler("keyboarding/useLongPress", (ApiRequest request) =>
			{
				try
				{
					//detect if some keyboarding system is active, e.g. KeyMan. If it is, don't enable LongPress
					var form = Application.OpenForms.Cast<Form>().Last();
					request.ReplyWithText(SIL.Windows.Forms.Keyboarding.KeyboardController.IsFormUsingInputProcessor(form)
						? "false"
						: "true");
				}
				catch(Exception error)
				{
					request.ReplyWithText("true"); // This is arbitrary. I don't know if it's better to assume keyman, or not.
					NonFatalProblem.Report(ModalIf.None, PassiveIf.All, "Error checking for keyman","", error);
				}
			}, handleOnUiThread:false);
		}
	}
}

Fix BL-3614 Crash while checking for keyman
Fix BL-3614 Crash while checking for keyman

I wasn't able to reproduce the crash, but I made it not require UI thread and catch any errors and report them passively.