|
| 1 | +// Copyright (c) 2022 Gitpod GmbH. All rights reserved. |
| 2 | +// Licensed under the GNU Affero General Public License (AGPL). |
| 3 | +// See License-AGPL.txt in the project root for license information. |
| 4 | + |
| 5 | +package io.gitpod.jetbrains.remote.actions |
| 6 | + |
| 7 | +import com.intellij.openapi.actionSystem.AnAction |
| 8 | +import com.intellij.openapi.actionSystem.AnActionEvent |
| 9 | +import com.intellij.openapi.components.service |
| 10 | +import com.intellij.openapi.diagnostic.thisLogger |
| 11 | +import io.gitpod.gitpodprotocol.api.entities.WorkspaceTimeoutDuration |
| 12 | +import io.gitpod.jetbrains.remote.GitpodManager |
| 13 | +import com.intellij.notification.NotificationType |
| 14 | + |
| 15 | +class ExtendWorkspaceTimeoutAction : AnAction() { |
| 16 | + private val manager = service<GitpodManager>() |
| 17 | + |
| 18 | + override fun actionPerformed(event: AnActionEvent) { |
| 19 | + manager.pendingInfo.thenAccept { workspaceInfo -> |
| 20 | + manager.trackEvent("jb_execute_command_gitpod_workspace", mapOf( |
| 21 | + "action" to "extend-timeout" |
| 22 | + )) |
| 23 | + |
| 24 | + manager.client.server.setWorkspaceTimeout(workspaceInfo.workspaceId, WorkspaceTimeoutDuration.DURATION_180M.toString()).whenComplete { result, e -> |
| 25 | + var message: String |
| 26 | + var notificationType: NotificationType |
| 27 | + |
| 28 | + if (e != null) { |
| 29 | + message = "Cannot extend workspace timeout: ${e.message}" |
| 30 | + notificationType = NotificationType.ERROR |
| 31 | + thisLogger().error("gitpod: failed to extend workspace timeout", e) |
| 32 | + } else { |
| 33 | + if (result.resetTimeoutOnWorkspaces.isNotEmpty()) { |
| 34 | + message = "Workspace timeout has been extended to three hours. This reset the workspace timeout for other workspaces." |
| 35 | + notificationType = NotificationType.WARNING |
| 36 | + } else { |
| 37 | + message = "Workspace timeout has been extended to three hours." |
| 38 | + notificationType = NotificationType.INFORMATION |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + val notification = manager.notificationGroup.createNotification(message, notificationType) |
| 43 | + notification.notify(null) |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments