Skip to content

Instantly share code, notes, and snippets.

@gvinaccia
Created March 5, 2018 18:14
Show Gist options
  • Save gvinaccia/ea8461cc2d251e5058c29e92b057d93b to your computer and use it in GitHub Desktop.
Save gvinaccia/ea8461cc2d251e5058c29e92b057d93b to your computer and use it in GitHub Desktop.
angular-electron-example-files
import { BrowserWindow } from 'electron';
export default class Application {
constructor(options) {
this.debug = options.debug || false;
this.mainWindow = null;
}
start(url) {
this.createMainWindow();
this.mainWindow.loadURL(url);
}
createMainWindow() {
// Create the browser window.
this.mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
// Open the DevTools.
this.mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
this.mainWindow.on('closed', () => {
// 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.
this.mainWindow = null;
});
}
}
import { app } from 'electron';
import Application from './app';
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit();
}
let application;
app.on('ready', () => {
application = new Application({
debug: true,
});
// impostiamo un timeout per dare il tempo ad ng serve di avviare il webserver
setTimeout(() => {
application.start('http://localhost:4200');
}, 5000);
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => { });
import { app } from 'electron';
import * as url from 'url';
import * as path from 'path';
import Application from './app';
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit();
}
let application;
app.on('ready', () => {
application = new Application({
debug: true,
});
application.start(url.format({
pathname: path.join(__dirname, '..', 'renderer', 'index.html'),
protocol: 'file',
slashes: 'true',
}));
});
// Quit when all windows are closed.
app.on('window-all-closed', () => {
app.quit();
});
app.on('will-quit', () => {
global.application.shutdown();
});
app.on('activate', () => { });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment