Skip to content

Commit 77365df

Browse files
committed
Prevent duplicate extension updates and disable the update button while an update is in progress
- once 'update' is clicked, updating should be locked until editor reload ├── apps │ └── editor │ └── src │ ├── commands │ │ └── check-for-updates-command.ts │ ├── utils │ │ └── update-extension.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-update-extension.ts │ │ │ └── index.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ └── Home │ │ └── Home.tsx │ └── types │ └── messages.ts └── packages └── ui └── src └── components └── editor ├── common │ └── Button │ ├── Button.module.scss │ └── Button.tsx └── prompt-view └── UpdateAvailable ├── UpdateAvailable.module.scss ├── UpdateAvailable.tsx └── index.ts
1 parent b85538b commit 77365df

6 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎apps/editor/src/commands/check-for-updates-command.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,19 @@ export const check_for_updates_command = (
3939
)
4040

4141
if (action === t('command.check-for-updates-command.action.update')) {
42+
if (prompt_view_provider.is_updating) {
43+
return
44+
}
45+
4246
if (prompt_view_provider.update_info.latest_version_tag) {
47+
prompt_view_provider.is_updating = true
48+
prompt_view_provider.send_message({
49+
command: 'UPDATE_INFO',
50+
update_info: {
51+
...prompt_view_provider.update_info,
52+
is_updating: true
53+
}
54+
})
4355
update_extension({
4456
tag_name: prompt_view_provider.update_info.latest_version_tag
4557
})

‎apps/editor/src/views/prompt/backend/message-handlers/handle-update-extension.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ import { PromptViewProvider } from '../prompt-view-provider'
44
export const handle_update_extension = (
55
prompt_view_provider: PromptViewProvider
66
) => {
7+
if (prompt_view_provider.is_updating) {
8+
return
9+
}
10+
711
if (prompt_view_provider.update_info.latest_version_tag) {
12+
prompt_view_provider.is_updating = true
13+
prompt_view_provider.send_message({
14+
command: 'UPDATE_INFO',
15+
update_info: {
16+
...prompt_view_provider.update_info,
17+
is_updating: true
18+
}
19+
})
820
update_extension({
921
tag_name: prompt_view_provider.update_info.latest_version_tag
1022
})

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
8787
public agentic_search_state: AgenticSearchState
8888
public completed_tasks: string[] = []
8989
public update_info: UpdateInfo = { is_available: false }
90+
public is_updating: boolean = false
9091

9192
// Voice input
9293
public is_recording = false
@@ -834,7 +835,10 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
834835
} else if (message.command === 'GET_UPDATE_INFO') {
835836
this.send_message({
836837
command: 'UPDATE_INFO',
837-
update_info: this.update_info
838+
update_info: {
839+
...this.update_info,
840+
is_updating: this.is_updating
841+
}
838842
})
839843
}
840844
} catch (error) {

‎apps/editor/src/views/prompt/frontend/Home/Home.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export const Home: React.FC<Props> = (props) => {
165165
on_update={() =>
166166
post_message(props.vscode, { command: 'UPDATE_EXTENSION' })
167167
}
168+
is_updating={props.update_info.is_updating}
168169
current_version={props.version}
169170
latest_version={props.update_info.latest_version}
170171
translations={{

‎apps/editor/src/views/prompt/types/messages.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ export type UpdateInfo = {
460460
latest_version?: string
461461
latest_version_tag?: string
462462
current_version_age_days?: number
463+
is_updating?: boolean
463464
}
464465

465466
export interface GetUpdateInfoMessage extends BaseMessage {

‎packages/ui/src/components/editor/prompt-view/UpdateAvailable/UpdateAvailable.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cn from 'classnames'
55

66
type Props = {
77
on_update: () => void
8+
is_updating?: boolean
89
current_version: string
910
latest_version?: string
1011
translations: {
@@ -17,6 +18,9 @@ type Props = {
1718

1819
export const UpdateAvailable: React.FC<Props> = (props) => {
1920
const [is_expanded, set_is_expanded] = React.useState(false)
21+
const [is_updating_local, set_is_updating_local] = React.useState(false)
22+
23+
const is_updating = props.is_updating || is_updating_local
2024

2125
return (
2226
<div
@@ -38,9 +42,11 @@ export const UpdateAvailable: React.FC<Props> = (props) => {
3842
<Button
3943
on_click={(e) => {
4044
e.stopPropagation()
45+
set_is_updating_local(true)
4146
props.on_update()
4247
}}
4348
is_small
49+
disabled={is_updating}
4450
>
4551
{props.translations.button}
4652
</Button>

0 commit comments

Comments
 (0)