Skip to content

The agent that grows with you

fix(web-access): show the web app stopped once Stop has finished

emozilla4504019f61db
diff --git a/apps/desktop/src/app/settings/web-access-settings.test.tsx b/apps/desktop/src/app/settings/web-access-settings.test.tsx
index 61900e7e882..21fbb05c76a 100644
--- a/apps/desktop/src/app/settings/web-access-settings.test.tsx
+++ b/apps/desktop/src/app/settings/web-access-settings.test.tsx
@@ -46,6 +46,16 @@ const OFF: WebAccessStatus = {
public_url: ''
}
+const SERVING: WebAccessStatus = {
+ ...OFF,
+ enabled: true,
+ gateway: { reason: null, state: 'serving', url: 'http://192.168.1.50:9120' },
+ mode: 'lan'
+}
+
+/** Turned off and saved, while the gateway that has not restarted yet still serves the web app. */
+const OLD_GATEWAY: WebAccessStatus = { ...OFF, gateway: SERVING.gateway }
+
function renderPane(status: WebAccessStatus) {
mocked.getWebAccessStatus.mockResolvedValue(status)
@@ -65,6 +75,8 @@ afterEach(() => {
clearNotifications()
platform.browserHosted = false
vi.clearAllMocks()
+ // A test that queued status answers it did not use must not hand them to the next one.
+ mocked.getWebAccessStatus.mockReset()
})
describe('WebAccessSettings', () => {
@@ -169,6 +181,70 @@ describe('WebAccessSettings', () => {
expect(await screen.findByText('Restart needed')).toBeTruthy()
})
+ it('waits after Stop until the restarted gateway no longer serves the web app', async () => {
+ // Stop saves `enabled: false` and starts a restart. Until the old gateway exits it still serves
+ // the web app; while it restarts nothing answers. The pane waits through both for the new one.
+ mocked.stopWebAccess.mockResolvedValue({ ...OLD_GATEWAY, restart_started: true })
+ renderPane(SERVING)
+ const stop = await screen.findByRole('button', { name: 'Stop' })
+ mocked.getWebAccessStatus
+ .mockResolvedValueOnce(OLD_GATEWAY)
+ .mockRejectedValueOnce(new Error('gateway restarting'))
+ .mockResolvedValue(OFF)
+
+ fireEvent.click(stop)
+
+ expect(await screen.findByText('Stopped', {}, { timeout: 8000 })).toBeTruthy()
+ expect(screen.queryByText('Restart needed')).toBeNull()
+ expect($notifications.get()).toEqual([])
+ }, 15_000)
+
+ it('shows the web app stopping, not waiting for a restart, while the restart runs', async () => {
+ mocked.stopWebAccess.mockResolvedValue({ ...OLD_GATEWAY, restart_started: true })
+ renderPane(SERVING)
+ const stop = await screen.findByRole('button', { name: 'Stop' })
+ // The restarting gateway has not answered yet.
+ mocked.getWebAccessStatus.mockReturnValue(new Promise<WebAccessStatus>(() => {}))
+
+ fireEvent.click(stop)
+
+ expect(await screen.findByText('Stopping')).toBeTruthy()
+ expect(screen.queryByText('Restart needed')).toBeNull()
+ })
+
+ it('waits after Restart until a turned-off web app is no longer served', async () => {
+ // Saved `enabled: false`, but the gateway still serves the web app: Restart applies the change.
+ mocked.restartWebAccess.mockResolvedValue({ ...OLD_GATEWAY, restart_started: true })
+ renderPane(OLD_GATEWAY)
+ const restart = await screen.findByRole('button', { name: 'Restart gateway' })
+ mocked.getWebAccessStatus.mockResolvedValueOnce(OLD_GATEWAY).mockResolvedValue(OFF)
+
+ fireEvent.click(restart)
+
+ expect(await screen.findByText('Stopped', {}, { timeout: 8000 })).toBeTruthy()
+ expect(screen.queryByText('Restart needed')).toBeNull()
+ }, 15_000)
+
+ it('says when the gateway still serves the web app 90 seconds after Stop', async () => {
+ mocked.stopWebAccess.mockResolvedValue({ ...OLD_GATEWAY, restart_started: true })
+ renderPane(SERVING)
+ const stop = await screen.findByRole('button', { name: 'Stop' })
+ mocked.getWebAccessStatus.mockResolvedValue(OLD_GATEWAY)
+ vi.useFakeTimers()
+
+ try {
+ fireEvent.click(stop)
+ await vi.advanceTimersByTimeAsync(92_000)
+ } finally {
+ vi.useRealTimers()
+ }
+
+ await waitFor(() => expect($notifications.get()).toHaveLength(1))
+ const [toast] = $notifications.get()
+ expect(toast.kind).toBe('error')
+ expect(toast.message).toBe("The gateway didn't stop serving the web app within 90 seconds.")
+ })
+
it('says that network access is not encrypted', async () => {
// LAN mode is plain HTTP: anyone on the network can read the traffic.
renderPane(OFF)
diff --git a/apps/desktop/src/app/settings/web-access-settings.tsx b/apps/desktop/src/app/settings/web-access-settings.tsx
index e07dcad863c..1a93a42464b 100644
--- a/apps/desktop/src/app/settings/web-access-settings.tsx
+++ b/apps/desktop/src/app/settings/web-access-settings.tsx
@@ -26,8 +26,8 @@ import { $connection } from '@/store/session'
import { CONTROL_TEXT } from './constants'
import { ListRow, Pill, SectionHeading, SettingsContent, SettingsSection, SettingsSkeleton } from './primitives'
-const START_POLL_MS = 1500
-const START_TIMEOUT_MS = 90_000
+const RESTART_POLL_MS = 1500
+const RESTART_TIMEOUT_MS = 90_000
/**
* The config says what the gateway serves from its next start; the gateway says what it serves now.
@@ -65,14 +65,23 @@ function phaseOf(status: WebAccessStatus): Phase {
return status.gateway.state === 'unavailable' ? 'unavailable' : 'pendingOn'
}
-/** Poll until the restarted gateway serves the web app or reports why it can't. */
-async function waitForWebApp(): Promise<WebAccessStatus> {
- for (const deadline = Date.now() + START_TIMEOUT_MS; Date.now() < deadline; ) {
- await new Promise(resolve => setTimeout(resolve, START_POLL_MS))
+/** The gateway applied the saved config: it serves the web app the config turns on (or says why it
+ * can't), or serves none when the config turns it off. */
+function appliesConfig(status: WebAccessStatus): boolean {
+ const phase = phaseOf(status)
+
+ return phase !== 'pendingOn' && phase !== 'pendingOff'
+}
+
+/** Poll until the restarted gateway applies the saved config. Start, Stop and Restart all wait here:
+ * until the old gateway exits it still answers with what it served before. */
+async function waitForRestart(): Promise<WebAccessStatus> {
+ for (const deadline = Date.now() + RESTART_TIMEOUT_MS; Date.now() < deadline; ) {
+ await new Promise(resolve => setTimeout(resolve, RESTART_POLL_MS))
// The backend answering this may be the gateway being restarted.
const status = await getWebAccessStatus().catch(() => null)
- if (status && (servesConfig(status) || status.gateway.state === 'unavailable')) {
+ if (status && appliesConfig(status)) {
return status
}
}
@@ -162,9 +171,8 @@ function WebAccessForm({ queryKey, status, w }: FormProps): ReactElement {
return
}
- if (result.enabled && kind !== 'stop') {
- apply(await waitForWebApp().catch(() => Promise.reject(new Error(w.startTimedOut))))
- }
+ const timedOut = result.enabled ? w.startTimedOut : w.stopTimedOut
+ apply(await waitForRestart().catch(() => Promise.reject(new Error(timedOut))))
} catch (err) {
notifyError(err, w.failed)
} finally {
@@ -281,7 +289,11 @@ function pillLabel(phase: Phase, busy: Busy, w: WebAccessTranslations): string {
unavailable: w.unavailable
}
- return busy === 'start' || (busy === 'restart' && phase === 'pendingOn') ? w.starting : labels[phase]
+ if (busy === 'start' || (busy === 'restart' && phase === 'pendingOn')) {
+ return w.starting
+ }
+
+ return busy === 'stop' || (busy === 'restart' && phase === 'pendingOff') ? w.stopping : labels[phase]
}
function describe(phase: Phase, status: WebAccessStatus, w: WebAccessTranslations): string {
diff --git a/apps/desktop/src/i18n/ar_settings.ts b/apps/desktop/src/i18n/ar_settings.ts
index 2df0a5002d2..67845dc87d4 100644
--- a/apps/desktop/src/i18n/ar_settings.ts
+++ b/apps/desktop/src/i18n/ar_settings.ts
@@ -715,6 +715,7 @@ export const arSettings = {
running: 'قيد التشغيل',
stopped: 'متوقف',
starting: 'جارٍ البدء',
+ stopping: 'جارٍ الإيقاف',
restartNeeded: 'يلزم إعادة التشغيل',
unavailable: 'غير متاح',
notRunningDetail: 'شغّله لفتح Hermes من جهاز آخر.',
@@ -728,6 +729,7 @@ export const arSettings = {
restartBusy: 'تم الحفظ. توجد محادثة قيد التشغيل، لذا لم تُعَد تشغيل البوابة. اختر «إعادة تشغيل البوابة» عند انتهائها.',
restartFailed: 'تم الحفظ، لكن تعذّرت إعادة تشغيل البوابة. اختر «إعادة تشغيل البوابة» للمحاولة مجددًا.',
startTimedOut: 'لم تقدّم البوابة تطبيق الويب خلال 90 ثانية.',
+ stopTimedOut: 'لم تتوقف البوابة عن تقديم تطبيق الويب خلال 90 ثانية.',
start: 'تشغيل',
stop: 'إيقاف',
restartGateway: 'إعادة تشغيل البوابة',
diff --git a/apps/desktop/src/i18n/de_gateway_host.ts b/apps/desktop/src/i18n/de_gateway_host.ts
index 89888f98f55..6f4681fac80 100644
--- a/apps/desktop/src/i18n/de_gateway_host.ts
+++ b/apps/desktop/src/i18n/de_gateway_host.ts
@@ -14,6 +14,7 @@ export const deGatewayHost: GatewayHostTranslations = {
running: 'Läuft',
stopped: 'Gestoppt',
starting: 'Wird gestartet',
+ stopping: 'Wird gestoppt',
restartNeeded: 'Neustart nötig',
unavailable: 'Nicht verfügbar',
notRunningDetail: 'Starte ihn, um Hermes von einem anderen Gerät aus zu öffnen.',
@@ -27,6 +28,7 @@ export const deGatewayHost: GatewayHostTranslations = {
restartBusy: 'Gespeichert. Ein Chat läuft, deshalb wurde das Gateway nicht neu gestartet. Wähle „Gateway neu starten“, sobald er beendet ist.',
restartFailed: 'Gespeichert, aber das Gateway konnte nicht neu starten. Wähle „Gateway neu starten“, um es erneut zu versuchen.',
startTimedOut: 'Das Gateway hat die Web-App nicht innerhalb von 90 Sekunden bereitgestellt.',
+ stopTimedOut: 'Das Gateway hat die Bereitstellung der Web-App nicht innerhalb von 90 Sekunden beendet.',
start: 'Starten',
stop: 'Stoppen',
restartGateway: 'Gateway neu starten',
diff --git a/apps/desktop/src/i18n/en_gateway_host.ts b/apps/desktop/src/i18n/en_gateway_host.ts
index 5bdd3c0215d..f8d837e47be 100644
--- a/apps/desktop/src/i18n/en_gateway_host.ts
+++ b/apps/desktop/src/i18n/en_gateway_host.ts
@@ -14,6 +14,7 @@ export const enGatewayHost: GatewayHostTranslations = {
running: 'Running',
stopped: 'Stopped',
starting: 'Starting',
+ stopping: 'Stopping',
restartNeeded: 'Restart needed',
unavailable: 'Unavailable',
notRunningDetail: 'Start it to open Hermes from another device.',
@@ -27,6 +28,7 @@ export const enGatewayHost: GatewayHostTranslations = {
restartBusy: "Saved. A chat is running, so the gateway didn't restart. Choose Restart gateway once it ends.",
restartFailed: "Saved, but the gateway couldn't restart. Choose Restart gateway to try again.",
startTimedOut: "The gateway didn't serve the web app within 90 seconds.",
+ stopTimedOut: "The gateway didn't stop serving the web app within 90 seconds.",
start: 'Start',
stop: 'Stop',
restartGateway: 'Restart gateway',
diff --git a/apps/desktop/src/i18n/es_gateway_host.ts b/apps/desktop/src/i18n/es_gateway_host.ts
index b4b1ac13e32..9a1b4e89069 100644
--- a/apps/desktop/src/i18n/es_gateway_host.ts
+++ b/apps/desktop/src/i18n/es_gateway_host.ts
@@ -15,6 +15,7 @@ export const esGatewayHost: GatewayHostTranslations = {
running: 'En ejecución',
stopped: 'Detenido',
starting: 'Iniciando',
+ stopping: 'Deteniendo',
restartNeeded: 'Reinicio necesario',
unavailable: 'No disponible',
notRunningDetail: 'Inícialo para abrir Hermes desde otro dispositivo.',
@@ -28,6 +29,7 @@ export const esGatewayHost: GatewayHostTranslations = {
restartBusy: 'Guardado. Hay un chat en curso, así que el gateway no se reinició. Elige «Reiniciar gateway» cuando termine.',
restartFailed: 'Guardado, pero el gateway no pudo reiniciarse. Elige «Reiniciar gateway» para volver a intentarlo.',
startTimedOut: 'El gateway no sirvió la aplicación web en 90 segundos.',
+ stopTimedOut: 'El gateway no dejó de servir la aplicación web en 90 segundos.',
start: 'Iniciar',
stop: 'Detener',
restartGateway: 'Reiniciar gateway',
diff --git a/apps/desktop/src/i18n/fr_gateway_host.ts b/apps/desktop/src/i18n/fr_gateway_host.ts
index 7279be7b988..6754f5e74a9 100644
--- a/apps/desktop/src/i18n/fr_gateway_host.ts
+++ b/apps/desktop/src/i18n/fr_gateway_host.ts
@@ -14,6 +14,7 @@ export const frGatewayHost: GatewayHostTranslations = {
running: 'En cours',
stopped: 'Arrêté',
starting: 'Démarrage',
+ stopping: 'Arrêt en cours',
restartNeeded: 'Redémarrage requis',
unavailable: 'Indisponible',
notRunningDetail: 'Démarrez-le pour ouvrir Hermes depuis un autre appareil.',
@@ -27,6 +28,7 @@ export const frGatewayHost: GatewayHostTranslations = {
restartBusy: "Enregistré. Une conversation est en cours, la passerelle n'a donc pas redémarré. Choisissez « Redémarrer la passerelle » une fois qu'elle est terminée.",
restartFailed: "Enregistré, mais la passerelle n'a pas pu redémarrer. Choisissez « Redémarrer la passerelle » pour réessayer.",
startTimedOut: "La passerelle n'a pas servi l'application web en 90 secondes.",
+ stopTimedOut: "La passerelle n'a pas cessé de servir l'application web en 90 secondes.",
start: 'Démarrer',
stop: 'Arrêter',
restartGateway: 'Redémarrer la passerelle',
diff --git a/apps/desktop/src/i18n/ja_gateway_host.ts b/apps/desktop/src/i18n/ja_gateway_host.ts
index b467bb51469..d89186b9784 100644
--- a/apps/desktop/src/i18n/ja_gateway_host.ts
+++ b/apps/desktop/src/i18n/ja_gateway_host.ts
@@ -14,6 +14,7 @@ export const jaGatewayHost: GatewayHostTranslations = {
running: '実行中',
stopped: '停止中',
starting: '起動中',
+ stopping: '停止処理中',
restartNeeded: '再起動が必要',
unavailable: '利用できません',
notRunningDetail: '起動すると、別のデバイスから Hermes を開けます。',
@@ -27,6 +28,7 @@ export const jaGatewayHost: GatewayHostTranslations = {
restartBusy: '保存しました。チャットが実行中のため、ゲートウェイは再起動しませんでした。終了したら「ゲートウェイを再起動」を選んでください。',
restartFailed: '保存しましたが、ゲートウェイを再起動できませんでした。「ゲートウェイを再起動」を選んで再試行してください。',
startTimedOut: 'ゲートウェイが 90 秒以内に Web アプリを提供しませんでした。',
+ stopTimedOut: 'ゲートウェイが 90 秒以内に Web アプリの提供を停止しませんでした。',
start: '開始',
stop: '停止',
restartGateway: 'ゲートウェイを再起動',
diff --git a/apps/desktop/src/i18n/ru_gateway_host.ts b/apps/desktop/src/i18n/ru_gateway_host.ts
index d111418dc3f..efb36b05558 100644
--- a/apps/desktop/src/i18n/ru_gateway_host.ts
+++ b/apps/desktop/src/i18n/ru_gateway_host.ts
@@ -14,6 +14,7 @@ export const ruGatewayHost: GatewayHostTranslations = {
running: 'Работает',
stopped: 'Остановлен',
starting: 'Запускается',
+ stopping: 'Останавливается',
restartNeeded: 'Нужен перезапуск',
unavailable: 'Недоступен',
notRunningDetail: 'Запустите его, чтобы открыть Hermes с другого устройства.',
@@ -27,6 +28,7 @@ export const ruGatewayHost: GatewayHostTranslations = {
restartBusy: 'Сохранено. Идёт чат, поэтому шлюз не перезапущен. Когда он закончится, нажмите «Перезапустить шлюз».',
restartFailed: 'Сохранено, но шлюз не удалось перезапустить. Нажмите «Перезапустить шлюз», чтобы попробовать снова.',
startTimedOut: 'Шлюз не открыл веб-приложение за 90 секунд.',
+ stopTimedOut: 'Шлюз не перестал открывать веб-приложение за 90 секунд.',
start: 'Запустить',
stop: 'Остановить',
restartGateway: 'Перезапустить шлюз',
diff --git a/apps/desktop/src/i18n/types_gateway_host.ts b/apps/desktop/src/i18n/types_gateway_host.ts
index cf7e0236c6a..be995939854 100644
--- a/apps/desktop/src/i18n/types_gateway_host.ts
+++ b/apps/desktop/src/i18n/types_gateway_host.ts
@@ -17,6 +17,7 @@ export interface WebAccessTranslations {
running: string
stopped: string
starting: string
+ stopping: string
restartNeeded: string
unavailable: string
notRunningDetail: string
@@ -30,6 +31,7 @@ export interface WebAccessTranslations {
restartBusy: string
restartFailed: string
startTimedOut: string
+ stopTimedOut: string
start: string
stop: string
restartGateway: string
diff --git a/apps/desktop/src/i18n/zh-hant_settings.ts b/apps/desktop/src/i18n/zh-hant_settings.ts
index d68df41d514..80a5201ed7e 100644
--- a/apps/desktop/src/i18n/zh-hant_settings.ts
+++ b/apps/desktop/src/i18n/zh-hant_settings.ts
@@ -982,6 +982,7 @@ export const zhHantSettings = {
running: '執行中',
stopped: '已停止',
starting: '正在啟動',
+ stopping: '正在停止',
restartNeeded: '需要重新啟動',
unavailable: '無法使用',
notRunningDetail: '啟動後即可從其他裝置開啟 Hermes。',
@@ -995,6 +996,7 @@ export const zhHantSettings = {
restartBusy: '已儲存。有對話正在進行,因此閘道沒有重新啟動。對話結束後請選擇「重新啟動閘道」。',
restartFailed: '已儲存,但閘道無法重新啟動。請選擇「重新啟動閘道」重試。',
startTimedOut: '閘道未能在 90 秒內提供網頁應用程式。',
+ stopTimedOut: '閘道未能在 90 秒內停止提供網頁應用程式。',
start: '啟動',
stop: '停止',
restartGateway: '重新啟動閘道',
diff --git a/apps/desktop/src/i18n/zh_gateway_host.ts b/apps/desktop/src/i18n/zh_gateway_host.ts
index 7d7ba523fed..47e8f45a00d 100644
--- a/apps/desktop/src/i18n/zh_gateway_host.ts
+++ b/apps/desktop/src/i18n/zh_gateway_host.ts
@@ -14,6 +14,7 @@ export const zhGatewayHost: GatewayHostTranslations = {
running: '运行中',
stopped: '已停止',
starting: '正在启动',
+ stopping: '正在停止',
restartNeeded: '需要重启',
unavailable: '不可用',
notRunningDetail: '启动后即可从其他设备打开 Hermes。',
@@ -27,6 +28,7 @@ export const zhGatewayHost: GatewayHostTranslations = {
restartBusy: '已保存。有对话正在进行,因此网关没有重启。对话结束后请选择“重启网关”。',
restartFailed: '已保存,但网关无法重启。请选择“重启网关”重试。',
startTimedOut: '网关未能在 90 秒内提供网页应用。',
+ stopTimedOut: '网关未能在 90 秒内停止提供网页应用。',
start: '启动',
stop: '停止',
restartGateway: '重启网关',
diff --git a/locales/_keys.desktop.json b/locales/_keys.desktop.json
index d7944d68c27..b2a3be39aac 100644
--- a/locales/_keys.desktop.json
+++ b/locales/_keys.desktop.json
@@ -3554,7 +3554,9 @@
"settings.gateway.webAccess.startTimedOut",
"settings.gateway.webAccess.starting",
"settings.gateway.webAccess.stop",
+ "settings.gateway.webAccess.stopTimedOut",
"settings.gateway.webAccess.stopped",
+ "settings.gateway.webAccess.stopping",
"settings.gateway.webAccess.title",
"settings.gateway.webAccess.unavailable",
"settings.gateway.webAccess.unavailableDetail",