Skip to content

Commit

Permalink
added wsl support
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiNageswarS committed Apr 5, 2021
1 parent 63ef6e1 commit acbc3da
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ jobs:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/compose/binaries/main/deb/omnishell_1.0.0-1_amd64.deb
asset_name: omnishell_1.0.0-1_amd64.deb
tag: Linux-0.0.5
tag: Linux-0.0.6
overwrite: true
body: "Linux Debian file"
2 changes: 1 addition & 1 deletion .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ jobs:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/compose/binaries/main/dmg/OmniShell-1.0.0.dmg
asset_name: OmniShell-1.0.0.dmg
tag: Mac-0.0.5
tag: Mac-0.0.6
overwrite: true
body: "Mac OS DMG"
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ jobs:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build\compose\binaries\main\msi\OmniShell-1.0.0.msi
asset_name: OmniShell-1.0.0.msi
tag: Windows-0.0.5
tag: Windows-0.0.6
overwrite: true
body: "Windows exe file"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Get latest version of Omnishell for your OS from:
https://github.com/SaiNageswarS/Omnishell/releases

# Notes
1. For adding to path edit ~/config/OmnishellEnv.json.
1. For adding to path, run export PATH=newPath:$PATH. Then click save to store new path permanently.



26 changes: 4 additions & 22 deletions src/main/kotlin/com/kotlang/HostAgent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.kotlang

import com.google.protobuf.StringValue
import com.kotlang.omnishell.*
import com.kotlang.remoting.RemoteTargetManager
import io.grpc.ManagedChannel
import io.grpc.ManagedChannelBuilder
import kotlinx.coroutines.runBlocking

