Compare commits
3 Commits
add-contro
...
2ba85992fd
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ba85992fd | |||
| 99e17f6a1d | |||
| be212c6c24 |
@@ -152,9 +152,10 @@ func GetDevContainerDetails(ctx *context.Context) {
|
||||
}
|
||||
terminalURL, err := devcontainer_service.Get_IDE_TerminalURL(ctx, ctx.Doer, ctx.Repo)
|
||||
if err == nil {
|
||||
ctx.Data["VSCodeUrl"] = "vscode" + terminalURL
|
||||
ctx.Data["CursorUrl"] = "cursor" + terminalURL
|
||||
ctx.Data["WindsurfUrl"] = "windsurf" + terminalURL
|
||||
ctx.Data["VSCodeUrl"] = "vscode" + terminalURL + "&cmd=code"
|
||||
ctx.Data["CursorUrl"] = "cursor" + terminalURL + "&cmd=cursor"
|
||||
ctx.Data["WindsurfUrl"] = "windsurf" + terminalURL + "&cmd=windsurf"
|
||||
ctx.Data["TraeUrl"] = "trae" + terminalURL + "&cmd=trae"
|
||||
}
|
||||
}
|
||||
// 3. 携带数据渲染页面,返回
|
||||
@@ -187,7 +188,7 @@ func GetDevContainerStatus(ctx *context.Context) {
|
||||
log.Info("%v\n", err)
|
||||
}
|
||||
|
||||
var vscodeUrl, cursorUrl, windsurfUrl string
|
||||
var vscodeUrl, cursorUrl, windsurfUrl, traeUrl string
|
||||
// 增加对 ctx.Doer、ctx.Repo、ctx.Repo.Repository 的检查,避免出现空指针异常
|
||||
// 只在第一次状态变为 "4" 时生成 URL,避免频繁调用导致 token 被删除,随 Session 过期(默认 24 小时)
|
||||
// 通过检查 session 中是否已有 terminal_url 来判断是否是第一次
|
||||
@@ -198,14 +199,16 @@ func GetDevContainerStatus(ctx *context.Context) {
|
||||
// 第一次状态为 "4",生成 URL 并缓存
|
||||
terminalURL, err := devcontainer_service.Get_IDE_TerminalURL(ctx, ctx.Doer, ctx.Repo)
|
||||
if err == nil {
|
||||
vscodeUrl = "vscode" + terminalURL
|
||||
cursorUrl = "cursor" + terminalURL
|
||||
windsurfUrl = "windsurf" + terminalURL
|
||||
vscodeUrl = "vscode" + terminalURL + "&cmd=code"
|
||||
cursorUrl = "cursor" + terminalURL + "&cmd=cursor"
|
||||
windsurfUrl = "windsurf" + terminalURL + "&cmd=windsurf"
|
||||
traeUrl = "trae" + terminalURL + "&cmd=trae"
|
||||
// 缓存 URL 到 session
|
||||
ctx.Session.Set("terminal_urls", map[string]string{
|
||||
"vscodeUrl": vscodeUrl,
|
||||
"cursorUrl": cursorUrl,
|
||||
"windsurfUrl": windsurfUrl,
|
||||
"traeUrl": traeUrl,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
@@ -214,6 +217,7 @@ func GetDevContainerStatus(ctx *context.Context) {
|
||||
vscodeUrl = urls["vscodeUrl"]
|
||||
cursorUrl = urls["cursorUrl"]
|
||||
windsurfUrl = urls["windsurfUrl"]
|
||||
traeUrl = urls["traeUrl"]
|
||||
}
|
||||
} else {
|
||||
// 状态不是 "4" 或 ctx.Doer 为 nil,清除缓存的 URL
|
||||
@@ -225,6 +229,7 @@ func GetDevContainerStatus(ctx *context.Context) {
|
||||
"vscodeUrl": vscodeUrl,
|
||||
"cursorUrl": cursorUrl,
|
||||
"windsurfUrl": windsurfUrl,
|
||||
"traeUrl": traeUrl,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
<div style=" display: none;" id="vsTerminal" class="item"><a class="flex-text-inline" style="color:black; " onclick="window.location.href = '{{.VSCodeUrl}}'">{{svg "octicon-code" 14}}open with VSCode</a ></div>
|
||||
<div style=" display: none;" id="cursorTerminal" class="item"><a class="flex-text-inline" style="color:black; " onclick="window.location.href = '{{.CursorUrl}}'">{{svg "octicon-code" 14}}open with Cursor</a ></div>
|
||||
<div style=" display: none;" id="windsurfTerminal" class="item"><a class="flex-text-inline" style="color:black;" onclick="window.location.href = '{{.WindsurfUrl}}'">{{svg "octicon-code" 14}}open with Windsurf</a ></div>
|
||||
<div style=" display: none;" id="traeTerminal" class="item"><a class="flex-text-inline" style="color:black;" onclick="window.location.href = '{{.TraeUrl}}'">{{svg "octicon-code" 14}}open with Trae</a ></div>
|
||||
|
||||
|
||||
{{end}}
|
||||
@@ -126,6 +127,7 @@ const webTerminal = document.getElementById('webTerminal');
|
||||
const vsTerminal = document.getElementById('vsTerminal');
|
||||
const cursorTerminal = document.getElementById('cursorTerminal');
|
||||
const windsurfTerminal = document.getElementById('windsurfTerminal');
|
||||
const traeTerminal = document.getElementById('traeTerminal');
|
||||
const webTerminalContainer = document.getElementById('webTerminalContainer');
|
||||
const loadingElement = document.getElementById('loading');
|
||||
|
||||
@@ -157,6 +159,9 @@ function concealElement(){
|
||||
if (windsurfTerminal) {
|
||||
windsurfTerminal.style.display = 'none';
|
||||
}
|
||||
if (traeTerminal) {
|
||||
traeTerminal.style.display = 'none';
|
||||
}
|
||||
if (webTerminalContainer) {
|
||||
webTerminalContainer.style.display = 'none';
|
||||
}
|
||||
@@ -190,6 +195,10 @@ function displayElement(){
|
||||
if (windsurfTerminal) {
|
||||
windsurfTerminal.style.display = 'block';
|
||||
}
|
||||
|
||||
if (traeTerminal) {
|
||||
traeTerminal.style.display = 'block';
|
||||
}
|
||||
if (webTerminalContainer) {
|
||||
webTerminalContainer.style.display = 'block';
|
||||
}
|
||||
@@ -255,6 +264,10 @@ function getStatus() {
|
||||
const windsurfBtn = document.querySelector('#windsurfTerminal a');
|
||||
if (windsurfBtn) windsurfBtn.onclick = function(e) { e.preventDefault(); window.location.href = data.windsurfUrl; };
|
||||
}
|
||||
if (data.traeUrl) {
|
||||
const traeBtn = document.querySelector('#traeTerminal a');
|
||||
if (traeBtn) traeBtn.onclick = function(e) { e.preventDefault(); window.location.href = data.traeUrl; };
|
||||
}
|
||||
displayElement();
|
||||
if (loadingElement) {
|
||||
loadingElement.style.display = 'none';
|
||||
|
||||
Reference in New Issue
Block a user