mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
* refactor(tooling): group remaining scripts by concrete domain owners * fix(tooling): preserve relocated launcher resource roots
37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
const { readdirSync, writeFileSync } = require('node:fs')
|
|
const { join } = require('node:path')
|
|
const { execFileSync } = require('node:child_process')
|
|
|
|
const MACOS_FOLDER_USAGE_DESCRIPTIONS = {
|
|
NSDesktopFolderUsageDescription:
|
|
"Orca allows terminal tools to access the user's Desktop folder when requested.",
|
|
NSDocumentsFolderUsageDescription:
|
|
"Orca allows terminal tools to access the user's Documents folder when requested.",
|
|
NSDownloadsFolderUsageDescription:
|
|
"Orca allows terminal tools to access the user's Downloads folder when requested."
|
|
}
|
|
|
|
function applyMacHelperFolderUsageDescriptions(appPath, productFilename, run = execFileSync) {
|
|
const frameworks = join(appPath, 'Contents', 'Frameworks')
|
|
for (const entry of readdirSync(frameworks, { withFileTypes: true })) {
|
|
if (
|
|
!entry.isDirectory() ||
|
|
!entry.name.startsWith(`${productFilename} Helper`) ||
|
|
!entry.name.endsWith('.app')
|
|
) {
|
|
continue
|
|
}
|
|
const plist = join(frameworks, entry.name, 'Contents', 'Info.plist')
|
|
const info = JSON.parse(
|
|
run('/usr/bin/plutil', ['-convert', 'json', '-o', '-', plist], { encoding: 'utf8' })
|
|
)
|
|
if (!info || typeof info !== 'object' || Array.isArray(info)) {
|
|
throw new Error('The packaged macOS Helper has an invalid Info.plist')
|
|
}
|
|
writeFileSync(plist, JSON.stringify({ ...info, ...MACOS_FOLDER_USAGE_DESCRIPTIONS }))
|
|
run('/usr/bin/plutil', ['-convert', 'xml1', plist], { encoding: 'utf8' })
|
|
}
|
|
}
|
|
|
|
module.exports = { MACOS_FOLDER_USAGE_DESCRIPTIONS, applyMacHelperFolderUsageDescriptions }
|