diff options
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/AppStore.ts | 6 | ||||
-rw-r--r-- | src/stores/ServicesStore.ts | 58 | ||||
-rw-r--r-- | src/stores/SettingsStore.ts | 10 | ||||
-rw-r--r-- | src/stores/UserStore.ts | 27 | ||||
-rw-r--r-- | src/stores/lib/Request.ts | 9 |
5 files changed, 59 insertions, 51 deletions
diff --git a/src/stores/AppStore.ts b/src/stores/AppStore.ts index 9af0a9a4f..b8356bd56 100644 --- a/src/stores/AppStore.ts +++ b/src/stores/AppStore.ts | |||
@@ -121,13 +121,11 @@ export default class AppStore extends TypedStore { | |||
121 | 121 | ||
122 | @observable isFocused = true; | 122 | @observable isFocused = true; |
123 | 123 | ||
124 | @observable lockingFeatureEnabled = | 124 | @observable isLockingFeatureEnabled = |
125 | DEFAULT_APP_SETTINGS.lockingFeatureEnabled; | 125 | DEFAULT_APP_SETTINGS.isLockingFeatureEnabled; |
126 | 126 | ||
127 | @observable launchInBackground = DEFAULT_APP_SETTINGS.autoLaunchInBackground; | 127 | @observable launchInBackground = DEFAULT_APP_SETTINGS.autoLaunchInBackground; |
128 | 128 | ||
129 | dictionaries = []; | ||
130 | |||
131 | fetchDataInterval: NodeJS.Timeout | null = null; | 129 | fetchDataInterval: NodeJS.Timeout | null = null; |
132 | 130 | ||
133 | @observable downloads: Download[] = []; | 131 | @observable downloads: Download[] = []; |
diff --git a/src/stores/ServicesStore.ts b/src/stores/ServicesStore.ts index 95aae6ccb..d7804a3fe 100644 --- a/src/stores/ServicesStore.ts +++ b/src/stores/ServicesStore.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { join } from 'node:path'; | 1 | import { join } from 'node:path'; |
2 | import { ipcRenderer, shell } from 'electron'; | 2 | import { clipboard, ipcRenderer, shell } from 'electron'; |
3 | import { action, reaction, computed, observable, makeObservable } from 'mobx'; | 3 | import { action, reaction, computed, observable, makeObservable } from 'mobx'; |
4 | import { debounce, remove } from 'lodash'; | 4 | import { debounce, remove } from 'lodash'; |
5 | import ms from 'ms'; | 5 | import ms from 'ms'; |
@@ -65,6 +65,8 @@ export default class ServicesStore extends TypedStore { | |||
65 | // No service ID should be in the list multiple times, not all service IDs have to be in the list | 65 | // No service ID should be in the list multiple times, not all service IDs have to be in the list |
66 | @observable lastUsedServices: string[] = []; | 66 | @observable lastUsedServices: string[] = []; |
67 | 67 | ||
68 | private toggleToTalkCallback = () => this.active?.toggleToTalk(); | ||
69 | |||
68 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 70 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
69 | super(stores, api, actions); | 71 | super(stores, api, actions); |
70 | 72 | ||
@@ -239,6 +241,8 @@ export default class ServicesStore extends TypedStore { | |||
239 | initialize() { | 241 | initialize() { |
240 | super.initialize(); | 242 | super.initialize(); |
241 | 243 | ||
244 | ipcRenderer.on('toggle-to-talk', this.toggleToTalkCallback); | ||
245 | |||
242 | // Check services to become hibernated | 246 | // Check services to become hibernated |
243 | this.serviceMaintenanceTick(); | 247 | this.serviceMaintenanceTick(); |
244 | } | 248 | } |
@@ -246,6 +250,8 @@ export default class ServicesStore extends TypedStore { | |||
246 | teardown() { | 250 | teardown() { |
247 | super.teardown(); | 251 | super.teardown(); |
248 | 252 | ||
253 | ipcRenderer.off('toggle-to-talk', this.toggleToTalkCallback); | ||
254 | |||
249 | // Stop checking services for hibernation | 255 | // Stop checking services for hibernation |
250 | this.serviceMaintenanceTick.cancel(); | 256 | this.serviceMaintenanceTick.cancel(); |
251 | } | 257 | } |
@@ -828,6 +834,54 @@ export default class ServicesStore extends TypedStore { | |||
828 | break; | 834 | break; |
829 | } | 835 | } |
830 | case 'notification': { | 836 | case 'notification': { |
837 | const { notificationId, options } = args[0]; | ||
838 | |||
839 | const { isTwoFactorAutoCatcherEnabled, twoFactorAutoCatcherMatcher } = | ||
840 | this.stores.settings.all.app; | ||
841 | |||
842 | debug( | ||
843 | 'Settings for catch tokens', | ||
844 | isTwoFactorAutoCatcherEnabled, | ||
845 | twoFactorAutoCatcherMatcher, | ||
846 | ); | ||
847 | |||
848 | if (isTwoFactorAutoCatcherEnabled) { | ||
849 | /* | ||
850 | parse the token digits from sms body, find "token" or "code" in options.body which reflect the sms content | ||
851 | --- | ||
852 | Token: 03624 / SMS-Code = PIN Token | ||
853 | --- | ||
854 | Prüfcode 010313 für Microsoft-Authentifizierung verwenden. | ||
855 | --- | ||
856 | 483133 is your GitHub authentication code. @github.com #483133 | ||
857 | --- | ||
858 | eBay: Ihr Sicherheitscode lautet 080090. \nEr läuft in 15 Minuten ab. Geben Sie den Code nicht an andere weiter. | ||
859 | --- | ||
860 | PayPal: Ihr Sicherheitscode lautet: 989605. Geben Sie diesen Code nicht weiter. | ||
861 | */ | ||
862 | |||
863 | const rawBody = options.body; | ||
864 | const { 0: token } = /\d{5,6}/.exec(options.body) || []; | ||
865 | |||
866 | const wordsToCatch = twoFactorAutoCatcherMatcher | ||
867 | .replaceAll(', ', ',') | ||
868 | .split(','); | ||
869 | |||
870 | debug('wordsToCatch', wordsToCatch); | ||
871 | |||
872 | if ( | ||
873 | token && | ||
874 | wordsToCatch.some(a => | ||
875 | options.body.toLowerCase().includes(a.toLowerCase()), | ||
876 | ) | ||
877 | ) { | ||
878 | // with the extra "+ " it shows its copied to clipboard in the notification | ||
879 | options.body = `+ ${rawBody}`; | ||
880 | clipboard.writeText(token); | ||
881 | debug('Token parsed and copied to clipboard'); | ||
882 | } | ||
883 | } | ||
884 | |||
831 | // Check if we are in scheduled Do-not-Disturb time | 885 | // Check if we are in scheduled Do-not-Disturb time |
832 | const { scheduledDNDEnabled, scheduledDNDStart, scheduledDNDEnd } = | 886 | const { scheduledDNDEnabled, scheduledDNDStart, scheduledDNDEnd } = |
833 | this.stores.settings.all.app; | 887 | this.stores.settings.all.app; |
@@ -839,8 +893,6 @@ export default class ServicesStore extends TypedStore { | |||
839 | return; | 893 | return; |
840 | } | 894 | } |
841 | 895 | ||
842 | const { notificationId, options } = args[0]; | ||
843 | |||
844 | if (service.isMuted || this.stores.settings.all.app.isAppMuted) { | 896 | if (service.isMuted || this.stores.settings.all.app.isAppMuted) { |
845 | Object.assign(options, { | 897 | Object.assign(options, { |
846 | silent: true, | 898 | silent: true, |
diff --git a/src/stores/SettingsStore.ts b/src/stores/SettingsStore.ts index 90cd82690..010290a4a 100644 --- a/src/stores/SettingsStore.ts +++ b/src/stores/SettingsStore.ts | |||
@@ -11,17 +11,11 @@ import { | |||
11 | LOCAL_SERVER, | 11 | LOCAL_SERVER, |
12 | } from '../config'; | 12 | } from '../config'; |
13 | import { hash } from '../helpers/password-helpers'; | 13 | import { hash } from '../helpers/password-helpers'; |
14 | import Request from './lib/Request'; | ||
15 | import TypedStore from './lib/TypedStore'; | 14 | import TypedStore from './lib/TypedStore'; |
16 | 15 | ||
17 | const debug = require('../preload-safe-debug')('Ferdium:SettingsStore'); | 16 | const debug = require('../preload-safe-debug')('Ferdium:SettingsStore'); |
18 | 17 | ||
19 | export default class SettingsStore extends TypedStore { | 18 | export default class SettingsStore extends TypedStore { |
20 | @observable updateAppSettingsRequest = new Request( | ||
21 | this.api.local, | ||
22 | 'updateAppSettings', | ||
23 | ); | ||
24 | |||
25 | @observable loaded: boolean = false; | 19 | @observable loaded: boolean = false; |
26 | 20 | ||
27 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; | 21 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; |
@@ -67,7 +61,7 @@ export default class SettingsStore extends TypedStore { | |||
67 | let inactivityTimer; | 61 | let inactivityTimer; |
68 | getCurrentWindow().on('blur', () => { | 62 | getCurrentWindow().on('blur', () => { |
69 | if ( | 63 | if ( |
70 | this.all.app.lockingFeatureEnabled && | 64 | this.all.app.isLockingFeatureEnabled && |
71 | this.all.app.inactivityLock !== 0 | 65 | this.all.app.inactivityLock !== 0 |
72 | ) { | 66 | ) { |
73 | inactivityTimer = setTimeout( | 67 | inactivityTimer = setTimeout( |
@@ -94,7 +88,7 @@ export default class SettingsStore extends TypedStore { | |||
94 | if ( | 88 | if ( |
95 | !this.loaded && | 89 | !this.loaded && |
96 | resp.type === 'app' && | 90 | resp.type === 'app' && |
97 | resp.data.lockingFeatureEnabled | 91 | resp.data.isLockingFeatureEnabled |
98 | ) { | 92 | ) { |
99 | process.nextTick(() => { | 93 | process.nextTick(() => { |
100 | if (!this.all.app.locked) { | 94 | if (!this.all.app.locked) { |
diff --git a/src/stores/UserStore.ts b/src/stores/UserStore.ts index f98f7d340..9c3fcd3b9 100644 --- a/src/stores/UserStore.ts +++ b/src/stores/UserStore.ts | |||
@@ -60,11 +60,6 @@ export default class UserStore extends TypedStore { | |||
60 | 'updateInfo', | 60 | 'updateInfo', |
61 | ); | 61 | ); |
62 | 62 | ||
63 | @observable getLegacyServicesRequest: CachedRequest = new CachedRequest( | ||
64 | this.api.user, | ||
65 | 'getLegacyServices', | ||
66 | ); | ||
67 | |||
68 | @observable deleteAccountRequest: CachedRequest = new CachedRequest( | 63 | @observable deleteAccountRequest: CachedRequest = new CachedRequest( |
69 | this.api.user, | 64 | this.api.user, |
70 | 'delete', | 65 | 'delete', |
@@ -93,8 +88,6 @@ export default class UserStore extends TypedStore { | |||
93 | 88 | ||
94 | @observable logoutReason: string | null = null; | 89 | @observable logoutReason: string | null = null; |
95 | 90 | ||
96 | fetchUserInfoInterval = null; | ||
97 | |||
98 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 91 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
99 | super(stores, api, actions); | 92 | super(stores, api, actions); |
100 | 93 | ||
@@ -132,26 +125,10 @@ export default class UserStore extends TypedStore { | |||
132 | return this.LOGIN_ROUTE; | 125 | return this.LOGIN_ROUTE; |
133 | } | 126 | } |
134 | 127 | ||
135 | get logoutRoute(): string { | ||
136 | return this.LOGOUT_ROUTE; | ||
137 | } | ||
138 | |||
139 | get signupRoute(): string { | 128 | get signupRoute(): string { |
140 | return this.SIGNUP_ROUTE; | 129 | return this.SIGNUP_ROUTE; |
141 | } | 130 | } |
142 | 131 | ||
143 | get setupRoute(): string { | ||
144 | return this.SETUP_ROUTE; | ||
145 | } | ||
146 | |||
147 | get inviteRoute(): string { | ||
148 | return this.INVITE_ROUTE; | ||
149 | } | ||
150 | |||
151 | get importRoute(): string { | ||
152 | return this.IMPORT_ROUTE; | ||
153 | } | ||
154 | |||
155 | get passwordRoute(): string { | 132 | get passwordRoute(): string { |
156 | return this.PASSWORD_ROUTE; | 133 | return this.PASSWORD_ROUTE; |
157 | } | 134 | } |
@@ -191,10 +168,6 @@ export default class UserStore extends TypedStore { | |||
191 | return this.data.team || null; | 168 | return this.data.team || null; |
192 | } | 169 | } |
193 | 170 | ||
194 | @computed get legacyServices(): any { | ||
195 | return this.getLegacyServicesRequest.execute() || {}; | ||
196 | } | ||
197 | |||
198 | // Actions | 171 | // Actions |
199 | @action async _login({ email, password }): Promise<void> { | 172 | @action async _login({ email, password }): Promise<void> { |
200 | const authToken = await this.loginRequest.execute(email, password).promise; | 173 | const authToken = await this.loginRequest.execute(email, password).promise; |
diff --git a/src/stores/lib/Request.ts b/src/stores/lib/Request.ts index 911c5ccfb..587af87d7 100644 --- a/src/stores/lib/Request.ts +++ b/src/stores/lib/Request.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import { observable, action, computed, makeObservable } from 'mobx'; | 1 | import { observable, action, computed, makeObservable } from 'mobx'; |
2 | import { isEqual } from 'lodash/fp'; | ||
3 | 2 | ||
4 | // eslint-disable-next-line no-use-before-define | 3 | // eslint-disable-next-line no-use-before-define |
5 | type Hook = (request: Request) => void; | 4 | type Hook = (request: Request) => void; |
@@ -123,14 +122,6 @@ export default class Request { | |||
123 | return this.execute(...args); | 122 | return this.execute(...args); |
124 | } | 123 | } |
125 | 124 | ||
126 | isExecutingWithArgs(...args: any[]): boolean { | ||
127 | return ( | ||
128 | this.isExecuting && | ||
129 | this.currentApiCall && | ||
130 | isEqual(this.currentApiCall.args, args) | ||
131 | ); | ||
132 | } | ||
133 | |||
134 | @computed get isExecutingFirstTime(): boolean { | 125 | @computed get isExecutingFirstTime(): boolean { |
135 | return !this.wasExecuted && this.isExecuting; | 126 | return !this.wasExecuted && this.isExecuting; |
136 | } | 127 | } |