aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/ServicesStore.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/ServicesStore.ts')
-rw-r--r--src/stores/ServicesStore.ts58
1 files changed, 55 insertions, 3 deletions
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 @@
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';
@@ -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,