Skip to content

Export icons in Dispatchers.IO#775

Merged
egorikftp merged 1 commit intomainfrom
task/write-files-in-io-dispatcheer
Dec 13, 2025
Merged

Export icons in Dispatchers.IO#775
egorikftp merged 1 commit intomainfrom
task/write-files-in-io-dispatcheer

Conversation

@egorikftp
Copy link
Copy Markdown
Member

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 12, 2025

Walkthrough

Vector output write operations are moved to the IO dispatcher by wrapping vectorSpecOutput.content.writeToKt calls in withContext(Dispatchers.IO) in both branches. An import for kotlinx.coroutines.withContext was added. A minor formatting change collapsed a runCatching expression in processText into a single line with no semantic change.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether the description relates to the changeset. Add a pull request description that explains the purpose and context of moving icon export operations to the IO dispatcher.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Export icons in Dispatchers.IO' directly relates to the main change of wrapping vectorSpecOutput.content.writeToKt calls inside withContext(Dispatchers.IO) for IO-bound work.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch task/write-files-in-io-dispatcheer

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd4e5a2 and a210cb5.

📒 Files selected for processing (1)
  • tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/conversion/IconPackConversionViewModel.kt (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/conversion/IconPackConversionViewModel.kt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (ubuntu-latest)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/conversion/IconPackConversionViewModel.kt (1)

166-238: Consider splitting CPU conversion vs filesystem writes + ensure state is reset on failure/cancel.
Switching to Dispatchers.IO matches writeToKt, but ImageVectorGenerator.convert(...) may be CPU-bound; also any exception/cancellation can strand the UI in ExportingState.

-    fun export() = viewModelScope.launch(Dispatchers.IO) {
+    fun export() = viewModelScope.launch(Dispatchers.IO) {
         val icons = when (val state = _state.value) {
             is BatchProcessing.IconPackCreationState -> state.icons
             else -> return@launch
         }

         _state.updateState { BatchProcessing.ExportingState }

-        val settings = inMemorySettings.current
-
-        icons
-            .filterIsInstance<BatchIcon.Valid>()
-            .forEach { icon ->
-                when (val iconPack = icon.iconPack) {
+        try {
+            val settings = inMemorySettings.current
+            icons
+                .filterIsInstance<BatchIcon.Valid>()
+                .forEach { icon ->
+                    when (val iconPack = icon.iconPack) {
                     is IconPack.Nested -> {
-                        val vectorSpecOutput = ImageVectorGenerator.convert(
+                        val vectorSpecOutput = kotlinx.coroutines.withContext(Dispatchers.Default) {
+                            ImageVectorGenerator.convert(
                             vector = icon.irImageVector,
                             iconName = icon.iconName.name,
                             config = ImageVectorGeneratorConfig(
                                 packageName = icon.iconPack.iconPackage,
                                 iconPackPackage = settings.iconPackPackage,
                                 packName = settings.iconPackName,
                                 nestedPackName = iconPack.currentNestedPack,
                                 outputFormat = settings.outputFormat,
                                 useComposeColors = settings.useComposeColors,
                                 generatePreview = settings.generatePreview,
                                 previewAnnotationType = settings.previewAnnotationType,
                                 useFlatPackage = settings.flatPackage,
                                 useExplicitMode = settings.useExplicitMode,
                                 addTrailingComma = settings.addTrailingComma,
                                 indentSize = settings.indentSize,
                             ),
-                        )
+                            )
+                        }

                         vectorSpecOutput.content.writeToKt(
                             outputDir = when {
                                 settings.flatPackage -> settings.iconPackDestination
                                 else -> "${settings.iconPackDestination}/${iconPack.currentNestedPack.lowercase()}"
                             },
                             nameWithoutExtension = vectorSpecOutput.name,
                         )
                     }
                     is IconPack.Single -> {
-                        val vectorSpecOutput = ImageVectorGenerator.convert(
+                        val vectorSpecOutput = kotlinx.coroutines.withContext(Dispatchers.Default) {
+                            ImageVectorGenerator.convert(
                             vector = icon.irImageVector,
                             iconName = icon.iconName.name,
                             config = ImageVectorGeneratorConfig(
                                 packageName = icon.iconPack.iconPackage,
                                 iconPackPackage = settings.iconPackPackage,
                                 packName = settings.iconPackName,
                                 nestedPackName = "",
                                 outputFormat = settings.outputFormat,
                                 useComposeColors = settings.useComposeColors,
                                 generatePreview = settings.generatePreview,
                                 previewAnnotationType = settings.previewAnnotationType,
-                                useFlatPackage = settings.flatPackage,
+                                useFlatPackage = false,
                                 useExplicitMode = settings.useExplicitMode,
                                 addTrailingComma = settings.addTrailingComma,
                                 indentSize = settings.indentSize,
                             ),
-                        )
+                            )
+                        }

                         vectorSpecOutput.content.writeToKt(
                             outputDir = settings.iconPackDestination,
                             nameWithoutExtension = vectorSpecOutput.name,
                         )
                     }
-                }
-            }
-
-        _events.emit(ConversionEvent.ExportCompleted)
-        reset()
+                    }
+                }
+
+            _events.emit(ConversionEvent.ExportCompleted)
+            reset()
+        } finally {
+            // optional: if you want to guarantee leaving ExportingState on failures, update state here
+        }
     }

(Setting useFlatPackage = false for IconPack.Single is based on retrieved learnings about nested-only applicability; if this plugin intentionally differs, ignore that part.) Based on learnings, useFlatPackage is intended to apply only when nested packs are configured.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b28c99 and dd4e5a2.

📒 Files selected for processing (1)
  • tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/conversion/IconPackConversionViewModel.kt (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: egorikftp
Repo: ComposeGears/Valkyrie PR: 750
File: tools/gradle-plugin/src/main/kotlin/io/github/composegears/valkyrie/gradle/internal/task/GenerateImageVectorsTask.kt:71-85
Timestamp: 2025-12-07T20:07:49.753Z
Learning: In the Valkyrie Gradle plugin (Kotlin), the `useFlatPackage` flag in `IconPackExtension` is only applicable when nested packs are configured. For single icon packs (without nested packs), the flag is intentionally not propagated to `ImageVectorGeneratorConfig` as there is no package hierarchy to flatten.
📚 Learning: 2025-12-07T20:07:49.753Z
Learnt from: egorikftp
Repo: ComposeGears/Valkyrie PR: 750
File: tools/gradle-plugin/src/main/kotlin/io/github/composegears/valkyrie/gradle/internal/task/GenerateImageVectorsTask.kt:71-85
Timestamp: 2025-12-07T20:07:49.753Z
Learning: In the Valkyrie Gradle plugin (Kotlin), the `useFlatPackage` flag in `IconPackExtension` is only applicable when nested packs are configured. For single icon packs (without nested packs), the flag is intentionally not propagated to `ImageVectorGeneratorConfig` as there is no package hierarchy to flatten.

Applied to files:

  • tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/conversion/IconPackConversionViewModel.kt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (1)
tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/conversion/IconPackConversionViewModel.kt (1)

317-320: Formatting-only change in processText is fine.
No semantic change; runCatching { ... }.getOrNull() still behaves the same.

@egorikftp egorikftp force-pushed the task/write-files-in-io-dispatcheer branch from dd4e5a2 to a210cb5 Compare December 12, 2025 11:28
@egorikftp egorikftp merged commit 4d463d2 into main Dec 13, 2025
3 checks passed
@egorikftp egorikftp deleted the task/write-files-in-io-dispatcheer branch December 13, 2025 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant