Exemple #1
0
        public static void SetToolbarSearchState(Action <bool, string> onUpdateOrNull = null)
        {
            Action <bool, string> searchUsed = (committed, queryUriEncoded) => {
                var query = Window.DecodeURIComponent(queryUriEncoded);
                Logger.Debug(typeof(IawAppApi), "androidPostToolbarSearchUpdate({0}, {1})", committed, query);
                onUpdateOrNull(committed, query);
            };

            if (onUpdateOrNull == null)
            {
                Logger.Debug(typeof(IawAppApi), "setToolbarSearchState() deactivation");
                BridgeObjectUtil.SetFieldValue(Window.Instance, "androidPostToolbarSearchUpdate", null);
            }
            else
            {
                Logger.Debug(typeof(IawAppApi), "setToolbarSearchState() deactivation");
                BridgeObjectUtil.SetFieldValue(Window.Instance, "androidPostToolbarSearchUpdate", searchUsed);
            }

            var impl = GetImpl();

            if (impl != null)
            {
                impl.setToolbarSearchState(onUpdateOrNull != null);
                Logger.Debug(typeof(IawAppApi), "IAWApp setToolbarSearchState() called");
            }
            else
            {
                BridgeObjectUtil.SetFieldValue(Window.Instance, "_iawapp_setToolbarSearchState", onUpdateOrNull != null);
                Logger.Debug(typeof(IawAppApi), "fake setToolbarItems() called");
            }
        }
Exemple #2
0
        public static void SetToolbarItems(Action <MenuItemInfo> onActivated, IEnumerable <MenuItemInfo> rawMenuItems)
        {
            var menuItems = rawMenuItems.ToList();

            Action <string> rawtoolbarItemActivated = webItemIdUriEncoded => {
                var webItemId     = Window.DecodeURIComponent(webItemIdUriEncoded);
                var maybeMenuItem = menuItems.FirstOrDefault(x => x.webMenuItemId == webItemId);

                Logger.Debug(typeof(IawAppApi), "androidPostToolbarItemActivated({0}) found?={1} allItems={2}", webItemId, maybeMenuItem, menuItems.PrettyToString(y => y.webMenuItemId));

                if (maybeMenuItem != null)
                {
                    onActivated(maybeMenuItem);
                }
            };

            BridgeObjectUtil.SetFieldValue(Window.Instance, "androidPostToolbarItemActivated", rawtoolbarItemActivated);

            var impl = GetImpl();

            var mi = JsonConvert.SerializeObject(menuItems.ToArray());

            if (impl != null)
            {
                impl.setToolbarItems(mi);
                Logger.Debug(typeof(IawAppApi), "IAWApp setToolbarItems() called");
            }
            else
            {
                BridgeObjectUtil.SetFieldValue(Window.Instance, "_iawapp_setToolbarItems", mi);
                Logger.Debug(typeof(IawAppApi), "fake setToolbarItems() called");
            }
        }
        public async Task <OutpT> RunHttpRequest <InpT, OutpT>(
            string interfaceName, string methodName, Func <string, OutpT> deserialize, InpT inp)
        {
            var inputAsJson = JSON.Stringify(inp);
            var requestId   = Guid.NewGuid().ToString();

            var url = string.Format("/{0}/{1}", interfaceName, methodName);

            Logger.Debug(typeof(BridgeHttpRequester), "Request id={0} to={1} starting", requestId, url);
            var result = await Task.FromPromise <ResultHolder <XMLHttpRequest> >(
                new XMLHttpRequestImplementingIPromise("POST", url, inputAsJson),
                (Func <ResultHolder <XMLHttpRequest>, ResultHolder <XMLHttpRequest> >)(x => x));

            if (result.Success)
            {
                Logger.Debug(typeof(BridgeHttpRequester), "Request id={0} Success now will deserialize", requestId);
                var bsd = deserialize(BridgeObjectUtil.NoOpCast <string>(result.Result.ResponseText));
                Logger.Debug(typeof(BridgeHttpRequester), "Success ok deserialized");

                return(bsd);
            }

            var answer = result.Result.ResponseText;

            Logger.Error(
                typeof(BridgeHttpRequester),
                $"Failed request id={requestId} while calling server. Got status={result.Result.Status} Response={answer}");
            var errMsg = result.Result.Status == 400 ? answer.TillFirstNewLineOrEverything() : answer;

            throw new Exception(errMsg);
        }
