Skip to content

Commit

Permalink
Add debugging information
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike committed Apr 30, 2024
1 parent 76639d7 commit 452b09c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
28 changes: 24 additions & 4 deletions lib/install/macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
const { exec: _exec } = require('child_process');
const { resolve } = require('path');
const { promisify } = require('util');

const debug = require('debug')('install');

const { 'interaction.pressKeys': pressKeys } = require('../modules/macos/interaction');

const LSREGISTER_EXECUTABLE_PATH =
Expand Down Expand Up @@ -137,17 +140,20 @@ const getExecOptions = async function () {
* https://support.apple.com/en-us/101987
*
* @param {ExecOptions} options
* @returns {Promise<void>}
* @returns {Promise<boolean>} Whether a change took place
*/
async function removeQuarantine(options) {
debug('Removing macOS quarantine');
await exec(`xattr -r -d com.apple.quarantine ${APPLICATION_NAME}`, options);
return true;
}

/**
* @param {ExecOptions} options
* @returns {Promise<void>}
*/
async function registerExtensions(options) {
debug('Registering trusted macOS extension');
await exec(`${LSREGISTER_EXECUTABLE_PATH} -f -R -trusted ${APPLICATION_NAME}`, options);
}

Expand All @@ -156,19 +162,33 @@ async function registerExtensions(options) {
* @returns {Promise<void>}
*/
async function unregisterExtensions(options) {
debug('Unregistering trusted macOS extension');
await exec(`${LSREGISTER_EXECUTABLE_PATH} -f -R -trusted -u ${APPLICATION_NAME}`, options);
}

async function enableExtension() {
debug('Enabling macOS extension');
await exec(`pluginkit -e use -i ${EXTENSION_IDENTIFIER}`);
}

/**
* @param {string} voice
* @param {string} newValue the identifier for the voice to set
* @returns {Promise<void>}
*/
async function setSystemVoice(voice) {
async function setSystemVoice(newValue) {
debug(`Setting macOS system voice to "${newValue}"`);

const {stdout} = await exec('defaults read com.apple.Accessibility SpeechVoiceIdentifierForLanguage');
const currentValue = stdout.replace(/[\s]/g, '').match(/2={en="([^"]+)";};/);

debug(`Current value: ${currentValue ? JSON.stringify(currentValue[1]) : '(unset)'}`);

if (currentValue && currentValue[1] === newValue) {
debug('Already set.');
return;
}

await exec(
`defaults write com.apple.Accessibility SpeechVoiceIdentifierForLanguage '{2 = {en = "${voice}";};}'`,
`defaults write com.apple.Accessibility SpeechVoiceIdentifierForLanguage '{2 = {en = "${newValue}";};}'`,
);
}
35 changes: 28 additions & 7 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"debug": "^4.3.4",
"robotjs": "^0.6.0",
"uuid": "^9.0.1",
"ws": "^8.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down

0 comments on commit 452b09c

Please sign in to comment.