Skip to content

Commit

Permalink
added more logging in the main process + fixed Application menubar me…
Browse files Browse the repository at this point in the history
…nu name
  • Loading branch information
jsmith committed Mar 5, 2020
1 parent dc02e1c commit dc4277f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import { isDevelopment } from './lib/electron/environment';
import eLog from 'electron-log';

eLog.transports.console.level = false;
eLog.transports.file.level = false;
eLog.transports.file.level = 'info';

eLog.catchErrors({
showDialog: false,
onError: (e) => {
eLog.error(`${e.name}: ${e.message}`);
},
});

// 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.
Expand Down
9 changes: 7 additions & 2 deletions src/lib/electron/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import electron, { Menu, MenuItemConstructorOptions } from 'electron';
import { MenuBarItem, MenuBarSections, MainEvents, RendererEvents } from '../ipc-interface';
import { defaultIpcMain } from '../ipc';
import { keys } from '../std';

export type ElectronMenuItem = {
type: 'callback';
Expand Down Expand Up @@ -131,7 +132,7 @@ const menuLookup: MenuLookup = {
const untypedMenu: { [K: string]: { [S: string]: ElectronMenuItem[]; } } = menuLookup;

const renderMenu = () => {
const template = Object.keys(menuLookup).map((menuLabel): MenuItemConstructorOptions => {
const template = keys(menuLookup).map((menuLabel): MenuItemConstructorOptions => {
const submenu: MenuItemConstructorOptions[] = [];
Object.keys(untypedMenu[menuLabel]).forEach((section, i) => {
if (i !== 0) {
Expand All @@ -157,7 +158,11 @@ const renderMenu = () => {
});

return {
label: menuLabel,
// On MacOS, this is done automatically. For consistency across operating systems we do this explicitly
// MacOS explicitly shows the application name as the first menu
// https://stackoverflow.com/questions/41551110/unable-to-override-app-name-on-mac-os-electron-menu
// provides a bit more info although it is not really related to this
label: menuLabel === 'Application' ? electron.app.getName() : menuLabel,
submenu,
};
});
Expand Down
14 changes: 12 additions & 2 deletions src/lib/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,22 @@ export const log = (message: LogMessage) => {
eLog!.transports.console.level = false;
eLog!.transports.file.level = 'warn';
eLog!.transports.file.format = '[{y}-{m}-{d} {h}:{i}:{s}.{ms}] {text}';
eLog!.catchErrors({
showDialog: false,
onError: (e) => {
log({
level: 'error',
message: e.message,
name: 'Unhandled',
setLevel: 'info',
args: [],
});
},
});
}

eLog![message.level](messageString, ...message.args);

// tslint:disable-next-line:no-console
console.log(`%c${messageString}`, styleString, ...message.args);
};


2 changes: 1 addition & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const middleware = () => {
});

const extensions = require.context(
'.//extra',
'./extra',
// Whether or not to look in subfolders
true,
/^.+\.ts/,
Expand Down

0 comments on commit dc4277f

Please sign in to comment.