diff options
author | Amine <amine@mouafik.fr> | 2020-02-28 02:39:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 02:39:40 +0100 |
commit | 4c084fd3b336dff2ca1d2c326b1e8e98af2b7e29 (patch) | |
tree | f91e6e4f4aa344e4788430691e72fd58fa1f2db6 | |
parent | Merge pull request #403 from getferdi/feat/#270 (diff) | |
parent | Fix lock at startup when previously closed while locked (diff) | |
download | ferdium-app-4c084fd3b336dff2ca1d2c326b1e8e98af2b7e29.tar.gz ferdium-app-4c084fd3b336dff2ca1d2c326b1e8e98af2b7e29.tar.zst ferdium-app-4c084fd3b336dff2ca1d2c326b1e8e98af2b7e29.zip |
Merge pull request #393 from getferdi/refactor/lock
Fix race condition in Ferdi Lock at startup
-rw-r--r-- | src/components/layout/Sidebar.js | 11 | ||||
-rw-r--r-- | src/lib/Menu.js | 27 | ||||
-rw-r--r-- | src/stores/SettingsStore.js | 68 |
3 files changed, 39 insertions, 67 deletions
diff --git a/src/components/layout/Sidebar.js b/src/components/layout/Sidebar.js index 48a83c5a1..bd10ccb4a 100644 --- a/src/components/layout/Sidebar.js +++ b/src/components/layout/Sidebar.js | |||
@@ -118,21 +118,12 @@ export default @inject('stores', 'actions') @observer class Sidebar extends Comp | |||
118 | type="button" | 118 | type="button" |
119 | className="sidebar__button" | 119 | className="sidebar__button" |
120 | onClick={() => { | 120 | onClick={() => { |
121 | // Disable lock first - otherwise the application might not update correctly | ||
122 | actions.settings.update({ | 121 | actions.settings.update({ |
123 | type: 'app', | 122 | type: 'app', |
124 | data: { | 123 | data: { |
125 | locked: false, | 124 | locked: true, |
126 | }, | 125 | }, |
127 | }); | 126 | }); |
128 | setTimeout(() => { | ||
129 | actions.settings.update({ | ||
130 | type: 'app', | ||
131 | data: { | ||
132 | locked: true, | ||
133 | }, | ||
134 | }); | ||
135 | }, 0); | ||
136 | }} | 127 | }} |
137 | data-tip={`${intl.formatMessage(messages.lockFerdi)} (${ctrlKey}+Shift+L)`} | 128 | data-tip={`${intl.formatMessage(messages.lockFerdi)} (${ctrlKey}+Shift+L)`} |
138 | > | 129 | > |
diff --git a/src/lib/Menu.js b/src/lib/Menu.js index f2669a106..f66dab111 100644 --- a/src/lib/Menu.js +++ b/src/lib/Menu.js | |||
@@ -1,15 +1,15 @@ | |||
1 | import { remote, shell, clipboard } from 'electron'; | 1 | import { clipboard, remote, shell } from 'electron'; |
2 | import { observable, autorun } from 'mobx'; | 2 | import { autorun, observable } from 'mobx'; |
3 | import { defineMessages } from 'react-intl'; | 3 | import { defineMessages } from 'react-intl'; |
4 | 4 | import { cmdKey, ctrlKey, isMac } from '../environment'; | |
5 | import { isMac, ctrlKey, cmdKey } from '../environment'; | ||
6 | import { workspaceStore } from '../features/workspaces/index'; | ||
7 | import { workspaceActions } from '../features/workspaces/actions'; | ||
8 | import { announcementActions } from '../features/announcements/actions'; | ||
9 | import { announcementsStore } from '../features/announcements'; | 5 | import { announcementsStore } from '../features/announcements'; |
6 | import { announcementActions } from '../features/announcements/actions'; | ||
10 | import { todosStore } from '../features/todos'; | 7 | import { todosStore } from '../features/todos'; |
11 | import { todoActions } from '../features/todos/actions'; | 8 | import { todoActions } from '../features/todos/actions'; |
12 | import { CUSTOM_WEBSITE_ID } from '../features/webControls/constants'; | 9 | import { CUSTOM_WEBSITE_ID } from '../features/webControls/constants'; |
10 | import { workspaceActions } from '../features/workspaces/actions'; | ||
11 | import { workspaceStore } from '../features/workspaces/index'; | ||
12 | |||
13 | 13 | ||
14 | const { app, Menu, dialog } = remote; | 14 | const { app, Menu, dialog } = remote; |
15 | 15 | ||
@@ -806,21 +806,12 @@ export default class FranzMenu { | |||
806 | accelerator: 'CmdOrCtrl+Shift+L', | 806 | accelerator: 'CmdOrCtrl+Shift+L', |
807 | enabled: this.stores.user.isLoggedIn && this.stores.settings.app.lockingFeatureEnabled, | 807 | enabled: this.stores.user.isLoggedIn && this.stores.settings.app.lockingFeatureEnabled, |
808 | click() { | 808 | click() { |
809 | // Disable lock first - otherwise the application might not update correctly | ||
810 | actions.settings.update({ | 809 | actions.settings.update({ |
811 | type: 'app', | 810 | type: 'app', |
812 | data: { | 811 | data: { |
813 | locked: false, | 812 | locked: true, |
814 | }, | 813 | }, |
815 | }); | 814 | }); |
816 | setTimeout(() => { | ||
817 | actions.settings.update({ | ||
818 | type: 'app', | ||
819 | data: { | ||
820 | locked: true, | ||
821 | }, | ||
822 | }); | ||
823 | }, 0); | ||
824 | }, | 815 | }, |
825 | }); | 816 | }); |
826 | 817 | ||
@@ -967,7 +958,7 @@ export default class FranzMenu { | |||
967 | 958 | ||
968 | this.currentTemplate = tpl; | 959 | this.currentTemplate = tpl; |
969 | const menu = Menu.buildFromTemplate(tpl); | 960 | const menu = Menu.buildFromTemplate(tpl); |
970 | const lockedMenu = Menu.buildFromTemplate([]); | 961 | const lockedMenu = new Menu(); |
971 | Menu.setApplicationMenu(this.stores.user.isLoggedIn && this.stores.settings.app.locked ? lockedMenu : menu); | 962 | Menu.setApplicationMenu(this.stores.user.isLoggedIn && this.stores.settings.app.locked ? lockedMenu : menu); |
972 | } | 963 | } |
973 | 964 | ||
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 43f00b723..26e83b725 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -1,21 +1,18 @@ | |||
1 | import { ipcRenderer, remote } from 'electron'; | 1 | import { ipcRenderer, remote } from 'electron'; |
2 | import { | 2 | import { action, computed, observable, reaction } from 'mobx'; |
3 | action, computed, observable, reaction, | ||
4 | } from 'mobx'; | ||
5 | import localStorage from 'mobx-localstorage'; | 3 | import localStorage from 'mobx-localstorage'; |
6 | |||
7 | import Store from './lib/Store'; | ||
8 | import Request from './lib/Request'; | ||
9 | import { getLocale } from '../helpers/i18n-helpers'; | ||
10 | import { API } from '../environment'; | ||
11 | |||
12 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES, LOCAL_SERVER } from '../config'; | 4 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES, LOCAL_SERVER } from '../config'; |
5 | import { API } from '../environment'; | ||
6 | import { getLocale } from '../helpers/i18n-helpers'; | ||
13 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 7 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
8 | import Request from './lib/Request'; | ||
9 | import Store from './lib/Store'; | ||
14 | 10 | ||
15 | const debug = require('debug')('Ferdi:SettingsStore'); | 11 | const debug = require('debug')('Ferdi:SettingsStore'); |
16 | 12 | ||
17 | export default class SettingsStore extends Store { | 13 | export default class SettingsStore extends Store { |
18 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); | 14 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); |
15 | startup = true; | ||
19 | 16 | ||
20 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; | 17 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; |
21 | 18 | ||
@@ -30,16 +27,6 @@ export default class SettingsStore extends Store { | |||
30 | // Register action handlers | 27 | // Register action handlers |
31 | this.actions.settings.update.listen(this._update.bind(this)); | 28 | this.actions.settings.update.listen(this._update.bind(this)); |
32 | this.actions.settings.remove.listen(this._remove.bind(this)); | 29 | this.actions.settings.remove.listen(this._remove.bind(this)); |
33 | |||
34 | ipcRenderer.on('appSettings', (event, resp) => { | ||
35 | debug('Get appSettings resolves', resp.type, resp.data); | ||
36 | |||
37 | Object.assign(this._fileSystemSettingsCache[resp.type], resp.data); | ||
38 | }); | ||
39 | |||
40 | this.fileSystemSettingsTypes.forEach((type) => { | ||
41 | ipcRenderer.send('getAppSettings', type); | ||
42 | }); | ||
43 | } | 30 | } |
44 | 31 | ||
45 | async setup() { | 32 | async setup() { |
@@ -101,27 +88,30 @@ export default class SettingsStore extends Store { | |||
101 | } | 88 | } |
102 | }); | 89 | }); |
103 | 90 | ||
104 | // Make sure to lock app on launch if locking feature is enabled | 91 | ipcRenderer.on('appSettings', (event, resp) => { |
105 | setTimeout(() => { | 92 | // Lock on startup if enabled in settings |
106 | const isLoggedIn = Boolean(localStorage.getItem('authToken')); | 93 | if (this.startup && resp.type === 'app' && resp.data.lockingFeatureEnabled) { |
107 | if (isLoggedIn && this.all.app.lockingFeatureEnabled) { | 94 | this.startup = false; |
108 | // Disable lock first - otherwise the lock might not get activated corrently | 95 | process.nextTick(() => { |
109 | this.actions.settings.update({ | 96 | // If the app was previously closed unlocked |
110 | type: 'app', | 97 | // we can update the `locked` setting and rely on the reaction to lock at startup |
111 | data: { | 98 | if (!this.all.app.locked) { |
112 | locked: false, | 99 | this.all.app.locked = true; |
113 | }, | 100 | } else { |
114 | }); | 101 | // Otherwise the app previously closed in a locked state |
115 | setTimeout(() => { | 102 | // We can't rely on updating the locked setting for the reaction to be triggered |
116 | this.actions.settings.update({ | 103 | // So we lock manually |
117 | type: 'app', | 104 | window.ferdi.stores.router.push('/auth/locked'); |
118 | data: { | 105 | } |
119 | locked: true, | 106 | }) |
120 | }, | ||
121 | }); | ||
122 | }, 0); | ||
123 | } | 107 | } |
124 | }, 1000); | 108 | debug('Get appSettings resolves', resp.type, resp.data); |
109 | Object.assign(this._fileSystemSettingsCache[resp.type], resp.data); | ||
110 | }); | ||
111 | |||
112 | this.fileSystemSettingsTypes.forEach((type) => { | ||
113 | ipcRenderer.send('getAppSettings', type); | ||
114 | }); | ||
125 | } | 115 | } |
126 | 116 | ||
127 | @computed get app() { | 117 | @computed get app() { |