Skip to content

Commit

Permalink
-Refactor menus to avoid passing null to menu array, which caused an …
Browse files Browse the repository at this point in the history
…immediate crash on Windows

-Begin replacing double quotes with single quotes
  • Loading branch information
chrisknepper committed Jun 22, 2018
1 parent df625ba commit 560abf1
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 52 deletions.
12 changes: 6 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import "./stylesheets/main.css";
import './stylesheets/main.css';

import "./helpers/context_menu.js";
import "./helpers/external_links.js";
import './helpers/context_menu.js';
import './helpers/external_links.js';

const state = {
loaded: false
};

import { remote } from "electron";
import jetpack from "fs-jetpack";
import { remote } from 'electron';
import jetpack from 'fs-jetpack';

const app = remote.app;
const appDir = jetpack.cwd(app.getAppPath());
Expand All @@ -22,7 +22,7 @@ androidMessagesWebview.addEventListener('did-start-loading', () => {


if (permission === 'notifications') {
return callback(true) // Approve
return callback(true); // Approve
}

// if (!url.startsWith('https://my-website.com')) {
Expand Down
37 changes: 18 additions & 19 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
// It doesn't have any windows which you can see on screen, but we can open
// window from here.

import path from "path";
import url from "url";
import { app, Menu } from "electron";
import path from 'path';
import url from 'url';
import { app, Menu } from 'electron';
import { autoUpdater } from 'electron-updater';
import { appMenuTemplate } from './menu/app_menu_template';
import { devMenuTemplate } from "./menu/dev_menu_template";
import { editMenuTemplate } from "./menu/edit_menu_template";
import { baseMenuTemplate } from './menu/base_menu_template';
import { devMenuTemplate } from './menu/dev_menu_template';
import { helpMenuTemplate } from './menu/help_menu_template';
import createWindow from "./helpers/window";
import createWindow from './helpers/window';

// Special module holding environment variables which you declared
// in config/env_xxx.json file.
import env from "env";
import env from 'env';

const setApplicationMenu = () => {
const menus = [appMenuTemplate, editMenuTemplate];
if (env.name !== "production") {
const menus = baseMenuTemplate;
if (env.name !== 'production') {
menus.push(devMenuTemplate);
}
menus.push(helpMenuTemplate);
Expand All @@ -29,33 +28,33 @@ const setApplicationMenu = () => {
// Save userData in separate folders for each environment.
// Thanks to this you can use production and development versions of the app
// on same machine like those are two separate apps.
if (env.name !== "production") {
const userDataPath = app.getPath("userData");
app.setPath("userData", `${userDataPath} (${env.name})`);
if (env.name !== 'production') {
const userDataPath = app.getPath('userData');
app.setPath('userData', `${userDataPath} (${env.name})`);
}

app.on("ready", () => {
app.on('ready', () => {
setApplicationMenu();
autoUpdater.checkForUpdatesAndNotify();

const mainWindow = createWindow("main", {
const mainWindow = createWindow('main', {
width: 1100,
height: 800
});

mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "app.html"),
protocol: "file:",
pathname: path.join(__dirname, 'app.html'),
protocol: 'file:',
slashes: true
})
);

if (env.name === "development") {
if (env.name === 'development') {
mainWindow.openDevTools();
}
});

app.on("window-all-closed", () => {
app.on('window-all-closed', () => {
app.quit();
});
41 changes: 17 additions & 24 deletions src/menu/app_menu_template.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import { app } from 'electron';
import { IS_MAC } from '../constants';
import { aboutMenu } from './items/about';

// This is the "Application" menu, which is only used on macOS
let appMenuTemplate = null;

if (IS_MAC) {
appMenuTemplate = {
label: 'Android Messages',
submenu: [,
{
label: 'About Android Messages Desktop',
click: () => aboutMenu()
},
{
type: 'separator',
},
{
label: 'Quit',
accelerator: 'Command+Q',
click: () => app.quit(),
}
]
};
}

export { appMenuTemplate };
export const appMenuTemplate = {
label: 'Android Messages',
submenu: [,
{
label: 'About Android Messages Desktop',
click: () => aboutMenu()
},
{
type: 'separator',
},
{
label: 'Quit',
accelerator: 'Command+Q',
click: () => app.quit(),
}
]
};
11 changes: 11 additions & 0 deletions src/menu/base_menu_template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { appMenuTemplate } from './app_menu_template';
import { editMenuTemplate } from './edit_menu_template';
import { IS_MAC } from '../constants';

const baseMenuTemplate = [editMenuTemplate];

if (IS_MAC) {
baseMenuTemplate.unshift(appMenuTemplate);
}

export { baseMenuTemplate };
6 changes: 3 additions & 3 deletions src/menu/help_menu_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { IS_MAC } from '../constants';
import { aboutMenu } from './items/about';

export const helpMenuTemplate = {
label: "Help",
label: 'Help',
submenu: [
{
label: "Learn More",
click: () => shell.openExternal('https://google.com')
label: 'Learn More',
click: () => shell.openExternal('https://github.com/chrisknepper/android-messages-desktop/')
}
]
};
Expand Down

0 comments on commit 560abf1

Please sign in to comment.