Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/electron/ipc-api/dnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { isDevMode } from '../../environment-remote';
const debug = require('../../preload-safe-debug')('Ferdium:ipcApi:dnd');

export default async () => {
ipcMain.handle('get-dnd', async () => {
ipcMain.handle('get-dnd-macos', async () => {
// In dev mode, we don't want to check DND status because it's not available
// TODO: This should be removed when we have a better way to handle this
if (isDevMode) {
return false;
}

if (!isMac) {
console.error("get-dnd-macos shouldn't be called when not on a Mac");
return false;
}

// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore
const { getDoNotDisturb } = await import('macos-notification-state');
Expand Down
17 changes: 11 additions & 6 deletions src/stores/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,10 @@ export default class AppStore extends TypedStore {

// Check if system is muted
// There are no events to subscribe so we need to poll every 5s
this._systemDND();
setInterval(() => this._systemDND(), ms('5s'));
if (isMac) {
this._systemDNDMac();
setInterval(() => this._systemDNDMac(), ms('5s'));
}

this.fetchDataInterval = setInterval(() => {
this.stores.user.getUserInfoRequest.invalidate({
Expand Down Expand Up @@ -830,10 +832,13 @@ export default class AppStore extends TypedStore {
return autoLauncher.isEnabled() || false;
}

async _systemDND() {
debug('Checking if Do Not Disturb Mode is on');
const dnd = await ipcRenderer.invoke('get-dnd');
debug('Do not disturb mode is', dnd);
/**
* This method could be refactored to be used on all desktop environments,
* but at the moment it only supports MacOS
*/
async _systemDNDMac() {
const dnd = await ipcRenderer.invoke('get-dnd-macos');
debug('Checking if Do Not Disturb Mode is on :', dnd);
if (
dnd !== this.stores.settings.all.app.isAppMuted &&
!this.isSystemMuteOverridden
Expand Down
48 changes: 29 additions & 19 deletions src/stores/ServicesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,18 +863,18 @@ export default class ServicesStore extends TypedStore {

if (isTwoFactorAutoCatcherEnabled) {
/*
parse the token digits from sms body, find "token" or "code" in options.body which reflect the sms content
---
Token: 03624 / SMS-Code = PIN Token
---
Prüfcode 010313 für Microsoft-Authentifizierung verwenden.
---
483133 is your GitHub authentication code. @github.com #483133
---
eBay: Ihr Sicherheitscode lautet 080090. \nEr läuft in 15 Minuten ab. Geben Sie den Code nicht an andere weiter.
---
PayPal: Ihr Sicherheitscode lautet: 989605. Geben Sie diesen Code nicht weiter.
*/
parse the token digits from sms body, find "token" or "code" in options.body which reflect the sms content
---
Token: 03624 / SMS-Code = PIN Token
---
Prüfcode 010313 für Microsoft-Authentifizierung verwenden.
---
483133 is your GitHub authentication code. @github.com #483133
---
eBay: Ihr Sicherheitscode lautet 080090. \nEr läuft in 15 Minuten ab. Geben Sie den Code nicht an andere weiter.
---
PayPal: Ihr Sicherheitscode lautet: 989605. Geben Sie diesen Code nicht weiter.
*/

const rawBody = options.body;
const { 0: token } = /\d{5,6}/.exec(options.body) || [];
Expand All @@ -899,14 +899,24 @@ export default class ServicesStore extends TypedStore {
}

// Check if we are in scheduled Do-not-Disturb time
const { scheduledDNDEnabled, scheduledDNDStart, scheduledDNDEnd } =
this.stores.settings.all.app;
if (this.stores.settings.all.app.scheduledDNDEnabled) {
const { scheduledDNDStart, scheduledDNDEnd } =
this.stores.settings.all.app;

if (
scheduledDNDEnabled &&
isInTimeframe(scheduledDNDStart, scheduledDNDEnd)
) {
return;
const shouldBeDnd = isInTimeframe(scheduledDNDStart, scheduledDNDEnd);
debug(
'Check if we are in a schedule Do not disturb window :',
shouldBeDnd,
scheduledDNDStart,
scheduledDNDEnd,
);

if (shouldBeDnd !== this.stores.settings.all.app.isAppMuted) {
debug('Toggle scheduled Do not disturb');
this.actions.app.muteApp({
isMuted: shouldBeDnd,
});
}
}

if (service.isMuted || this.stores.settings.all.app.isAppMuted) {
Expand Down