In this lesson, you will learn how to build native desktop apps with SAP UI5 and Electron. You might be surprised how easy it is to start building high-quality desktop apps for any platform, or even port your existing SAP UI5 app to native desktop platforms.
Electron is an open source library developed by GitHub for building cross-platform desktop applications with HTML, CSS, and JavaScript. Electron accomplishes this by combining Chromium and Node.js into a single runtime and apps can be packaged for Mac, Windows, and Linux.
In this blog I would like to go with a Windows 10 machine, so I’m going to show you how to install all the needed tools for SAPUI5 Desktop application development. We will go through the installation of the following components:
cd <path to root folder of your app>
// Example
cd C:\XXX\XXX\ztest_emp_prfl
npm init
description: Employee Profile
entry point: (index.js) main.js
author: Irfan G
const {app, BrowserWindow} = require('electron');
// Global reference of the window object.
let mainWindow;
// When Electron finish initialization, create window and load app index.html with size 800x600
app.on('ready', () => {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false
}
});
// Path to your index.html
mainWindow.loadURL('file://' + __dirname + '/WebContent/index.html');
});
<script id="sap-ui-bootstrap"
src="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-compatVersion="edge"
data-sap-ui-resourceroots='{"com.empprfl": ""}'>
</script>
<script id="sap-ui-bootstrap"
src="./resources/sap-ui-core.js"
data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-compatVersion="edge"
data-sap-ui-resourceroots='{"com.empprfl": ""}'>
</script>
npm install electron --save-dev
"start": "electron ."
npm start
cd <path to root folder of your app>
// Example
cd C:\XXX\XXX\ztest_emp_prfl
// for use in npm scripts
npm install electron-packager --save-dev
// for use from cli (Command Line Interface)
npm install electron-packager –g
// for creating prebuild
npm install --save-dev electron-prebuilt
Xxx/xxx/ztest_emp_prfl/assets
Xxx/xxx/ztest_emp_prfl/icons
Xxx/xxx/ztest_emp_prfl/WinIcon.ico
// For windows = XXX.ico
// For Mac = XXX.icns
// For Linux = XXX.png
"productName": "Employee Profile App",
// For Mac
electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/WinIcon.ico --prune=true --out=release-builds
// For Windows
electron-packager . ztest_emp_prfl --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/WinIcon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"Employee Profile App\"
// For Linux
electron-packager . ztest_emp_prfl --overwrite --asar=true --platform=linux --arch=x64 --icon=assets/icons/WinIcon.ico --prune=true --out=release-builds
{
"name": "ztest_emp_prfl",
"productName": "Employee Profile App",
"version": "1.0.0",
"description": "Employee Profile",
"main": "main.js",
"scripts": {
"start": "electron .",
"package-win": "electron-packager . ztest_emp_prfl --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/WinIcon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"Employee Profile App\""
},
"author": "Irfan G",
"license": "ISC",
"devDependencies": {
"electron": "^1.7.9",
"electron-packager": "^10.1.0",
"electron-prebuilt": "^1.4.13"
}
}
npm run package-win
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false
}
});
// Example
npm start –verbose
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |