Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #77 from tahnik/tray
Browse files Browse the repository at this point in the history
Added tray icon
  • Loading branch information
tahnik authored Jul 16, 2017
2 parents 485400f + b05ddd3 commit 9bf7dab
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 28 deletions.
42 changes: 37 additions & 5 deletions app/src/main/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const electron = require('electron');
// Module to control application life.
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;

const { app, BrowserWindow, Menu, Tray } = electron;


const os = require('os');
const path = require('path');
Expand Down Expand Up @@ -35,6 +34,33 @@ let mainWindow;

console.time('startup'); //eslint-disable-line

function openRantComposer() {
mainWindow.show();
mainWindow.webContents.send('compose_rant');
}

function quitApp() {
mainWindow.webContents.send('quitApp');
}

/** This function will create the tray icon */
function initTray() {
// No idea why using let or var or const with tray causes the tray not to display anything
/* eslint-disable */
tray = new Tray(path.join(__dirname, '/res/images/devrantLogo512.png'));
const contextMenu = Menu.buildFromTemplate([
{ label: 'Open App', click() { mainWindow.show(); } },
{ type: 'separator' },
{ label: 'Compose A Rant', click() { openRantComposer(); } },
{ type: 'separator' },
{ label: 'Quit', click() { quitApp(); } },
]);
tray.setToolTip('devRantron');
tray.setContextMenu(contextMenu);
tray.on('click', () => { mainWindow.show(); });
/* eslint-enable */
}

/** This function will create the mainWindow */
function createWindow() {
// Create the browser window.
Expand Down Expand Up @@ -88,6 +114,8 @@ function createWindow() {
// when you should delete the corresponding element.
mainWindow = null;
});

initTray();
}

// This method will be called when Electron has finished
Expand Down Expand Up @@ -133,5 +161,9 @@ ipcMain.on('auto-launch', (event, arg) => {


ipcMain.on('minimiseApp', () => {
mainWindow.minimize();
mainWindow.hide();
});

ipcMain.on('forceQuitApp', () => {
app.exit(0);
});
3 changes: 1 addition & 2 deletions app/src/main/js/actions/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const saveUserState = (state) => {
const setOnBeforeUnload = (state, value) => {
if (value) {
window.onbeforeunload = (e) => {
saveUserState(state);
ipcRenderer.send('minimiseApp');
e.returnValue = false;
};
Expand Down Expand Up @@ -84,4 +83,4 @@ const changeTheme = () => () => {
};


export { changeGeneral, changeTheme, setAutoLaunch, setMinimiseOnClose };
export { changeGeneral, changeTheme, setAutoLaunch, setMinimiseOnClose, saveUserState };
3 changes: 3 additions & 0 deletions app/src/main/js/components/notifs/notifs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import NotifBubbles from './notif_bubbles';
import { getNotifText } from '../../consts/DOMFunctions';

const currentWindow = require('electron').remote.getCurrentWindow();
const { ipcRenderer } = require('electron');

class Notifs extends Component {
constructor() {
Expand All @@ -27,6 +28,8 @@ class Notifs extends Component {
setInterval(() => {
fetchNotifs();
}, 10000);

ipcRenderer.on('open_notif', () => { this.setState({ active: true }); });
}
shouldComponentUpdate(nextProps, nextState) {
if (this.state.firstFetch) {
Expand Down
26 changes: 7 additions & 19 deletions app/src/main/js/store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { applyMiddleware, createStore, compose } from 'redux';
import thunk from 'redux-thunk';
import reducers from './reducers/index';
import { setAutoLaunch, setMinimiseOnClose } from './actions/settings';
import { setAutoLaunch, setMinimiseOnClose, saveUserState } from './actions/settings';

const { ipcRenderer } = require('electron');

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; //eslint-disable-line
const middleware = applyMiddleware(thunk);
Expand Down Expand Up @@ -37,23 +39,9 @@ if (initialState) {
}
}


// window.onbeforeunload = () => {
// const state = store.getState();
// const customCols = [...state.columns];
// for (let index = 0; index < customCols.length; index += 1) {
// customCols[index].items = [];
// customCols[index].prev_set = 0;
// customCols[index].page = 0;
// }
// const savedState = {
// auth: state.auth,
// user: state.user,
// settings: state.settings,
// notifs: state.notifs,
// columns: customCols,
// };
// localStorage.setItem('savedState', JSON.stringify(savedState));
// };
ipcRenderer.on('quitApp', () => {
saveUserState(store.getState());
ipcRenderer.sendSync('forceQuitApp');
});

export default store;
Binary file added app/src/main/res/images/devrantLogo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "devrantron",
"version": "0.2.1",
"version": "0.3.0",
"main": "./app/build/app.js",
"description": "An open source cross platform desktop application for devRant",
"scripts": {
Expand Down

0 comments on commit 9bf7dab

Please sign in to comment.