Skip to content

Commit

Permalink
Fix macOS DND detection
Browse files Browse the repository at this point in the history
  • Loading branch information
hovancik committed Jan 18, 2025
1 parent 0b7cee2 commit 6aed7a2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Fixed
- Linux DND detection
- improve macOS DND detection
- debug info when from Windows Store

## [1.17.1] - 2024-12-25
Expand Down
10 changes: 8 additions & 2 deletions app/utils/dndManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DndManager extends EventEmitter {
this.windowsFocusAssist = require('windows-focus-assist')
this.windowsQuietHours = require('windows-quiet-hours')
} else if (process.platform === 'darwin') {
this.macosNotificationState = require('macos-notification-state')
this.util = require('node:util')
} else if (process.platform === 'linux') {
this.bus = require('dbus-final').sessionBus()
this.util = require('node:util')
Expand Down Expand Up @@ -124,7 +124,13 @@ class DndManager extends EventEmitter {
const wqh = this.windowsQuietHours.getIsQuietHours()
return wqh || (wfa !== -1 && wfa !== 0)
} else if (process.platform === 'darwin') {
return this.macosNotificationState.getDoNotDisturb()
try {
const exec = this.util.promisify(require('node:child_process').exec)
const { stdout } = await exec('defaults read com.apple.controlcenter "NSStatusItem Visible FocusModes"')
if (stdout.replace(/[^0-9a-zA-Z]/g, '') === '1') {
return true

Check warning on line 131 in app/utils/dndManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/dndManager.js#L127-L131

Added lines #L127 - L131 were not covered by tests
}
} catch (e) { }
} else if (process.platform === 'linux') {
return await this._isDndEnabledLinux()
}
Expand Down
18 changes: 0 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
],
"extendInfo": {
"LSBackgroundOnly": 1,
"LSUIElement": 1,
"NSFocusStatusUsageDescription": "Stretchly will respect Do Not Disturb mode"
"LSUIElement": 1
}
},
"linux": {
Expand Down Expand Up @@ -157,7 +156,6 @@
"i18next": "^23.16.8",
"i18next-fs-backend": "^2.6.0",
"luxon": "^3.5.0",
"macos-notification-state": "^3.0.0",
"meeussunmoon": "^3.0.3",
"ps-list": "7.2",
"rtl-detect": "^1.1.2",
Expand Down

0 comments on commit 6aed7a2

Please sign in to comment.