Easily Bridge Your FireMonkey Windows Apps And JavaScript Using ScriptGate
Before knowing how to bridge FireMonkey application and JavaScript using ScriptGate, Let’s understand what is Native App and Hybrid App? What’s the difference between them? How to develop a Hybrid App using Delphi? Is it possible? What’s the challenge? This post will guide you to understand better.
Native Apps : A software application built in a programming language, for the specific platform like iOS, Android ,Windows, macOS and Linux. The pros and cons are,
- The Best performance – no extra calculations or interpretations layers.
- No way to update UI without updating the app (only if you don’t have some built-in UI update engine)
- Your app can be used only for target platforms. You cannot start the app inside the browser without using something like Thinfinity Virtual UI.
Hybrid Apps: Hybrid apps are part native apps, part web apps. It can take advantage of some device features available. Like web apps, they rely on HTML being rendered in a browser, with the caveat that the browser is embedded within the app. The pros and cons are,
- Possibility to update the UI and logic without updating the whole app.
- Great opportunity if you like to use HTML/CSS/Javascript for UI and even for business logic.
- Not the best performance – your app UI or business logic ( like Javascript) executes inside the browser component.
- Risk during submission to app stores (but your app still looks like a native app to the play store).
Hybrid apps with Delphi is that possible? Yes, using the TWebBrowser component and ScriptGate.
Why do we want to use ScriptGate?
It looks like a native application, access to platform-specific features, like get device token, working with push notifications (including background mode), access to BLE and other hardware onboard features, working with permissions, and so on. Possibility to publish the application to app stores like a native app.
What’s the challenge here?
The main challenge – organize communication between your HTML/CSS/JavaScript web application, stored inside the TWebBrowser component, and your Host application code..E.g)
- Get Push notifications token in the host app and transfer it to the web app.
- Initiate permission requests from web app before calling some restricted function, e.g perform calls.
- Register geofences for the platform, e.g get a list of geofences via Rest API from Web Server using javascript code and put them to the OS using host app.
ScriptGate solves the above challenges: ScriptGate is a library that allows you to call back and forth between JavaScript and Delphi code on TWebBrowser across Android, iOS, macOS, and Windows.
Watch the Video Demonstration on how to bridge the FMX and JavaScript using ScriptGate mentioned below.
Check out the other ways to Bridge Your Delphi Application and Javascript here.
You can download the ScriptGate library for Delphi over on BitBucket.