I'm trying to figure out how I can close an electron app with an angular component. I removed the menu bar by setting frame: false
on BrowserWindow({... inside main.js. I have a close button on the top right corner of the electron app from a component. I want to be able to close the app from the component.ts file on click, but I haven't seen any examples of closing electron from an angular component.
I thought the following would work, but didn't. I'm exporting a function from main.js and calling the function from the component.
like so (see closeApp()
):
const { app, BrowserWindow } = require('electron')
const url = require("url");
const path = require("path");
let mainWindow
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false,
webPreferences: {
nodeIntegration: true
}
})
mainWindow.maximize();
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, `/dist/index.html`),
protocol: "file:",
slashes: true
})
);
...
function closeApp() {
mainWindow = null
}
export { closeApp };
Then I would try and import it into component like
import { Component, OnInit } from '@angular/core';
import { closeApp } from '../../../main.js';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
testClose() {
closeApp();
}
}
How can I close the electron app from angular? I appreciate any help!