-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add action
Copy Port URL
on forwarded ports in terminals from JetBr…
…ains EAP IDEs Co-authored-by: Andrea Falzetti <[email protected]>
- Loading branch information
Showing
3 changed files
with
66 additions
and
29 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...ckend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodCopyPortUrlAction.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,64 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package io.gitpod.jetbrains.remote.latest | ||
|
||
import com.intellij.ide.BrowserUtil | ||
import com.intellij.notification.NotificationAction | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.openapi.actionSystem.ActionPlaces | ||
import com.intellij.openapi.actionSystem.ActionUpdateThread | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.ide.CopyPasteManager | ||
import com.intellij.util.application | ||
import com.jetbrains.rd.platform.codeWithMe.portForwarding.PortForwardingDataKeys | ||
import io.gitpod.jetbrains.remote.GitpodManager | ||
import io.gitpod.supervisor.api.Status.PortsStatusRequest | ||
import io.gitpod.supervisor.api.StatusServiceGrpc | ||
import kotlinx.coroutines.launch | ||
import java.awt.datatransfer.StringSelection | ||
|
||
@Suppress("ComponentNotRegistered", "UnstableApiUsage") | ||
class GitpodCopyPortUrlAction : AnAction() { | ||
override fun actionPerformed(e: AnActionEvent) { | ||
e.dataContext.getData(PortForwardingDataKeys.PORT)?.let { forwardedPort -> | ||
application.coroutineScope.launch { | ||
getUrlFromPort(forwardedPort.hostPortNumber)?.let { | ||
CopyPasteManager.getInstance().setContents(StringSelection(it)) | ||
service<GitpodManager>() | ||
.notificationGroup | ||
.createNotification("Port URL copied to clipboard!", NotificationType.INFORMATION) | ||
.addAction(NotificationAction.createSimple("Open in browser") { | ||
BrowserUtil.browse(it, e.project) | ||
}).notify(e.project) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
// We want it to be enabled only when action comes from the Port Forwarding Suggestion Popup. | ||
// In other places, like the Search Actions Menu, we want it disabled (greyed-out). | ||
e.presentation.isEnabled = (e.place == ActionPlaces.POPUP) | ||
} | ||
|
||
override fun getActionUpdateThread(): ActionUpdateThread { | ||
return ActionUpdateThread.BGT | ||
} | ||
|
||
private fun getUrlFromPort(port: Number): String? { | ||
val blockingStub = StatusServiceGrpc.newBlockingStub(GitpodManager.supervisorChannel) | ||
val request = PortsStatusRequest.newBuilder().setObserve(false).build() | ||
val response = blockingStub.portsStatus(request) | ||
while (response.hasNext()) { | ||
val portStatusResponse = response.next() | ||
for (portStatus in portStatusResponse.portsList) { | ||
if (portStatus.localPort == port) return portStatus.exposed.url | ||
} | ||
} | ||
return null | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
...kend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodPortsActionCopyUrl.kt
This file was deleted.
Oops, something went wrong.
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