Getting only first few characters when getting input value using Ionic 4 Keypress event with a scanner - ipad

I'm implementing a ionic 4 based iOS app specifically designed for iPad. The app sends barcode data to server, scanned using a wireless scanner connected thru bluetooth to the app. TO enable autosave, I have written a keypress event capture method, which detects "enter" key press on scanner. When it detects "enter key" the data is automatically send to backend server.
Here is my html
<ion-item>
<ion-label position = "floating" class="lab-font">Order/Tracking/UCC No.<ion-note style="color: red">*</ion-note></ion-label>
<ion-input #order type = "text" text-uppercase formControlName = "order" (ionFocus) = "enableKey()" (ionBlur) = "scanOrder($event)"
(ionInput) = "checkRepeat()" (keypress)="handleKeyboardEvent($event)" class="lab-font" required ></ion-input>
</ion-item>
The keypress is triggered using (keypress)="handleKeyboardEvent($event)"
On the Typescript file, I have
handleKeyboardEvent(event: KeyboardEvent) {
if(event.key.toLowerCase() === "enter"){
this.submitOrderSearch(this.order.value);
}
}
When we manually type using virtual keyboard, this works perfectly. But when we use a scanner (Wireless, bluetooth connected to iPAD, used as an input device) and scan a barcode last few characters are missed while we call submitOrderSearch method.
Will there be a delay in binding the value to the input field? Because the scanners reads the data pretty quickly and I can see the method detects enter key as soon as the scanner beeps. Or Am I missing something here?
Below is the bar code I'm using.

Right now, we have worked around this issue with Timeout. I'm not sure whether this is the right approach, but for now, nothing else works with reliability.
In the type script I have changed this to
//Method to handle enter event
handleScanner(evt){
setTimeout(() => {
let value = evt.target.value;
this.enterEvt = true;
this.submitOrderSearch(value);
},800);
}
and in the HTML
<ion-input #order type = "text" text-uppercase formControlName = "order"
(ionInput) = "enableSerialNumbers($event)" class="lab-font" (keyup.enter)="handleScanner($event)" required ></ion-input>
Basically the binding is happening little slower than the event itself. So a slight delay make sure that the value is properly bound to the control. The other way is to buffer key key which is pressed, and use the buffer to convert to string when enter key is pressed.

Related

Google Workspace Add-ons Quickstart Cats stopped working on iOS gmail

