From 88faef416eadc891537f03926160e35245125c72 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Sun, 18 Mar 2018 16:37:21 +0100 Subject: Replace console logs with debugger --- src/api/server/LocalApi.js | 8 +++--- src/api/server/ServerApi.js | 60 +++++++++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 32 deletions(-) (limited to 'src/api/server') diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.js index aa3a7d655..4d2497c61 100644 --- a/src/api/server/LocalApi.js +++ b/src/api/server/LocalApi.js @@ -3,6 +3,8 @@ import du from 'du'; import { getServicePartitionsDirectory } from '../../helpers/service-helpers.js'; +const debug = require('debug')('LocalApi'); + const { session } = remote; export default class LocalApi { @@ -13,7 +15,7 @@ export default class LocalApi { du(partitionsDir, (err, size) => { if (err) reject(err); - console.debug('LocalApi::getAppCacheSize resolves', size); + debug('LocalApi::getAppCacheSize resolves', size); resolve(size); }); }); @@ -22,14 +24,14 @@ export default class LocalApi { async clearCache(serviceId) { const s = session.fromPartition(`persist:service-${serviceId}`); - console.debug('LocalApi::clearCache resolves', serviceId); + debug('LocalApi::clearCache resolves', serviceId); return new Promise(resolve => s.clearCache(resolve)); } async clearAppCache() { const s = session.defaultSession; - console.debug('LocalApi::clearCache clearAppCache'); + debug('LocalApi::clearCache clearAppCache'); return new Promise(resolve => s.clearCache(resolve)); } } diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 8f3297d13..353faa7f4 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js @@ -27,6 +27,8 @@ import { removeServicePartitionDirectory, } from '../../helpers/service-helpers.js'; +const debug = require('debug')('ServerApi'); + module.paths.unshift( getDevRecipeDirectory(), getRecipeDirectory(), @@ -55,7 +57,7 @@ export default class ServerApi { } const u = await request.json(); - console.debug('ServerApi::login resolves', u); + debug('ServerApi::login resolves', u); return u.token; } @@ -69,7 +71,7 @@ export default class ServerApi { } const u = await request.json(); - console.debug('ServerApi::signup resolves', u); + debug('ServerApi::signup resolves', u); return u.token; } @@ -82,7 +84,7 @@ export default class ServerApi { throw request; } - console.debug('ServerApi::inviteUser'); + debug('ServerApi::inviteUser'); return true; } @@ -98,7 +100,7 @@ export default class ServerApi { } const r = await request.json(); - console.debug('ServerApi::retrievePassword'); + debug('ServerApi::retrievePassword'); return r; } @@ -112,7 +114,7 @@ export default class ServerApi { const data = await request.json(); const user = new UserModel(data); - console.debug('ServerApi::userInfo resolves', user); + debug('ServerApi::userInfo resolves', user); return user; } @@ -128,7 +130,7 @@ export default class ServerApi { const updatedData = await request.json(); const user = Object.assign(updatedData, { data: new UserModel(updatedData.data) }); - console.debug('ServerApi::updateUserInfo resolves', user); + debug('ServerApi::updateUserInfo resolves', user); return user; } @@ -141,7 +143,7 @@ export default class ServerApi { } const data = await request.json(); - console.debug('ServerApi::deleteAccount resolves', data); + debug('ServerApi::deleteAccount resolves', data); return data; } @@ -157,7 +159,7 @@ export default class ServerApi { let services = await this._mapServiceModels(data); services = services.filter(service => service !== null); - console.debug('ServerApi::getServices resolves', services); + debug('ServerApi::getServices resolves', services); return services; } @@ -181,7 +183,7 @@ export default class ServerApi { const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); - console.debug('ServerApi::createService resolves', service); + debug('ServerApi::createService resolves', service); return service; } @@ -205,7 +207,7 @@ export default class ServerApi { const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); - console.debug('ServerApi::updateService resolves', service); + debug('ServerApi::updateService resolves', service); return service; } @@ -240,7 +242,7 @@ export default class ServerApi { throw request; } const serviceData = await request.json(); - console.debug('ServerApi::reorderService resolves', serviceData); + debug('ServerApi::reorderService resolves', serviceData); return serviceData; } @@ -255,7 +257,7 @@ export default class ServerApi { removeServicePartitionDirectory(id, true); - console.debug('ServerApi::deleteService resolves', data); + debug('ServerApi::deleteService resolves', data); return data; } @@ -277,7 +279,7 @@ export default class ServerApi { this.recipes = this.recipes.concat(this._getDevRecipes()); - console.debug('StubServerApi::getInstalledRecipes resolves', this.recipes); + debug('StubServerApi::getInstalledRecipes resolves', this.recipes); return this.recipes; } @@ -290,7 +292,7 @@ export default class ServerApi { throw request; } const recipes = await request.json(); - console.debug('ServerApi::getRecipeUpdates resolves', recipes); + debug('ServerApi::getRecipeUpdates resolves', recipes); return recipes; } @@ -305,7 +307,7 @@ export default class ServerApi { const data = await request.json(); const recipePreviews = this._mapRecipePreviewModel(data); - console.debug('ServerApi::getRecipes resolves', recipePreviews); + debug('ServerApi::getRecipes resolves', recipePreviews); return recipePreviews; } @@ -322,7 +324,7 @@ export default class ServerApi { // data = this._addLocalRecipesToPreviews(data); const recipePreviews = this._mapRecipePreviewModel(data); - console.debug('ServerApi::getFeaturedRecipes resolves', recipePreviews); + debug('ServerApi::getFeaturedRecipes resolves', recipePreviews); return recipePreviews; } @@ -336,7 +338,7 @@ export default class ServerApi { const data = await request.json(); const recipePreviews = this._mapRecipePreviewModel(data); - console.debug('ServerApi::searchRecipePreviews resolves', recipePreviews); + debug('ServerApi::searchRecipePreviews resolves', recipePreviews); return recipePreviews; } @@ -350,7 +352,7 @@ export default class ServerApi { fs.ensureDirSync(recipeTempDirectory); const res = await fetch(packageUrl); - console.debug('Recipe downloaded', recipeId); + debug('Recipe downloaded', recipeId); const buffer = await res.buffer(); fs.writeFileSync(archivePath, buffer); @@ -392,7 +394,7 @@ export default class ServerApi { const data = await request.json(); const plan = new PlanModel(data); - console.debug('ServerApi::getPlans resolves', plan); + debug('ServerApi::getPlans resolves', plan); return plan; } @@ -408,7 +410,7 @@ export default class ServerApi { } const data = await request.json(); - console.debug('ServerApi::getHostedPage resolves', data); + debug('ServerApi::getHostedPage resolves', data); return data; } @@ -421,7 +423,7 @@ export default class ServerApi { } const data = await request.json(); - console.debug('ServerApi::getPaymentDashboardUrl resolves', data); + debug('ServerApi::getPaymentDashboardUrl resolves', data); return data; } @@ -434,7 +436,7 @@ export default class ServerApi { } const data = await request.json(); const orders = this._mapOrderModels(data); - console.debug('ServerApi::getSubscriptionOrders resolves', orders); + debug('ServerApi::getSubscriptionOrders resolves', orders); return orders; } @@ -451,7 +453,7 @@ export default class ServerApi { } const data = await request.json(); const news = this._mapNewsModels(data); - console.debug('ServerApi::getLatestNews resolves', news); + debug('ServerApi::getLatestNews resolves', news); return news; } @@ -465,7 +467,7 @@ export default class ServerApi { throw request; } - console.debug('ServerApi::hideNews resolves', id); + debug('ServerApi::hideNews resolves', id); } // Health Check @@ -476,7 +478,7 @@ export default class ServerApi { if (!request.ok) { throw request; } - console.debug('ServerApi::healthCheck resolves'); + debug('ServerApi::healthCheck resolves'); } async getLegacyServices() { @@ -502,7 +504,7 @@ export default class ServerApi { return service; })); - console.debug('ServerApi::getLegacyServices resolves', services); + debug('ServerApi::getLegacyServices resolves', services); return services; } } catch (err) { @@ -535,7 +537,7 @@ export default class ServerApi { return new ServiceModel(service, recipe); } catch (e) { - console.debug(e); + debug(e); return null; } } @@ -553,7 +555,7 @@ export default class ServerApi { await this.getRecipePackage(recipeId); - console.debug('Rerun ServerAPI::getInstalledRecipes'); + debug('Rerun ServerAPI::getInstalledRecipes'); await this.getInstalledRecipes(); recipe = this.recipes.find(r => r.id === recipeId); @@ -653,7 +655,7 @@ export default class ServerApi { return recipes; } catch (err) { - console.debug('Could not load dev recipes'); + debug('Could not load dev recipes'); return false; } } -- cgit v1.2.3-54-g00ecf From 8aab8699e02ed9ec736bb6dfab0edd3fe9156c8d Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Tue, 27 Mar 2018 21:25:56 +0200 Subject: Split settings into multiple stores; app specific settings are now stored in config file --- src/actions/settings.js | 4 ++- src/api/LocalApi.js | 8 +++++ src/api/server/LocalApi.js | 19 +++++++++++- src/config.js | 8 ++++- src/containers/layout/AppLayoutContainer.js | 6 ++-- src/containers/settings/EditSettingsScreen.js | 32 +++++++------------- src/electron/Settings.js | 34 ++++++++++++++++++--- src/electron/ipc-api/settings.js | 8 +++++ src/models/Settings.js | 43 +++++++++++++++++++-------- src/stores/AppStore.js | 17 ++++++----- src/stores/ServicesStore.js | 15 +++++----- src/stores/SettingsStore.js | 41 ++++++++++++++++--------- src/stores/UIStore.js | 2 +- 13 files changed, 164 insertions(+), 73 deletions(-) (limited to 'src/api/server') diff --git a/src/actions/settings.js b/src/actions/settings.js index 3d53cd674..fd29b798b 100644 --- a/src/actions/settings.js +++ b/src/actions/settings.js @@ -2,9 +2,11 @@ import PropTypes from 'prop-types'; export default { update: { - settings: PropTypes.object.isRequired, + type: PropTypes.string.isRequired, + data: PropTypes.object.isRequired, }, remove: { + type: PropTypes.string.isRequired, key: PropTypes.string.isRequired, }, }; diff --git a/src/api/LocalApi.js b/src/api/LocalApi.js index 59d7d8fa2..741917104 100644 --- a/src/api/LocalApi.js +++ b/src/api/LocalApi.js @@ -4,6 +4,14 @@ export default class LocalApi { this.local = local; } + getAppSettings() { + return this.local.getAppSettings(); + } + + updateAppSettings(data) { + return this.local.updateAppSettings(data); + } + getAppCacheSize() { return this.local.getAppCacheSize(); } diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.js index 4d2497c61..78deb7aa5 100644 --- a/src/api/server/LocalApi.js +++ b/src/api/server/LocalApi.js @@ -1,4 +1,4 @@ -import { remote } from 'electron'; +import { ipcRenderer, remote } from 'electron'; import du from 'du'; import { getServicePartitionsDirectory } from '../../helpers/service-helpers.js'; @@ -8,6 +8,23 @@ const debug = require('debug')('LocalApi'); const { session } = remote; export default class LocalApi { + // Settings + getAppSettings() { + return new Promise((resolve) => { + ipcRenderer.once('appSettings', (event, data) => { + debug('LocalApi::getAppSettings resolves', data); + resolve(data); + }); + + ipcRenderer.send('getAppSettings'); + }); + } + + async updateAppSettings(data) { + debug('LocalApi::updateAppSettings resolves', data); + ipcRenderer.send('updateAppSettings', data); + } + // Services async getAppCacheSize() { const partitionsDir = getServicePartitionsDirectory(); diff --git a/src/config.js b/src/config.js index e66594c59..366231f79 100644 --- a/src/config.js +++ b/src/config.js @@ -1,3 +1,8 @@ +import electron from 'electron'; +import path from 'path'; + +const app = process.type === 'renderer' ? electron.remote.app : electron.app; + export const CHECK_INTERVAL = 1000 * 3600; // How often should we perform checks export const LOCAL_API = 'http://localhost:3000'; export const DEV_API = 'https://dev.franzinfra.com'; @@ -13,7 +18,6 @@ export const DEFAULT_APP_SETTINGS = { showDisabledServices: true, showMessageBadgeWhenMuted: true, enableSpellchecking: true, - // spellcheckingLanguage: 'auto', locale: '', fallbackLocale: 'en-US', beta: false, @@ -22,3 +26,5 @@ export const DEFAULT_APP_SETTINGS = { export const FRANZ_SERVICE_REQUEST = 'http://bit.ly/franz-service-request'; export const FRANZ_TRANSLATION = 'http://bit.ly/franz-translate'; + +export const SETTINGS_PATH = path.join(app.getPath('userData'), 'config', 'settings.json'); diff --git a/src/containers/layout/AppLayoutContainer.js b/src/containers/layout/AppLayoutContainer.js index 075bd5e34..0931738fd 100644 --- a/src/containers/layout/AppLayoutContainer.js +++ b/src/containers/layout/AppLayoutContainer.js @@ -77,7 +77,7 @@ export default class AppLayoutContainer extends Component { ); @@ -99,7 +99,7 @@ export default class AppLayoutContainer extends Component { setWebviewReference={setWebviewReference} openWindow={openWindow} reload={reload} - isAppMuted={settings.all.isAppMuted} + isAppMuted={settings.all.app.isAppMuted} update={updateService} /> ); diff --git a/src/containers/settings/EditSettingsScreen.js b/src/containers/settings/EditSettingsScreen.js index e67c2964b..1bd147099 100644 --- a/src/containers/settings/EditSettingsScreen.js +++ b/src/containers/settings/EditSettingsScreen.js @@ -55,10 +55,6 @@ const messages = defineMessages({ id: 'settings.app.form.spellcheckingLanguage', defaultMessage: '!!!Language for spell checking', }, - // spellcheckingAutomaticDetection: { - // id: 'settings.app.form.spellcheckingAutomaticDetection', - // defaultMessage: '!!!Detect language automatically', - // }, beta: { id: 'settings.app.form.beta', defaultMessage: '!!!Include beta versions', @@ -84,13 +80,16 @@ export default class EditSettingsScreen extends Component { }); settings.update({ - settings: { + type: 'app', + data: { runInBackground: settingsData.runInBackground, enableSystemTray: settingsData.enableSystemTray, minimizeToSystemTray: settingsData.minimizeToSystemTray, showDisabledServices: settingsData.showDisabledServices, showMessageBadgeWhenMuted: settingsData.showMessageBadgeWhenMuted, enableSpellchecking: settingsData.enableSpellchecking, + beta: settingsData.beta, // we need this info in the main process as well + locale: settingsData.locale, // we need this info in the main process as well }, }); @@ -114,17 +113,6 @@ export default class EditSettingsScreen extends Component { }); }); - // const spellcheckerLocales = [{ - // value: 'auto', - // label: intl.formatMessage(messages.spellcheckingAutomaticDetection), - // }]; - // Object.keys(SPELLCHECKER_LOCALES).forEach((key) => { - // spellcheckerLocales.push({ - // value: key, - // label: SPELLCHECKER_LOCALES[key], - // }); - // }); - const config = { fields: { autoLaunchOnStart: { @@ -139,32 +127,32 @@ export default class EditSettingsScreen extends Component { }, runInBackground: { label: intl.formatMessage(messages.runInBackground), - value: settings.all.runInBackground, + value: settings.all.app.runInBackground, default: DEFAULT_APP_SETTINGS.runInBackground, }, enableSystemTray: { label: intl.formatMessage(messages.enableSystemTray), - value: settings.all.enableSystemTray, + value: settings.all.app.enableSystemTray, default: DEFAULT_APP_SETTINGS.enableSystemTray, }, minimizeToSystemTray: { label: intl.formatMessage(messages.minimizeToSystemTray), - value: settings.all.minimizeToSystemTray, + value: settings.all.app.minimizeToSystemTray, default: DEFAULT_APP_SETTINGS.minimizeToSystemTray, }, showDisabledServices: { label: intl.formatMessage(messages.showDisabledServices), - value: settings.all.showDisabledServices, + value: settings.all.app.showDisabledServices, default: DEFAULT_APP_SETTINGS.showDisabledServices, }, showMessageBadgeWhenMuted: { label: intl.formatMessage(messages.showMessageBadgeWhenMuted), - value: settings.all.showMessageBadgeWhenMuted, + value: settings.all.app.showMessageBadgeWhenMuted, default: DEFAULT_APP_SETTINGS.showMessageBadgeWhenMuted, }, enableSpellchecking: { label: intl.formatMessage(messages.enableSpellchecking), - value: settings.all.enableSpellchecking, + value: settings.all.app.enableSpellchecking, default: DEFAULT_APP_SETTINGS.enableSpellchecking, }, locale: { diff --git a/src/electron/Settings.js b/src/electron/Settings.js index 824b4c20c..e24aefdbb 100644 --- a/src/electron/Settings.js +++ b/src/electron/Settings.js @@ -1,27 +1,53 @@ -import { observable } from 'mobx'; +import { observable, toJS } from 'mobx'; +import { pathExistsSync, outputJsonSync, readJsonSync } from 'fs-extra'; -import { DEFAULT_APP_SETTINGS } from '../config'; +import { SETTINGS_PATH, DEFAULT_APP_SETTINGS } from '../config'; + +const debug = require('debug')('Settings'); export default class Settings { @observable store = { - autoLaunchOnStart: DEFAULT_APP_SETTINGS.autoLaunchOnStart, autoLaunchInBackground: DEFAULT_APP_SETTINGS.autoLaunchInBackground, runInBackground: DEFAULT_APP_SETTINGS.runInBackground, enableSystemTray: DEFAULT_APP_SETTINGS.enableSystemTray, minimizeToSystemTray: DEFAULT_APP_SETTINGS.minimizeToSystemTray, locale: DEFAULT_APP_SETTINGS.locale, beta: DEFAULT_APP_SETTINGS.beta, + isAppMuted: DEFAULT_APP_SETTINGS.isAppMuted, + showMessageBadgeWhenMuted: DEFAULT_APP_SETTINGS.showMessageBadgeWhenMuted, + showDisabledServices: DEFAULT_APP_SETTINGS.showDisabledServices, + enableSpellchecking: DEFAULT_APP_SETTINGS.enableSpellchecking, }; + constructor() { + if (!pathExistsSync(SETTINGS_PATH)) { + this._writeFile(); + } else { + this._hydrate(); + } + } + set(settings) { this.store = Object.assign(this.store, settings); + + this._writeFile(); } - all() { + get all() { return this.store; } get(key) { return this.store[key]; } + + _hydrate() { + this.store = readJsonSync(SETTINGS_PATH); + debug('Hydrate store', toJS(this.store)); + } + + _writeFile() { + outputJsonSync(SETTINGS_PATH, this.store); + debug('Write settings file', toJS(this.store)); + } } diff --git a/src/electron/ipc-api/settings.js b/src/electron/ipc-api/settings.js index 995b28fbd..00bdc0113 100644 --- a/src/electron/ipc-api/settings.js +++ b/src/electron/ipc-api/settings.js @@ -4,4 +4,12 @@ export default (params) => { ipcMain.on('settings', (event, args) => { params.settings.set(args); }); + + ipcMain.on('getAppSettings', () => { + params.mainWindow.webContents.send('appSettings', params.settings.all); + }); + + ipcMain.on('updateAppSettings', (event, args) => { + params.settings.set(args); + }); }; diff --git a/src/models/Settings.js b/src/models/Settings.js index e39b63087..f58c05b38 100644 --- a/src/models/Settings.js +++ b/src/models/Settings.js @@ -2,19 +2,38 @@ import { observable, extendObservable } from 'mobx'; import { DEFAULT_APP_SETTINGS } from '../config'; export default class Settings { - @observable autoLaunchInBackground = DEFAULT_APP_SETTINGS.autoLaunchInBackground; - @observable runInBackground = DEFAULT_APP_SETTINGS.runInBackground; - @observable enableSystemTray = DEFAULT_APP_SETTINGS.enableSystemTray; - @observable minimizeToSystemTray = DEFAULT_APP_SETTINGS.minimizeToSystemTray; - @observable showDisabledServices = DEFAULT_APP_SETTINGS.showDisabledServices; - @observable showMessageBadgeWhenMuted = DEFAULT_APP_SETTINGS.showMessageBadgeWhenMuted; - @observable enableSpellchecking = DEFAULT_APP_SETTINGS.enableSpellchecking; - @observable locale = DEFAULT_APP_SETTINGS.locale; - @observable beta = DEFAULT_APP_SETTINGS.beta; - @observable isAppMuted = DEFAULT_APP_SETTINGS.isAppMuted; + @observable app = { + autoLaunchInBackground: DEFAULT_APP_SETTINGS.autoLaunchInBackground, + runInBackground: DEFAULT_APP_SETTINGS.runInBackground, + enableSystemTray: DEFAULT_APP_SETTINGS.enableSystemTray, + minimizeToSystemTray: DEFAULT_APP_SETTINGS.minimizeToSystemTray, + isAppMuted: DEFAULT_APP_SETTINGS.isAppMuted, + showMessageBadgeWhenMuted: DEFAULT_APP_SETTINGS.showMessageBadgeWhenMuted, + showDisabledServices: DEFAULT_APP_SETTINGS.showDisabledServices, + enableSpellchecking: DEFAULT_APP_SETTINGS.enableSpellchecking, + locale: DEFAULT_APP_SETTINGS.locale, + beta: DEFAULT_APP_SETTINGS.beta, - constructor(data) { - Object.assign(this, data); + } + + @observable service = { + activeService: DEFAULT_APP_SETTINGS.autoLaunchInBackground, + } + + @observable group = { + collapsed: [], + disabled: [], + } + + @observable stats = { + appStarts: 0, + } + + constructor({ app, service, group, stats }) { + Object.assign(this.app, app); + Object.assign(this.service, service); + Object.assign(this.group, group); + Object.assign(this.stats, stats); } update(data) { diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 94ed308f3..3c6c24b59 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -159,7 +159,7 @@ export default class AppStore extends Store { // Actions @action _notify({ title, options, notificationId, serviceId = null }) { - if (this.stores.settings.all.isAppMuted) return; + if (this.stores.settings.all.app.isAppMuted) return; const notification = new window.Notification(title, options); notification.onclick = (e) => { @@ -240,14 +240,15 @@ export default class AppStore extends Store { this.isSystemMuteOverridden = overrideSystemMute; this.actions.settings.update({ - settings: { + type: 'app', + data: { isAppMuted: isMuted, }, }); } @action _toggleMuteApp() { - this._muteApp({ isMuted: !this.stores.settings.all.isAppMuted }); + this._muteApp({ isMuted: !this.stores.settings.all.app.isAppMuted }); } @action async _clearAllCache() { @@ -331,8 +332,9 @@ export default class AppStore extends Store { // Helpers _appStartsCounter() { this.actions.settings.update({ - settings: { - appStarts: (this.stores.settings.all.appStarts || 0) + 1, + type: 'stats', + data: { + appStarts: (this.stores.settings.all.stats.appStarts || 0) + 1, }, }); } @@ -340,7 +342,8 @@ export default class AppStore extends Store { async _autoStart() { this.autoLaunchOnStart = await this._checkAutoStart(); - if (this.stores.settings.all.appStarts === 1) { + if (this.stores.settings.all.stats.appStarts === 1) { + debug('Set app to launch on start'); this.actions.app.launchOnStartup({ enable: true, }); @@ -353,7 +356,7 @@ export default class AppStore extends Store { _systemDND() { const dnd = getDoNotDisturb(); - if (dnd !== this.stores.settings.all.isAppMuted && !this.isSystemMuteOverridden) { + if (dnd !== this.stores.settings.all.app.isAppMuted && !this.isSystemMuteOverridden) { this.actions.app.muteApp({ isMuted: dnd, overrideSystemMute: false, diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index f7d92b1ff..b96bc506b 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js @@ -86,13 +86,13 @@ export default class ServicesStore extends Store { } @computed get allDisplayed() { - return this.stores.settings.all.showDisabledServices ? this.all : this.enabled; + return this.stores.settings.all.service.showDisabledServices ? this.all : this.enabled; } // This is just used to avoid unnecessary rerendering of resource-heavy webviews @computed get allDisplayedUnordered() { const services = this.allServicesRequest.execute().result || []; - return this.stores.settings.all.showDisabledServices ? services : services.filter(service => service.isEnabled); + return this.stores.settings.all.service.showDisabledServices ? services : services.filter(service => service.isEnabled); } @computed get filtered() { @@ -334,7 +334,7 @@ export default class ServicesStore extends Store { }); } else if (channel === 'notification') { const options = args[0].options; - if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.isAppMuted) { + if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.app.isAppMuted) { Object.assign(options, { silent: true, }); @@ -434,7 +434,7 @@ export default class ServicesStore extends Store { } @action _reorder({ oldIndex, newIndex }) { - const showDisabledServices = this.stores.settings.all.showDisabledServices; + const showDisabledServices = this.stores.settings.all.service.showDisabledServices; const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); @@ -512,7 +512,8 @@ export default class ServicesStore extends Store { if (service) { this.actions.settings.update({ - settings: { + type: 'service', + data: { activeService: service.id, }, }); @@ -520,7 +521,7 @@ export default class ServicesStore extends Store { } _mapActiveServiceToServiceModelReaction() { - const { activeService } = this.stores.settings.all; + const { activeService } = this.stores.settings.all.service; if (this.allDisplayed.length) { this.allDisplayed.map(service => Object.assign(service, { isActive: activeService ? activeService === service.id : this.allDisplayed[0].id === service.id, @@ -529,7 +530,7 @@ export default class ServicesStore extends Store { } _getUnreadMessageCountReaction() { - const showMessageBadgeWhenMuted = this.stores.settings.all.showMessageBadgeWhenMuted; + const showMessageBadgeWhenMuted = this.stores.settings.all.app.showMessageBadgeWhenMuted; const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; const unreadDirectMessageCount = this.allDisplayed diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index b7d803398..b3f5d3eaf 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -1,12 +1,18 @@ import { ipcRenderer } from 'electron'; -import { action, computed } from 'mobx'; +import { action, computed, observable } from 'mobx'; import localStorage from 'mobx-localstorage'; import Store from './lib/Store'; -import { gaEvent } from '../lib/analytics'; import SettingsModel from '../models/Settings'; +import Request from './lib/Request'; +import CachedRequest from './lib/CachedRequest'; + +const debug = require('debug')('SettingsStore'); export default class SettingsStore extends Store { + @observable appSettingsRequest = new CachedRequest(this.api.local, 'getAppSettings'); + @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); + constructor(...args) { super(...args); @@ -15,22 +21,29 @@ export default class SettingsStore extends Store { this.actions.settings.remove.listen(this._remove.bind(this)); } - setup() { - this._shareSettingsWithMainProcess(); - } - @computed get all() { - return new SettingsModel(localStorage.getItem('app') || {}); + return new SettingsModel({ + app: this.appSettingsRequest.execute().result || {}, + service: localStorage.getItem('service') || {}, + group: localStorage.getItem('group') || {}, + stats: localStorage.getItem('stats') || {}, + }); } - @action async _update({ settings }) { + @action async _update({ type, data }) { + debug('Update settings', type, data, this.all); const appSettings = this.all; - localStorage.setItem('app', Object.assign(appSettings, settings)); - - // We need a little hack to wait until everything is patched - setTimeout(() => this._shareSettingsWithMainProcess(), 0); - - gaEvent('Settings', 'update'); + if (type !== 'app') { + localStorage.setItem(type, Object.assign(appSettings[type], data)); + } else { + debug('Store app settings on file system', type, data); + this.updateAppSettingsRequest.execute(data); + + this.appSettingsRequest.patch((result) => { + if (!result) return; + Object.assign(result, data); + }); + } } @action async _remove({ key }) { diff --git a/src/stores/UIStore.js b/src/stores/UIStore.js index 5e9cc9ba7..b391bdcae 100644 --- a/src/stores/UIStore.js +++ b/src/stores/UIStore.js @@ -17,7 +17,7 @@ export default class UIStore extends Store { @computed get showMessageBadgesEvenWhenMuted() { const settings = this.stores.settings.all; - return (settings.isAppMuted && settings.showMessageBadgeWhenMuted) || !settings.isAppMuted; + return (settings.app.isAppMuted && settings.app.showMessageBadgeWhenMuted) || !settings.isAppMuted; } // Actions -- cgit v1.2.3-54-g00ecf From 8f5de18c754230540f731dbd12828ad8b850d1f2 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Thu, 15 Nov 2018 12:21:28 +0100 Subject: Fix minor issues due to babel upgrade --- src/api/server/ServerApi.js | 2 +- src/index.js | 5 +++++ src/stores/SettingsStore.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/api/server') diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 353faa7f4..2e80e520b 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js @@ -35,7 +35,7 @@ module.paths.unshift( ); const { app } = remote; -const fetch = remote.require('electron-fetch'); +const { default: fetch } = remote.require('electron-fetch'); const SERVER_URL = API; const API_VERSION = 'v1'; diff --git a/src/index.js b/src/index.js index 5ba901b89..5fbe3bc4f 100644 --- a/src/index.js +++ b/src/index.js @@ -19,6 +19,11 @@ const debug = require('debug')('App'); let mainWindow; let willQuitApp = false; +// DEV MODE: Save user data into FranzDev +if (isDevMode) { + app.setPath('userData', path.join(app.getPath('appData'), 'FranzDev')); +} + // Ensure that the recipe directory exists fs.emptyDirSync(path.join(app.getPath('userData'), 'recipes', 'temp')); fs.ensureFileSync(path.join(app.getPath('userData'), 'window-state.json')); diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index d8519c609..9270a6481 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -68,7 +68,7 @@ export default class SettingsStore extends Store { // Helper _migrate() { - const legacySettings = localStorage.getItem('app'); + const legacySettings = localStorage.getItem('app') || {}; if (!this.all.migration['5.0.0-beta.17-settings']) { this.actions.settings.update({ -- cgit v1.2.3-54-g00ecf From df01b73f92dd61659fb14231ce6eb84feb134992 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Mon, 19 Nov 2018 16:52:32 +0100 Subject: Fix fetch is undefined --- src/api/server/ServerApi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/api/server') diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 2e80e520b..353faa7f4 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js @@ -35,7 +35,7 @@ module.paths.unshift( ); const { app } = remote; -const { default: fetch } = remote.require('electron-fetch'); +const fetch = remote.require('electron-fetch'); const SERVER_URL = API; const API_VERSION = 'v1'; -- cgit v1.2.3-54-g00ecf From b05e27fe1944866d0636cb248166f81310b0b7d6 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Wed, 21 Nov 2018 13:45:43 +0100 Subject: Revert "Fix fetch is undefined" This reverts commit df01b73f92dd61659fb14231ce6eb84feb134992. --- src/api/server/ServerApi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/api/server') diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 353faa7f4..2e80e520b 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js @@ -35,7 +35,7 @@ module.paths.unshift( ); const { app } = remote; -const fetch = remote.require('electron-fetch'); +const { default: fetch } = remote.require('electron-fetch'); const SERVER_URL = API; const API_VERSION = 'v1'; -- cgit v1.2.3-54-g00ecf From aef5033ef19bf51dbacc0dcdfe76ec2d90173531 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Thu, 22 Nov 2018 10:53:11 +0100 Subject: Add "Franz" to debug identifiers --- package.json | 2 +- src/api/server/LocalApi.js | 2 +- src/api/server/ServerApi.js | 2 +- src/electron/Settings.js | 2 +- src/index.js | 2 +- src/lib/analytics.js | 2 +- src/stores/AppStore.js | 2 +- src/stores/RecipesStore.js | 2 +- src/stores/RequestStore.js | 2 +- src/stores/ServicesStore.js | 2 +- src/stores/SettingsStore.js | 2 +- src/stores/UserStore.js | 2 +- src/webview/plugin.js | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/api/server') diff --git a/package.json b/package.json index 6be38cd6f..ee2b12e99 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "private": true, "scripts": { "prestart": "npm run rebuild", - "start": "electron ./build", + "start": "DEBUG=Franz:* electron ./build", "start:local": "cross-env LOCAL_API=1 npm start", "start:live": "cross-env LIVE_API=1 npm start", "dev": "cross-env NODE_ENV=development gulp dev", diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.js index 78deb7aa5..4814bba66 100644 --- a/src/api/server/LocalApi.js +++ b/src/api/server/LocalApi.js @@ -3,7 +3,7 @@ import du from 'du'; import { getServicePartitionsDirectory } from '../../helpers/service-helpers.js'; -const debug = require('debug')('LocalApi'); +const debug = require('debug')('Franz:LocalApi'); const { session } = remote; diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 2e80e520b..ad1ffa59a 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js @@ -27,7 +27,7 @@ import { removeServicePartitionDirectory, } from '../../helpers/service-helpers.js'; -const debug = require('debug')('ServerApi'); +const debug = require('debug')('Franz:ServerApi'); module.paths.unshift( getDevRecipeDirectory(), diff --git a/src/electron/Settings.js b/src/electron/Settings.js index 254180b73..7b04406a2 100644 --- a/src/electron/Settings.js +++ b/src/electron/Settings.js @@ -3,7 +3,7 @@ import { pathExistsSync, outputJsonSync, readJsonSync } from 'fs-extra'; import { SETTINGS_PATH, DEFAULT_APP_SETTINGS } from '../config'; -const debug = require('debug')('Settings'); +const debug = require('debug')('Franz:Settings'); export default class Settings { @observable store = DEFAULT_APP_SETTINGS; diff --git a/src/index.js b/src/index.js index 65f18bb55..7d906ad71 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,7 @@ import handleDeepLink from './electron/deepLinking'; import { appId } from './package.json'; // eslint-disable-line import/no-unresolved import './electron/exception'; -const debug = require('debug')('App'); +const debug = require('debug')('Franz:App'); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. diff --git a/src/lib/analytics.js b/src/lib/analytics.js index 585cbcdba..8b9a44579 100644 --- a/src/lib/analytics.js +++ b/src/lib/analytics.js @@ -2,7 +2,7 @@ import { remote } from 'electron'; import { GA_ID } from '../config'; // import { isDevMode } from '../environment'; -const debug = require('debug')('Analytics'); +const debug = require('debug')('Franz:Analytics'); const { app } = remote; diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 76d9bfa53..9ad4cd531 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -15,7 +15,7 @@ import { gaEvent } from '../lib/analytics'; import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; -const debug = require('debug')('AppStore'); +const debug = require('debug')('Franz:AppStore'); const { app, systemPreferences } = remote; diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js index a24308f6a..f2480bc8e 100644 --- a/src/stores/RecipesStore.js +++ b/src/stores/RecipesStore.js @@ -5,7 +5,7 @@ import CachedRequest from './lib/CachedRequest'; import Request from './lib/Request'; import { matchRoute } from '../helpers/routing-helpers'; -const debug = require('debug')('RecipeStore'); +const debug = require('debug')('Franz:RecipeStore'); export default class RecipesStore extends Store { @observable allRecipesRequest = new CachedRequest(this.api.recipes, 'all'); diff --git a/src/stores/RequestStore.js b/src/stores/RequestStore.js index 595852583..bbfe6f6df 100644 --- a/src/stores/RequestStore.js +++ b/src/stores/RequestStore.js @@ -2,7 +2,7 @@ import { action, computed, observable } from 'mobx'; import Store from './lib/Store'; -const debug = require('debug')('RequestsStore'); +const debug = require('debug')('Franz:RequestsStore'); export default class RequestStore extends Store { @observable userInfoRequest; diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 4c2992c70..c5822968a 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js @@ -7,7 +7,7 @@ import CachedRequest from './lib/CachedRequest'; import { matchRoute } from '../helpers/routing-helpers'; import { gaEvent } from '../lib/analytics'; -const debug = require('debug')('ServiceStore'); +const debug = require('debug')('Franz:ServiceStore'); export default class ServicesStore extends Store { @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 4b5715628..f1b067115 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -8,7 +8,7 @@ import Request from './lib/Request'; import CachedRequest from './lib/CachedRequest'; const { systemPreferences } = remote; -const debug = require('debug')('SettingsStore'); +const debug = require('debug')('Franz:SettingsStore'); export default class SettingsStore extends Store { @observable appSettingsRequest = new CachedRequest(this.api.local, 'getAppSettings'); diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index 574616925..9d8ac5657 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js @@ -9,7 +9,7 @@ import Request from './lib/Request'; import CachedRequest from './lib/CachedRequest'; import { gaEvent } from '../lib/analytics'; -const debug = require('debug')('UserStore'); +const debug = require('debug')('Franz:UserStore'); // TODO: split stores into UserStore and AuthStore export default class UserStore extends Store { diff --git a/src/webview/plugin.js b/src/webview/plugin.js index a148d4633..ee8cedbab 100644 --- a/src/webview/plugin.js +++ b/src/webview/plugin.js @@ -8,7 +8,7 @@ import RecipeWebview from './lib/RecipeWebview'; import Spellchecker from './spellchecker'; import './notifications'; -const debug = require('debug')('Plugin'); +const debug = require('debug')('Franz:Plugin'); ipcRenderer.on('initializeRecipe', (e, data) => { const modulePath = path.join(data.recipe.path, 'webview.js'); -- cgit v1.2.3-54-g00ecf