summaryrefslogtreecommitdiffstats
path: root/src/stores/ServicesStore.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/ServicesStore.ts')
-rw-r--r--src/stores/ServicesStore.ts52
1 files changed, 49 insertions, 3 deletions
diff --git a/src/stores/ServicesStore.ts b/src/stores/ServicesStore.ts
index 175a2ce16..d7804a3fe 100644
--- a/src/stores/ServicesStore.ts
+++ b/src/stores/ServicesStore.ts
@@ -1,5 +1,5 @@
1import { join } from 'node:path'; 1import { join } from 'node:path';
2import { ipcRenderer, shell } from 'electron'; 2import { clipboard, ipcRenderer, shell } from 'electron';
3import { action, reaction, computed, observable, makeObservable } from 'mobx'; 3import { action, reaction, computed, observable, makeObservable } from 'mobx';
4import { debounce, remove } from 'lodash'; 4import { debounce, remove } from 'lodash';
5import ms from 'ms'; 5import ms from 'ms';
@@ -834,6 +834,54 @@ export default class ServicesStore extends TypedStore {
834 break; 834 break;
835 } 835 }
836 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
837 // Check if we are in scheduled Do-not-Disturb time 885 // Check if we are in scheduled Do-not-Disturb time
838 const { scheduledDNDEnabled, scheduledDNDStart, scheduledDNDEnd } = 886 const { scheduledDNDEnabled, scheduledDNDStart, scheduledDNDEnd } =
839 this.stores.settings.all.app; 887 this.stores.settings.all.app;
@@ -845,8 +893,6 @@ export default class ServicesStore extends TypedStore {
845 return; 893 return;
846 } 894 }
847 895
848 const { notificationId, options } = args[0];
849
850 if (service.isMuted || this.stores.settings.all.app.isAppMuted) { 896 if (service.isMuted || this.stores.settings.all.app.isAppMuted) {
851 Object.assign(options, { 897 Object.assign(options, {
852 silent: true, 898 silent: true,