Skip to content

build: refactor Flatpak packaging to use online builds and force X11 …#339

Merged
rainxchzed merged 16 commits intomainfrom
flatpak-pr
Mar 23, 2026
Merged

build: refactor Flatpak packaging to use online builds and force X11 …#339
rainxchzed merged 16 commits intomainfrom
flatpak-pr

Conversation

@rainxchzed
Copy link
Copy Markdown
Member

@rainxchzed rainxchzed commented Mar 20, 2026

…backend

  • Enable network access during the Flatpak build process to allow Gradle to download dependencies directly.
  • Remove pre-downloaded Gradle distribution and the offline flatpak-sources.json dependency list.
  • Switch the build command from packageReleaseUberJarForCurrentOS to packageUberJarForCurrentOS to avoid ProGuard duplicate jar conflicts.
  • Force GDK_BACKEND=x11 in the launch script to improve reliability for Skiko/Compose on Wayland environments.
  • Enhance disable-android-for-flatpak.sh to more aggressively strip Android-specific configuration blocks (androidMain, debugImplementation) across all project modules.
  • Refactor the RoomConventionPlugin within the Flatpak build logic to remove Android-specific KSP dependencies.
  • Update the Flatpak manifest to point to the latest commit for version 1.6.2.

Summary by CodeRabbit

  • New Features

    • Added a Room database convention plugin for JVM (non‑Android) targets.
    • Flatpak-aware installer: detects Flatpak, prefers host packages, uses host-safe install flows, desktop notifications, and file‑manager fallbacks.
  • Chores

    • Enabled network dependency resolution for Flatpak builds, simplified sources to local directory, and changed packaging Gradle task.
    • Removed Android-related build/config entries across modules and expanded automated removals.
  • Style

    • Adjusted progress/log step counts in packaging scripts.
  • Bug Fixes

    • Force X11 backend for Flatpak launches and restrict Flatpak finish-args to X11.

…backend

- Enable network access during the Flatpak build process to allow Gradle to download dependencies directly.
- Remove pre-downloaded Gradle distribution and the offline `flatpak-sources.json` dependency list.
- Switch the build command from `packageReleaseUberJarForCurrentOS` to `packageUberJarForCurrentOS` to avoid ProGuard duplicate jar conflicts.
- Force `GDK_BACKEND=x11` in the launch script to improve reliability for Skiko/Compose on Wayland environments.
- Enhance `disable-android-for-flatpak.sh` to more aggressively strip Android-specific configuration blocks (`androidMain`, `debugImplementation`) across all project modules.
- Refactor the `RoomConventionPlugin` within the Flatpak build logic to remove Android-specific KSP dependencies.
- Update the Flatpak manifest to point to the latest commit for version 1.6.2.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 20, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Flatpak packaging and runtime changes: broadened Android-removal in build scripts, added a non‑Android Room convention plugin, forced X11 for the bundled app, allowed network during Flatpak builds, simplified Flatpak sources, and added Flatpak-aware install detection and helpers in the desktop installer.

Changes

