dart2js compiled code running in an unsupported browser - dart

What happens if I try to run my generated javascript code in an unsupported browser? Like IE6?
I don't want to end up in a situation that my users will see a partly working broken app. Is there a way how to ensure that the dart/javascript will run only if the browser is supported and have my app degrade gracefully to some html banner "use a newer browser please" if it is not?

You could use the browser detector script here: http://www.quirksmode.org/js/detect.html
I wrote this code from the top of my head, I don't have a testing machine at my disposal right now:
var isNewFirefox = BrowserDetect.browser === 'Firefox' && BrowserDetect.version >= 7;
var isNewChrome = BrowserDetect.browser === 'Chrome';
var isNewIE = BrowserDetect.browser === 'Explorer' && BrowserDetect.version >= 9;
var isNewSafari = BrowserDetect.browser === 'Safari' && BrowserDetect.version >= 5.1;
var isNewOpera = BrowserDetect.browser === 'Opera' && BrowserDetect.version >= 12;
if (isNewFirefox || isNewChrome || isNewIE || isNewSafari || isNewOpera) {
var script = document.createElement('script');
if (navigator.webkitStartDart || navigator.startDart || navigator.mozStartDart || navigator.oStartDart || navigator.msStartDart) {
// Load Dart code!
script.setAttribute('type', 'application/dart');
script.setAttribute('src', 'http://.../foo.dart');
} else {
// Load dart2js code!
script.setAttribute('src', 'http://.../foo.js');
}
document.body.appendChild(script);
} else {
alert('Application wont work');
}
The version information can be found on: http://www.dartlang.org/support/faq.html#what-browsers-supported
Dart VM detection: http://www.dartlang.org/dartium/#detect

You can always detect browser in pure javascript and do not run dart program till you make sure browser is valid.

Related

Cannot use serialBluetooth functions even tough the plugin was installed

