-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
Submodule gui
updated
5 files
+14 −6 | src/util/MessageUtil.ts | |
+56 −2 | src/util/ideaBridge.ts | |
+49 −3 | src/views/App.tsx | |
+1 −6 | src/views/pages/Config.tsx | |
+153 −74 | src/views/stores/ConfigStore.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/ai/devchat/core/handlers/GetServerSettingsRequestHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ai.devchat.core.handlers | ||
|
||
import ai.devchat.core.BaseActionHandler | ||
import ai.devchat.core.DevChatActions | ||
import ai.devchat.storage.SERVER_CONFIG | ||
import com.alibaba.fastjson.JSONObject | ||
import com.intellij.openapi.diagnostic.Logger | ||
|
||
|
||
class GetServerSettingsRequestHandler(requestAction: String, metadata: JSONObject?, payload: JSONObject?) : BaseActionHandler( | ||
requestAction, | ||
metadata, | ||
payload | ||
) { | ||
private val logger = Logger.getInstance(GetServerSettingsRequestHandler::class.java) | ||
override val actionName: String = DevChatActions.GET_SERVER_SETTINGS_RESPONSE | ||
@Suppress("UNCHECKED_CAST") | ||
override fun action() { | ||
logger.info("^^^^^^^^^^^^^^^^^^^^^ get server settings") | ||
send(payload= SERVER_CONFIG.get() as? Map<String, *>) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/ai/devchat/core/handlers/UpdateServerSettingsRequestHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ai.devchat.core.handlers | ||
|
||
import ai.devchat.core.BaseActionHandler | ||
import ai.devchat.core.DevChatActions | ||
import ai.devchat.storage.SERVER_CONFIG | ||
import com.alibaba.fastjson.JSONObject | ||
|
||
class UpdateServerSettingsRequestHandler(requestAction: String, metadata: JSONObject?, payload: JSONObject?) : BaseActionHandler( | ||
requestAction, | ||
metadata, | ||
payload | ||
) { | ||
override val actionName: String = DevChatActions.UPDATE_SERVER_SETTINGS_RESPONSE | ||
|
||
override fun action() { | ||
SERVER_CONFIG.replaceAll(payload!!) | ||
send() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ai.devchat.storage | ||
|
||
import ai.devchat.common.PathUtils | ||
import com.fasterxml.jackson.core.type.TypeReference | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import java.io.File | ||
import java.nio.file.Paths | ||
|
||
class ServerConfig( | ||
private val configPath: String = Paths.get(PathUtils.workPath, "server_config.yml").toString() | ||
) { | ||
private var data: MutableMap<String, Any?> = mutableMapOf() | ||
|
||
init { load() } | ||
|
||
fun load(): Map<String, Any?> { | ||
val mapper = ObjectMapper(YAMLFactory()).apply { registerKotlinModule() } | ||
val configFile = File(configPath) | ||
data = if (configFile.isFile) { | ||
try { | ||
mapper.readValue(configFile, dataType) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
mutableMapOf() | ||
} | ||
} else { mutableMapOf() } | ||
return data | ||
} | ||
|
||
fun save() { | ||
val file = File(configPath) | ||
file.parentFile?.takeIf { !it.exists() }?.mkdirs() //Ensure parent directories exist | ||
val mapper = ObjectMapper(YAMLFactory()) | ||
try { | ||
mapper.writeValue(file, data) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
throw RuntimeException("Failed to save config", e) | ||
} | ||
} | ||
|
||
fun get(): Any { | ||
return data | ||
} | ||
|
||
fun replaceAll(newData: Map<String, Any?>) { | ||
data = newData.toMutableMap() | ||
save() | ||
} | ||
|
||
companion object { | ||
val dataType = object : TypeReference<MutableMap<String, Any?>>() {} | ||
} | ||
} | ||
|
||
val SERVER_CONFIG: ServerConfig = ServerConfig() |