Skip to content

Commit 5c4c371

Browse files
committed
Add in-app update detection and terminal-based installation while switching install scripts to download tagged source archives
- whenever home opens, should check if there is newer version of the vscode extension. the endpoint: https://api.github.com/repos/robertpiosik/CodeWebChat/tags, example output: [Pasted text]. note all results on the page could be of other extensions, e.g. browser. then should go thorugh page 2, page 3, etc. until *-vscode is found. If there is a newer version, show a new component 'UpdateAvailable' above 'target' buttons. The 'Update Available' should simply say, 'Update is available!' and show button 'Update' that upon click places command from `README.md` (depending on platform) in a new terminal. [Accuracy boost] - make 'update is available' hoverable and the whole component expandable. hover effect is setting bg to [Fragment]. Once expanded show 3 lines of text: 1) Current version: X 2) Latest version: Y 3) Your version is 5 days old. - strings in `apps/editor/src/views/prompt/frontend/Home/components/UpdateAvailable/UpdateAvailable.tsx` should be translated - 'update available' should be UI component with tranlsations passed through props - in installation scripts, instead of cloning git, we need to find the most recent *-vscode version in tags https://api.github.com/repos/robertpiosik/CodeWebChat/tags and get the zip (example response of this enpoint: [Pasted text]) [Accuracy boost] - when querying https://api.github.com/repos/robertpiosik/CodeWebChat/tags use the default per page value - some logs are different between scripts - rename 'downloading latest version' to 'downloading latest source code' ├── README.md ├── apps │ └── editor │ └── src │ └── views │ ├── prompt │ │ ├── backend │ │ │ ├── message-handlers │ │ │ │ ├── handle-get-version.ts │ │ │ │ ├── handle-update-extension.ts │ │ │ │ └── index.ts │ │ │ └── prompt-view-provider.ts │ │ ├── frontend │ │ │ ├── App.tsx │ │ │ ├── Home │ │ │ │ ├── Home.module.scss │ │ │ │ ├── Home.tsx │ │ │ │ ├── hooks │ │ │ │ │ ├── use-has-scrolled-past-mode-button.ts │ │ │ │ │ ├── use-keyboard-shortcuts.ts │ │ │ │ │ ├── use-tasks.ts │ │ │ │ │ └── use-update-check.ts │ │ │ │ └── index.ts │ │ │ ├── Prompt.module.scss │ │ │ ├── Prompt.tsx │ │ │ ├── hooks │ │ │ │ └── use-prompt │ │ │ │ ├── hooks │ │ │ │ │ └── use-instructions.ts │ │ │ │ ├── index.ts │ │ │ │ └── use-prompt.ts │ │ │ └── i18n │ │ │ ├── translations │ │ │ │ ├── home.ts │ │ │ │ └── index.ts │ │ │ └── use-translation.tsx │ │ └── types │ │ └── messages.ts │ └── shared │ └── hooks │ └── use-translation.tsx ├── install.ps1 ├── install.sh └── packages └── ui └── src ├── components │ └── editor │ ├── common │ │ └── Button │ │ └── Button.tsx │ └── prompt-view │ ├── Fieldset │ │ ├── Fieldset.module.scss │ │ └── Fieldset.tsx │ ├── TargetButton │ │ ├── TargetButton.module.scss │ │ ├── TargetButton.stories.tsx │ │ ├── TargetButton.tsx │ │ └── index.ts │ └── UpdateAvailable │ ├── UpdateAvailable.module.scss │ ├── UpdateAvailable.tsx │ └── index.ts └── styles └── foundation └── _colors.scss
1 parent d15dbf0 commit 5c4c371

14 files changed

Lines changed: 471 additions & 26 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as vscode from 'vscode'
2+
import * as os from 'os'
3+
4+
export const handle_update_extension = () => {
5+
const terminal = vscode.window.createTerminal('CodeWebChat Update')
6+
terminal.show()
7+
8+
if (os.platform() === 'win32') {
9+
terminal.sendText(
10+
'powershell -c "irm https://raw.githubusercontent.com/robertpiosik/CodeWebChat/main/install.ps1 | iex"',
11+
false
12+
)
13+
} else {
14+
terminal.sendText(
15+
'curl -fsSL https://raw.githubusercontent.com/robertpiosik/CodeWebChat/main/install.sh | bash',
16+
false
17+
)
18+
}
19+
}

‎apps/editor/src/views/prompt/backend/message-handlers/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ export * from './handle-get-completed-tasks'
6565
export * from './handle-save-completed-tasks'
6666
export * from './handle-clear-completed-tasks'
6767
export * from './handle-show-accuracy-boost-info'
68+
export * from './handle-update-extension'

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ import {
100100
handle_get_completed_tasks,
101101
handle_save_completed_tasks,
102102
handle_clear_completed_tasks,
103-
handle_show_accuracy_boost_info
103+
handle_show_accuracy_boost_info,
104+
handle_update_extension
104105
} from './message-handlers'
105106
import { handle_agentic_search } from './message-handlers/handle-agentic-search'
106107
import { handle_preview_saved_context_symbol } from './message-handlers/handle-preview-saved-context-symbol'
@@ -931,6 +932,8 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
931932
await handle_save_completed_tasks(this)
932933
} else if (message.command === 'CLEAR_COMPLETED_TASKS') {
933934
await handle_clear_completed_tasks(this)
935+
} else if (message.command === 'UPDATE_EXTENSION') {
936+
handle_update_extension()
934937
}
935938
} catch (error) {
936939
Logger.error({

‎apps/editor/src/views/prompt/frontend/Home/Home.module.scss‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@
139139
}
140140
}
141141

142+
&__update {
143+
margin: 0 12px;
144+
145+
@include modern-ui {
146+
margin: 0 10px;
147+
}
148+
}
149+
142150
&__workspace-dropdown {
143151
position: relative;
144152
display: flex;

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
CliPromptType
2121
} from '@shared/types/prompt-types'
2222
import { use_is_landscape } from '../hooks/use-is-landscape'
23+
import { use_update_check } from './hooks/use-update-check'
24+
import { UpdateAvailable as UiUpdateAvailable } from '@ui/components/editor/prompt-view/UpdateAvailable'
2325

2426
type Props = {
2527
vscode: any
@@ -69,6 +71,8 @@ export const Home: React.FC<Props> = (props) => {
6971
is_disabled: is_landscape
7072
})
7173

74+
const update_info = use_update_check(props.version, props.is_active)
75+
7276
const header_targets_ref = useRef<HTMLDivElement>(null)
7377

7478
const discord_label = 'Discord'
@@ -155,6 +159,43 @@ export const Home: React.FC<Props> = (props) => {
155159
</div>
156160
)
157161

162+
const update_section = !update_info.is_available ? (
163+
<>
164+
<div className={styles.inner__update}>
165+
<UiUpdateAvailable
166+
on_update={() =>
167+
post_message(props.vscode, { command: 'UPDATE_EXTENSION' })
168+
}
169+
translations={{
170+
title: t('home.update.title'),
171+
button: t('home.update.button'),
172+
installed_version: (
173+
<Translation
174+
id="home.update.installed-version"
175+
components={{ version: props.version }}
176+
/>
177+
),
178+
latest_version: (
179+
<Translation
180+
id="home.update.latest-version"
181+
components={{ version: update_info.latest_version }}
182+
/>
183+
),
184+
age: (
185+
<Translation
186+
id="home.update.age"
187+
components={{
188+
days: update_info.current_version_age_days!.toString()
189+
}}
190+
/>
191+
)
192+
}}
193+
/>
194+
</div>
195+
<UiSpacer height={6} />
196+
</>
197+
) : null
198+
158199
const targets_section = (
159200
<div className={styles.inner__target} ref={target_ref}>
160201
<UiTargetButton
@@ -292,6 +333,7 @@ export const Home: React.FC<Props> = (props) => {
292333
<div className={styles.content}>
293334
<div className={styles.inner}>
294335
<UiSpacer height={6} />
336+
{update_section}
295337
{targets_section}
296338
<UiSpacer height={6} />
297339
</div>
@@ -322,6 +364,7 @@ export const Home: React.FC<Props> = (props) => {
322364
<div className={styles.content}>
323365
<div className={styles.inner}>
324366
<UiSpacer height={2} />
367+
{update_section}
325368
{targets_section}
326369
<UiSpacer height={10} />
327370
{tasks_section}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { useState, useEffect } from 'react'
2+
3+
type UpdateInfo = {
4+
is_available: boolean
5+
latest_version?: string
6+
current_version_age_days?: number
7+
}
8+
9+
let has_checked = false
10+
let global_update_info: UpdateInfo = { is_available: false }
11+
12+
const is_newer = (latest: string, current: string) => {
13+
const l = latest.split('.').map(Number)
14+
const c = current.split('.').map(Number)
15+
for (let i = 0; i < Math.max(l.length, c.length); i++) {
16+
const l_val = l[i] || 0
17+
const c_val = c[i] || 0
18+
if (l_val > c_val) return true
19+
if (l_val < c_val) return false
20+
}
21+
return false
22+
}
23+
24+
export const use_update_check = (current_version: string, is_active: boolean) => {
25+
const [update_info, set_update_info] = useState<UpdateInfo>(global_update_info)
26+
27+
useEffect(() => {
28+
if (!is_active || !current_version || has_checked) {
29+
if (has_checked) {
30+
set_update_info(global_update_info)
31+
}
32+
return
33+
}
34+
let is_mounted = true
35+
has_checked = true
36+
37+
const check = async () => {
38+
try {
39+
let page = 1
40+
while (page <= 10) {
41+
const res = await fetch(
42+
`https://api.github.com/repos/robertpiosik/CodeWebChat/tags?page=${page}`
43+
)
44+
if (!res.ok) break
45+
const tags = await res.json()
46+
if (!Array.isArray(tags) || tags.length === 0) break
47+
48+
const vscode_tag = tags.find((t: any) => t.name?.endsWith('-vscode'))
49+
if (vscode_tag) {
50+
const latest_version = vscode_tag.name.replace('-vscode', '')
51+
if (is_newer(latest_version, current_version)) {
52+
let age_days = 0
53+
try {
54+
const commit_res = await fetch(
55+
`https://api.github.com/repos/robertpiosik/CodeWebChat/commits/${current_version}-vscode`
56+
)
57+
if (commit_res.ok) {
58+
const commit_data = await commit_res.json()
59+
const date = commit_data.commit?.committer?.date
60+
if (date) {
61+
age_days = Math.floor(
62+
(Date.now() - new Date(date).getTime()) / (1000 * 60 * 60 * 24)
63+
)
64+
}
65+
}
66+
} catch (e) {
67+
console.error('Failed to fetch commit date:', e)
68+
}
69+
70+
global_update_info = {
71+
is_available: true,
72+
latest_version,
73+
current_version_age_days: age_days
74+
}
75+
if (is_mounted) {
76+
set_update_info(global_update_info)
77+
}
78+
}
79+
break
80+
}
81+
page++
82+
}
83+
} catch (e) {
84+
console.error('Failed to check for updates:', e)
85+
}
86+
}
87+
88+
check()
89+
90+
return () => {
91+
is_mounted = false
92+
}
93+
}, [current_version, is_active])
94+
95+
return update_info
96+
}

‎apps/editor/src/views/prompt/frontend/i18n/translations/home.ts‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,95 @@ export const home = {
178178
cs: 'Vyvolat agenty',
179179
hu: 'Ügynökök meghívása',
180180
bg: 'Извикване на агенти'
181+
},
182+
'home.update.title': {
183+
en: 'Update is available!',
184+
pl: 'Dostępna jest aktualizacja!',
185+
'zh-cn': '有可用更新!',
186+
ja: 'アップデートが利用可能です!',
187+
'zh-tw': '有可用更新!',
188+
de: 'Update ist verfügbar!',
189+
es: '¡Actualización disponible!',
190+
fr: 'Une mise à jour est disponible !',
191+
'pt-br': 'Atualização disponível!',
192+
ru: 'Доступно обновление!',
193+
ko: '업데이트가 가능합니다!',
194+
it: 'Aggiornamento disponibile!',
195+
tr: 'Güncelleme mevcut!',
196+
cs: 'Je k dispozici aktualizace!',
197+
hu: 'Frissítés érhető el!',
198+
bg: 'Налична е актуализация!'
199+
},
200+
'home.update.button': {
201+
en: 'Update',
202+
pl: 'Aktualizuj',
203+
'zh-cn': '更新',
204+
ja: '更新',
205+
'zh-tw': '更新',
206+
de: 'Aktualisieren',
207+
es: 'Actualizar',
208+
fr: 'Mettre à jour',
209+
'pt-br': 'Atualizar',
210+
ru: 'Обновить',
211+
ko: '업데이트',
212+
it: 'Aggiorna',
213+
tr: 'Güncelle',
214+
cs: 'Aktualizovat',
215+
hu: 'Frissítés',
216+
bg: 'Актуализиране'
217+
},
218+
'home.update.installed-version': {
219+
en: 'Installed version: {version}',
220+
pl: 'Zainstalowana wersja: {version}',
221+
'zh-cn': '已安装版本: {version}',
222+
ja: 'インストール済みバージョン: {version}',
223+
'zh-tw': '已安裝版本: {version}',
224+
de: 'Installierte Version: {version}',
225+
es: 'Versión instalada: {version}',
226+
fr: 'Version installée : {version}',
227+
'pt-br': 'Versão instalada: {version}',
228+
ru: 'Установленная версия: {version}',
229+
ko: '설치된 버전: {version}',
230+
it: 'Versione installata: {version}',
231+
tr: 'Yüklü sürüm: {version}',
232+
cs: 'Nainstalovaná verze: {version}',
233+
hu: 'Telepített verzió: {version}',
234+
bg: 'Инсталирана версия: {version}'
235+
},
236+
'home.update.latest-version': {
237+
en: 'Latest version: {version}',
238+
pl: 'Najnowsza wersja: {version}',
239+
'zh-cn': '最新版本: {version}',
240+
ja: '最新バージョン: {version}',
241+
'zh-tw': '最新版本: {version}',
242+
de: 'Neueste Version: {version}',
243+
es: 'Última versión: {version}',
244+
fr: 'Dernière version : {version}',
245+
'pt-br': 'Versão mais recente: {version}',
246+
ru: 'Последняя версия: {version}',
247+
ko: '최신 버전: {version}',
248+
it: 'Ultima versione: {version}',
249+
tr: 'En son sürüm: {version}',
250+
cs: 'Nejnovější verze: {version}',
251+
hu: 'Legújabb verzió: {version}',
252+
bg: 'Последна версия: {version}'
253+
},
254+
'home.update.age': {
255+
en: 'Your version is {days} days old.',
256+
pl: 'Twoja wersja ma {days} dni.',
257+
'zh-cn': '您的版本已有 {days} 天。',
258+
ja: 'お使いのバージョンは {days} 日前のものです。',
259+
'zh-tw': '您的版本已有 {days} 天。',
260+
de: 'Ihre Version ist {days} Tage alt.',
261+
es: 'Su versión tiene {days} días.',
262+
fr: 'Votre version a {days} jours.',
263+
'pt-br': 'Sua versão tem {days} dias.',
264+
ru: 'Вашей версии {days} дней.',
265+
ko: '현재 버전은 {days}일 되었습니다.',
266+
it: 'La tua versione ha {days} giorni.',
267+
tr: 'Sürümünüz {days} günlük.',
268+
cs: 'Vaše verze je stará {days} dní.',
269+
hu: 'Az Ön verziója {days} napos.',
270+
bg: 'Вашата версия е на {days} дни.'
181271
}
182272
} as const

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ export interface CompletedTasksMessage extends BaseMessage {
636636
completed_tasks: string[]
637637
}
638638

639+
export interface UpdateExtensionMessage extends BaseMessage {
640+
command: 'UPDATE_EXTENSION'
641+
}
642+
639643
export type FrontendMessage =
640644
| GetInstructionsMessage
641645
| SaveInstructionsMessage
@@ -746,6 +750,7 @@ export type FrontendMessage =
746750
| GetCompletedTasksMessage
747751
| SaveCompletedTasksMessage
748752
| ClearCompletedTasksMessage
753+
| UpdateExtensionMessage
749754

750755
// === FROM BACKEND TO FRONTEND ===
751756
export interface InstructionsMessage extends BaseMessage {

0 commit comments

Comments
 (0)