diff --git a/main.js b/main.js index 6e683fe7e..f6fafc664 100644 --- a/main.js +++ b/main.js @@ -23,7 +23,8 @@ var isWindows = (process.platform === 'win32'); var autoStart = new AutoLaunch({ name: 'Gitify', - path: process.execPath.match(/.*?\.app/)[0] + path: process.execPath.match(/.*?\.app/)[0], + isHidden: true }); app.on('ready', function() { diff --git a/package.json b/package.json index 57ee91967..a9e8d8806 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "homepage": "https://github.com/ekonstantinidis/gitify", "dependencies": { - "auto-launch": "=2.0.1", + "auto-launch": "=4.0.0", "bootstrap": "=4.0.0-alpha.2", "electron-gh-releases": "=2.0.3", "electron-positioner": "=3.0.0", diff --git a/src/js/__tests__/middleware/settings.js b/src/js/__tests__/middleware/settings.js new file mode 100644 index 000000000..8fd8c9f4a --- /dev/null +++ b/src/js/__tests__/middleware/settings.js @@ -0,0 +1,61 @@ +import { expect } from 'chai'; +import * as actions from '../../actions'; +import settingsMiddleware from '../../middleware/settings'; +const ipcRenderer = window.require('electron').ipcRenderer; + +const createFakeStore = fakeData => ({ + getState() { + return { + notifications: {}, + settings: { + openAtStartup: false, + playSound: false, + showNotifications: false + } + }; + } +}); + +const dispatchWithStoreOf = (storeData, action) => { + let dispatched = null; + const dispatch = settingsMiddleware(createFakeStore(storeData))(actionAttempt => dispatched = actionAttempt); + dispatch(action); + return dispatched; +}; + +describe('middleware/settings.js', () => { + + beforeEach(function() { + ipcRenderer.send.reset(); + }); + + it('should mark auto-launch setting to true (enable)', () => { + + const action = { + type: actions.UPDATE_SETTING, + setting: 'openAtStartup', + value: true + }; + + expect(dispatchWithStoreOf({}, action)).to.eql(action); + + expect(ipcRenderer.send).to.have.been.calledOnce; + expect(ipcRenderer.send).to.have.been.calledWith('startup-enable'); + + }); + + it('should mark auto-launch setting to false (disable)', () => { + + const action = { + type: actions.UPDATE_SETTING, + setting: 'openAtStartup', + value: false + }; + + expect(dispatchWithStoreOf({}, action)).to.eql(action); + + expect(ipcRenderer.send).to.have.been.calledOnce; + expect(ipcRenderer.send).to.have.been.calledWith('startup-disable'); + + }); +}); diff --git a/src/js/middleware/settings.js b/src/js/middleware/settings.js new file mode 100644 index 000000000..94dfdb56b --- /dev/null +++ b/src/js/middleware/settings.js @@ -0,0 +1,18 @@ +const ipcRenderer = window.require('electron').ipcRenderer; +import { UPDATE_SETTING } from '../actions'; + +export default store => next => action => { + + switch (action.type) { + case UPDATE_SETTING: + if (action.setting === 'openAtStartup') { + if (action.value) { + ipcRenderer.send('startup-enable'); + } else { + ipcRenderer.send('startup-disable'); + } + } + } + + return next(action); +}; diff --git a/src/js/store/configureStore.js b/src/js/store/configureStore.js index 531037483..cf1eb4d21 100644 --- a/src/js/store/configureStore.js +++ b/src/js/store/configureStore.js @@ -8,6 +8,7 @@ import filter from 'redux-storage-decorator-filter'; import { fetchNotifications, UPDATE_SETTING, LOGIN_SUCCESS, LOGOUT } from '../actions'; import constants from '../utils/constants'; import notifications from '../middleware/notifications'; +import settings from '../middleware/settings'; import requests from '../middleware/requests'; import rootReducer from '../reducers'; @@ -19,6 +20,7 @@ export default function configureStore(initialState) { requests, // Should be passed before 'apiMiddleware' apiMiddleware, notifications, + settings, storageMiddleware )(createStore);