Cohort / File(s) Summary
Flatpak Android-disable script & repo Gradle patching
packaging/flatpak/disable-android-for-flatpak.sh
Adjusted progress step counts and comments; replaced hardcoded module list with a repo-wide find (excluding build-logic and .flatpak-builder), added pre-scan skip when no Android patterns, and extended Python in-place block removal to strip android { ... }, androidMain.dependencies { ... }, androidMain { ... }, plus Android implementation lines.
Convention plugin edits
build-logic/convention/src/main/kotlin/CmpLibraryConventionPlugin.kt, build-logic/convention/src/main/kotlin/CmpFeatureConventionPlugin.kt
Expanded Android-removal to delete debugImplementation and androidMainImplementation patterns when preparing modules for Flatpak.
New Room convention plugin
build-logic/convention/src/main/kotlin/RoomConventionPlugin.kt
Added RoomConventionPlugin applying KSP and Room, setting Room schema dir, wiring runtime via commonMainApi (runtime + bundled sqlite) and kspJvm (compiler), intentionally without Android targets.
Launcher / GTK backend
packaging/flatpak/githubstore.sh
Export GDK_BACKEND=x11 before launching the bundled JRE to force X11 (works via XWayland when needed).
Flatpak manifest / build config
packaging/flatpak/zed.rainxch.githubstore.yml
Changed finish-args to --socket=x11 (removed Wayland/fallback sockets), added build-args: [--share=network], removed Gradle --offline, switched Gradle task to :composeApp:packageUberJarForCurrentOS, and simplified sources to a local directory source while keeping Gradle wrapper zip.
Desktop installer (Flatpak-aware install flow)
core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt
Added Flatpak detection (/.flatpak-info, FLATPAK_ID), prefer host .deb/.rpm when running in Flatpak, use /run/host/os-release for distro detection inside Flatpak, skip AppImage permission checks in Flatpak, added installFromFlatpak using xdg-open for native packages or chmod+notifications for AppImages, plus showFlatpakNotification and openInFileManager helpers.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant App as App (caller)
participant Installer as DesktopInstaller
participant Host as Host OS / External Installer
participant Notifier as Notification Portal
App->>Installer: request install(asset)
Installer->>Installer: detect Flatpak (/.flatpak-info or FLATPAK_ID)
alt Running inside Flatpak
Installer->>Installer: choose preferred host package (.deb/.rpm) or .appimage
Installer->>Host: xdg-open (open with host installer)
Host-->>Installer: success/failure
Installer->>Notifier: showFlatpakNotification(instructions/results)
Installer->>Host: open file manager (DBus ShowItems) if needed
else Not Flatpak
Installer->>Installer: run normal OS-specific installer flow
Installer->>Host: launch native installer with privileges
end

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰
I hop through build files, snip and softly prune,
I whisper X11 beneath the Flatpak moon,
Room lives in common, Android set aside,
I nudge installs gently, notifications guide,
A tiny rabbit cheers: package and glide!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: refactoring Flatpak packaging for online builds and forcing X11 backend, which aligns with the primary objectives of enabling network access and improving display backend reliability.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch flatpak-pr

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.

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

Copy link
Copy Markdown
Contributor

@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: 2

🧹 Nitpick comments (1)
packaging/flatpak/disable-android-for-flatpak.sh (1)

256-285: Avoid forking RoomConventionPlugin.kt inside this patch script.

These lines create a second full copy of build-logic/convention/src/main/kotlin/RoomConventionPlugin.kt. Any later Room convention change will land in normal builds but be silently skipped by Flatpak builds. Prefer a targeted edit that removes only the Android-specific KSP wiring, like the smaller patches above.

Based on learnings: Use convention plugins from build-logic/convention/ for module setup: convention.kmp.library, convention.cmp.library, convention.cmp.feature, convention.cmp.application, convention.room, convention.buildkonfig

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packaging/flatpak/disable-android-for-flatpak.sh` around lines 256 - 285,
This patch currently forks RoomConventionPlugin by writing a full duplicate file
(creating RoomConventionPlugin.kt) which will diverge from
build-logic/convention; instead, change the script to perform a targeted edit on
the existing RoomConventionPlugin in build-logic/convention: remove only the
Android/KSP-specific wiring — i.e., delete or conditionalize the
apply("com.google.devtools.ksp") call and the
"kspJvm"(libs.findLibrary("androidx-room-compiler").get()) dependency while
keeping the RoomExtension.schemaDirectory and commonMainApi lines intact — so
that you do not create a second copy and Flatpak builds reuse the canonical
RoomConventionPlugin implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packaging/flatpak/githubstore.sh`:
- Around line 11-13: The script currently force-sets GDK_BACKEND to x11; change
it to only default to x11 when GDK_BACKEND is not already defined so
Wayland-only users can override it. Locate the export of GDK_BACKEND (symbol:
GDK_BACKEND) and modify the assignment to use the existing environment value if
present (i.e., leave GDK_BACKEND alone when set, otherwise set it to x11) so the
manifest's Wayland socket access can be used when desired.

