Esempio n. 1
0
        internal static void Init(BrowserRenderer br, string domElementSelector, Action onFinish)
        {
            if (br == null)
            {
                throw new NullReferenceException();
            }

            br.AddComponent <BlazorXamarinExtensionScript>(domElementSelector);

            xamService = new BlazorXamarinDeviceService();

            InternalHelper.SetTimeout(async() => {
                //Safety for detect if RuntimePlatform is a Mobile app or a Browser
                //First detect Browser context eligible for Xamarin, then returning the proper Xamarin RuntimePlatform
                try
                {
                    if (RegisteredFunction.Invoke <bool>("BlazorXamarinRuntimeCheck"))
                    {
                        string resultRuntimePlatform = await xamService.GetRuntimePlatform();
                        RuntimePlatform = resultRuntimePlatform;
                    }
                    else
                    {
                        RuntimePlatform = Browser;
                    }
                }
                catch (Exception ex)
                {
                    RuntimePlatform = Browser;
                }

                onFinish?.Invoke();
            }, 100);
        }
        private async Task InitXamService()
        {
            xamService = new BlazorXamarinDeviceService();
            bool success;

            try
            {
                if (Runtime != null && await Runtime.InvokeAsync <bool>("BlazorXamarinRuntimeCheck"))
                {
                    string resultRuntimePlatform = await xamService.GetRuntimePlatform();

                    Device.RuntimePlatform = resultRuntimePlatform;
                }
                else
                {
                    //If service return false or if JSRuntime is not yet ready (on server side scenario), we return the Browser default value
                    Device.RuntimePlatform = Device.Browser;
                }

                success = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                Device.RuntimePlatform = Device.Browser;
                success = false;
            }
            Device._onFinishCallback?.Invoke(success);
        }
Esempio n. 3
0
        internal static void Init(IComponentsApplicationBuilder app, string domElementSelector, Action <bool> onFinish)
        {
            bool success = false;

            if (app == null)
            {
                onFinish?.Invoke(success);
                throw new NullReferenceException($"{nameof(IComponentsApplicationBuilder)} object is null");
            }

            app.AddComponent <BlazorXamarinExtensionScript>(domElementSelector);

            InternalHelper.SetTimeout(async() =>
            {
                xamService = new BlazorXamarinDeviceService();
                try
                {
                    if (await JSRuntime.Current.InvokeAsync <bool>("BlazorXamarinRuntimeCheck"))
                    {
                        string resultRuntimePlatform = await xamService.GetRuntimePlatform();
                        RuntimePlatform = resultRuntimePlatform;
                    }
                    else
                    {
                        RuntimePlatform = Browser;
                    }

                    success = true;
                }
                catch (Exception ex)
                {
                    RuntimePlatform = Browser;
                    throw;
                }
                onFinish?.Invoke(success);
            }, 10);
        }