Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Catalyst apps #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 25 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ function getAppNamesToIconPaths(parsedDockData) {
for (const parsedAppData of persistentApps ?? []) {
const appName = parsedAppData.dict[0].string[1];
const appDirectoryUrl = parsedAppData.dict[0].dict?.[0].string[0];

if (appDirectoryUrl && isAppNameAllowed(appName)) {
const appDirectory = url.fileURLToPath(appDirectoryUrl)
result[appName] = getIconPath(appDirectory);
result[appName] = getIconPath(appDirectory) || getIconPathForCatalystApp(appDirectory);
}
}
return result;
Expand Down Expand Up @@ -80,6 +81,29 @@ function getIconPath(appDirectory) {
return null;
}

/**
* Returns path to icon for a Catalyst app
* @param appDirectory
* @return {string|null}
*/
function getIconPathForCatalystApp(appDirectory) {
const bundleDirectory = path.join(appDirectory, 'Wrapper', path.basename(appDirectory));
if (!fs.pathExistsSync(bundleDirectory)) return null;
let largestIcon = {size: 0, fileName: null}
fs.readdirSync(bundleDirectory).forEach(fileName => {
// '[email protected]' -> groups: { size: '60' }
// 'AppIcon76x76@2x~ipad.png' -> groups: { size: '76' }
const match = fileName.match(/AppIcon(?<size>\d+)x\d+.*.png/);
if (match && match.groups.size && parseInt(match.groups.size) > largestIcon.size) {
largestIcon = {
size: match.groups.size,
fileName: path.join(bundleDirectory, fileName)
}
}
})
return largestIcon.fileName;
}

/**
*
* @param appName {string}
Expand Down