Skip to content

Commit

Permalink
Merge pull request #2 from h0m36r0wn/master
Browse files Browse the repository at this point in the history
Class implementation and concurrently as dev dependency
  • Loading branch information
mackignacio authored Jul 27, 2018
2 parents 4210f8b + e07799f commit eb60ad2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 25 deletions.
88 changes: 63 additions & 25 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { app, ipcMain, ipcRenderer, BrowserWindow, screen } from "electron";
import * as path from "path";
import * as url from "url";
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";

class ElectronMain {
appTitle = "Electron Angular Quickstart";
Expand All @@ -10,14 +9,33 @@ class ElectronMain {
mainWindow: BrowserWindow;

constructor() {
this.checkElectronArgs();
this.initApp();
this.initAppEvents();
this.initIpc();
}


initApp(){
this.checkElectronArgs();
this.disableSecurityWarnings();
}

initAppEvents() {
app.on("ready", () => this.createMainWindow());
app.on("window-all-closed", () => this.quitAppOnNonDarwin());
app.on("activate", () => this.createDefaultWindow());
}

initIpc() {
ipcMain.on("event", (e, data) => this.ipcEventHandler(e, data));
}

checkElectronArgs() {
this.args = process.argv.slice(1);
this.serve = this.args.some(val => val === "--serve");
this.enableHotReload();
}

enableHotReload() {
if (this.serve) {
require("electron-reload")(__dirname, {
electron: require(`${__dirname}/node_modules/electron`)
Expand All @@ -26,44 +44,64 @@ class ElectronMain {
}

createMainWindow() {
this.mainWindow = new BrowserWindow({
title: this.appTitle,
this.mainWindow = this.createBrowserWindow();
this.loadFromFile(this.mainWindow);
this.openWindowDevTools(this.mainWindow);
this.onWindowClosed(this.mainWindow);
}

createBrowserWindow(): BrowserWindow {
return new BrowserWindow({
title: this.appTitle,
fullscreen: true,
minimizable: false,
maximizable: false,
autoHideMenuBar: true,
alwaysOnTop: true,
closable: false
});
this.mainWindow.loadURL(
}

loadFromFile(electronWindow: BrowserWindow) {
electronWindow.loadURL(
url.format({
pathname: path.join(__dirname, "/dist/electron-angular/index.html"),
protocol: "file:",
slashes: true
})
);
this.mainWindow.webContents.openDevTools();
this.mainWindow.on("closed", () => {
}

openWindowDevTools(electronWindow: BrowserWindow) {
electronWindow.webContents.openDevTools();
}

onWindowClosed(electronWindow: BrowserWindow) {
electronWindow.on("closed", () => app.quit());
}


createDefaultWindow() {
if (null === this.mainWindow) {
this.createMainWindow();
}
}

quitAppOnNonDarwin() {
if (process.platform !== "darwin") {
app.quit();
});
}
}

initApp() {
app.on("ready", this.createMainWindow);

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});

app.on("activate", () => {
if (this.mainWindow === null) {
this.createMainWindow();
}
});

ipcEventHandler(e: any, data: any) {
console.log("[EVENT]:", "recieved from main process");
}

disableSecurityWarnings() {
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";
}
initIpc() {}

}

export default new ElectronMain();

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"concurrently": "^3.6.1",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
Expand Down

0 comments on commit eb60ad2

Please sign in to comment.