Skip to content

Commit

Permalink
update ui take 2
Browse files Browse the repository at this point in the history
  • Loading branch information
shalom938 committed Dec 11, 2024
1 parent 460fcb1 commit 6697ebe
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fun getPluginVersion(defaultIfNotFound: String = "0.0.0"): String {
}

fun getUiVersion(): String {
return service<UIVersioningService>().getCurrentUiVersion()
return service<UIVersioningService>().getUiVersionForVersionRequest()
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.digma.intellij.plugin.paths

import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.application.ApplicationNamesInfo
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.util.SystemInfo
import org.digma.intellij.plugin.errorreporting.ErrorReporter
import java.io.File

const val DIGMA_DIR = "digma-intellij-plugin"

class DigmaPathManager {


companion object {

fun getLocalFilesDirectoryPath(): String {
val ideFullName = ApplicationNamesInfo.getInstance().fullProductNameWithEdition
val ideHomeDir = PathManager.getHomePath().substringAfterLast("/")
val ideName = "$ideFullName-$ideHomeDir".replace(" ", "-").replace(".","-")
return try {
val baseDir = getBaseDirectory()
val ideDir = File(baseDir,ideName)
ideDir.mkdirs()
ideDir.absolutePath
}catch (e:Throwable){
ErrorReporter.getInstance().reportError("DigmaPathManager.getLocalFilesDirectoryPath", e)
val fallback = File(System.getProperty("java.io.tmpdir"), "$DIGMA_DIR/$ideName")
fallback.mkdirs()
fallback.absolutePath
}
}


private fun getUserHome(): String {
//user.home should never be null, but just in case,use temp dir
return System.getProperty("user.home") ?: System.getProperty("java.io.tmpdir")
}


private fun getBaseDirectory(): File {

return try {
if (SystemInfo.isMac) {
val userHome = getUserHome()
val digmaDir = File(userHome, "Library/Application Support/$DIGMA_DIR")
digmaDir.mkdirs()
digmaDir
} else if (SystemInfo.isWindows) {
val userHome = System.getenv("LOCALAPPDATA") ?: getUserHome()
val digmaDir = File(userHome, DIGMA_DIR)
digmaDir.mkdirs()
digmaDir
} else {
//for linux or any other os
val userHome = getUserHome()
val digmaDir = File(userHome, ".$DIGMA_DIR")
digmaDir.mkdirs()
digmaDir
}

} catch (e: Throwable) {
ErrorReporter.getInstance().reportError("DigmaPathManager.getBaseDirectory", e)
val userHome = getUserHome()
val digmaDir = File(userHome, ".$DIGMA_DIR")
digmaDir.mkdirs()
digmaDir
}

}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ internal data class PersistenceData(

var engagementScorePersistenceFileFixed: Boolean = false,

var currentUiVersion: String? = null
var currentUiVersion: String? = null,
var latestDownloadedUiVersion: String? = null

)
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,12 @@ class PersistenceService {
state.currentUiVersion = uiVersion
}

fun getLatestDownloadedUiVersion(): String? {
return state.latestDownloadedUiVersion
}

fun setLatestDownloadedUiVersion(uiVersion: String?) {
state.latestDownloadedUiVersion = uiVersion
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.digma.intellij.plugin.reload

enum class ReloadSource {
RELOAD_ACTION,RELOAD_OBSERVER
RELOAD_ACTION,RELOAD_OBSERVER,UI_UPDATE
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ data class UpdateState(
val backendDeploymentType: BackendDeploymentType,
val shouldUpdateBackend: Boolean,
val shouldUpdatePlugin: Boolean,
val shouldUpdateUi: Boolean,
) {

fun shouldUpdateAny(): Boolean {
return shouldUpdateBackend || shouldUpdatePlugin
return shouldUpdateBackend || shouldUpdatePlugin || shouldUpdateUi
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.digma.intellij.plugin.scheduling.disposingPeriodicTask
import org.digma.intellij.plugin.scheduling.oneShotTask
import org.digma.intellij.plugin.settings.InternalFileSettings
import org.digma.intellij.plugin.ui.panels.DigmaResettablePanel
import org.digma.intellij.plugin.updates.ui.UIVersioningService
import java.util.concurrent.TimeUnit
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -174,6 +175,7 @@ class UpdatesService(private val project: Project) : Disposable {
stateBackendVersion.deploymentType,
shouldUpdateBackend(),
shouldUpdatePlugin(),
UIVersioningService.getInstance().isNewUIBundleAvailable()
)
Log.log(logger::debug, "current state is {}", state)
return state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class UIResourcesService {

private fun getUIBundlePath():String{
//todo: support also downloading from url
return System.getProperty("org.digma.plugin.ui.bundle.path") ?:UIVersioningService.getInstance().currentUiBundlePath
return System.getProperty("org.digma.plugin.ui.bundle.path") ?:UIVersioningService.getInstance().getCurrentUiBundlePath()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import org.digma.intellij.plugin.startup.DigmaProjectActivity
class UIUpdateStarter : DigmaProjectActivity() {

override fun executeProjectStartup(project: Project) {
UIVersioningService.getInstance().updateUiBundleOnStartup(project)
UIVersioningService.getInstance()
}
}
Loading

0 comments on commit 6697ebe

Please sign in to comment.