class HostAgent(host: String, port: Int) {
class HostAgent(remoteHost: RemoteTargetManager) {
private val channel: ManagedChannel

val historyManagerClient: HistoryManagerGrpcKt.HistoryManagerCoroutineStub
Expand All @@ -17,28 +18,9 @@ class HostAgent(host: String, port: Int) {

val process: Process

private fun getHostAgentUrl(): String {
val os = System.getProperty("os.name").toLowerCase()
return when {
os.indexOf("win") >= 0 -> "$hostManagerPath/hostManager/windows/OmnishellProcessManager.exe"
os.indexOf("mac") >= 0 -> {
val hostAgentUrl = "$hostManagerPath/hostManager/mac/OmnishellProcessManager"
Runtime.getRuntime().exec("chmod +x $hostAgentUrl")
hostAgentUrl
}
else -> {
val hostAgentUrl = "$hostManagerPath/hostManager/linux/OmnishellProcessManager"
Runtime.getRuntime().exec("chmod +x $hostAgentUrl")
hostAgentUrl
}
}
}

init {
val hostAgentUrl = getHostAgentUrl()
process = Runtime.getRuntime().exec("$hostAgentUrl :$port $hostManagerPath/hostManager/app.log")

channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build()
process = remoteHost.runRemoteHostManager()
channel = ManagedChannelBuilder.forAddress(remoteHost.host, remoteHost.port).usePlaintext().build()
historyManagerClient = HistoryManagerGrpcKt.HistoryManagerCoroutineStub(channel)
autoCompleteClient = AutoCompleteServiceGrpcKt.AutoCompleteServiceCoroutineStub(channel)
fileSystemClient = FileSystemManagerGrpcKt.FileSystemManagerCoroutineStub(channel)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/kotlang/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.desktop.WindowEvents
import androidx.compose.material.*
import com.kotlang.ui.window.OmnishellWindow
import com.kotlang.ui.window.SplashWindow
import com.kotlang.util.HostManagerUtil
import com.kotlang.util.HostAgentDownloadUtil
import com.kotlang.util.VersionVerificationUtil
import java.net.URL
import java.nio.file.Files
Expand All @@ -22,7 +22,7 @@ fun main() {

if (!Files.exists(Path.of("$hostManagerPath/hostManager"))) {
Files.createDirectories(hostManagerPath)
HostManagerUtil.downloadHostManager(hostManagerPath)
HostAgentDownloadUtil.downloadHostManager(hostManagerPath)
}

//show splash screen
Expand Down
24 changes: 24 additions & 0 deletions src/main/kotlin/com/kotlang/remoting/LocalTargetManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.kotlang.remoting

import com.kotlang.hostManagerPath
import com.kotlang.util.PortUtil

class LocalTargetManager: RemoteTargetManager() {
private val availablePort = PortUtil.getFreePort()
override fun runRemoteHostManager(): Process {
val os = System.getProperty("os.name").toLowerCase()
val hostAgentUrl = getHostAgentUrl(os)

if (os.indexOf("mac") >= 0 || os.indexOf("linux") >= 0) {
val p = Runtime.getRuntime().exec("chmod +x $hostAgentUrl")
p.waitFor()
}

return Runtime.getRuntime().exec("$hostAgentUrl :$availablePort $hostManagerPath/hostManager/app.log")
}

override val port: Int
get() = availablePort
override val host: String
get() = "localhost"
}
24 changes: 24 additions & 0 deletions src/main/kotlin/com/kotlang/remoting/RemoteTargetManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.kotlang.remoting

import com.kotlang.hostManagerPath

abstract class RemoteTargetManager {
abstract fun runRemoteHostManager(): Process

abstract val port: Int
abstract val host: String

fun getHostAgentUrl(os: String): String {
return when {
os.indexOf("win") >= 0 -> "$hostManagerPath/hostManager/windows/OmnishellProcessManager.exe"
os.indexOf("mac") >= 0 -> {
val hostAgentUrl = "$hostManagerPath/hostManager/mac/OmnishellProcessManager"
hostAgentUrl
}
else -> {
val hostAgentUrl = "$hostManagerPath/hostManager/linux/OmnishellProcessManager"
hostAgentUrl
}
}
}
}
27 changes: 0 additions & 27 deletions src/main/kotlin/com/kotlang/remoting/Wsl.kt

This file was deleted.

56 changes: 56 additions & 0 deletions src/main/kotlin/com/kotlang/remoting/WslTargetManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.kotlang.remoting

import com.kotlang.hostManagerPath
import com.kotlang.util.PortUtil
import java.util.*

class WslTargetManager(private val wslTarget: String): RemoteTargetManager() {
companion object {
fun listWsl(): List<String> {
val os = System.getProperty("os.name").toLowerCase()
val result = mutableListOf<String>()
if (os.indexOf("win") >= 0) {
val process = Runtime.getRuntime().exec("wsl --list")
process.waitFor()
val sc = Scanner(process.inputStream)
sc.nextLine()
while (sc.hasNextLine()) {
var outLine = sc.nextLine()

outLine = outLine.replace(0.toChar().toString(), "")
outLine = outLine.removeSuffix("(Default)").trim()
if (outLine.isNotEmpty()) {
result.add(outLine)
}
}
}
return result
}
}

fun getWslPath(windowsPath: String): String {
var process = Runtime.getRuntime().exec("wsl wslpath $windowsPath")
process.waitFor()
val sc = Scanner(process.inputStream)
//get wsl path from command output
val wslPath = sc.nextLine().replace(0.toChar().toString(), "")

//make the file executable
process = Runtime.getRuntime().exec("$wslTarget run chmod +x $wslPath")
process.waitFor()
return wslPath
}

private val availablePort = PortUtil.getFreePort()
override fun runRemoteHostManager(): Process {
val hostAgentUrl = getWslPath(getHostAgentUrl("linux").replace("\\", "/"))
val hostManagerPathWsl = getWslPath(hostManagerPath.toString().replace("\\", "/"))

return Runtime.getRuntime().exec("$wslTarget run $hostAgentUrl :$availablePort $hostManagerPathWsl/hostManager/appWsl.log")
}

override val port: Int
get() = availablePort
override val host: String
get() = "localhost"
}
14 changes: 8 additions & 6 deletions src/main/kotlin/com/kotlang/ui/shell/Shell.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.kotlang.HostAgent
import com.kotlang.isOldVersion
import com.kotlang.ui.window.refreshShell
import com.kotlang.util.PortUtil
import com.kotlang.remoting.RemoteTargetManager
import com.kotlang.ui.window.OmnishellWindow
import java.util.*

class Shell(var commandExecutionCards: LinkedList<CommandExecutionCard> = LinkedList<CommandExecutionCard>(),
var index: Int = 0,
var hostAgent: HostAgent = HostAgent("localhost", PortUtil.getFreePort())) {
val remoteTargetManager: RemoteTargetManager) {

val hostAgent: HostAgent = HostAgent(remoteTargetManager)
private val currentWorkingDirState = mutableStateOf(hostAgent.getHome())

fun addCommandExecution(commandExecution: CommandExecutionCard) {
commandExecutionCards.addFirst(commandExecution)
refreshShell()
OmnishellWindow.refreshShell()
}

fun clearHistory() {
commandExecutionCards = LinkedList<CommandExecutionCard>()
refreshShell()
OmnishellWindow.refreshShell()
}

fun getCurrentWorkingDir(): String = currentWorkingDirState.value
Expand Down Expand Up @@ -76,7 +78,7 @@ class Shell(var commandExecutionCards: LinkedList<CommandExecutionCard> = Linked
fun Draw(shellStateVersion: Int) {
val shell = this

ShellHeader(shell).Draw("localhost", currentWorkingDirState.value)
ShellHeader(shell).Draw(currentWorkingDirState.value)
Row(modifier = Modifier.background(Color(red = 34, green = 51, blue = 68))) {
FileTree(shell).FileTreeWidget(currentWorkingDirState.value)
ShellCommandPallete(shellStateVersion)
Expand Down
30 changes: 17 additions & 13 deletions src/main/kotlin/com/kotlang/ui/shell/ShellHeader.kt
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
package com.kotlang.ui.shell

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.DropdownMenu
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.kotlang.remoting.Wsl
import com.kotlang.remoting.LocalTargetManager
import com.kotlang.remoting.WslTargetManager
import com.kotlang.ui.Chip
import com.kotlang.ui.dialogs.EnvironmentDialog
import com.kotlang.ui.window.OmnishellWindow

class ShellHeader(private val shell: Shell) {
fun getHost(): String {
return when(shell.remoteTargetManager) {
is LocalTargetManager -> "localhost"
is WslTargetManager -> "wsl"
else -> "ssh"
}
}

@Composable
fun currentHostInfo(host: String, currentWorkingDir: String) {
fun currentHostInfo(currentWorkingDir: String) {
Row(modifier = Modifier.padding(horizontal = 10.dp, vertical = 8.dp)) {
Card(
shape = RoundedCornerShape(topStart = 8.dp, bottomStart = 8.dp),
backgroundColor = Color(red = 253, green = 224, blue = 222),
) {
Text(
host,
getHost(),
color = Color.DarkGray,
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(10.dp)
Expand Down Expand Up @@ -66,14 +70,14 @@ class ShellHeader(private val shell: Shell) {

@Composable
fun remoteOptions() {
val wslRemotes = Wsl.listWsl()
val wslRemotes = WslTargetManager.listWsl()

Row(
modifier = Modifier.padding(horizontal = 10.dp).fillMaxWidth().
fillMaxHeight(),
) {
Chip("WSL", wslRemotes) {
println("Selected $it")
OmnishellWindow.addTab(WslTargetManager(wslRemotes[it]))
}
Spacer(Modifier.width(30.dp))

Expand All @@ -85,12 +89,12 @@ class ShellHeader(private val shell: Shell) {
}

@Composable
fun Draw(host: String, currentWorkingDir: String) {
fun Draw(currentWorkingDir: String) {
TopAppBar(
modifier = Modifier.height(105.dp)
) {
Column {
currentHostInfo(host, currentWorkingDir)
currentHostInfo(currentWorkingDir)
remoteOptions()
}
}
Expand Down
Loading

0 comments on commit acbc3da

Please sign in to comment.