I've started to receive reports that the add-on we have been using for a while stopped working on iOS mobile. I was able to confirm this and started to dig into the issues. I've been able to reproduce the error with the "Quickstart: Cats Google Workspace Add-on" using multiple google accounts (gmail and workspace). It appears that cards, navigation, and notifications being returned from a function called by a button in card do not render on iOS Gmail. The code appears to work on desktop. I was able to demo this with the Quickstart tutorial. I removed the need for whitelist urls on mobile using the following createCatCard that shows the current time instead of a cat picture. This project works on desktop but not on iOS Gmail.
I've reported this to google via their issue tracker (https://issuetracker.google.com/issues/210484310) but they state that "The Issue Tracker is intended for reporting issues and asking for features related to development with/on Google products, therefore it is not the best place to ask for support on this matter."
Does anyone know if iOS Gmail add-ons are still supported and if there is a workaround for this behavior?
/**
* Creates a card with an image of a cat, overlayed with the text.
* #param {String} text The text to overlay on the image.
* #param {Boolean} isHomepage True if the card created here is a homepage;
* false otherwise. Defaults to false.
* #return {CardService.Card} The assembled card.
*/
function createCatCard(text, isHomepage) {
// Explicitly set the value of isHomepage as false if null or undefined.
if (!isHomepage) {
isHomepage = false;
}
// Use the "Cat as a service" API to get the cat image. Add a "time" URL
// parameter to act as a cache buster.
var now = new Date();
// Replace formward slashes in the text, as they break the CataaS API.
var caption = text.replace(/\//g, ' ');
var d = new Date();
var textLabel = CardService.newTextParagraph().setText("Current Time." + d.toLocaleTimeString());
// Create a button that changes the cat image when pressed.
// Note: Action parameter keys and values must be strings.
var action = CardService.newAction()
.setFunctionName('onChangeCat')
.setParameters({text: text, isHomepage: isHomepage.toString()});
var button = CardService.newTextButton()
.setText('Change cat')
.setOnClickAction(action)
.setTextButtonStyle(CardService.TextButtonStyle.FILLED);
var buttonSet = CardService.newButtonSet()
.addButton(button);
// Assemble the widgets and return the card.
var section = CardService.newCardSection()
.addWidget(textLabel)
.addWidget(buttonSet);
var card = CardService.newCardBuilder()
.addSection(section);
if (!isHomepage) {
// Create the header shown when the card is minimized,
// but only when this card is a contextual card. Peek headers
// are never used by non-contexual cards like homepages.
var peekHeader = CardService.newCardHeader()
.setTitle('Contextual Cat')
.setImageUrl('https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png')
.setSubtitle(text);
card.setPeekCardHeader(peekHeader)
}
return card.build();
}

Block script execution in Firefox extension?

Probably looking for an answer to an age-old question, but I would like to block script execution. In my use-case blocking the browser is acceptable.
Also, in my use-case I am trying to do this from a Firefox extension, which means my code is "Chrome code", running in the browser environment.
This can easily be done by using a modal window, then programmatically closing the window. So this demonstrates that there is a blocking mechanism that exists.
Is there any way to achieve modal blocking without actually creating or opening the modal window? Some way to tap into the blocking mechanism used for modal windows?
I've done a lot of searching on this subject, but to no avail.
Using nsIProcess you can block the thread.
You can create an executable which has a sleep or usleep method or equivalent. Then run the process synchronously (nsIProcess.run) and set blocking argument to true.
Of course for portability you will need to create an executable appropriate for each platform you wish to support, and supply code for discrimination.
Basic code is something like the following. I have verified on 'nix (Mac OS X) this code to work, using a bash script with only the line sleep .03:
let testex = Components.classes["#mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile);
testex.initWithPath("/Users/allasso/Desktop/pause.sh");
let process = Components.classes["#mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(testex);
let delay = 30; // convert this to milliseconds in the executable
process.run(true,[delay],1); // `run` method runs synchronously, first arg says to block thread
In an extension you probably would want to make your nsIFile file object more portable:
Components.utils.import("resource://gre/modules/FileUtils.jsm");
let testex = FileUtils.getFile("ProfD",["extension#moz.org","resources","pause.sh"]);
Of course keep in mind that Javascript is basically single-threaded, so unless you are blocking a thread spawned using Web Workers you will be freezing the entire UI during the sleep period (just like you would if you opened a modal window).
References:
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcess
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFile
https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O#Getting_special_files
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/basic_usage
OPTION 1
There is enterModalState and leaveModalState in nsIDOMWindowUtils here: MDN :: nsIDOMWindowUtils Reference
However they don't seem to work for me. This topic might explain why: nsIDOMWindowUtils.isInModalState() not working they topic says isInModalState is marked [noscript] which I see, but enterModalState and leaveModalState are not marked [noscript] I have no idea why it's not working.
What does work for me though is suppressEventHandling:
var utils = Services.wm.getMostRecentWindow('navigator:browser').
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.suppressEventHandling(true); //set arg to false to unsupress
OPTION 2
You can open a tiny window with the source window as the window you want to make modal and as dialog but open it off screen. Its dialog so it wont show a new window the OS tab bars. However hitting alt+f4 will close that win, but you can attach event listeners (or maybe use the utils.suppressEventHandling so keyboard doesnt work in it) to avoid the closing till you want it closed. Here's the code:
var sDOMWin = Services.wm.getMostRecentWindow(null);
var sa = Cc["#mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
var wuri = Cc["#mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
wuri.data = 'about:blank';
sa.AppendElement(wuri);
let features = "chrome,modal,width=1,height=1,left=-100";
if (PrivateBrowsingUtils.permanentPrivateBrowsing || PrivateBrowsingUtils.isWindowPrivate(sDOMWin)) {
features += ",private";
} else {
features += ",non-private";
}
var XULWindow = Services.ww.openWindow(sDOMWin, 'chrome://browser/content/browser.xul', null, features, sa);
/*
XULWindow.addEventListener('load', function() {
var DOMWindow = XULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
DOMWindow.gBrowser.selectedTab.linkedBrowser.webNavigation.stop(Ci.nsIWebNavigation.STOP_ALL);
DOMWindow.gBrowser.swapBrowsersAndCloseOther(DOMWindow.gBrowser.selectedTab, aTab);
//DOMWindow.gBrowser.selectedTab = newTab;
}, false);
*/

eVar value not getting passed in s.tl call

I have a page that contains a login form. I am calling a separate function (which resides in a separate .js file) on the onsubmit event of the form. Below is the function
var LoginClick = function() {
// Omniture Code
s.linkTrackVars="events, eVar1";
s.linkTrackEvents="event1";
s.events="event1";
s.eVar1="Login";
s.tl(true, "o", "Login Clicks");
};
while the events data is getting passed on the s.tl call, the evar1 value turns up as "none" in the conversion report. I used a packet sniffer (omnibug) to check the values being passed. Even though s.eVar1 is assigned the value "Login" it does not pass that value.
Ofcourse, s.t() works well (evar value gets passed) but I dont want to do that.
I have tried s.tl(this, "o"...) which doesnt work either.
What am I doing wrong here?
Appreciate your time and help.
remove the space between the comma and eVar1
s.linkTrackVars="events, eVar1"
should be
s.linkTrackVars="events,eVar1"

Issue with using int.parse() in Dart

I'm currently teaching myself the Dart language, and my first app doesn't seem to be working right. Here's the code that's causing trouble:
usrLoc = int.parse(query("#txtLoc").text);
When I try to run the app, it opens fine, but when I click the button that triggers this (and three other similar parses), the debugger stops and tells me "Source not found" for int._native_parse(), int._parse(), and int.parse().
Any help would be greatly appreciated.
The text property for the specified element #txtLoc returns an empty string.
The parse method requires that:
The source must be a non-empty sequence of base- radix digits, optionally prefixed with a minus or plus sign ('-' or '+').
You can specify an onError named argument in your call to parse, which takes a callback that handles the invalid input. E.g., if you want the parse call to return the value 42 for all invalid input, you can do this:
usrLoc = int.parse(query("#txtLoc").text, onError: (val) => 42);
If you really expect the element to have some text, you can store the result of query("#txtLoc").text into a separate variable and verify the value. It would also be interesting to check what the real element type is or which tag is marked with id #txtLoc.
If you want to get the content of an input element, you should use the value property instead of text:
query("#txtLoc").value

World of Warcraft Lua - Changing frame:SetAttribute()

I'm working on an addon for World of Warcraft that completely overhauls the interface to adapt to my play style.
In this addon, I would like to have a large button that acts as a "main dps rotation" for my mage. I would like it to change what spell it casts based on what is optimal at any given time. It doesn't cast the spell automatically, it just presents the next best option for the user.
Here is my code so far:
print "Interface Overhaul : LOADED"
heatingUpIsActive = false
print(heatingUpIsActive)
local Button = CreateFrame("Button", "MyButton", UIParent,"SecureActionButtonTemplate")
Button:SetWidth(256)
Button:SetHeight(256)
Button:SetFrameStrata("HIGH")
Button:SetPoint("LEFT")
Button:SetText("Main Rotation")
Button:RegisterForClicks("AnyUp")
Button:SetAttribute("type", "spell")
Button:SetAttribute("spell", "Fireball")
Button:RegisterEvent("UNIT_AURA");
local function auraGained(self, event, ...)
if (UnitAura("player", "Heating Up")) then
if (heatingUpIsActive == false) then
heatingUpIsActive = true
print (heatingUpIsActive)
print ("Heating Up is active!")
Button:SetAttribute("spell", "Inferno Blast")
end
else
heatingUpIsActive = false
print("Heating Up is NOT active.")
print(heatingUpIsActive)
end
end
Button:SetScript("OnEvent", auraGained);
local tex = Button:CreateTexture("ARTWORK");
tex:SetPoint("LEFT")
tex:SetWidth(256)
tex:SetHeight(256)
tex:SetTexture("Interface\\AddOns\\InterfaceOverhaul\\Button2")
If heatingUpIsActive == true, I would like the button to cast ("spell", "Inferno Blast") instead of ("spell", "Fireball"), but it doesn't work if I place that into the correct part of the if statements.
Any thoughts?
As Mud said, you cannot rebind buttons in combat anymore. Blizzard made this change to prevent bots from being able to automate combat. Notably, in order to cast a spell you need to use one of the secure templates, and these secure templates only allow modification of the attributes that control what they do when you're not in combat. So you cannot have one button change spells mid-combat. Similarly, they also prevent you from modifying attributes like their position or visibility, so you cannot move buttons under the mouse either.
The best you can do is display a visual indicator of what spell should be cast, but rely on the user to actually press the correct button.

Resources