Skip to content

Commit

Permalink
feat: Support Ventura (#19)
Browse files Browse the repository at this point in the history
* feat: ventura support
* ci: add macos-13 runner

---------

Co-authored-by: cmorten <[email protected]>
  • Loading branch information
jlp-craigmorten and cmorten authored Nov 30, 2023
1 parent 12dfced commit 90c2414
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 181 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
[
macos-11,
macos-12,
macos-latest,
windows-2019,
windows-2022,
windows-latest,
]
os: [macos-11, macos-12, macos-13, windows-2019, windows-2022]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@guidepup/setup",
"version": "0.11.2",
"version": "0.12.0",
"description": "Setup your environment for screen-reader automation.",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
62 changes: 60 additions & 2 deletions src/macOS/enableDoNotDisturb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { retryOnError } from "./retryOnError";
// REF: https://github.com/sindresorhus/do-not-disturb/issues/9
const enableFocusModeShellscript = `defaults write com.apple.ncprefs.plist dnd_prefs -data 62706C6973743030D60102030405060708080A08085B646E644D6972726F7265645F100F646E64446973706C6179536C6565705F101E72657065617465644661636574696D6543616C6C73427265616B73444E445875736572507265665E646E64446973706C61794C6F636B5F10136661636574696D6543616E427265616B444E44090808D30B0C0D070F1057656E61626C6564546461746556726561736F6E093341C2B41C4FC9D3891001080808152133545D6C828384858C9499A0A1AAACAD00000000000001010000000000000013000000000000000000000000000000AE && killall usernoted && killall ControlCenter`;

const getLocale = `defaults read -g AppleLocale`;

const enableFocusModeAppleScript = `
-- Startup delay to reduce chance of "Application isn't running (-600)" errors
delay 1
set timeoutSeconds to 30.0
set command to "
Expand All @@ -32,17 +37,70 @@ set command to "
my withTimeout(command, timeoutSeconds)
`;

const enableFocusModeVenturaAppleScript = (locale: string) => {
// TODO: attempt to rewrite scripts without any locale specific instructions
// so this setup can be used regardless of user locale preferences.
const center = locale.trim() === "en_GB" ? "Centre" : "Center";

return `-- Startup delay to reduce chance of "Application isn't running (-600)" errors
delay 1
set timeoutSeconds to 30.0
set command to "
tell application \\"System Events\\"
tell its application process \\"Control ${center}\\"
-- Click on and open Control ${center} drop down
tell its menu bar 1
tell (UI elements whose description is \\"Control ${center}\\")
click
end tell
end tell
-- Check if Do Not Disturb already enabled
set doNotDisturbCheckbox to checkbox 2 of group 1 of window \\"Control ${center}\\"
set doNotDisturbCheckboxStatus to value of doNotDisturbCheckbox as boolean
tell doNotDisturbCheckbox
if doNotDisturbCheckboxStatus is false then
perform action 1 of doNotDisturbCheckbox
end if
end tell
-- Click on and close Control ${center} drop down
tell its menu bar 1
tell (UI elements whose description is \\"Control ${center}\\")
click
end tell
end tell
end tell
end tell
"
my withTimeout(command, timeoutSeconds)
`;
};

export async function enableDoNotDisturb() {
const platformMajor = Number(os.version().split("Version ")[1].split(".")[0]);

try {
if (platformMajor <= 20) {
await promisify(exec)(enableFocusModeShellscript);
} else {
} else if (platformMajor === 21) {
// From MacOS 12 Monterey (Darwin 21) there is no known way to enable DND via system defaults
await retryOnError(() => runAppleScript(enableFocusModeAppleScript));
} else {
const { stdout: locale } = await promisify(exec)(getLocale);

// From MacOS 13 Ventura (Darwin 22) there is no known way to enable DND via system settings
await retryOnError(() =>
runAppleScript(enableFocusModeVenturaAppleScript(locale))
);
}
} catch (e) {
throw new Error(`${ERR_MACOS_FAILED_TO_ENABLE_DO_NOT_DISTURB}\n\n${e.message}`);
throw new Error(
`${ERR_MACOS_FAILED_TO_ENABLE_DO_NOT_DISTURB}\n\n${e.message}`
);
}
}
1 change: 1 addition & 0 deletions src/macOS/setVoiceOverEnabledViaUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ tell application "System Events"
exit repeat
end if
tell application "VoiceOver Utility" to activate
delay 0.1
end repeat
Expand Down
10 changes: 7 additions & 3 deletions src/macOS/updateTccDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const getEntries = (): string[] => {
let gitlabRunnerPath: string;

try {
gitlabRunnerPath = execSync("which gitlab-runner", { encoding: "utf8" }).trim();
gitlabRunnerPath = execSync("which gitlab-runner", {
encoding: "utf8",
}).trim();
} catch {
gitlabRunnerPath = "/usr/local/bin/gitlab-runner";
}
Expand Down Expand Up @@ -177,7 +179,7 @@ const getEntries = (): string[] => {
`'kTCCServiceAppleEvents','/usr/sbin/sshd',1,2,3,1,NULL,NULL,0,'org.webkit.Playwright',NULL,NULL,${epoch}`,
`'kTCCServiceAppleEvents','/bin/bash',1,2,3,1,NULL,NULL,0,'org.webkit.Playwright',NULL,NULL,${epoch}`,
`'kTCCServiceAppleEvents','/bin/zsh',1,2,3,1,NULL,NULL,0,'org.webkit.Playwright',NULL,NULL,${epoch}`,
`'kTCCServiceAppleEvents','/usr/bin/osascript',1,2,3,1,NULL,NULL,0,'com.webkit.Playwright',NULL,NULL,${epoch}`,
`'kTCCServiceAppleEvents','/usr/bin/osascript',1,2,3,1,NULL,NULL,0,'org.webkit.Playwright',NULL,NULL,${epoch}`,
`'kTCCServiceAppleEvents','com.apple.Terminal',0,2,3,1,NULL,NULL,0,'org.webkit.Playwright',NULL,NULL,${epoch}`,
`'kTCCServiceAppleEvents','/usr/local/opt/runner/runprovisioner.sh',0,2,3,1,NULL,NULL,0,'org.webkit.Playwright',NULL,NULL,${epoch}`,
`'kTCCServiceAppleEvents','${gitlabRunnerPath}',0,2,3,1,NULL,NULL,0,'org.webkit.Playwright',NULL,NULL,${epoch}`,
Expand All @@ -193,7 +195,9 @@ export function updateTccDb(): void {
try {
execSync(`sqlite3 "${path}" "${query}" >/dev/null 2>&1`);
} catch (e) {
throw new Error(`${ERR_MACOS_UNABLE_TO_WRITE_USER_TCC_DB}\n\n${e.message}`);
throw new Error(
`${ERR_MACOS_UNABLE_TO_WRITE_USER_TCC_DB}\n\n${e.message}`
);
}
}
}
Loading

0 comments on commit 90c2414

Please sign in to comment.