diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 91b07cd..11ab68b 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -21,9 +21,5 @@ Just open the project and use “Run Plugin” in the run drop down. ## Develop with Neovim - Make sure to enable [`kotlin_language_server` from nvim-lspconfig][nvim-kls]. -- Overwrite `cmd` by following [this fix][kls-fix] ([use the new Kotlin language server][community-kls] - because this language server is better maintained works with this plugin) [nvim-kls]: https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md#kotlin_language_server -[kls-fix]: https://github.com/fwcd/kotlin-language-server/issues/600#issuecomment-2471327399 -[community-kls]: https://github.com/kotlin-community-tools/kotlin-language-server diff --git a/src/main/kotlin/io/github/ethersync/EthersyncService.kt b/src/main/kotlin/io/github/ethersync/EthersyncService.kt index 306abd5..893030a 100644 --- a/src/main/kotlin/io/github/ethersync/EthersyncService.kt +++ b/src/main/kotlin/io/github/ethersync/EthersyncService.kt @@ -2,7 +2,7 @@ package io.github.ethersync interface EthersyncService { - fun start(peer: String?) + fun start(joinCode: String?) fun shutdown() diff --git a/src/main/kotlin/io/github/ethersync/EthersyncServiceImpl.kt b/src/main/kotlin/io/github/ethersync/EthersyncServiceImpl.kt index 1460744..5b5dd0b 100644 --- a/src/main/kotlin/io/github/ethersync/EthersyncServiceImpl.kt +++ b/src/main/kotlin/io/github/ethersync/EthersyncServiceImpl.kt @@ -35,6 +35,8 @@ import org.eclipse.lsp4j.jsonrpc.ResponseErrorException import java.io.BufferedReader import java.io.File import java.io.InputStreamReader +import java.nio.file.Files +import java.nio.file.attribute.PosixFilePermissions import java.util.concurrent.Executors private val LOG = logger() @@ -128,20 +130,16 @@ class EthersyncServiceImpl( cursortracker.clear() } - override fun start(peer: String?) { - val socket = "ethersync-%s-socket".format(project.name) - + override fun start(joinCode: String?) { val cmd = GeneralCommandLine(AppSettings.getInstance().state.ethersyncBinaryPath) - cmd.addParameter("daemon") - peer?.let { - if (peer.isNotBlank()) { - cmd.addParameter("--peer") - cmd.addParameter(peer) - } + if (joinCode == null || joinCode.trim().isEmpty()) { + cmd.addParameter("share") + } + else { + cmd.addParameter("join") + cmd.addParameter(joinCode.trim()) } - cmd.addParameter("--socket-name") - cmd.addParameter(socket) launchDaemon(cmd) } @@ -158,24 +156,13 @@ class EthersyncServiceImpl( val ethersyncDirectory = File(projectDirectory, ".ethersync") cmd.workDirectory = projectDirectory - var socket: String? = null - if (cmd.parametersList.hasParameter("--socket-name") || cmd.parametersList.hasParameter("-s")) { - for (i in 0..(cmd.parametersList.parametersCount - 1)) { - val name = cmd.parametersList[i] - - if (name == "--socket-name" || name == "-s") { - socket = cmd.parametersList[i + 1] - break - } - } - } - cs.launch { shutdownImpl() if (!ethersyncDirectory.exists()) { LOG.debug("Creating ethersync directory") - ethersyncDirectory.mkdir() + val permissions = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwx------")); + Files.createDirectory(ethersyncDirectory.toPath(), permissions); } withContext(Dispatchers.EDT) { @@ -183,8 +170,8 @@ class EthersyncServiceImpl( daemonProcess!!.addProcessListener(object : ProcessListener { override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) { - if (event.text.contains("Others can connect with")) { - launchEthersyncClient(socket, projectDirectory) + if (event.text.contains("One other person can use this to connect to you") || event.text.contains("Connected to peer:")) { + launchEthersyncClient(projectDirectory) } } @@ -221,26 +208,15 @@ class EthersyncServiceImpl( } } - private fun launchEthersyncClient(socket: String?, projectDirectory: File) { + private fun launchEthersyncClient(projectDirectory: File) { if (clientProcess != null) { return } cs.launch { - val cmd = GeneralCommandLine(AppSettings.getInstance().state.ethersyncBinaryPath) - cmd.workDirectory = projectDirectory - cmd.addParameter("client") - - socket?.let { - cmd.addParameter("--socket-name") - cmd.addParameter(it) - } - LOG.info("Starting ethersync client") // TODO: try catch not existing binary - val clientProcessBuilder = ProcessBuilder( - AppSettings.getInstance().state.ethersyncBinaryPath, - "client", "--socket-name", socket) + val clientProcessBuilder = ProcessBuilder(AppSettings.getInstance().state.ethersyncBinaryPath, "client") .directory(projectDirectory) clientProcess = clientProcessBuilder.start() val clientProcess = clientProcess!! diff --git a/src/main/kotlin/io/github/ethersync/StartEthersyncDaemonAction.kt b/src/main/kotlin/io/github/ethersync/StartEthersyncDaemonAction.kt index ef7ec23..ea57025 100644 --- a/src/main/kotlin/io/github/ethersync/StartEthersyncDaemonAction.kt +++ b/src/main/kotlin/io/github/ethersync/StartEthersyncDaemonAction.kt @@ -11,17 +11,17 @@ class StartEthersyncDaemonAction : AnAction("Connect to peer", "Connect to a run override fun actionPerformed(e: AnActionEvent) { val project = e.project ?: return - val address = Messages.showInputDialog( + val joinCode = Messages.showInputDialog( project, - "Provide ethersync peer address. Leave empty if you want to host a new session.", - "Peer Address", + "Provide ethersync join code. Leave empty if you want to host a new session.", + "Join Code", Icons.ToolbarIcon ) - if (address != null) { + if (joinCode != null) { val service = project.service() - service.start(address) + service.start(joinCode) } } } diff --git a/src/main/kotlin/io/github/ethersync/StartEthersyncDaemonTerminalShellCommandHandler.kt b/src/main/kotlin/io/github/ethersync/StartEthersyncDaemonTerminalShellCommandHandler.kt index a338973..8511b0c 100644 --- a/src/main/kotlin/io/github/ethersync/StartEthersyncDaemonTerminalShellCommandHandler.kt +++ b/src/main/kotlin/io/github/ethersync/StartEthersyncDaemonTerminalShellCommandHandler.kt @@ -14,17 +14,19 @@ class StartEthersyncDaemonTerminalShellCommandHandler : TerminalShellCommandHand command: String, executor: Executor ): Boolean { - workingDirectory?.let { - if (project.basePath != it) { - return false - } - } val ethersyncService = project.service() ethersyncService.startWithCustomCommandLine(command) return true } override fun matches(project: Project, workingDirectory: String?, localSession: Boolean, command: String): Boolean { + if (workingDirectory == null) { + return false + } + else if (project.basePath != workingDirectory) { + return false + } + val ethersyncBinary = AppSettings.getInstance().state.ethersyncBinaryPath if (!command.startsWith(ethersyncBinary)) { @@ -33,6 +35,6 @@ class StartEthersyncDaemonTerminalShellCommandHandler : TerminalShellCommandHand val rest = command.substring(ethersyncBinary.length).trim() - return rest.startsWith("daemon") + return rest.startsWith("share") || rest.startsWith("join") } }