In `@packaging/flatpak/zed.rainxch.githubstore.yml`:
- Around line 52-60: Remove the sed replacement that rewrites distributionUrl to
gradle-bin.zip in the build-commands (the line that runs sed on
gradle/wrapper/gradle-wrapper.properties); since --share=network is enabled the
wrapper should download the distribution from the original URL, so delete or
comment out that sed invocation and keep the remaining build-commands (including
disable-android-for-flatpak.sh and ./gradlew
:composeApp:packageUberJarForCurrentOS) intact.

---

Nitpick comments:
In `@packaging/flatpak/disable-android-for-flatpak.sh`:
- Around line 256-285: This patch currently forks RoomConventionPlugin by
writing a full duplicate file (creating RoomConventionPlugin.kt) which will
diverge from build-logic/convention; instead, change the script to perform a
targeted edit on the existing RoomConventionPlugin in build-logic/convention:
remove only the Android/KSP-specific wiring — i.e., delete or conditionalize the
apply("com.google.devtools.ksp") call and the
"kspJvm"(libs.findLibrary("androidx-room-compiler").get()) dependency while
keeping the RoomExtension.schemaDirectory and commonMainApi lines intact — so
that you do not create a second copy and Flatpak builds reuse the canonical
RoomConventionPlugin implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 91ef71f0-d5fd-4ccd-b1bf-aec2f23aa629

📥 Commits

Reviewing files that changed from the base of the PR and between cc768fa and c2bfddd.

📒 Files selected for processing (4)
  • packaging/flatpak/disable-android-for-flatpak.sh
  • packaging/flatpak/flatpak-sources.json
  • packaging/flatpak/githubstore.sh
  • packaging/flatpak/zed.rainxch.githubstore.yml

Comment on lines +11 to +13
# Force X11 (via XWayland on Wayland) — Skiko/Compose doesn't yet
# reliably support native Wayland drawing surfaces with JBR.
export GDK_BACKEND=x11
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Check if the file exists and read the relevant section
fd -t f "githubstore.sh" packaging/flatpak/ 2>/dev/null && \
  echo "=== File content (lines 1-20) ===" && \
  head -20 packaging/flatpak/githubstore.sh

Repository: OpenHub-Store/GitHub-Store

Length of output: 851


🏁 Script executed:

# Also check for the manifest file mentioned
find packaging/flatpak -type f -name "*.json" -o -name "*manifest*" -o -name "*.yml" | head -10

Repository: OpenHub-Store/GitHub-Store

Length of output: 154


🏁 Script executed:

# Look for all relevant shell scripts in the flatpak directory
ls -la packaging/flatpak/

Repository: OpenHub-Store/GitHub-Store

Length of output: 656


🏁 Script executed:

cat packaging/flatpak/zed.rainxch.githubstore.yml

Repository: OpenHub-Store/GitHub-Store

Length of output: 3463


Allow GDK_BACKEND to be overridden for Wayland-only sessions.

Line 13 hard-codes GDK_BACKEND=x11, preventing users on Wayland-only systems without XWayland from overriding it when the app fails to start. The manifest already grants Wayland socket access. While defaulting to X11 is reasonable due to current Skiko/Compose limitations, allow environment override so Wayland-only users can attempt workarounds.

Suggested change
-export GDK_BACKEND=x11
+export GDK_BACKEND="${GDK_BACKEND:-x11}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Force X11 (via XWayland on Wayland) — Skiko/Compose doesn't yet
# reliably support native Wayland drawing surfaces with JBR.
export GDK_BACKEND=x11
# Force X11 (via XWayland on Wayland) — Skiko/Compose doesn't yet
# reliably support native Wayland drawing surfaces with JBR.
export GDK_BACKEND="${GDK_BACKEND:-x11}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packaging/flatpak/githubstore.sh` around lines 11 - 13, The script currently
force-sets GDK_BACKEND to x11; change it to only default to x11 when GDK_BACKEND
is not already defined so Wayland-only users can override it. Locate the export
of GDK_BACKEND (symbol: GDK_BACKEND) and modify the assignment to use the
existing environment value if present (i.e., leave GDK_BACKEND alone when set,
otherwise set it to x11) so the manifest's Wayland socket access can be used
when desired.