Exemple #4
0
        /// <summary>input must be focused in order for createTextRange() to work ! </summary>
        /// <param name="self"></param>
        public static void SelectWholeTextAndMoveCursorToEnd(this Element self)
        {
            //original idea from https://css-tricks.com/snippets/javascript/move-cursor-to-end-of-input/

            if (self.HasFieldOrMethod("selectionStart") && self.IsFieldReadable("selectionStart"))
            {
                var selectionStart = self.GetFieldValue("selectionStart");

                if (Script.TypeOf(selectionStart) != "number")
                {
                    return;
                }

                var len = self.GetFieldValue("value.length");
                self.SetFieldValue("selectionStart", 0);
                self.SetFieldValue("selectionEnd", len);
                return;
            }

            var createTextRange = BridgeObjectUtil.GetFieldValue(self, "createTextRange");

            if (BridgeObjectUtil.HasFieldOrMethod(self, "select"))
            {
                BridgeObjectUtil.CallMethodPlain(self, "select");
            }

            if (Script.TypeOf(createTextRange) != "undefined")
            {
                var range = BridgeObjectUtil.CallSelf(createTextRange);
                BridgeObjectUtil.CallMethodPlain(range, "collapse", false);
                BridgeObjectUtil.CallMethodPlain(range, "select");
            }
        }
Exemple #5
0
        public void requestScanQr(string webRequestId, bool askJsForValidation, LayoutStrategy layout)
        {
            var layoutAsJson = JsonConvert.SerializeObject(layout);

            BridgeObjectUtil.CallMethodPlain(_impl, nameof(requestScanQr),
                                             webRequestId,
                                             askJsForValidation ? BridgeObjectUtil.True : BridgeObjectUtil.False,
                                             layoutAsJson);
        }
        public TValue Get(TKey key)
        {
            var result = _impl.Get(key);

            if (result == null)
            {
                // friendlier exception instead of default Bridge.InvalidCastException
                throw new KeyNotFoundException("No value for key present in WeakMap");
            }

            return(BridgeObjectUtil.NoOpCast <TValue>(result));
        }
Exemple #7
0
        private static IAWAppHostApi GetImpl()
        {
            var impl = BridgeObjectUtil.GetFieldValue(Window.Instance, "IAWApp");

            if (impl != null)
            {
                Logger.Debug(typeof(IawAppApi), "has proper IAWApp API");
                return(new IAWAppHostApi(impl));
            }

            Logger.Debug(typeof(IawAppApi), "doesn't have proper IAWApp API");
            return(null);
        }
Exemple #8
0
        public static bool SetPausedScanOverlayImage(string mediaIdentifierId)
        {
            var impl = GetImpl();

            if (impl != null)
            {
                var res = impl.setPausedScanOverlayImage(mediaIdentifierId);
                Logger.Debug(typeof(IawAppApi), "IAWApp setPausedScanOverlayImage() called");
                return(res);
            }

            BridgeObjectUtil.SetFieldValue(Window.Instance, "_iawapp_setPausedScanOverlayImage", mediaIdentifierId);
            Logger.Debug(typeof(IawAppApi), "fake setPausedScanOverlayImage() called");
            return(true);
        }
Exemple #9
0
        public static void SetToolbarBackButtonState(bool enabled)
        {
            var impl = GetImpl();

            if (impl != null)
            {
                impl.setToolbarBackButtonState(enabled);
                Logger.Debug(typeof(IawAppApi), "IAWApp SetToolbarBackButtonState() called");
            }
            else
            {
                BridgeObjectUtil.SetFieldValue(Window.Instance, "_iawapp_setToolbarBackButtonState", enabled);
                Logger.Debug(typeof(IawAppApi), "fake SetToolbarBackButtonState() called");
            }
        }
Exemple #10
0
        public static void SetToolbarColors(string backgroundColor, string foregroundColor)
        {
            var impl = GetImpl();

            if (impl != null)
            {
                impl.setToolbarColors(backgroundColor, foregroundColor);
                Logger.Debug(typeof(IawAppApi), "IAWApp SetToolbarColors() called");
            }
            else
            {
                var v = backgroundColor + "_" + foregroundColor;
                BridgeObjectUtil.SetFieldValue(Window.Instance, "_iawapp_setToolbarColors", v);
                Logger.Debug(typeof(IawAppApi), "fake SetToolbarColors() called");
            }
        }
