ADFA-2673 | Refactor and centralize auto-open project logic#899
ADFA-2673 | Refactor and centralize auto-open project logic#899
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughCentralizes project validation into new utilities and updates project-opening flows: MainActivity moves last-project discovery to an IO coroutine, adds handleOpenProject(root: File) for permission-guarded opening, and RecentProjectsFragment now uses shared validation utilities instead of local helpers. (46 words) Changes
Sequence DiagramsequenceDiagram
participant UI as MainActivity (UI)
participant IO as IO Dispatcher
participant PV as ProjectValidations
participant Handler as handleOpenProject
participant Perm as Permission flow
UI->>IO: tryOpenLastProject()
IO->>PV: findValidProjects(projectsRoot)
PV-->>IO: validProjects
IO-->>UI: candidateProject (withContext Main)
alt project found
UI->>Handler: handleOpenProject(root)
Handler->>Perm: check confirmProjectOpen / permissions
alt confirmation required
Perm-->>UI: askProjectOpenPermission(root)
else no confirmation
Handler-->>UI: openProject(root)
end
else no project found
UI->>UI: show missing / skip auto-open
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@app/src/main/java/com/itsaky/androidide/activities/MainActivity.kt`:
- Around line 262-285: The auto-open logic in tryOpenLastProject currently only
considers projects returned by findValidProjects(Environment.PROJECTS_DIR),
which skips a valid GeneralPreferences.lastOpenedProject if it's outside
PROJECTS_DIR; change the selection so you first check if
GeneralPreferences.lastOpenedProject is non-blank and points to an existing
valid project (use isValidProjectDirectory(path) or equivalent) and if so set
projectToOpen to that File, otherwise fall back to selecting the most recent
project from findValidProjects(Environment.PROJECTS_DIR); keep the existing UI
branch that calls handleOpenProject(projectToOpen) and the flashInfo path for
missing lastOpenedPath.
e536016 to
e82ba6a
Compare
4eb5896 to
7c12bd2
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/src/main/java/com/itsaky/androidide/fragments/RecentProjectsFragment.kt (1)
285-291:⚠️ Potential issue | 🟡 MinorPotential race condition:
insertProjectFromFolderis not awaited before opening the project.At lines 322-328, you correctly collect jobs and call
joinAll()before opening. However, here the project is opened immediately afterinsertProjectFromFolderwithout waiting for the insertion to complete. If the insertion is asynchronous, the database entry may not exist when subsequent operations (e.g.,onResumecallingloadProjects) execute.🔧 Proposed fix to await the insertion
if (isValidProjectDirectory(directory)) { - viewModel.insertProjectFromFolder( + val job = viewModel.insertProjectFromFolder( name = directory.name, location = directory.absolutePath ) + viewLifecycleScope.launch { + job.join() + openProject(root = directory) + } + return +} - - openProject(root = directory) - return -}Alternatively, if the insertion is synchronous or fire-and-forget by design, consider adding a comment clarifying the intent.
3f9beab to
d66b45d
Compare
…ve validation utils to shared file and improve startup project detection
f1dee78 to
d28722e
Compare
Description
This PR refactors the project opening logic to centralize the "Auto Open" feature within
MainActivity, removing the dependency onRecentProjectsFragmentfor this task. It introduces a robust fallback mechanism that scans the file system to ensure the project exists before attempting to open it.Details
findValidProjects,isValidProjectDirectory, etc.) fromRecentProjectsFragmentinto a new utility fileProjectValidations.ktto allow shared access.MainActivity.tryOpenLastProject()to run onDispatchers.IO. It now verifies physically existing projects.lastOpenedProjectpreference points to a non-existent directory (or is empty), the app now automatically attempts to open the most recently modified valid project found in the projects directory.Screen.Recording.2026-01-28.at.2.02.06.PM.mov
Ticket
ADFA-2673
Observation
The validation logic was duplicated and isolated in the fragment previously. Moving it to
ProjectValidations.ktmakes it reusable and testable. The new logic inMainActivityhandles edge cases where the user might have deleted the project folder externally.