Comment on lines +52 to +60
build-args:
- --share=network
build-commands:
# Use local Gradle distribution (no network in sandbox)
- sed -i 's|distributionUrl=.*|distributionUrl=gradle-bin.zip|' gradle/wrapper/gradle-wrapper.properties
# Disable Android targets (no Android SDK in Flatpak sandbox)
- bash packaging/flatpak/disable-android-for-flatpak.sh
# Build uber JAR
- ./gradlew :composeApp:packageReleaseUberJarForCurrentOS
# Build uber JAR (using non-release to avoid ProGuard duplicate jar conflicts)
- ./gradlew :composeApp:packageUberJarForCurrentOS
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Confirm the manifest still rewrites the wrapper to a local ZIP.
sed -n '52,60p' packaging/flatpak/zed.rainxch.githubstore.yml

echo
# Show the wrapper URL that exists in the repository before the Flatpak patch runs.
grep -n 'distributionUrl' gradle/wrapper/gradle-wrapper.properties

echo
# If this prints nothing, the manifest is forcing a local ZIP that is no longer staged.
find . -name 'gradle-bin.zip' -print

Repository: OpenHub-Store/GitHub-Store

Length of output: 663


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check if the disable-android-for-flatpak.sh script exists
ls -la packaging/flatpak/disable-android-for-flatpak.sh

echo "---"

# Check the full sources section of the githubstore module in the manifest
# to see if gradle-bin.zip is referenced anywhere
sed -n '40,75p' packaging/flatpak/zed.rainxch.githubstore.yml

Repository: OpenHub-Store/GitHub-Store

Length of output: 1842


Remove the sed command that forces a non-existent local Gradle distribution.

Line 56 rewrites distributionUrl to gradle-bin.zip, but this file is not staged in the manifest. With --share=network enabled, Gradle should fetch the distribution from the internet using the original URL in gradle/wrapper/gradle-wrapper.properties. The current sed command causes the build to fail immediately.

Suggested fix
-      # Use local Gradle distribution (no network in sandbox)
-      - sed -i 's|distributionUrl=.*|distributionUrl=gradle-bin.zip|' gradle/wrapper/gradle-wrapper.properties
+      # Keep the repository's wrapper URL so Gradle can fetch its own distribution
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
build-args:
- --share=network
build-commands:
# Use local Gradle distribution (no network in sandbox)
- sed -i 's|distributionUrl=.*|distributionUrl=gradle-bin.zip|' gradle/wrapper/gradle-wrapper.properties
# Disable Android targets (no Android SDK in Flatpak sandbox)
- bash packaging/flatpak/disable-android-for-flatpak.sh
# Build uber JAR
- ./gradlew :composeApp:packageReleaseUberJarForCurrentOS
# Build uber JAR (using non-release to avoid ProGuard duplicate jar conflicts)
- ./gradlew :composeApp:packageUberJarForCurrentOS
build-args:
- --share=network
build-commands:
# Keep the repository's wrapper URL so Gradle can fetch its own distribution
# Disable Android targets (no Android SDK in Flatpak sandbox)
- bash packaging/flatpak/disable-android-for-flatpak.sh
# Build uber JAR (using non-release to avoid ProGuard duplicate jar conflicts)
- ./gradlew :composeApp:packageUberJarForCurrentOS
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packaging/flatpak/zed.rainxch.githubstore.yml` around lines 52 - 60, Remove
the sed replacement that rewrites distributionUrl to gradle-bin.zip in the
build-commands (the line that runs sed on
gradle/wrapper/gradle-wrapper.properties); since --share=network is enabled the
wrapper should download the distribution from the original URL, so delete or
comment out that sed invocation and keep the remaining build-commands (including
disable-android-for-flatpak.sh and ./gradlew
:composeApp:packageUberJarForCurrentOS) intact.

Change flatpak - force X11 backend and update build sources for development
Copy link
Copy Markdown
Contributor

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packaging/flatpak/zed.rainxch.githubstore.yml`:
- Around line 51-55: Update the misleading comment in the build-commands block:
replace "Use local Gradle distribution (no network in sandbox)" with a note that
the Gradle distribution is pre-downloaded for reproducible builds and that
sandbox network access is enabled via the build-args (--share=network) so
dependency resolution may use the network; ensure the comment sits next to the
sed line modifying gradle/wrapper/gradle-wrapper.properties so readers
understand the wrapper points to a local gradle-bin.zip while network access
remains available for dependencies.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b6ec47a8-4df7-4b4c-92dd-232bbc1634e1

📥 Commits

Reviewing files that changed from the base of the PR and between c2bfddd and 7c807b3.

📒 Files selected for processing (2)
  • packaging/flatpak/githubstore.sh
  • packaging/flatpak/zed.rainxch.githubstore.yml

- Implement Flatpak detection by checking `/.flatpak-info` and environment variables.
- Add host OS detection from within Flatpak by reading `/run/host/os-release`.
- Update asset filtering to prefer native packages (`.deb`, `.rpm`) over AppImages when running in Flatpak due to FUSE limitations.
- Implement a delegated installation flow using `xdg-open` portals to hand off package installation to the host system.
- Add desktop notification support for Flatpak using `notify-send` via the notifications portal.
- Skip executable permission checks for Linux downloads when sandboxed.
Copy link
Copy Markdown
Contributor

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt`:
- Around line 516-535: The Flatpak AppImage branch only sets the executable bit
and shows a notification but the fallback shell commands are fragile and
directory-dependent; update the notification text to use the absolute path
(file.absolutePath) for both chmod and execution and make the path shell-safe by
escaping single quotes (e.g., implement a small helper like shellEscape(path:
String) and use it when building the message), and avoid suggesting "./" which
assumes current dir; also make it clear Install will not auto-open the host app
(leave launch to user) and consider adding a "Show in Files" / open-folder hint
in the notification (reference showFlatpakNotification, file.setExecutable,
file.absolutePath, file.name and add a shellEscape helper).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3a0f215a-f977-4569-84f9-355923d3e511

📥 Commits

Reviewing files that changed from the base of the PR and between 7c807b3 and 43da234.

📒 Files selected for processing (1)
  • core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt

- Implement `openInFileManager` to highlight downloaded files using D-Bus `org.freedesktop.FileManager1.ShowItems`, with a fallback to `xdg-open` on the parent directory.
- Update Flatpak notification messages to be more concise, removing absolute file paths in favor of automatically opening the file manager.
- Refactor package installation and AppImage handling to trigger the file manager focus after download.
- Simplify the fallback case for unknown file types to notify the user and open the download location.
Copy link
Copy Markdown
Contributor

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt`:
- Around line 582-604: The openInFileManager method currently attempts a gdbus
ProcessBuilder call to org.freedesktop.FileManager1 which will fail inside
Flatpak unless the manifest includes --talk-name=org.freedesktop.FileManager1,
and it constructs a GVariant string by interpolating fileUri unsafely
(vulnerable to single-quote/] injection). Fix by either removing this D-Bus
branch and relying on xdg-open, or ensure the Flatpak manifest grants
talk-name=org.freedesktop.FileManager1; if keeping the gdbus call, sanitize the
path before building the GVariant: compute an escapedPath from file.absolutePath
that replaces single quotes and other problematic chars (e.g., replace "'" with
"\\'") and use that escaped value when constructing the GVariant argument passed
to ProcessBuilder (identify openInFileManager, fileUri/escapedPath, and the
ProcessBuilder call to locate the code).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aa7628f7-8b01-4f72-8362-b946fdc449f0

📥 Commits

Reviewing files that changed from the base of the PR and between 43da234 and 8e0aa65.

📒 Files selected for processing (1)
  • core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt

