-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Add support for macOS layered icons #5451
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
Open
Sanlorng
wants to merge
5
commits into
JetBrains:master
Choose a base branch
from
Sanlorng:support_macos_new_icon
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b608da2
feat: Add support for macOS layered icons
Sanlorng 6878a0a
Remove unused `macAssetsDir` property
Sanlorng 27e4a6b
clean code
Sanlorng 3cce19c
Refactor: Use placeholders for Compose dependencies in test
Sanlorng f6d1291
Refactor: Use `plutil` to parse `actool` version
Sanlorng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...mpose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/MacAssetsTool.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package org.jetbrains.compose.desktop.application.internal | ||
|
|
||
| import org.gradle.api.logging.Logger | ||
| import org.jetbrains.compose.internal.utils.MacUtils | ||
| import java.io.File | ||
|
|
||
| internal class MacAssetsTool(private val runTool: ExternalToolRunner, private val logger: Logger) { | ||
|
|
||
| fun compileAssets(iconDir: File, workingDir: File, minimumSystemVersion: String?): File { | ||
| val toolVersion = checkAssetsToolVersion() | ||
| logger.info("compile mac assets is starting, supported actool version:$toolVersion") | ||
|
|
||
| val result = runTool( | ||
| tool = MacUtils.xcrun, | ||
| args = listOf( | ||
| "actool", | ||
| iconDir.absolutePath, // Input asset catalog | ||
| "--compile", workingDir.absolutePath, | ||
| "--app-icon", iconDir.name.removeSuffix(".icon"), | ||
| "--enable-on-demand-resources", "NO", | ||
| "--development-region", "en", | ||
| "--target-device", "mac", | ||
| "--platform", "macosx", | ||
| "--enable-icon-stack-fallback-generation=disabled", | ||
| "--include-all-app-icons", | ||
| "--minimum-deployment-target", minimumSystemVersion ?: "10.13", | ||
| "--output-partial-info-plist", "/dev/null" | ||
| ), | ||
| ) | ||
|
|
||
| if (result.exitValue != 0) { | ||
| error("Could not compile the layered icons directory into Assets.car.") | ||
| } | ||
| if (!assetsFile(workingDir).exists()) { | ||
| error("Could not find Assets.car in the working directory.") | ||
| } | ||
| return workingDir.resolve("Assets.car") | ||
| } | ||
|
|
||
| fun assetsFile(workingDir: File): File = workingDir.resolve("Assets.car") | ||
|
|
||
| private fun checkAssetsToolVersion(): String { | ||
| val requiredVersion = 26.0 | ||
| var outputContent = "" | ||
| val result = runTool( | ||
| tool = MacUtils.xcrun, | ||
| args = listOf("actool", "--version"), | ||
| processStdout = { outputContent = it }, | ||
| ) | ||
|
|
||
| if (result.exitValue != 0) { | ||
| error("Could not get actool version: Command `xcrun actool -version` exited with code ${result.exitValue}\nStdOut: $outputContent\n") | ||
| } | ||
|
|
||
| val versionString: String? = try { | ||
| var versionContent = "" | ||
| runTool( | ||
| tool = MacUtils.plutil, | ||
| args = listOf( | ||
| "-extract", | ||
| "com\\.apple\\.actool\\.version.short-bundle-version", | ||
| "raw", | ||
| "-expect", | ||
| "string", | ||
| "-o", | ||
| "-", | ||
| "-" | ||
| ), | ||
| stdinStr = outputContent, | ||
| processStdout = { | ||
| versionContent = it | ||
| } | ||
| ) | ||
| versionContent | ||
| } catch (e: Exception) { | ||
| error("Could not check actool version. Error: ${e.message}") | ||
| } | ||
|
|
||
| if (versionString.isNullOrBlank()) { | ||
| error("Could not extract short-bundle-version from actool output: '$outputContent'. Assuming it meets requirements.") | ||
| } | ||
|
|
||
| val majorVersion = versionString | ||
| .split(".") | ||
| .firstOrNull() | ||
| ?.toIntOrNull() | ||
| ?: error("Could not get actool major version from version string '$versionString' . Output was: '$outputContent'. Assuming it meets requirements.") | ||
|
|
||
| if (majorVersion < requiredVersion) { | ||
| error( | ||
| "Unsupported actool version: $versionString. " + | ||
| "Version $requiredVersion or higher is required. " + | ||
| "Please update your Xcode Command Line Tools." | ||
| ) | ||
| } else { | ||
| return versionString | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing EOF here