From a8fdceba5bd6d95f69aa1eb95b5b0ee1fa4419ea Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sun, 18 Oct 2026 01:01:32 +0200 Subject: [PATCH] ui: Quit Strata in the menu in browser mode (confirm, stopped screen), 8 languages; host: open the page without changing the mode --- apps/host/src/app/Sidebar.tsx | 6 ++++- apps/host/src/components/QuitStrata.tsx | 29 +++++++++++++++++++++++++ apps/host/src/lib/app-mode.ts | 25 +++++++++++++++++++++ apps/host/src/locales/de.json | 9 +++++++- apps/host/src/locales/en.json | 9 +++++++- apps/host/src/locales/es.json | 9 +++++++- apps/host/src/locales/ja.json | 9 +++++++- apps/host/src/locales/ko.json | 9 +++++++- apps/host/src/locales/pt.json | 9 +++++++- apps/host/src/locales/ru.json | 9 +++++++- apps/host/src/locales/zh.json | 9 +++++++- 11 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 apps/host/src/components/QuitStrata.tsx create mode 100644 apps/host/src/lib/app-mode.ts diff --git a/apps/host/src/app/Sidebar.tsx b/apps/host/src/app/Sidebar.tsx index e51571f2..c2218d9c 100644 --- a/apps/host/src/app/Sidebar.tsx +++ b/apps/host/src/app/Sidebar.tsx @@ -7,6 +7,8 @@ import { TaskTree } from './TaskTree'; import { useEffect, useId, useLayoutEffect, useRef, useState, type RefObject } from 'react'; import { createPortal } from 'react-dom'; import { FloatingMenu } from '../components/FloatingMenu'; +import { QuitStrataDialog } from '../components/QuitStrata'; +import { useAppMode } from '../lib/app-mode'; import { href, useLocation, type Route } from '../lib/router'; import { cx, relTime } from '../lib/format'; import { useMedia } from '../lib/responsive'; @@ -182,6 +184,8 @@ function MoreMenu({ current }: { current: string; }) { const [open, setOpen] = useState(false); + const [quitOpen, setQuitOpen] = useState(false); + const appMode = useAppMode(); const ref = useRef(null); - return <>{tr(open ? { setOpen(false); ref.current?.focus(); }}>{tr(([{ route: 'serving', label: 'Serving', icon: 'link' }, { route: 'settings', label: 'Settings', icon: 'settings' }] as const).map(d => setOpen(false)}>{tr(d.label)}))} : null)}; + return <>{tr(open ? { setOpen(false); ref.current?.focus(); }}>{tr(([{ route: 'serving', label: 'Serving', icon: 'link' }, { route: 'settings', label: 'Settings', icon: 'settings' }] as const).map(d => setOpen(false)}>{tr(d.label)}))}{appMode.canQuit ? : null} : null)} setQuitOpen(false)}/>; } diff --git a/apps/host/src/components/QuitStrata.tsx b/apps/host/src/components/QuitStrata.tsx new file mode 100644 index 00000000..15704a66 --- /dev/null +++ b/apps/host/src/components/QuitStrata.tsx @@ -0,0 +1,29 @@ +import { useEffect, useState } from 'react'; +import { tr } from '../lib/i18n'; +import { Btn, Dialog } from './ui'; + +/** + * Browser mode only (the app window could not start, or the person asked for `--browser`): closing the tab does not stop Strata or + * its engine, so the menu has "Quit Strata". The host refuses the request in the app window, where closing the window quits. + */ +export function QuitStrataDialog({ open, onClose }: { open: boolean; onClose: () => void }) { + const [state, setState] = useState<'ask' | 'stopping' | 'stopped' | 'failed'>('ask'); + useEffect(() => { if (open) setState('ask'); }, [open]); + async function quit() { + setState('stopping'); + try { + // the header is what a web page on another site cannot send; the host also refuses any request that does not come from this computer + const response = await fetch('/api/app/quit', { method: 'POST', headers: { 'x-strata-client': 'ui' } }); + setState(response.ok ? 'stopped' : 'failed'); + } catch { setState('failed'); } + } + const stopped = state === 'stopped'; + return {} : onClose} + actions={stopped ? undefined : <>{tr("Cancel")} void quit()}>{tr(state === 'stopping' ? "Quitting…" : "Quit Strata")}}> +

{tr(stopped + ? "Strata has stopped. You can close this tab. To use it again, start Strata from its icon." + : state === 'failed' + ? "Strata could not be stopped from here. Run the app with --quit in a terminal, or try again." + : "This stops the model and ends Strata. Your chats and files stay as they are. Closing the browser tab alone would leave Strata running.")}

+
; +} diff --git a/apps/host/src/lib/app-mode.ts b/apps/host/src/lib/app-mode.ts new file mode 100644 index 00000000..8c481dcb --- /dev/null +++ b/apps/host/src/lib/app-mode.ts @@ -0,0 +1,25 @@ +import { useEffect, useState } from 'react'; +import { api } from './client'; + +/** Which window shows the page: the app window ('window'), a browser tab ('browser'), or neither (a host nobody started: null). */ +export interface AppMode { + mode: 'window' | 'browser' | null; + reason: string | null; + canQuit: boolean; + appUpdate: 'available' | 'unavailable'; +} + +const NONE: AppMode = { mode: null, reason: null, canQuit: false, appUpdate: 'unavailable' }; +let loading: Promise | null = null; + +/** Asked once per page load; an older host without the route (404) or a failed call means "not the app": nothing extra is shown. */ +export function loadAppMode(): Promise { + loading ??= api.get('/api/app/mode').catch(() => NONE); + return loading; +} + +export function useAppMode(): AppMode { + const [mode, setMode] = useState(NONE); + useEffect(() => { let live = true; void loadAppMode().then(m => { if (live) setMode(m); }); return () => { live = false; }; }, []); + return mode; +} diff --git a/apps/host/src/locales/de.json b/apps/host/src/locales/de.json index 1c7b0f4f..f16510a9 100644 --- a/apps/host/src/locales/de.json +++ b/apps/host/src/locales/de.json @@ -3143,5 +3143,12 @@ "s3147": "Der Ordner-Auswahldialog konnte nicht geöffnet werden. Installiere zenity oder kdialog, um einen Ordner auszuwählen, oder gib den Pfad ein.", "s3148": "Ordnerpfad eingeben", "s3149": "Ordnerpfad", - "s3150": "/home/du/Dokumente" + "s3150": "/home/du/Dokumente", + "s3151": "Strata beenden", + "s3152": "Strata beenden?", + "s3153": "Dadurch wird das Modell gestoppt und Strata beendet. Deine Chats und Dateien bleiben erhalten. Nur den Browser-Tab zu schließen, lässt Strata weiterlaufen.", + "s3154": "Strata wurde beendet", + "s3155": "Strata wurde beendet. Du kannst diesen Tab schließen. Um es wieder zu nutzen, starte Strata über sein Symbol.", + "s3156": "Strata konnte von hier aus nicht beendet werden. Starte die App im Terminal mit --quit oder versuche es erneut.", + "s3157": "Wird beendet …" } diff --git a/apps/host/src/locales/en.json b/apps/host/src/locales/en.json index cd59f462..724c44a1 100644 --- a/apps/host/src/locales/en.json +++ b/apps/host/src/locales/en.json @@ -3143,5 +3143,12 @@ "s3147": "The folder chooser could not open. Install zenity or kdialog to pick a folder, or type the path.", "s3148": "Type the folder path", "s3149": "Folder path", - "s3150": "/home/you/Documents" + "s3150": "/home/you/Documents", + "s3151": "Quit Strata", + "s3152": "Quit Strata?", + "s3153": "This stops the model and ends Strata. Your chats and files stay as they are. Closing the browser tab alone would leave Strata running.", + "s3154": "Strata has stopped", + "s3155": "Strata has stopped. You can close this tab. To use it again, start Strata from its icon.", + "s3156": "Strata could not be stopped from here. Run the app with --quit in a terminal, or try again.", + "s3157": "Quitting…" } diff --git a/apps/host/src/locales/es.json b/apps/host/src/locales/es.json index eb20f8e2..8d385cad 100644 --- a/apps/host/src/locales/es.json +++ b/apps/host/src/locales/es.json @@ -3143,5 +3143,12 @@ "s3147": "No se pudo abrir el selector de carpetas. Instala zenity o kdialog para elegir una carpeta, o escribe la ruta.", "s3148": "Escribe la ruta de la carpeta", "s3149": "Ruta de la carpeta", - "s3150": "/home/tu/Documentos" + "s3150": "/home/tu/Documentos", + "s3151": "Salir de Strata", + "s3152": "¿Salir de Strata?", + "s3153": "Esto detiene el modelo y cierra Strata. Tus chats y archivos se quedan como están. Cerrar solo la pestaña del navegador dejaría Strata en marcha.", + "s3154": "Strata se ha detenido", + "s3155": "Strata se ha detenido. Puedes cerrar esta pestaña. Para volver a usarlo, inicia Strata desde su icono.", + "s3156": "No se pudo detener Strata desde aquí. Ejecuta la app con --quit en una terminal o inténtalo de nuevo.", + "s3157": "Saliendo…" } diff --git a/apps/host/src/locales/ja.json b/apps/host/src/locales/ja.json index 2bf26ac0..247bfcaa 100644 --- a/apps/host/src/locales/ja.json +++ b/apps/host/src/locales/ja.json @@ -3143,5 +3143,12 @@ "s3147": "フォルダー選択ツールを開けませんでした。zenity か kdialog をインストールしてフォルダーを選ぶか、パスを入力してください。", "s3148": "フォルダーのパスを入力", "s3149": "フォルダーのパス", - "s3150": "/home/you/Documents" + "s3150": "/home/you/Documents", + "s3151": "Strata を終了", + "s3152": "Strata を終了しますか?", + "s3153": "モデルを停止して Strata を終了します。チャットとファイルはそのまま残ります。ブラウザのタブを閉じるだけでは Strata は動き続けます。", + "s3154": "Strata を停止しました", + "s3155": "Strata を停止しました。このタブを閉じて構いません。もう一度使うには、アイコンから Strata を起動してください。", + "s3156": "ここから Strata を停止できませんでした。ターミナルで --quit を付けてアプリを実行するか、もう一度お試しください。", + "s3157": "終了しています…" } diff --git a/apps/host/src/locales/ko.json b/apps/host/src/locales/ko.json index 84616405..cd047999 100644 --- a/apps/host/src/locales/ko.json +++ b/apps/host/src/locales/ko.json @@ -3143,5 +3143,12 @@ "s3147": "폴더 선택 도구를 열지 못했습니다. zenity 또는 kdialog를 설치해 폴더를 고르거나, 경로를 직접 입력하세요.", "s3148": "폴더 경로 입력", "s3149": "폴더 경로", - "s3150": "/home/you/Documents" + "s3150": "/home/you/Documents", + "s3151": "Strata 종료", + "s3152": "Strata를 종료할까요?", + "s3153": "모델을 멈추고 Strata를 종료합니다. 채팅과 파일은 그대로 남습니다. 브라우저 탭만 닫으면 Strata는 계속 실행됩니다.", + "s3154": "Strata가 종료되었습니다", + "s3155": "Strata가 종료되었습니다. 이 탭을 닫아도 됩니다. 다시 사용하려면 아이콘에서 Strata를 실행하세요.", + "s3156": "여기서는 Strata를 종료하지 못했습니다. 터미널에서 --quit 옵션으로 앱을 실행하거나 다시 시도하세요.", + "s3157": "종료하는 중…" } diff --git a/apps/host/src/locales/pt.json b/apps/host/src/locales/pt.json index a561ec0d..72f7f90b 100644 --- a/apps/host/src/locales/pt.json +++ b/apps/host/src/locales/pt.json @@ -3143,5 +3143,12 @@ "s3147": "Não foi possível abrir o seletor de pastas. Instale o zenity ou o kdialog para escolher uma pasta, ou digite o caminho.", "s3148": "Digite o caminho da pasta", "s3149": "Caminho da pasta", - "s3150": "/home/voce/Documentos" + "s3150": "/home/voce/Documentos", + "s3151": "Sair do Strata", + "s3152": "Sair do Strata?", + "s3153": "Isto para o modelo e encerra o Strata. Os seus chats e ficheiros ficam como estão. Fechar apenas o separador do navegador deixaria o Strata a funcionar.", + "s3154": "O Strata parou", + "s3155": "O Strata parou. Pode fechar este separador. Para o usar de novo, inicie o Strata a partir do seu ícone.", + "s3156": "Não foi possível parar o Strata a partir daqui. Execute a app com --quit num terminal ou tente novamente.", + "s3157": "A sair…" } diff --git a/apps/host/src/locales/ru.json b/apps/host/src/locales/ru.json index 887efcf2..b896d691 100644 --- a/apps/host/src/locales/ru.json +++ b/apps/host/src/locales/ru.json @@ -3143,5 +3143,12 @@ "s3147": "Не удалось открыть окно выбора папки. Установите zenity или kdialog, чтобы выбрать папку, или введите путь.", "s3148": "Введите путь к папке", "s3149": "Путь к папке", - "s3150": "/home/you/Documents" + "s3150": "/home/you/Documents", + "s3151": "Выйти из Strata", + "s3152": "Выйти из Strata?", + "s3153": "Модель будет остановлена, а Strata закрыта. Ваши чаты и файлы останутся как есть. Если просто закрыть вкладку браузера, Strata продолжит работать.", + "s3154": "Strata остановлена", + "s3155": "Strata остановлена. Эту вкладку можно закрыть. Чтобы снова пользоваться, запустите Strata по её значку.", + "s3156": "Не удалось остановить Strata отсюда. Запустите приложение с --quit в терминале или повторите попытку.", + "s3157": "Выход…" } diff --git a/apps/host/src/locales/zh.json b/apps/host/src/locales/zh.json index b49b384b..faf43c01 100644 --- a/apps/host/src/locales/zh.json +++ b/apps/host/src/locales/zh.json @@ -3143,5 +3143,12 @@ "s3147": "无法打开文件夹选择器。请安装 zenity 或 kdialog 来选择文件夹,或直接输入路径。", "s3148": "输入文件夹路径", "s3149": "文件夹路径", - "s3150": "/home/you/Documents" + "s3150": "/home/you/Documents", + "s3151": "退出 Strata", + "s3152": "退出 Strata?", + "s3153": "这会停止模型并结束 Strata。你的聊天和文件保持原样。仅关闭浏览器标签页会让 Strata 继续运行。", + "s3154": "Strata 已停止", + "s3155": "Strata 已停止。你可以关闭此标签页。要再次使用,请从图标启动 Strata。", + "s3156": "无法在这里停止 Strata。请在终端中用 --quit 运行应用,或再试一次。", + "s3157": "正在退出…" }