Override worklight.js - ibm-mobilefirst

I'm developing an app with IBM MobileFirst Platform and I find an issue with Worklight.js file. Worklight.js is extending Function prototype defining several methods like bind, curry, wrap and so on.
My app is built with aurelia framework an after upgrading the framework to the last version I'm facing a funky issue related to bind extension.
If I comment the bind extension in worklight.js everything seems to work like a charm (don't know why worklight implements its bind version).
Worklight.js file seems to be added to the wlapp package at build time. Is there a way I can override this file so I do not have to modify .wlapp file each time app is built?
Thanks

The direct answer to the specific question you've asked is, no, there is no way provided to override worklight.js. This is the core JavaScript code needed for the MobileFirst Platform client-side to function, and as such the user isn't given any means to modify it - it's injected into your app (i.e., into the WLAPP file) during the build process.
I'm not aware of any specific issues with Aurelia, but have certainly seen cases in the past where an app that uses two different frameworks (e.g., MobileFirst Platform / Worklight, and something else) "fight" with each other because they both want to implement extensions that are not compatible with each other - in which case, one framework or the other usually needs to change to accommodate the other.
If you are a customer with paid support, I'd suggest opening a PMR so we can get our developers to take a look at the issue.

I have the same problem with Angular. Worklight bind makes Angular controller fail to instantiate. The solution is to recover the bind function after worklight is loaded.
var bind = Function.prototype.bind;
window.wlCommonInit = function() {
Function.prototype.bind = bind;
};

Related

Chrome manifest v3 - is there a viable workaround to use Google's File Picker in a Chrome extension?

My searches have turned up nothing concrete. My extension uses Google's file picker to allow the user to browse their sheets and choose a desired file to write some data to, which manifest v3 breaks because of some GAPI limitations. Unless I've missed something obvious, there does not seem to be a simple workaround or method for this to migrate to v3 -- it just seems to be disallowed.
I'm not asking if there's a way to do something that they intend to not be possible (even though I doubt such a thing would exist with Google) but I'm optimistically hoping that maybe there is some hacky/annoying workaround that still fits within their rules. If I absolutely have to just allow them to set a sheet URL manually I will...I'm just trying to avoid it.
Any tips or suggestions would be appreciated.
You may have to test it yourself to make sure there are no weird behaviors, but Google has some recommendations regarding this in their migration guide:
In Manifest V3, all of your extension's logic must be included in the extension. You can no longer load and execute a remotely hosted file. A number of alternative approaches are available, depending on your use case and the reason for remote hosting. Here are approaches to consider:
Configuration-driven features and logic
In this approach, your extension loads a remote configuration (for example a JSON file) at runtime and caches the configuration locally. The extension then uses this cached configuration to decide which features to enable.
Externalize logic with a remote service
Consider migrating application logic from the extension to a remote web service that your extension can call. (Essentially a form of message passing.) This provides you the ability to keep code private and change the code on demand while avoiding the extra overhead of resubmitting to the Chrome Web Store.
Bundle third-party libraries
If you are using a popular framework like React or Bootstrap, you can download the minified files, add them to your project and import them locally.
For your case, option #3 seems like the easiest. Looking at the Google Picker API documentation it only uses two relatively small script files, https://apis.google.com/js/api.js and https://accounts.google.com/gsi/client. You could try to bundle these in your Chrome extension and call the methods locally.

Windows Store: how to test whether specific "metro" app is installed?

Well, the title says it all. From my Windows Store (a.k.a. "Metro") application, I need to know whether some other specific application is installed on that machine. Alternatively, I want to know whether there is some application that able to handle URL of specific theme (for me its the same problem) - without launching it.
I tried to use PackageManager from Windows.Management.Deployment namespace, but it not accessible from winrt...
http://msdn.microsoft.com/en-us/library/windows/apps/windows.management.deployment.aspx
Is there any other way to do that?
Thanks!
No, there isn't any way to do it. If you want to invoke another app though - you can use a custom protocol with protocol activation to invoke an app that supports that protocol or have it installed from the store.

iOS App Settings/Preferences in Worklight

I am working on a Hybrid Application, targeting (for the moment) iOS. Does Worklight have a utility to handle application settings/preferences for iOS? I know how to write the native code to do this, but do not yet know how to gain access to the application settings from the JavaScript. Can anyone point me in the right direction or provide a working example?
In application-descriptor.xml, there is a worklightSettings flag you can set, however the settings page it creates is not user facing. That is, it is meant only for development time, or internal usage, and not production. It allows control of the server address that athe client connects to and change the web resources it will fetch.
So the answer is, no.
The mentioned settings page has set items in it that cannot be altered much (settings.bundle which does not allow much room for play. Maybe you could change it a bit, but doing so would void giving support to you if problems arise). I would recommend against doing so.
So this leaves you the option of creating this on your own. Maybe there is an existing Cordova plug-in that does something similar. Review these training modules of how to incorporate Cordova plug-ins to your application. Cordova bridges between JavaScript to native code, so it could be what you're looking for.

How to recognize programmatically that application is installed vs development mode?

I'm trying to get information about license info of my app and MSDN docs (http://msdn.microsoft.com/en-us/library/windows/apps/hh694065.aspx) advice to use Windows.ApplicationModel.Store.CurrentAppSimulator class for that purposes during development/testing and when submitting app to store replace that class with Windows.ApplicationModel.Store.CurrentApp.
I wonder if there is any way to check in code (javascript in my case) if app is already installed from store so my code should use proper class and I won't have to remember every time I submit update of app to store to replacing those classes properly.
As far as I know, I could not find such thing. In fact, LicenseInfo is what provides information about the store listing.
I use a config.js file to keep settings at place which change between development and production. For example - if your app talks to a service, service URL also will likely change between development and production; the service might be running at localhost for development and for production in azure environment. I keep a bool in here and change by hand.
I have not automated it fully. but it is likely possible. need to dig through the msbuild logs for the build created for the store. if there is configuration setting found, then project can have two config.dev.js and config.release.js and msbuild need to conditionally pick the right file. I haven't looked into this yet.
I think I found at solution as described here WinJS are there #DEBUG or #RELEASE directives? . Not ideal, but works for me.

Can we package our existing HTML5 JS App for Windows 8

I have read some posts on S/O and also around the web. We are producing a HTML5 JS based web app that runs on the web. We are packaging it up for Google apps, and also for phonegap.
Can we package this app for windows 8? Of course, I appreciate it won't use the windows 8 features. But, will the app run none the less, as it stands. So that we can place it in the store and build out windows 8 features as we move forward.
I appreciate this is a slightly non-concise question, but I guess the real point is what is our quickest route to take our existing HTML 5, CSS, JS App and deploy it in the store and get it working on this platform.
In general, the answer is yes. The transition is not seamless, but you will be able to use a ton, if not all, of the application artifacts in Win8. A good test is if you can run it in IE10, you can run the app as a Win8 app. Again, this is a very broad brush - things you need to worry about are things like all scripts files need to be local (no CDN), changes to web and security contexts, and the fact that Win8 is a horizontal paradigm whereas most web apps are vertical. But in general, you should be able to make the move. Usual caveat - your mileage will vary.
Yes, although not recommended, you can package your existing app for Win8. You'll need to add a few bits of code though. The minimum would be to embed your app's start/init code within WinJS's first promise callback, like so:
args.setPromise(WinJS.UI.processAll().then(function () {
// your init code
}
You'll also need to create a couple of icons for the start screen and an image for your app's launch screen.
It is possible that you'll run into a few issues, like some security related restrictions, where you'll have to modify your code to use some native WinJS functions. This all depends on you app's implementation.
You can also check Microsoft's guidelines for migrating a web app to win8, here: http://msdn.microsoft.com/en-us/library/windows/apps/hh465143