-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dnd doesn't work on macOS Big Sur
- Loading branch information
Showing
9 changed files
with
150 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const os = require('os'); | ||
const semverParse = require('semver/functions/parse'); | ||
const LegacyDndProvider = require("./legacy-dnd"); | ||
const ShellBigSurDndProvider = require("./shell-bigsur-dnd"); | ||
|
||
function isBigSurOrNewer() { | ||
const { major } = semverParse(os.release()) | ||
return major >= 20; | ||
} | ||
|
||
function getDndProvider() { | ||
if (isBigSurOrNewer()) { | ||
return new ShellBigSurDndProvider(); | ||
} | ||
|
||
return new LegacyDndProvider(); | ||
} | ||
|
||
module.exports = { | ||
getDndProvider, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const doNotDisturb = require("@sindresorhus/do-not-disturb"); | ||
|
||
class LegacyDndProvider { | ||
enable() { | ||
return doNotDisturb.enable(); | ||
} | ||
|
||
disable() { | ||
return doNotDisturb.disable(); | ||
} | ||
} | ||
|
||
module.exports = LegacyDndProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# https://github.com/sindresorhus/do-not-disturb/issues/9#issuecomment-768492417 | ||
plutil -extract dnd_prefs xml1 -o - /Users/"$USER"/Library/Preferences/com.apple.ncprefs.plist | xmllint --xpath "string(//data)" - | base64 --decode | plutil -convert xml1 - -o - | xmllint --xpath 'boolean(//key[text()="userPref"]/following-sibling::dict/key[text()="enabled"])' - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# https://github.com/sindresorhus/do-not-disturb/issues/9#issuecomment-768492417 | ||
defaults read /Users/"$USER"/Library/Preferences/com.apple.ncprefs.plist >/dev/null | ||
DND_HEX_DATA=$(plutil -extract dnd_prefs xml1 -o - /Users/"$USER"/Library/Preferences/com.apple.ncprefs.plist | xmllint --xpath "string(//data)" - | base64 --decode | plutil -convert xml1 - -o - | plutil -remove userPref - -o - | plutil -convert binary1 - -o - | xxd -p | tr -d '\n') | ||
defaults write com.apple.ncprefs.plist dnd_prefs -data "$DND_HEX_DATA" | ||
PROCESS_LIST=( | ||
#cfprefsd | ||
usernoted | ||
#NotificationCenter | ||
) | ||
while IFS= read -r line || [[ -n "$line" ]]; do | ||
if [[ "$line" == "" ]]; then continue; fi | ||
i="$line" | ||
#echo "$i" | ||
if [[ $(ps aux | grep "$i" | grep -v grep | awk '{print $2;}') != "" ]]; then | ||
killall "$i" && sleep 0.1 && while [[ $(ps aux | grep "$i" | grep -v grep | awk '{print $2;}') == "" ]]; do sleep 0.5; done | ||
else | ||
: | ||
fi | ||
done <<<"$(printf "%s\n" "${PROCESS_LIST[@]}")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# https://github.com/sindresorhus/do-not-disturb/issues/9#issuecomment-768492417 | ||
defaults read /Users/"$USER"/Library/Preferences/com.apple.ncprefs.plist >/dev/null | ||
DND_HEX_DATA=$(plutil -extract dnd_prefs xml1 -o - /Users/"$USER"/Library/Preferences/com.apple.ncprefs.plist | xmllint --xpath "string(//data)" - | base64 --decode | plutil -convert xml1 - -o - | plutil -insert userPref -xml " | ||
<dict> | ||
<key>date</key> | ||
<date>$(date -u +"%Y-%m-%dT%H:%M:%SZ")</date> | ||
<key>enabled</key> | ||
<true/> | ||
<key>reason</key> | ||
<integer>1</integer> | ||
</dict> " - -o - | plutil -convert binary1 - -o - | xxd -p | tr -d '\n') | ||
defaults write com.apple.ncprefs.plist dnd_prefs -data "$DND_HEX_DATA" | ||
PROCESS_LIST=( | ||
#cfprefsd | ||
usernoted | ||
#NotificationCenter | ||
) | ||
while IFS= read -r line || [[ -n "$line" ]]; do | ||
if [[ "$line" == "" ]]; then continue; fi | ||
i="$line" | ||
#echo "$i" | ||
if [[ $(ps aux | grep "$i" | grep -v grep | awk '{print $2;}') != "" ]]; then | ||
killall "$i" && sleep 0.1 && while [[ $(ps aux | grep "$i" | grep -v grep | awk '{print $2;}') == "" ]]; do sleep 0.5; done | ||
else | ||
: | ||
fi | ||
done <<<"$(printf "%s\n" "${PROCESS_LIST[@]}")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const util = require('util'); | ||
const path = require('path'); | ||
const execFile = util.promisify(require('child_process').execFile); | ||
|
||
const execShellScript = filename => execFile(path.resolve(__dirname, filename)); | ||
|
||
class ShellBigsurDndProvider { | ||
async enable() { | ||
if (await this._isDnDEnabled()) { | ||
return; | ||
} | ||
return execShellScript('./enable.sh'); | ||
} | ||
|
||
async disable() { | ||
if (!await this._isDnDEnabled()) { | ||
return; | ||
} | ||
return execShellScript('./disable.sh'); | ||
} | ||
|
||
async _isDnDEnabled() { | ||
const { stdout } = await execShellScript('./check.sh'); | ||
return stdout === 'true'; | ||
} | ||
} | ||
|
||
module.exports = ShellBigsurDndProvider; |