Skip to content

Commit

Permalink
Package app with electron-forge!
Browse files Browse the repository at this point in the history
  • Loading branch information
xidb committed Dec 22, 2017
1 parent 0b00309 commit 55fd51a
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 224 deletions.
3 changes: 2 additions & 1 deletion .compilerc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"production": {
"application/javascript": {
"presets": ["es2016-node5", "react", "babel-preset-stage-2"],
"sourceMaps": "none"
"sourceMaps": "none",
"plugins": ["transform-decorators-legacy"]
}
}
}
Expand Down
1 change: 0 additions & 1 deletion app/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

<body id="main-window">
<div id="react-container">

</div>
<script type="application/javascript">
import React from 'react';
Expand Down
76 changes: 41 additions & 35 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ const {app, BrowserWindow, shell, Menu, MenuItem} = require('electron');
const windowStateKeeper = require('electron-window-state');
const url = require('url');
const path = require('path');

import {enableLiveReload} from 'electron-compile';
enableLiveReload();

let dev = process.env.DEV === 'true';

if (dev) {
enableLiveReload();
}

// 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;

let dev = process.env.DEV === 'true';

function createWindow() {
let windowArgs = {
show: false
};
let windowArgs = {};

if (dev) {
const devWindowArgs = {
width: 1280,
height: 720
};
windowArgs = {windowArgs, ...devWindowArgs};
windowArgs = {...windowArgs, ...devWindowArgs};
}

// Load the previous state with fallback to defaults
Expand All @@ -49,17 +49,7 @@ function createWindow() {
slashes: true
});
mainWindow.loadURL(indexPath);

// Don't show until we are ready and loaded
mainWindow.once('ready-to-show', () => {
// Open the DevTools automatically if developing
if (dev) {
// mainWindow.maximize();
mainWindow.webContents.openDevTools();
}

mainWindow.show();
});
mainWindow.webContents.openDevTools();

// Emitted when the window is closed.
mainWindow.on('closed', function() {
Expand All @@ -70,30 +60,46 @@ function createWindow() {
});
}

function changeMenu() {
let menu = Menu.getApplicationMenu();

menu.items.map(
(menuItem) => {
if (menuItem.label === 'Help') {
menuItem.submenu.clear();
menuItem.submenu.append(
new MenuItem({
label: 'Google it',
click() { shell.openExternal('https://www.youtube.com/watch?v=dQw4w9WgXcQ?autoplay=1'); }
})
);
function createMenu() {
let menu;

const preciousMenuItem = {
label: 'Dance!',
click() { shell.openExternal('https://www.youtube.com/watch?v=dQw4w9WgXcQ?autoplay=1'); }
};

if (dev) {
// Just edit default menu
menu = Menu.getApplicationMenu();

menu.items.map(
(menuItem) => {
if (menuItem.label === 'Help') {
menuItem.submenu.clear();
menuItem.submenu.append(
new MenuItem(preciousMenuItem)
);
}
}
}
);
);

} else {
// Create new
const subMenuHelp = {
label: 'Help',
submenu: [ preciousMenuItem ]
};

menu = Menu.buildFromTemplate([subMenuHelp]);
}

Menu.setApplicationMenu(menu);
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', changeMenu);
app.on('ready', createMenu);
app.on('ready', createWindow);

// Quit when all windows are closed.
Expand Down
Loading

0 comments on commit 55fd51a

Please sign in to comment.