Browse Source
Merge pull request #552 from gre/lock-on-close
lock if i close the app (on mac close it's a simple hide)
master
Meriadec Pillet
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
20 additions and
13 deletions
-
src/actions/accounts.js
-
src/main/app.js
-
src/reducers/application.js
-
src/renderer/events.js
-
src/renderer/init.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', |
|
|
|
|
|
@ -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() |
|
|
|
} |
|
|
|
|
|
@ -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
|
|
|
|
|
|
@ -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 => { |
|
|
|
|
|
@ -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) |
|
|
|