Exemple #11
0
        public static void RegisterPostMediaAssetReady(string requestId, Action <string> action)
        {
            Logger.Debug(typeof(IAWAppHostApi), "RegisterPostMediaAssetReady {0}", requestId);
            var handler = BridgeObjectUtil.GetFieldValue(Window.Instance, "androidPostMediaAssetReady");

            if (handler == null)
            {
                Logger.Debug(typeof(IAWAppHostApi), "setup handler");
                BridgeObjectUtil.SetFieldValue(Window.Instance, nameof(androidPostMediaAssetReady), (Action <string, string>)androidPostMediaAssetReady);
            }
            else
            {
                Logger.Debug(typeof(IAWAppHostApi), "handler already installed");
            }

            _mediaReadyCallbacks.Add(requestId, action);
        }
Exemple #12
0
        public static void RegisterPostScanQrReplyHandler(string requestId, Action <IAWAppScanReply> action)
        {
            Logger.Debug(typeof(IAWAppHostApi), "RegisterPostScanQrReplyHandler {0}", requestId);
            var handler = BridgeObjectUtil.GetFieldValue(Window.Instance, nameof(androidPostScanQrReply));

            if (handler == null)
            {
                Logger.Debug(typeof(IAWAppHostApi), "setup handler");
                BridgeObjectUtil.SetFieldValue(Window.Instance, nameof(androidPostScanQrReply), (Action <string>)androidPostScanQrReply);
            }
            else
            {
                Logger.Debug(typeof(IAWAppHostApi), "handler already installed");
            }

            _scanQrCallbacks.Add(requestId, action);
        }
Exemple #13
0
        public async Task <RemoteFileId[]> Upload(
            IEnumerable <Bridge.Html5.File> uploaded, FileUploadOperation operation, RemoteFileId toReplaceOrRemoveId)
        {
            var input = _input?.Invoke();
            var res   = await XMLHttpRequestUtils.Upload(
                _interfaceName, _setterMethod, uploaded, operation, toReplaceOrRemoveId, input);

            if (!res.Success)
            {
                throw new Exception(res.Result.ResponseText);
            }

            var output = res.Result.Response;

            Logger.Debug(GetType(), "upload success file id json is {0}", output);
            return(JsonConvert.DeserializeObject <RemoteFileId[]>(
                       BridgeObjectUtil.NoOpCast <string>(output)));
        }
 public static EnvironmentType GetInstanceFromWindow(WindowInstance win) =>
 (win.Navigator.UserAgent.Contains("IndustrialAndroidWebApp") ||
  BridgeObjectUtil.HasFieldOrMethod(win, "IAWApp"))
         ? EnvironmentType.IndustrialAndroidWebApp
         : EnvironmentType.Desktop;
Exemple #15
0
 public void setToolbarItems(string menuItemInfosAsJson)
 {
     BridgeObjectUtil.CallMethodPlain(_impl, nameof(setToolbarItems), menuItemInfosAsJson);
 }
Exemple #16
0
 public void setToolbarSearchState(bool v)
 {
     BridgeObjectUtil.CallMethodPlain(_impl, nameof(setToolbarSearchState),
                                      //avoid boxing
                                      v ? BridgeObjectUtil.True : BridgeObjectUtil.False);
 }
Exemple #17
0
 public bool setPausedScanOverlayImage(string mediaAssetId) =>
 (bool)BridgeObjectUtil.CallMethodPlain(_impl, nameof(setPausedScanOverlayImage), mediaAssetId);
Exemple #18
0
 public bool setScanSuccessSound(string mediaAssetId) =>
 (bool)BridgeObjectUtil.CallMethodPlain(_impl, nameof(setScanSuccessSound), mediaAssetId);
Exemple #19
0
 public bool hasMediaAsset(string mediaAssetId) =>
 (bool)BridgeObjectUtil.CallMethodPlain(_impl, nameof(hasMediaAsset), mediaAssetId);
Exemple #20
0
 public void setToolbarColors(string backgroundColor, string foregroundColor)
 {
     BridgeObjectUtil.CallMethodPlain(_impl, "setToolbarColors", backgroundColor, foregroundColor);
 }
Exemple #21
0
 public void cancelScanQr(string webRequestId) =>
 BridgeObjectUtil.CallMethodPlain(_impl, nameof(cancelScanQr), webRequestId);
Exemple #22
0
 /// <param name="callback">return true if webapp consumed event. false if it didn't</param>
 public static void SetOnBackPressed(Func <bool> callback) =>
 BridgeObjectUtil.SetFieldValue(Window.Instance, "androidBackConsumed", callback);
Exemple #23
0
 public void registerMediaAsset(string webRequestId, string fileContent) =>
 BridgeObjectUtil.CallMethodPlain(_impl, nameof(registerMediaAsset), webRequestId, fileContent);