Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WorkflowBridge(
private val aiRequestQuery = JBCefJSQuery.create(browser as JBCefBrowserBase)
private val resolveFileQuery = JBCefJSQuery.create(browser as JBCefBrowserBase)
private val saveFilesQuery = JBCefJSQuery.create(browser as JBCefBrowserBase)
private val layoutQuery = JBCefJSQuery.create(browser as JBCefBrowserBase)
private var updatingFromEditor = false
private var updatingFromWebview = false

Expand Down Expand Up @@ -63,6 +64,13 @@ class WorkflowBridge(
JBCefJSQuery.Response("")
}

this.layoutQuery.addHandler { layoutJson ->
val yamlPath = file.path
val sidecarPath = yamlPath.replace(Regex("\\.ya?ml$"), ".workflow-editor.json")
java.io.File(sidecarPath).writeText(layoutJson)
null
}

// Inject bridge functions after page load
browser.jbCefClient.addLoadHandler(object : CefLoadHandlerAdapter() {
override fun onLoadEnd(b: CefBrowser?, frame: org.cef.browser.CefFrame?, httpStatusCode: Int) {
Expand Down Expand Up @@ -97,6 +105,9 @@ class WorkflowBridge(
},
sendSaveFiles: function(data) {
${saveFilesQuery.inject("data")}
},
saveLayout: function(json) {
${layoutQuery.inject("json")}
}
};
window.dispatchEvent(new Event('hostBridgeReady'));
Expand All @@ -116,6 +127,16 @@ class WorkflowBridge(
"", 0
)
updatingFromEditor = false

val sidecarPath = file.path.replace(Regex("\\.ya?ml$"), ".workflow-editor.json")
val sidecarFile = java.io.File(sidecarPath)
if (sidecarFile.exists()) {
val escaped = sidecarFile.readText()
.replace("\\", "\\\\")
.replace("`", "\\`")
.replace("\$", "\\\$")
browser.cefBrowser.executeJavaScript("window.onLayoutLoaded && window.onLayoutLoaded(JSON.parse(`$escaped`))", "", 0)
}
}

private fun handleYamlFromWebview(content: String) {
Expand Down Expand Up @@ -385,5 +406,6 @@ class WorkflowBridge(
aiRequestQuery.dispose()
resolveFileQuery.dispose()
saveFilesQuery.dispose()
layoutQuery.dispose()
}
}
Loading