Comment on lines +582 to +604
private fun openInFileManager(file: File) {
try {
// D-Bus call to org.freedesktop.FileManager1.ShowItems — this highlights
// the specific file in the file manager. Works via Flatpak portal.
val fileUri = "file://${file.absolutePath}"
val process = ProcessBuilder(
"gdbus", "call",
"--session",
"--dest", "org.freedesktop.FileManager1",
"--object-path", "/org/freedesktop/FileManager1",
"--method", "org.freedesktop.FileManager1.ShowItems",
"['$fileUri']", "",
).start()
val exitCode = process.waitFor()

if (exitCode == 0) {
Logger.d { "Opened file manager via D-Bus ShowItems: ${file.absolutePath}" }
return
}
Logger.w { "D-Bus ShowItems failed with exit code $exitCode" }
} catch (e: Exception) {
Logger.w { "D-Bus ShowItems not available: ${e.message}" }
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if FileManager1 D-Bus permission is declared
grep -r "FileManager1" packaging/flatpak/ 2>/dev/null || echo "No FileManager1 permission found"
echo "---"
# Check finish-args for talk-name permissions
grep -A 30 "finish-args" packaging/flatpak/zed.rainxch.githubstore.yml | grep "talk-name" || echo "No talk-name permissions declared"

Repository: OpenHub-Store/GitHub-Store

Length of output: 140


🏁 Script executed:

#!/bin/bash
# Check if file exists and get line count
if [ -f "core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt" ]; then
    wc -l "core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt"
else
    echo "File not found at expected path"
    # Try to find it
    find . -name "DesktopInstaller.kt" 2>/dev/null
fi

Repository: OpenHub-Store/GitHub-Store

Length of output: 154


🏁 Script executed:

#!/bin/bash
# Read the openInFileManager method context (lines 575-614)
if [ -f "core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt" ]; then
    echo "=== Lines 575-614 ==="
    sed -n '575,614p' "core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt"
else
    echo "File not found, searching..."
    find . -name "DesktopInstaller.kt" -exec echo "Found: {}" \; -exec head -650 {} \; 2>/dev/null | tail -100
fi

Repository: OpenHub-Store/GitHub-Store

Length of output: 1794


🏁 Script executed:

#!/bin/bash
# Verify package naming compliance with coding guideline: zed.rainxch.{module}.{layer}
grep -n "^package " "core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt" 2>/dev/null || echo "Package declaration not found"

Repository: OpenHub-Store/GitHub-Store

Length of output: 110


D-Bus FileManager1 call will fail in Flatpak; GVariant argument is injection-vulnerable.

Two issues:

  1. Missing D-Bus permission: The code comment claims the D-Bus call "works via Flatpak portal," but this is misleading. The org.freedesktop.FileManager1 service is not a Flatpak portal — it requires explicit --talk-name=org.freedesktop.FileManager1 in the manifest's finish-args. This permission is not currently declared, so the gdbus call will fail with a permission error and always fall back to xdg-open. Either add the permission to the manifest, or remove this dead code path entirely and rely solely on xdg-open.

  2. GVariant format injection: The file URI is interpolated directly into ['$fileUri']. Paths containing ' or ] will break GVariant parsing. For example, a file named app'name.deb produces ['file:///path/app'name.deb'] with unbalanced quotes. Escape single quotes in the path: val escapedPath = file.absolutePath.replace("'", "\\'") and use it in the GVariant argument.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt`
around lines 582 - 604, The openInFileManager method currently attempts a gdbus
ProcessBuilder call to org.freedesktop.FileManager1 which will fail inside
Flatpak unless the manifest includes --talk-name=org.freedesktop.FileManager1,
and it constructs a GVariant string by interpolating fileUri unsafely
(vulnerable to single-quote/] injection). Fix by either removing this D-Bus
branch and relying on xdg-open, or ensure the Flatpak manifest grants
talk-name=org.freedesktop.FileManager1; if keeping the gdbus call, sanitize the
path before building the GVariant: compute an escapedPath from file.absolutePath
that replaces single quotes and other problematic chars (e.g., replace "'" with
"\\'") and use that escaped value when constructing the GVariant argument passed
to ProcessBuilder (identify openInFileManager, fileUri/escapedPath, and the
ProcessBuilder call to locate the code).

# Conflicts:
#	core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt
Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (1)
core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt (1)

264-299: Consider extracting shared distro classification logic.

The distro classification (checking ID/ID_LIKE for Debian/RPM-based systems) is duplicated between detectHostLinuxPackageType and determineLinuxPackageType. A small helper could reduce duplication:

private fun classifyDistro(id: String, idLike: String): LinuxPackageType {
    if (id in listOf("debian", "ubuntu", "linuxmint", "pop", "elementary") ||
        idLike.contains("debian") || idLike.contains("ubuntu")) {
        return LinuxPackageType.DEB
    }
    if (id in listOf("fedora", "rhel", "centos", "rocky", "almalinux", "opensuse", "suse") ||
        idLike.contains("fedora") || idLike.contains("rhel") ||
        idLike.contains("suse") || idLike.contains("centos")) {
        return LinuxPackageType.RPM
    }
    return LinuxPackageType.UNIVERSAL
}

Otherwise, the approach of reading /run/host/os-release for Flatpak is correct.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt`
around lines 264 - 299, Extract the duplicated distro classification logic into
a private helper (e.g., classifyDistro(id: String, idLike: String):
LinuxPackageType) and replace the inlined ID/ID_LIKE checks in both
detectHostLinuxPackageType() and determineLinuxPackageType() to call that
helper; ensure the helper returns LinuxPackageType.DEB for Debian/Ubuntu family
checks, LinuxPackageType.RPM for Fedora/RHEL/SUSE families, and
LinuxPackageType.UNIVERSAL otherwise, and keep the existing logging in the
caller functions (or add minimal caller-specific logs) so behavior and return
values remain identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt`:
- Around line 264-299: Extract the duplicated distro classification logic into a
private helper (e.g., classifyDistro(id: String, idLike: String):
LinuxPackageType) and replace the inlined ID/ID_LIKE checks in both
detectHostLinuxPackageType() and determineLinuxPackageType() to call that
helper; ensure the helper returns LinuxPackageType.DEB for Debian/Ubuntu family
checks, LinuxPackageType.RPM for Fedora/RHEL/SUSE families, and
LinuxPackageType.UNIVERSAL otherwise, and keep the existing logging in the
caller functions (or add minimal caller-specific logs) so behavior and return
values remain identical.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5166e9b9-5fee-4cc1-9cf7-611384afa6da

📥 Commits

Reviewing files that changed from the base of the PR and between 8e0aa65 and 10f49f8.

📒 Files selected for processing (1)
  • core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt

… installation

- Clear `cachedDownloadAssetName` on non-Android platforms when a file is installed or handed off to the system.
- Prevents the `onCleared()` lifecycle method from deleting the downloaded asset once it has been saved to the user's downloads or installed.
- Update Flatpak manifest to support fully offline builds by removing network access during the build stage.
- Configure Gradle to use a pre-populated offline Maven repository via `settings.gradle.kts` injection.
- Update build commands to use the `--offline` flag and local Gradle distribution.
- Switch source from local directory to GitHub repository tagged at version `1.6.2`.
- Include `flatpak-sources.json` for pre-downloaded dependencies.
- Add branding colors (light and dark schemes) to the AppStream metainfo file.
…-logic resolution

- Replace basic `settings.gradle.kts` appending with a Python-based rewriting script for both root and `build-logic` settings.
- Configure `pluginManagement` and `dependencyResolutionManagement` to strictly use the local offline repository for all project modules.
- Explicitly include `build-logic` and configure its version catalog resolution from `gradle/libs.versions.toml`.
- Update build source from a remote Git tag to the local directory for development builds.
- Remove the `--offline` flag from the Gradle execution as network isolation is handled by the Flatpak sandbox.
- Update comments to clarify Flathub submission requirements for source types.
- Add `flatpak-gradle-generator` plugin to the Version Catalog.
- Update the root `flatpakGradleGenerator` task to output to `packaging/flatpak/flatpak-sources.json` and exclude test configurations.
- Apply and configure the generator plugin within `build-logic/convention` to generate `flatpak-sources-convention.json`.
- Update the Flatpak manifest to include the newly generated convention sources.
- Set the generator's download directory to `./offline-repository` for dependency caching.
- Add `ls` and `find` commands to the Flatpak manifest to debug the directory structure and locate `gradle-wrapper.properties` during the build process.
- Add `.gitattributes` to ensure Flatpak packaging files use Unix LF line endings to prevent parsing errors in `flatpak-builder`.
- Remove debug `ls` and `find` commands from the Flatpak build manifest.
- Remove `flatpak-sources-convention.json` and `flatpak-sources-manual.json` from the build sources.
@rainxchzed rainxchzed merged commit 0d44525 into main Mar 23, 2026
1 check passed
@rainxchzed rainxchzed deleted the flatpak-pr branch March 23, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant