Skip to content

Commit 6e85422

Browse files
committed
Wait for the updater terminal to close before reloading the window after updating the extension
- once terminal closes, reload window [Pasted text]
1 parent 9003c30 commit 6e85422

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
import * as vscode from 'vscode'
22
import * as os from 'os'
33

4-
export const update_extension = (params: { tag_name: string }) => {
4+
export const update_extension = async (params: { tag_name: string }) => {
55
const terminal = vscode.window.createTerminal('CWC Updater')
66
terminal.show()
77

88
const uri_scheme = vscode.env.uriScheme
99
const lang = vscode.env.language
1010

11-
if (os.platform() === 'win32') {
12-
terminal.sendText(
13-
`powershell -c "& ([scriptblock]::Create((irm https://github.com/CodeWebChat/CWC/raw/refs/heads/main/install.ps1))) -editor '${uri_scheme}' -lang '${lang}' -tag '${params.tag_name}'"`
14-
)
15-
} else {
16-
terminal.sendText(
17-
`curl -fsSL https://github.com/CodeWebChat/CWC/raw/refs/heads/main/install.sh | bash -s -- --editor "${uri_scheme}" --lang "${lang}" --tag "${params.tag_name}"`
18-
)
19-
}
11+
const command =
12+
os.platform() === 'win32'
13+
? `powershell -c "& ([scriptblock]::Create((irm https://github.com/CodeWebChat/CWC/raw/refs/heads/main/install.ps1))) -editor '${uri_scheme}' -lang '${lang}' -tag '${params.tag_name}'"; exit $LASTEXITCODE`
14+
: `curl -fsSL https://github.com/CodeWebChat/CWC/raw/refs/heads/main/install.sh | bash -s -- --editor "${uri_scheme}" --lang "${lang}" --tag "${params.tag_name}" && exit`
15+
16+
const terminal_closed = new Promise<vscode.TerminalExitStatus | undefined>(
17+
(resolve) => {
18+
const disposable = vscode.window.onDidCloseTerminal((t) => {
19+
if (t === terminal) {
20+
disposable.dispose()
21+
resolve(t.exitStatus)
22+
}
23+
})
24+
}
25+
)
26+
27+
terminal.sendText(command)
28+
29+
await terminal_closed
30+
vscode.commands.executeCommand('workbench.action.reloadWindow')
2031
}

0 commit comments

Comments
 (0)