Browse Source

lock if i close the app (on mac close it's a simple hide)

master
Gaëtan Renaudeau 7 years ago
parent
commit
f2eae14f0a
  1. 1
      src/actions/accounts.js
  2. 2
      src/main/app.js
  3. 7
      src/reducers/application.js
  4. 11
      src/renderer/events.js
  5. 12
      src/renderer/init.js

1
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',

2
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()
}

7
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

11
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 => {

12
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)

Loading…
Cancel
Save