Skip to content

Commit

Permalink
Add Minimize To Tray functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynael committed Mar 11, 2017
1 parent e3aeb13 commit ad441e7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
Binary file added app/icon.ico
Binary file not shown.
47 changes: 42 additions & 5 deletions src/background.js
Expand Up @@ -5,11 +5,15 @@

import path from 'path';
import url from 'url';
import { app, Menu } from 'electron';
import { app, Menu, Tray, BrowserWindow } from 'electron';
import { devMenuTemplate } from './menu/dev_menu_template';
import { editMenuTemplate } from './menu/edit_menu_template';
import createWindow from './helpers/window';
const path = require('path');
const iconPath = path.join(__dirname, 'icon.ico');

let appIcon = null;
let win = null;
// Special module holding environment variables which you declared
// in config/env_xxx.json file.
import env from './env';
Expand Down Expand Up @@ -37,7 +41,10 @@ app.on('ready', function () {

var mainWindow = createWindow('main', {
width: 1000,
height: 600
height: 600,
title: "Hear Me Type",
icon: iconPath
// frame: false
});

mainWindow.loadURL(url.format({
Expand All @@ -49,8 +56,38 @@ app.on('ready', function () {
if (env.name === 'development') {
mainWindow.openDevTools();
}
});

app.on('window-all-closed', function () {
app.quit();
app.on('window-all-closed', function () {
app.quit();
});

appIcon = new Tray(iconPath);
var contextMenu = Menu.buildFromTemplate([
{
label: 'Show app',
click: function() {
mainWindow.show();
}
},
{ label: 'Quit',
click: function() {
app.quit();
}
}
]);
appIcon.setToolTip('Hear Me Type is minimized to tray.');
appIcon.setContextMenu(contextMenu);

mainWindow.on('minimize',function(event){
event.preventDefault()
mainWindow.hide();
});
//
// mainWindow.on('close', function (event) {
// if( !app.isQuiting){
// event.preventDefault()
// mainWindow.hide();
// }
// return false;
// });
});

0 comments on commit ad441e7

Please sign in to comment.