Skip to content
Merged
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
15 changes: 10 additions & 5 deletions src/commands/setup/macOS/enableDoNotDisturb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,20 @@ export async function enableDoNotDisturb() {
await promisify(exec)(enableFocusModeShellscript);
} 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));
await retryOnError(() => runAppleScript(enableFocusModeAppleScript), {
retries: 5,
delay: 500,
});
} 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, platformMajor),
),
await retryOnError(
() =>
runAppleScript(
enableFocusModeVenturaAppleScript(locale, platformMajor),
),
{ retries: 5, delay: 500 },
);
}
} catch (cause) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/setup/macOS/runAppleScript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execFile } from "child_process";

export const DEFAULT_TIMEOUT = 10000;
export const DEFAULT_TIMEOUT = 120;
export const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;

export async function runAppleScript<T = string | void>(
Expand Down Expand Up @@ -28,7 +28,7 @@ end tell"

delay 0.2
end repeat
end doWithTimeout
end withTimeout
`;

return (await new Promise<string | void>((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/setup/macOS/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function setup({
}: MacOSSetupOptions = {}): Promise<void> {
if (!macosIgnoreTccDb) {
try {
updateTccDb(USER_PATH);
await updateTccDb(USER_PATH);
} catch (e) {
if (ci) {
throw e;
Expand All @@ -43,7 +43,7 @@ export async function setup({
}

try {
updateTccDb(SYSTEM_PATH);
await updateTccDb(SYSTEM_PATH);
} catch {
// Swallow error - most CI don't allow system configuration
}
Expand Down
5 changes: 4 additions & 1 deletion src/commands/setup/macOS/updateTccDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const getEntries = (): string[] => {
export const USER_PATH = `${homedir()}/Library/Application Support/com.apple.TCC/TCC.db`;
export const SYSTEM_PATH = "/Library/Application Support/com.apple.TCC/TCC.db";

export function updateTccDb(path: string): void {
export async function updateTccDb(path: string): Promise<void> {
const osRelease = release();
const isSonomaOrNewer = parseInt(osRelease.split(".")[0], 10) >= 23;

Expand All @@ -204,4 +204,7 @@ export function updateTccDb(path: string): void {
});
}
}

// 1s sleep to give cache for updates to propagate
await new Promise((resolve) => setTimeout(resolve, 1000));
}
Loading