diff --git a/src/actions/accounts.js b/src/actions/accounts.js index 4649c97e..99ffe0c6 100644 --- a/src/actions/accounts.js +++ b/src/actions/accounts.js @@ -24,6 +24,7 @@ export const reorderAccounts: ReorderAccounts = payload => ({ export type FetchAccounts = () => * export const fetchAccounts: FetchAccounts = () => { + db.init('accounts', []) // FIXME the "init" pattern to drop imo. a simple get()||[] is enough const accounts = db.get('accounts') return { type: 'SET_ACCOUNTS', diff --git a/src/main/app.js b/src/main/app.js index 6c6c9e71..068fdfa1 100644 --- a/src/main/app.js +++ b/src/main/app.js @@ -29,7 +29,7 @@ const getWindowPosition = (height, width, display = screen.getPrimaryDisplay()) const handleCloseWindow = w => e => { if (!forceClose) { e.preventDefault() - + w.webContents.send('lock') if (w !== null) { w.hide() } diff --git a/src/reducers/application.js b/src/reducers/application.js index 644d94e1..4d44cc70 100644 --- a/src/reducers/application.js +++ b/src/reducers/application.js @@ -4,7 +4,9 @@ import { handleActions, createAction } from 'redux-actions' import { hasPassword } from 'reducers/settings' -export type ApplicationState = {} +export type ApplicationState = { + isLocked?: boolean, +} const state: ApplicationState = {} @@ -15,7 +17,7 @@ const handlers = { }), } -// Actions +// Actions // FIXME why isn't this in actions/* export const unlock = createAction('APPLICATION_SET_DATA', () => ({ isLocked: false })) export const lock = createAction('APPLICATION_SET_DATA', () => ({ isLocked: true })) @@ -23,6 +25,7 @@ export const lock = createAction('APPLICATION_SET_DATA', () => ({ isLocked: true // Selectors export const isLocked = (state: Object) => + // FIXME why!? state.application.isLocked === undefined ? hasPassword(state) : state.application.isLocked // Exporting reducer diff --git a/src/renderer/events.js b/src/renderer/events.js index e28f9387..bb106f27 100644 --- a/src/renderer/events.js +++ b/src/renderer/events.js @@ -17,8 +17,9 @@ import debug from 'debug' import { CHECK_UPDATE_DELAY } from 'config/constants' +import { hasPassword } from 'reducers/settings' +import { lock } from 'reducers/application' import { setUpdateStatus } from 'reducers/update' - import { addDevice, removeDevice, resetDevices } from 'actions/devices' import listenDevices from 'commands/listenDevices' @@ -43,7 +44,7 @@ export function sendEvent(channel: string, msgType: string, data: any) { } let syncDeviceSub -export default ({ store }: { store: Object, locked: boolean }) => { +export default ({ store }: { store: Object }) => { // Ensure all sub-processes are killed before creating new ones (dev mode...) ipcRenderer.send('clean-processes') @@ -80,6 +81,12 @@ export default ({ store }: { store: Object, locked: boolean }) => { syncDevices() + ipcRenderer.on('lock', () => { + if (hasPassword(store.getState())) { + store.dispatch(lock()) + } + }) + ipcRenderer.on('executeHttpQuery', (event: any, { networkArg, id }) => { network(networkArg).then( result => { diff --git a/src/renderer/init.js b/src/renderer/init.js index 2afa5483..b04bda46 100644 --- a/src/renderer/init.js +++ b/src/renderer/init.js @@ -59,18 +59,14 @@ async function init() { const state = store.getState() const language = getLanguage(state) - const locked = isLocked(state) - sentry(() => sentryLogsBooleanSelector(store.getState())) - moment.locale(language) + sentry(() => sentryLogsBooleanSelector(store.getState())) + // FIXME IMO init() really should only be for window. any other case is a hack! const isMainWindow = remote.getCurrentWindow().name === 'MainWindow' - if (!locked) { - // Init accounts with defaults if needed - db.init('accounts', []) - + if (!isLocked(store.getState())) { await store.dispatch(fetchAccounts()) } @@ -80,7 +76,7 @@ async function init() { if (isMainWindow) { webFrame.setVisualZoomLevelLimits(1, 1) - events({ store, locked }) + events({ store }) const libcoreVersion = await libcoreGetVersion.send().toPromise() logger.log('libcore', libcoreVersion)