I cannot use the bluetoothSerial functions even though I installed the plugin by running cordova "plugin add cordova-plugin-bluetooth-serial" command in the project folder. I have received no errors and the plugin exists in the plugins folder.
I have tried adding plugin tag to the config.xml,
I have tried adding bluetooth permission to the AndroidManifest.xml
but none helped.
My cordova version is 9.0.0 (cordova-lib#9.0.1)
var app = {
initialize: function()
{
this.bindEvents();
},
bindEvents: function ()
{
document.addEventListener('deviceready',this.onDeviceReady(),
false)},
onDeviceReady: function () {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
window.addEventListener('touchstart', function(event){
console.log(event.touches);
touchX = event.touches[0].pageX;
touchY = event.touches[0].pageY;
console.log(touchX, touchY);
if (touchX <= button1.x + button1.width && touchX >= button1.x)
{
if (touchY <= button1.y + button1.height && touchY >=
button1.y) {
check = 1; // Everything is fine until here.
bluetoothSerial.isEnabled(success(), fail()); // the code
here and below here is never executed.
c.font = "80px Arial";
c.fillText("here",50,50);
}
}
When I debug using chrome://inspect/#devices I receive:
serialBluetooth is not defined error.
why is that happening?
It turned out that it is necessary to include the script tag, cordova.js.

jsctypes finalizer cross domain issue

I've successfully used jsctypes in the past but the latest version of firefox (32) has started to give me an odd error message
here is what used to work-
javascript content sends a message to a javascript extension in chrome (the extension uses ctypes to call a special device allocator. it then returns a cdata.finalizer to the content
later when the content is garbage collected the finaizer gets called to release the special device allocation
while this used to work fine, I'm now getting an exception ctypes.CDataFinalizer
Not allowed to define cross-origin object as property on [Object] or [Array] XrayWrapper
searching on Google did not seem to find anything related.
on the extension I have this code( the func... things are access methods for c code)
Any suggestions?
self.addEventListener("allocArray", function (event) {
var info = event.detail.info;
try {
var cBytes = ctypes.int32_t(info.bytes);
var cArrayId = ctypes.uint32_t(0);
var err = funcAllocArray(cBytes, cArrayId.address());
if(err !== 0) {
info.rtnCode = err;
info.arrayId = -1;
info.error = "Error: " + (err === 2)? "out of memory": "allocation failed";
} else {
info.rtnCode = 0;
info.arrayId = ctypes.CDataFinalizer(cArrayId.value, funcReleaseArray);
}
}
catch(exception) {
info.rtnCode = -1;
info.arrayId = -1;
info.error = report(exception);
}
}, true, true);

Blackberry Package project issue -1.debug

I'm using BlackBerry_JDE_PluginFull_1.1.2.201003212304-12 (BB 5 SO).
When i rich click project -> BlackBerry -> Package Project its, generates some files on my deliverable folder. This files are the one u use to put the App on the web so my client can download the app and install it on his BlackBerry.
Now i'm facing a problem, some times, its create a file that prevent me install the app on BB. this file is ProjectName-1.debug.
What is making this error is why i am here. I don't know why this is happening.
My code that works fine:
public void agendar(){
String msg = "asdasd";
boolean seguir = true;
if(_cedula.getText() == null){
seguir = false;
}
if(seguir && _fechaNac.getDate() < 1){
seguir = false;
}
if(seguir && _tel.getText() == null){
seguir = false;
}
if(seguir && _pnombre.getText() == null ){
seguir = false;
}
if(seguir && _papellido.getText() != null){
seguir = false;
}
int i = Dialog.ask(Dialog.D_OK, msg);
}
Same code with one line that makes the "error":
public void agendar(){
String msg = "asdasd";
boolean seguir = true;
if(_cedula.getText() == null){
seguir = false;
msg = " xxx ";
}
if(seguir && _fechaNac.getDate() < 1){
seguir = false;
}
if(seguir && _tel.getText() == null){
seguir = false;
}
if(seguir && _pnombre.getText() == null ){
seguir = false;
}
if(seguir && _papellido.getText() != null){
seguir = false;
}
int i = Dialog.ask(Dialog.D_OK, msg);
}
The only difference is the line msg = " xxx ".
The components im using are BasicEditField and one DateField.
Also if i add this
int i = Dialog.ask(Dialog.D_OK, "aaaaaaaaa asdasd ");
the package get corrupted.
Yesterday, i created a new class in the project and just that was enough to corrupt the package.
So far, i re installed the eclipse plugin, and nothing changed. I can't fine any reference to this problem on google. Im stuck here with this and i dont know what else to check. On the simulator its works fine.
What is making this happening? What does -1.debug mean? When i try to install the app it looks for -1.cod file.
Any help is appreciated.
Regards.
Answered on the Official BlackBerry Java Forum:
http://supportforums.blackberry.com/t5/Java-Development/Blackberry-Package-project-issue-1-debug/td-p/2508105
As requested, here are the important details from the linked post:
There is no corruption, what is happening here is that your project has got large enough to exceed the limits of a single cod, and so the project is being built into multiple cods.
Typically you don't see that, because the build process zips up the individual cods, and puts them all in one large cod. However the debug-n files are a good indication that you exceeded one cod file - these are always kept separate and there is a debug-n file for each cod file.
So take your single file ".cod", rename it to ".zip", and then open the zip file. You will probably see 2 cods in there.
Unzip this and put the multiple cod files on the web site for download. If you check the jad file that has been created, you will see that it lists multiple cods.
If you want to read more about this, search the BlackBerry forum for 'sibling'. The multiple cod files are generally referred as sibling cod files.
Also see here for more on this:
http://supportforums.blackberry.com/t5/Testing-and-Deployment/The-maximum-size-of-a-BlackBerry-7-or-earlier-smartphone/ta-p/1300209

How to check for iOS5 using web technologies?

I'm working on a mobile app using jQuery Mobile and I would like to check if I'm on iOS5, cause it has some great features, like true fixed toolbars, etc. I'm looking for a javascript solution.
This works for me with a bit of string manipulation of the user-agent.
var ua = navigator.userAgent;
var detail = ua.split('(')[1];
var device = detail.split(';')[0];
if (device == 'iPhone' || device == 'iPod' || device == 'iPad') {
var ios = detail.split(' ')[5].split('_')[0];
if (ios == '5') {
alert('ios 5');
}
}

How to open the page in browser at the time of uninstalling the firefox addon

I want to open the link when the user uninstalls the addon, so for this what i have to code and under which event.
If anybody know about this then please help me out.
Currently this is what I am doing at the time of uninstall. But gBrowser.addTab(Website + 'uninstalled=true&token=' + uniqueguid); is not working over here.
var UninstallObserver = {
_uninstall : false,
observe : function(subject, topic, data) {
//===Write Code here for Delete File Uninsatll Time
//alert("Uninstall Time Delete File");
var Filename = "webmail";
// Delete all template file.
try{
var pref = Components.classes["#mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
var finished = "";
pref.setBoolPref("myextension.install.just_installed", false);
}
catch(e) {}
gBrowser.addTab(Website + 'uninstalled=true&token=' + uniqueguid);
var file = Components.classes["#mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(Components.classes["#mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path+"\\DefaultTemplate.txt");
if ( file.exists() == true )
{
var aFile = Components.classes["#mozilla.org/file/local;1"].createInstance();
if (aFile instanceof Components.interfaces.nsILocalFile)
{
aFile.initWithPath(Components.classes["#mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path + "\\DefaultTemplate.txt");
aFile.remove(false);
}
}
//=======
if (topic == "em-action-requested") {
subject.QueryInterface(Components.interfaces.nsIUpdateItem);
if (subject.id == MY_EXTENSION_UUID)
{
if (data == "item-uninstalled")
{
//==Delete File Whenever Uninstall
//alert("When Uninatall");
//===========
data = "item-cancel-action";
this._uninstall = true;
}
if (data == "disabled")
{
// alert("You are not allow to disable SysLocker.");
this._uninstall = true;
}
else if (data == "item-cancel-action")
{
this._uninstall = false;
}
}
}
else if (topic == "quit-application-granted")
{
data = "item-cancel-action";
if (this._uninstall)
{
//Code here to delete registry
}
this.unregister();
}
},
register : function() {
var observerService =
Components.classes["#mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "em-action-requested", false);
observerService.addObserver(this, "quit-application-granted", false);
},
unregister : function() {
var observerService =
Components.classes["#mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this,"em-action-requested");
observerService.removeObserver(this,"quit-application-granted");
}
}
Thanks
0) What kind of extension is this? I assume it's a regular extension requiring restart; bootstrapped (restartless) extensions have their own uninstall notification.
1) Per the MDC docs, the em-action-requested notification was replaced with a different notification in Firefox 4+, are you testing with Firefox 4 or 3.6?
2) How exactly is gBrowser.addTab "not working over here"? Does the code get to that point? Do you get any messages in the Error Console (see that page for set up tips)? If you put your code in an XPCOM component (which is correct), you'll first have to get a reference to a browser window. See Working with windows in chrome code.
I don't think that the em-action-requested topic is posted to observers until the extension is actually uninstalled, which happens on restart (assuming it is not a restartless extension). When are you expecting the new tab to appear? I would try setting a pref when the uninstall topic is triggered and checking for that pref on startup. If it is there, you can display your tab and remove the pref.

Resources