aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-02-15 17:38:13 +0100
committerLibravatar Stefan Malzner <stefan@adlk.io>2018-02-15 17:38:13 +0100
commit9a89ef51cded72d5e6d378211e8a74964cfc8cc2 (patch)
treeee4c0d7913119d52b266f66f46d99ee9ef3b9ed8 /src/stores
parentreplace localStorage with mobx-localstorage (diff)
downloadferdium-app-9a89ef51cded72d5e6d378211e8a74964cfc8cc2.tar.gz
ferdium-app-9a89ef51cded72d5e6d378211e8a74964cfc8cc2.tar.zst
ferdium-app-9a89ef51cded72d5e6d378211e8a74964cfc8cc2.zip
Replace localAPI requests with mobx-localstorage
Diffstat (limited to 'src/stores')
-rw-r--r--src/stores/AppStore.js9
-rw-r--r--src/stores/SettingsStore.js21
-rw-r--r--src/stores/UserStore.js1
3 files changed, 12 insertions, 19 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 06c43f83f..77027f88d 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -331,10 +331,7 @@ export default class AppStore extends Store {
331 } 331 }
332 332
333 // Helpers 333 // Helpers
334 async _appStartsCounter() { 334 _appStartsCounter() {
335 // we need to wait until the settings request is resolved
336 await this.stores.settings.allSettingsRequest;
337
338 this.actions.settings.update({ 335 this.actions.settings.update({
339 settings: { 336 settings: {
340 appStarts: (this.stores.settings.all.appStarts || 0) + 1, 337 appStarts: (this.stores.settings.all.appStarts || 0) + 1,
@@ -345,10 +342,10 @@ export default class AppStore extends Store {
345 async _autoStart() { 342 async _autoStart() {
346 this.autoLaunchOnStart = await this._checkAutoStart(); 343 this.autoLaunchOnStart = await this._checkAutoStart();
347 344
348 // we need to wait until the settings request is resolved 345 console.log('### settings appstarts', this.stores.settings.all.appStarts);
349 await this.stores.settings.allSettingsRequest;
350 346
351 if (!this.stores.settings.all.appStarts) { 347 if (!this.stores.settings.all.appStarts) {
348 console.log('launch Franz on start');
352 this.actions.app.launchOnStartup({ 349 this.actions.app.launchOnStartup({
353 enable: true, 350 enable: true,
354 }); 351 });
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index 26d895b7e..f6f340c2b 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -1,5 +1,6 @@
1import { ipcRenderer } from 'electron'; 1import { ipcRenderer } from 'electron';
2import { action, computed, observable, extendObservable } from 'mobx'; 2import { action, computed, observable, extendObservable } from 'mobx';
3import localStorage from 'mobx-localstorage';
3 4
4import Store from './lib/Store'; 5import Store from './lib/Store';
5import Request from './lib/Request'; 6import Request from './lib/Request';
@@ -26,19 +27,12 @@ export default class SettingsStore extends Store {
26 } 27 }
27 28
28 @computed get all() { 29 @computed get all() {
29 console.log('get all settings'); 30 return new SettingsModel(localStorage.getItem('app') || {});
30 return new SettingsModel(this.allSettingsRequest.result);
31 } 31 }
32 32
33 @action async _update({ settings }) { 33 @action async _update({ settings }) {
34 await this.updateSettingsRequest.execute(settings)._promise; 34 const appSettings = this.all;
35 // await this.allSettingsRequest.patch((result) => { 35 localStorage.setItem('app', Object.assign(appSettings, settings));
36 // if (!result) return;
37 // console.log(result.runInBackground, settings.runInBackground);
38 // extendObservable(result, settings);
39 // console.log(result.runInBackground);
40 // // result.update(settings);
41 // });
42 36
43 // We need a little hack to wait until everything is patched 37 // We need a little hack to wait until everything is patched
44 setTimeout(() => this._shareSettingsWithMainProcess(), 0); 38 setTimeout(() => this._shareSettingsWithMainProcess(), 0);
@@ -47,8 +41,11 @@ export default class SettingsStore extends Store {
47 } 41 }
48 42
49 @action async _remove({ key }) { 43 @action async _remove({ key }) {
50 await this.removeSettingsKeyRequest.execute(key); 44 const appSettings = this.all;
51 await this.allSettingsRequest.invalidate({ immediately: true }); 45 if (Object.hasOwnProperty.call(appSettings, key)) {
46 delete appSettings[key];
47 localStorage.setItem('app', appSettings);
48 }
52 49
53 this._shareSettingsWithMainProcess(); 50 this._shareSettingsWithMainProcess();
54 } 51 }
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js
index 7b8ffb2b2..7dbbd955b 100644
--- a/src/stores/UserStore.js
+++ b/src/stores/UserStore.js
@@ -226,7 +226,6 @@ export default class UserStore extends Store {
226 226
227 // This is a mobx autorun which forces the user to login if not authenticated 227 // This is a mobx autorun which forces the user to login if not authenticated
228 _requireAuthenticatedUser = () => { 228 _requireAuthenticatedUser = () => {
229 console.log('requireAuthenticatedUser');
230 if (this.isTokenExpired) { 229 if (this.isTokenExpired) {
231 this._logout(); 230 this._logout();
232 } 231 }