aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Amine <amine@mouafik.fr>2020-02-28 02:39:40 +0100
committerLibravatar GitHub <noreply@github.com>2020-02-28 02:39:40 +0100
commit4c084fd3b336dff2ca1d2c326b1e8e98af2b7e29 (patch)
treef91e6e4f4aa344e4788430691e72fd58fa1f2db6 /src
parentMerge pull request #403 from getferdi/feat/#270 (diff)
parentFix lock at startup when previously closed while locked (diff)
downloadferdium-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
Diffstat (limited to 'src')
-rw-r--r--src/components/layout/Sidebar.js11
-rw-r--r--src/lib/Menu.js27
-rw-r--r--src/stores/SettingsStore.js68
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 @@
1import { remote, shell, clipboard } from 'electron'; 1import { clipboard, remote, shell } from 'electron';
2import { observable, autorun } from 'mobx'; 2import { autorun, observable } from 'mobx';
3import { defineMessages } from 'react-intl'; 3import { defineMessages } from 'react-intl';
4 4import { cmdKey, ctrlKey, isMac } from '../environment';
5import { isMac, ctrlKey, cmdKey } from '../environment';
6import { workspaceStore } from '../features/workspaces/index';
7import { workspaceActions } from '../features/workspaces/actions';
8import { announcementActions } from '../features/announcements/actions';
9import { announcementsStore } from '../features/announcements'; 5import { announcementsStore } from '../features/announcements';
6import { announcementActions } from '../features/announcements/actions';
10import { todosStore } from '../features/todos'; 7import { todosStore } from '../features/todos';
11import { todoActions } from '../features/todos/actions'; 8import { todoActions } from '../features/todos/actions';
12import { CUSTOM_WEBSITE_ID } from '../features/webControls/constants'; 9import { CUSTOM_WEBSITE_ID } from '../features/webControls/constants';
10import { workspaceActions } from '../features/workspaces/actions';
11import { workspaceStore } from '../features/workspaces/index';
12
13 13
14const { app, Menu, dialog } = remote; 14const { 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 @@
1import { ipcRenderer, remote } from 'electron'; 1import { ipcRenderer, remote } from 'electron';
2import { 2import { action, computed, observable, reaction } from 'mobx';
3 action, computed, observable, reaction,
4} from 'mobx';
5import localStorage from 'mobx-localstorage'; 3import localStorage from 'mobx-localstorage';
6
7import Store from './lib/Store';
8import Request from './lib/Request';
9import { getLocale } from '../helpers/i18n-helpers';
10import { API } from '../environment';
11
12import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES, LOCAL_SERVER } from '../config'; 4import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES, LOCAL_SERVER } from '../config';
5import { API } from '../environment';
6import { getLocale } from '../helpers/i18n-helpers';
13import { SPELLCHECKER_LOCALES } from '../i18n/languages'; 7import { SPELLCHECKER_LOCALES } from '../i18n/languages';
8import Request from './lib/Request';
9import Store from './lib/Store';
14 10
15const debug = require('debug')('Ferdi:SettingsStore'); 11const debug = require('debug')('Ferdi:SettingsStore');
16 12
17export default class SettingsStore extends Store { 13export 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() {