diff --git a/gitpod-remote/package.json b/gitpod-remote/package.json index de32b81..fb1fa45 100644 --- a/gitpod-remote/package.json +++ b/gitpod-remote/package.json @@ -93,6 +93,11 @@ "title": "%extendTimeout%", "enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true" }, + { + "command": "gitpod.setWorkspaceTimeout", + "title": "%customizeTimeout%", + "enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true" + }, { "command": "gitpod.takeSnapshot", "title": "%takeSnapshot%", diff --git a/gitpod-remote/package.nls.json b/gitpod-remote/package.nls.json index 3013bad..8386f6c 100644 --- a/gitpod-remote/package.nls.json +++ b/gitpod-remote/package.nls.json @@ -11,7 +11,8 @@ "reportIssue": "Gitpod: Report Issue", "stopWorkspace": "Gitpod: Stop Workspace", "upgradeSubscription": "Gitpod: Upgrade Subscription", - "extendTimeout": "Gitpod: Extend Workspace Timeout", + "extendTimeout": "Gitpod: Extend Workspace Timeout (180m)", + "configureTimeout": "Gitpod: Configure Workspace Timeout", "takeSnapshot": "Gitpod: Share Workspace Snapshot", "shareWorkspace": "Gitpod: Share Running Workspace", "stopSharingWorkspace": "Gitpod: Stop Sharing Running Workspace", diff --git a/gitpod-shared/src/analytics.ts b/gitpod-shared/src/analytics.ts index e92ecb3..4aef0fc 100644 --- a/gitpod-shared/src/analytics.ts +++ b/gitpod-shared/src/analytics.ts @@ -35,7 +35,7 @@ export type GitpodAnalyticsEvent = targetQualifier?: 'stable' | 'insiders'; }> | GAET<'vscode_execute_command_gitpod_workspace', { - action: 'share' | 'stop-sharing' | 'stop' | 'snapshot' | 'extend-timeout'; + action: 'share' | 'stop-sharing' | 'stop' | 'snapshot' | 'extend-timeout'| 'configure-timeout'; }> | GAET<'vscode_execute_command_gitpod_ports', { action: 'private' | 'public' | 'preview' | 'openBrowser' | 'urlCopy'; diff --git a/gitpod-shared/src/features.ts b/gitpod-shared/src/features.ts index b7c88a7..68bf709 100644 --- a/gitpod-shared/src/features.ts +++ b/gitpod-shared/src/features.ts @@ -239,7 +239,7 @@ export async function registerWorkspaceCommands(context: GitpodExtensionContext) return context.gitpod.server.stopWorkspace(context.info.workspaceId); })); context.subscriptions.push(vscode.commands.registerCommand('gitpod.upgradeSubscription', () => { - const url = new GitpodHostUrl(context.info.gitpodHost).asUpgradeSubscription().toString(); + const url = new GitpodHostUrl(context.info.gitpodHost).asBilling().toString(); context.fireAnalyticsEvent({ eventName: 'vscode_execute_command_gitpod_open_link', properties: { url } @@ -387,17 +387,36 @@ export async function registerWorkspaceTimeout(context: GitpodExtensionContext): } }); try { - const result = await context.gitpod.server.setWorkspaceTimeout(context.info.workspaceId, '180m'); - if (result.resetTimeoutOnWorkspaces?.length > 0) { - vscode.window.showWarningMessage('Workspace timeout has been extended to three hours. This reset the workspace timeout for other workspaces.'); - } else { - vscode.window.showInformationMessage('Workspace timeout has been extended to three hours.'); - } + await context.gitpod.server.setWorkspaceTimeout(context.info.workspaceId, '180m'); + vscode.window.showWarningMessage(`Workspace timeout has been extended to 180m.`); } catch (err) { vscode.window.showErrorMessage(`Cannot extend workspace timeout: ${err.toString()}`); } })); + + context.subscriptions.push(vscode.commands.registerCommand('gitpod.setWorkspaceTimeout', async () => { + const timeout = await vscode.window.showInputBox({ + value: '180m', + prompt: 'Please input the timeout time, such as 30m, 1h, 2h, 3h', + }); + if (!timeout) { + return; + } + context.fireAnalyticsEvent({ + eventName: 'vscode_execute_command_gitpod_workspace', + properties: { + action: 'configure-timeout' + } + }); + try { + const { humanReadableDuration } = await context.gitpod.server.setWorkspaceTimeout(context.info.workspaceId, timeout); + vscode.window.showWarningMessage(`Workspace timeout has been changed to ${humanReadableDuration ?? timeout}.`); + } catch (err) { + vscode.window.showErrorMessage(`Cannot configure workspace timeout: ${err.toString()}`); + } + })); + const workspaceTimeout = await context.gitpod.server.getWorkspaceTimeout(context.info.workspaceId); if (!workspaceTimeout.canChange) { return; @@ -405,10 +424,10 @@ export async function registerWorkspaceTimeout(context: GitpodExtensionContext): const listener = await context.instanceListener; const extendTimeoutStatusBarItem = vscode.window.createStatusBarItem('gitpod.extendTimeout', vscode.StatusBarAlignment.Right, -100); - extendTimeoutStatusBarItem.name = 'Click to extend the workspace timeout.'; + extendTimeoutStatusBarItem.name = 'Extend the workspace timeout.'; context.subscriptions.push(extendTimeoutStatusBarItem); extendTimeoutStatusBarItem.text = '$(watch)'; - extendTimeoutStatusBarItem.command = 'gitpod.ExtendTimeout'; + extendTimeoutStatusBarItem.command = 'gitpod.setWorkspaceTimeout'; const update = () => { const instance = listener.info.latestInstance; if (!instance) { @@ -416,7 +435,9 @@ export async function registerWorkspaceTimeout(context: GitpodExtensionContext): return; } extendTimeoutStatusBarItem.tooltip = `Workspace Timeout: ${instance.status.timeout}. Click to extend.`; - extendTimeoutStatusBarItem.color = instance.status.timeout === '180m' ? new vscode.ThemeColor('notificationsWarningIcon.foreground') : undefined; + + // TODO: query default timeout, currently all paid plan default timeout is 60m. + extendTimeoutStatusBarItem.color = instance.status.timeout !== '60m' ? new vscode.ThemeColor('notificationsWarningIcon.foreground') : undefined; extendTimeoutStatusBarItem.show(); }; update(); diff --git a/gitpod-shared/yarn.lock b/gitpod-shared/yarn.lock index a802584..6bdbe9a 100644 --- a/gitpod-shared/yarn.lock +++ b/gitpod-shared/yarn.lock @@ -3,9 +3,9 @@ "@gitpod/gitpod-protocol@main": - version "0.1.5-main.6379" - resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-main.6379.tgz#8c654e9d1658a62648ec4a1bc837f3d5756f8a14" - integrity sha512-QLScSNODhMle/w23HSr3RihIh7S+ZE46JRbOqbFgR9+a0FBoxPtHi6kqUmeNgqvt+hfyjgdPG5/yddU7j0uznA== + version "0.1.5-main.6559" + resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-main.6559.tgz#e771beee25447b12dce79fea4abad4caed8db9fc" + integrity sha512-v6E5AnpiTkWEBhyuBT8/gXVYzSKHUK1IUoa9CCr3q5jsdgG0egGzotcsu1OTmDZ68R1UKCvu4RddQZgU5ZGTjg== dependencies: "@types/react" "17.0.32" abort-controller-x "^0.4.0" @@ -589,9 +589,9 @@ content-disposition@0.5.4: safe-buffer "5.2.1" content-type@~1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" - integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA== + version "1.0.5" + resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.5.tgz#8b773162656d1d1086784c8f23a54ce6d73d7918" + integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA== cookie-signature@1.0.6: version "1.0.6" @@ -1222,7 +1222,12 @@ minimatch@^3.0.4, minimatch@^3.1.1: dependencies: brace-expansion "^1.1.7" -minimist@^1.1.0, minimist@^1.2.0, minimist@^1.2.6: +minimist@^1.1.0: + version "1.2.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" + integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== + +minimist@^1.2.0, minimist@^1.2.6: version "1.2.7" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18" integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g== diff --git a/gitpod-web/package.json b/gitpod-web/package.json index ee24816..b037743 100644 --- a/gitpod-web/package.json +++ b/gitpod-web/package.json @@ -97,6 +97,11 @@ "title": "%extendTimeout%", "enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true" }, + { + "command": "gitpod.setWorkspaceTimeout", + "title": "%configureTimeout%", + "enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true" + }, { "command": "gitpod.takeSnapshot", "title": "%takeSnapshot%", diff --git a/gitpod-web/package.nls.json b/gitpod-web/package.nls.json index a806efb..a15c89e 100644 --- a/gitpod-web/package.nls.json +++ b/gitpod-web/package.nls.json @@ -22,7 +22,8 @@ "stopWorkspace": "Gitpod: Stop Workspace", "showReleaseNotes": "Gitpod: Show Release Notes", "upgradeSubscription": "Gitpod: Upgrade Subscription", - "extendTimeout": "Gitpod: Extend Workspace Timeout", + "extendTimeout": "Gitpod: Extend Workspace Timeout (180m)", + "configureTimeout": "Gitpod: Configure Workspace Timeout", "takeSnapshot": "Gitpod: Share Workspace Snapshot", "shareWorkspace": "Gitpod: Share Running Workspace", "stopSharingWorkspace": "Gitpod: Stop Sharing Running Workspace",