|
| 1 | +package dev.encore.intellij |
| 2 | + |
| 3 | +import com.intellij.openapi.project.Project |
| 4 | +import com.intellij.openapi.startup.StartupActivity |
| 5 | +import com.intellij.util.text.SemVer |
| 6 | +import dev.encore.intellij.sqldb.Detector |
| 7 | +import dev.encore.intellij.utils.isInEncoreApp |
| 8 | +import dev.encore.intellij.utils.runEncoreCommand |
| 9 | + |
| 10 | +/* |
| 11 | + * Startup Activity allows us to run blocking external calls to the encore daemon to extract information |
| 12 | + * about the project, which we can then store and reference at runtime |
| 13 | + */ |
| 14 | +class StartupActivity : StartupActivity.Background, StartupActivity.RequiredForSmartMode { |
| 15 | + override fun runActivity(project: Project) { |
| 16 | + // Skip our startup if it's not an Encore app |
| 17 | + if (!isInEncoreApp(project)) { |
| 18 | + return |
| 19 | + } |
| 20 | + |
| 21 | + Encore.LOG.info("Performing startup activity for Encore...") |
| 22 | + |
| 23 | + // Verify Encore is installed |
| 24 | + val versionOutput = runEncoreCommand(project, "version") ?: return |
| 25 | + if (!versionOutput.startsWith("encore version ")) { |
| 26 | + return |
| 27 | + } |
| 28 | + Encore.encoreInstalled = true |
| 29 | + |
| 30 | + // Get the version |
| 31 | + val versionString = versionOutput.trim().lines()[0].removePrefix("encore version ") |
| 32 | + if (versionString.startsWith("v")) { |
| 33 | + Encore.encoreVersion = SemVer.parseFromText(versionString.removePrefix("v")) |
| 34 | + } else { |
| 35 | + // If the version string doesn't start with v then it's a dev build, so default to 999.999.999 |
| 36 | + Encore.encoreVersion = SemVer(versionString, 999, 999, 999) |
| 37 | + } |
| 38 | + Encore.LOG.info("Verified that Encore is installed and running version ${Encore.encoreVersion}") |
| 39 | + |
| 40 | + // Ask encore for the database connection info |
| 41 | + if (Encore.isAtLeast(1, 9, 2)) { |
| 42 | + Encore.LOG.info("Getting database connection information from Encore...") |
| 43 | + Detector.loadDatabaseConnection(project) |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments