I found the solution
With ionic-cli 3.0.1 to create a desktop electron application it’s verys simple:
In index.html add
<script
const electron = require('electron')
</script
In a other page of your app .ts add:
delcare var electron: any
In your package.json add:
“main” : “main.js”
Where main.js sample :
const electron = require('electron')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const {BrowserWindow, ipcMain} = electron;
const path = require('path')
const url = require('url')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600})
// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'www/index.html'),
protocol: 'file:',
slashes: true
}))
// Open the DevTools.
mainWindow.webContents.openDevTools()
ipcMain.on("test_channel",function(err,arg){
console.log(err);
console.log("Received message: "+arg);
console.log("Sending message back!");
// Send message back!
mainWindow.webContents.send("test_channel","pong");
})
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}