diff --git a/docs/design-guidelines.md b/docs/design-guidelines.md index 1e75b1c..481e3fb 100644 --- a/docs/design-guidelines.md +++ b/docs/design-guidelines.md @@ -20,7 +20,7 @@ Reims-Go 的桌面外壳遵循「**macOS 的结构与词表,Windows 的平台 | :--- | :--- | | **声明式配置** | 一台虚拟机对应一份声明式配置,界面只编辑配置项,不让用户直接拼 QEMU 命令行参数。 | | **先校验,后保存** | 保存前在 Go 端完成前置校验(CPU 核数、可用提交内存上限、Vulkan ICD 路径存在性、切换磁盘控制器前是否已弹出安装盘),非法值在提交前拦截。 | -| **随时可编辑,标明生效时机** | 无论虚拟机运行与否,设置面板均可打开编辑;每项设置明确标注生效时机。运行中保存「下次启动生效」的修改时,详情页汇总待生效项并提供「重启以应用」。 | +| **标明设置的生效时机** | 虚拟机运行中或已停止时可编辑设置。每项设置明确标注生效时机。运行中保存「下次启动生效」的修改时,详情页汇总待生效项并提供「重启以应用」。 | **写入约束**:凡属于上游 `reims-ctl` 管理的配置项,一律通过 `reims-ctl set` 写入,不直接改写 `vm.toml`,确保上游校验与 OpenCore 重建逻辑照常生效。 @@ -55,11 +55,14 @@ Reims-Go 的桌面外壳遵循「**macOS 的结构与词表,Windows 的平台 | **正在创建** | 创建流程进行中 | 无(展示分步进度) | 取消创建 | | **已停止** | 上游 `stopped` | **启动** | 设置、恢复点、更多(派生副本、扩容/回收、打开目录、删除) | | **正在启动** | 发起 `start` 至 `running` | 启动中(忙碌态,禁用) | 设置、强制关机 | -| **运行中** | 上游 `running` | **显示 VM 窗口** | 关机、截屏、设置、更多(重启、强制关机、发送文本、进入/退出恢复模式、导出排障包) | +| **运行中** | 上游 `running` | **显示 VM 窗口** | 挂起(需支持此功能的内核)、关机、截屏、设置、更多(重启、强制关机、发送文本、进入/退出恢复模式、导出排障包) | | **正在停止** | 发起 `stop` 至 `stopped` | 停止中(忙碌态,禁用) | 强制关机 | +| **正在挂起** | 正在保存运行状态 | 挂起中(忙碌态,禁用) | 强制关机 | +| **已挂起** | 运行状态已保存到磁盘 | **恢复**(需支持此功能的内核) | 更多(放弃挂起状态、打开目录) | +| **正在恢复** | 正在从磁盘恢复运行状态 | 恢复中(忙碌态,禁用) | 强制关机 | | **配置损坏** | 上游 `broken` | **查看问题** | 打开目录、删除 | -- 暂不提供暂停或运行中热快照状态(`paused` / `saving` / `restoring`),直到上游验证 `reims-vgpu` 显存与设备状态序列化。 +- 已挂起时,恢复或放弃挂起状态后才可修改配置、管理磁盘和安装或弹出 Guest Tools。切换到不支持挂起的内核时,禁用恢复并提示用户切换内核。放弃挂起状态须经破坏性操作确认框确认。 - 禁用按钮不占据主操作位置;状态变化时直接切换为当前最合适的主操作。 --- diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 9f9c55c..11d5d38 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -20,7 +20,7 @@ import { applyActiveLocaleFonts, applyActiveTheme, disposeActiveThemeAndLocaleFo import { latestVMStats, refreshSubscribedVMStats, refreshVMStats } from './lib/vmStats' import { ActiveThemePayload, AppState, AppUpdateInfo, CachedInstaller, CreateOpts, Locale, PluginUIContributions, Task, VMDetail } from './types' import { Button, Tip, TooltipProvider } from './ui/controls' -import { Modal } from './ui/dialog' +import { ConfirmDialog, Modal } from './ui/dialog' import { Toaster, useToasts } from './ui/toast' import { api, events, OnFileDrop, OnFileDropOff, WindowMinimise, WindowToggleMaximise } from './wails' @@ -335,15 +335,7 @@ export const App: React.FC = () => { const effectiveState = selectedVM ? (state?.transitions[selectedVM.name] ?? selectedVM.state) : '' const pending = selectedVM ? (state?.pending_changes[selectedVM.name] ?? []) : [] const hostReady = !!state && state.host.whpx === 'ready' && !!state.active_runtime - const activeManifest = state?.active_runtime?.manifest - const canSuspend = Boolean( - activeManifest?.capabilities?.some((c) => c.toLowerCase() === 'vm-suspend') - || ( - activeManifest?.patches?.some((p) => p.name.toLowerCase().includes('win32-mapped-ram-io')) - && activeManifest?.patches?.some((p) => p.name.toLowerCase().includes('intel-whpx-suspend')) - && activeManifest?.patches?.some((p) => p.name.toLowerCase().includes('reims-vgpu-snapshot-replay')) - ), - ) + const canSuspend = state?.can_suspend ?? false onTaskRef.current = (task: Task) => { if (task.kind === 'app-update' && task.status === 'failed' && !notifiedTasks.current.has(task.id)) { @@ -669,6 +661,7 @@ export const App: React.FC = () => { } const onVMActionFor = (name: string, action: VMAction, isRunning: boolean) => { + if (!canSuspend && (action === 'suspend' || action === 'resume')) return const activeBusy = activeVMBusy(name) if ( activeBusy @@ -905,7 +898,11 @@ export const App: React.FC = () => { useEffect(() => { const offSelect = events.onTraySelectVM((name) => { setSelected(name) }) const offNew = events.onTrayNewVM(() => { openWizardRef.current() }) - return () => { offSelect(); offNew() } + const offDiscard = events.onTrayDiscardSuspend((name) => { + setSelected(name) + setDiscardSuspendTarget(name) + }) + return () => { offSelect(); offNew(); offDiscard() } }, []) // Native Wails file drag-and-drop delivery into the selected VM's shared folder. @@ -1309,22 +1306,14 @@ export const App: React.FC = () => { )} {discardSuspendTarget && ( - setDiscardSuspendTarget(null)} - > - - {tr('discardSuspendDesc')} - - - - - setDiscardSuspendTarget(null)}>{tr('cancel')} - {tr('discardSuspendConfirm')} - - - + description={tr('discardSuspendDesc')} + cancelLabel={tr('cancel')} + confirmLabel={tr('discardSuspendConfirm')} + onCancel={() => setDiscardSuspendTarget(null)} + onConfirm={confirmDiscardSuspend} + /> )} {cloneSource && ( diff --git a/frontend/src/components/DeleteDialog.tsx b/frontend/src/components/DeleteDialog.tsx index fd2e4b8..50943b1 100644 --- a/frontend/src/components/DeleteDialog.tsx +++ b/frontend/src/components/DeleteDialog.tsx @@ -1,7 +1,7 @@ -import * as Alert from '@radix-ui/react-alert-dialog' import React, { useState } from 'react' import { t } from '../i18n' import { Locale } from '../types' +import { ConfirmDialog } from '../ui/dialog' interface Props { locale: Locale @@ -13,32 +13,18 @@ interface Props { export const DeleteDialog: React.FC = ({ locale, name, onCancel, onConfirm }) => { const [keepFiles, setKeepFiles] = useState(false) return ( - { if (!open) onCancel() }}> - - - - - {t(locale, 'deleteTitle', { name })} - - {t(locale, keepFiles ? 'deleteDescKeep' : 'deleteDesc')} - - - setKeepFiles(e.target.checked)} /> - {t(locale, 'deleteKeepFiles')} - - - - - {t(locale, 'cancel')} - - - onConfirm(keepFiles)}> - {t(locale, 'deleteConfirm')} - - - - - - + onConfirm(keepFiles)} + > + + setKeepFiles(e.target.checked)} /> + {t(locale, 'deleteKeepFiles')} + + ) } diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx index c6bdd41..850dc2e 100644 --- a/frontend/src/components/Sidebar.tsx +++ b/frontend/src/components/Sidebar.tsx @@ -25,7 +25,7 @@ interface Props { selected: string hostReady: boolean /** Whether the active runtime supports VM suspend/resume. */ - canSuspend?: boolean + canSuspend: boolean onSelect: (id: string) => void /** VM name → display name (its note); empty or missing shows the name. */ displayNames?: Record @@ -164,9 +164,10 @@ export const Sidebar: React.FC = ({ )} {suspended && ( <> - onVMContextAction(vm.name, 'resume')}> + onVMContextAction(vm.name, 'resume')}> {tr('resume')} + {!canSuspend && {tr('resumeUnavailable')}} onVMContextAction(vm.name, 'discardSuspend')}> {tr('discardSuspend')} diff --git a/frontend/src/components/TitleMenus.tsx b/frontend/src/components/TitleMenus.tsx index 4253d95..477d11b 100644 --- a/frontend/src/components/TitleMenus.tsx +++ b/frontend/src/components/TitleMenus.tsx @@ -27,7 +27,7 @@ interface Props { canDark?: boolean onThemeMode: (mode: ThemeMode) => void /** The selected VM and its current state, or null on the system pages. */ - vm: { name: string; state: string; busy: boolean; graphics?: string; canSuspend?: boolean } | null + vm: { name: string; state: string; busy: boolean; graphics?: string; canSuspend: boolean } | null onNewVM: () => void onVMAction: (action: VMAction) => void onVMSettings: () => void @@ -220,8 +220,9 @@ export const TitleMenus: React.FC = ({ {running ? item(tr('showWindow'), () => onVMAction('focus'), { shortcut: 'Ctrl+Enter', disabled: vmBusy }) : suspended - ? item(tr('resume'), () => onVMAction('resume'), { shortcut: 'Ctrl+Enter', disabled: vmBusy }) + ? item(tr('resume'), () => onVMAction('resume'), { shortcut: vm?.canSuspend ? 'Ctrl+Enter' : undefined, disabled: vmBusy || !vm?.canSuspend }) : item(tr('start'), () => onVMAction('start'), { shortcut: 'Ctrl+Enter', disabled: vmBusy || !stopped })} + {suspended && !vm?.canSuspend && {tr('resumeUnavailable')}} {item(fullscreenLabel, () => onVMAction('fullscreen'), { disabled: vmBusy || !canFullscreen })} {item(tr('suspend'), () => onVMAction('suspend'), { disabled: vmBusy || !running || !vm?.canSuspend })} {item(tr('stop'), () => onVMAction('stop'), { disabled: vmBusy || !running })} diff --git a/frontend/src/components/VMPage.tsx b/frontend/src/components/VMPage.tsx index f42998f..cf1adb0 100644 --- a/frontend/src/components/VMPage.tsx +++ b/frontend/src/components/VMPage.tsx @@ -41,7 +41,7 @@ import { Upload, UserRound, } from 'lucide-react' -import React, { useEffect, useRef, useState } from 'react' +import React, { useEffect, useId, useRef, useState } from 'react' import { I18nKey, locText, t } from '../i18n' import { controllerLabel, formatBytes, formatDiskUsage, formatMemory, formatUptime, graphicsLabel, @@ -97,7 +97,7 @@ interface Props { macosMajor: number | null state: string /** Whether the active runtime supports VM suspend/resume. */ - canSuspend?: boolean + canSuspend: boolean /** Whether the native VM-window installation guide is currently active for this boot. */ guideActive: boolean /** Whether the builtin.install-guide plugin is enabled. */ @@ -144,6 +144,9 @@ export const VMPage: React.FC = ({ const busy = busyAction !== undefined const running = state === 'running' const suspended = state === 'suspended' + const guestToolsLocked = suspended || state === 'suspending' || state === 'resuming' + const resumeHintId = useId() + const guestToolsHintId = useId() const installing = !!detail && (detail.has_installer || detail.recovery_mode) const transitioning = state === 'starting' || state === 'stopping' || state === 'suspending' || state === 'resuming' // Polled here rather than in App so each tick re-renders only this page. @@ -338,17 +341,19 @@ export const VMPage: React.FC = ({ ) } else if (suspended) { primary = ( - - } busy={busyAction === 'resume'} disabled={busy} onClick={() => onAction('resume')}> + + } + busy={busyAction === 'resume'} + disabled={busy || !canSuspend} + aria-describedby={!canSuspend ? resumeHintId : undefined} + onClick={() => onAction('resume')} + > {tr('resume')} ) - secondary = ( - } busy={busyAction === 'discardSuspend'} disabled={busy} onClick={() => onAction('discardSuspend')}> - {tr('discardSuspend')} - - ) } else if (state === 'starting') { primary = {tr('state_starting')} } else if (state === 'stopping') { @@ -444,11 +449,6 @@ export const VMPage: React.FC = ({ : <> {tr('enterFullscreen')}>} )} - {canSuspend && ( - onAction('suspend')}> - {tr('suspend')} - - )} onAction('restart')}> {tr('restart')} @@ -644,7 +644,7 @@ export const VMPage: React.FC = ({ startLabel={suspended ? tr('resume') : tr('start')} showLabel={tr('showWindow')} shotLabel={tr('copyScreenshot')} - onStart={!busy && (state === 'stopped' || suspended) ? () => onAction(suspended ? 'resume' : 'start') : undefined} + onStart={!busy && (state === 'stopped' || (suspended && canSuspend)) ? () => onAction(suspended ? 'resume' : 'start') : undefined} onShow={running && !busy ? () => onAction('focus') : undefined} onScreenshot={running && !busy ? () => onAction('screenshot') : undefined} /> @@ -738,6 +738,7 @@ export const VMPage: React.FC = ({ ? tr('suspendedNoticeDescWithTime', { time: suspTime, size: suspSize }) : tr('suspendedNoticeDesc', { size: suspSize })} + {!canSuspend && {tr('resumeUnavailable')}} @@ -933,6 +934,10 @@ export const VMPage: React.FC = ({ const needsUpgrade = gtConnected && (detail.guest_tools_agent_version ?? 0) > 0 && (detail.guest_tools_agent_version ?? 0) < 3 // Plugin switched off: show the state and hide controls that would only fail. const gtOff = !!detail.guest_tools_disabled + const gtAttached = detail.guest_tools_attached + const showToolsAction = !gtOff && (gtAttached || !gtConnected || needsUpgrade) + const toolsAction = gtAttached ? 'detachGuestTools' : 'attachGuestTools' + const toolsActionLabel = gtAttached ? 'detachGuestTools' : needsUpgrade ? 'gtUpdate' : 'gtInstall' // One status word per state; how files are shared goes in the tooltip. let gtTone: 'ok' | 'warn' | 'idle' = 'idle' @@ -1045,20 +1050,20 @@ export const VMPage: React.FC = ({ + {suspended && showToolsAction && ( + {tr('suspendedGuestToolsHint')} + )} - {gtOff ? null : detail.guest_tools_attached ? ( - onAction('detachGuestTools')}> - {tr('detachGuestTools')} - - ) : (!gtConnected || needsUpgrade) && ( + {showToolsAction && ( } - busy={busyAction === 'attachGuestTools'} - disabled={busy} - onClick={() => onAction('attachGuestTools')} + variant={gtAttached || detail.guest_tools_configured || guestToolsLocked ? 'secondary' : 'primary'} + icon={gtAttached ? undefined : } + busy={busyAction === toolsAction} + disabled={busy || guestToolsLocked} + aria-describedby={suspended ? guestToolsHintId : undefined} + onClick={() => onAction(toolsAction)} > - {needsUpgrade ? tr('gtUpdate') : tr('gtInstall')} + {tr(toolsActionLabel)} )} diff --git a/frontend/src/i18n/domains/vm.gen.ts b/frontend/src/i18n/domains/vm.gen.ts index 312faa3..1a97e4e 100644 --- a/frontend/src/i18n/domains/vm.gen.ts +++ b/frontend/src/i18n/domains/vm.gen.ts @@ -119,6 +119,7 @@ export const vmZh: Record = { "pickRecoveryTitle": "选择离线镜像(.img / .dmg)", "restartToApply": "重启以应用", "resume": "恢复", + "resumeUnavailable": "切换到支持挂起的内核后可恢复", "sendText": "发送文本到虚拟机…", "sendTextConfirm": "发送 (Ctrl+Enter)", "sendTextDesc": "支持中文、Emoji、宿主机输入法与语音输入,按 Ctrl+Enter 发送到 macOS 当前输入框。", @@ -171,6 +172,7 @@ export const vmZh: Record = { "state_suspended": "已挂起", "state_suspending": "挂起中", "suspend": "挂起", + "suspendedGuestToolsHint": "恢复或放弃挂起状态后可更改", "suspendedNoticeDesc": "恢复后将回到挂起前的桌面与应用状态({size});修改硬件配置或管理磁盘前请先恢复或放弃挂起状态。", "suspendedNoticeDescWithTime": "挂起于 {time}({size})· 恢复后将回到原桌面与应用状态;修改硬件配置或管理磁盘前请先恢复或放弃挂起状态。", "suspendedNoticeTitle": "已保存运行状态", @@ -333,6 +335,7 @@ export const vmEn: Record = { "pickRecoveryTitle": "Choose an offline image (.img / .dmg)", "restartToApply": "Restart to apply", "resume": "Resume", + "resumeUnavailable": "Switch to a runtime that supports suspend to resume this VM", "sendText": "Send text to VM…", "sendTextConfirm": "Send (Ctrl+Enter)", "sendTextDesc": "Supports Chinese, emoji, host IME, and dictation. Press Ctrl+Enter to inject into the focused macOS field.", @@ -385,6 +388,7 @@ export const vmEn: Record = { "state_suspended": "Suspended", "state_suspending": "Suspending", "suspend": "Suspend", + "suspendedGuestToolsHint": "Resume or discard saved state to make changes", "suspendedNoticeDesc": "Resuming restores your desktop and running apps ({size}). Resume or discard the saved state before changing settings or managing disks.", "suspendedNoticeDescWithTime": "Suspended {time} ({size}) · Resuming restores your desktop and running apps. Resume or discard before changing settings or disks.", "suspendedNoticeTitle": "Saved state ready", diff --git a/frontend/src/i18n/keys.gen.ts b/frontend/src/i18n/keys.gen.ts index ffd4062..9ee8854 100644 --- a/frontend/src/i18n/keys.gen.ts +++ b/frontend/src/i18n/keys.gen.ts @@ -625,6 +625,7 @@ export type I18nKey = | "restart" | "restartToApply" | "resume" + | "resumeUnavailable" | "runtimeAlpha" | "runtimeAlphaHint" | "runtimeChannel_alpha" @@ -786,6 +787,7 @@ export type I18nKey = | "summarySSHPort" | "summarySource" | "suspend" + | "suspendedGuestToolsHint" | "suspendedNoticeDesc" | "suspendedNoticeDescWithTime" | "suspendedNoticeTitle" diff --git a/frontend/src/styles/app.css b/frontend/src/styles/app.css index 7e628f1..6710013 100644 --- a/frontend/src/styles/app.css +++ b/frontend/src/styles/app.css @@ -909,7 +909,6 @@ button.status-issue + .status-metric { margin-left: 6px; } .dialog-title { font-size: var(--fs-16); font-weight: var(--fw-strong); letter-spacing: -0.01em; text-wrap: balance; } .dialog-desc { font-size: var(--fs-13); color: var(--text-2); margin-top: 2px; } .dialog-body { padding: 20px 22px; overflow-y: auto; overscroll-behavior: contain; flex: 1; display: flex; flex-direction: column; gap: var(--sp-4); } -.dialog-body > .dialog-desc:only-child { margin-top: 0; } .dialog-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: 12px 22px; border-top: 1px solid var(--border); } .dialog.sm .dialog-body { padding: 22px 22px 14px; gap: var(--sp-3); } .dialog.sm .dialog-foot { border-top: none; justify-content: flex-end; padding-top: 0; padding-bottom: 20px; } diff --git a/frontend/src/ui/dialog.tsx b/frontend/src/ui/dialog.tsx index 7ce95d4..16ddcdc 100644 --- a/frontend/src/ui/dialog.tsx +++ b/frontend/src/ui/dialog.tsx @@ -1,7 +1,37 @@ +import * as Alert from '@radix-ui/react-alert-dialog' import * as RDialog from '@radix-ui/react-dialog' import { X } from 'lucide-react' import React from 'react' -import { IconButton } from './controls' +import { Button, IconButton } from './controls' + +interface ConfirmDialogProps { + title: string + description: string + cancelLabel: string + confirmLabel: string + onCancel: () => void + onConfirm: () => void + children?: React.ReactNode +} + +export const ConfirmDialog: React.FC = ({ title, description, cancelLabel, confirmLabel, onCancel, onConfirm, children }) => ( + { if (!open) onCancel() }}> + + + + + {title} + {description} + {children} + + + {cancelLabel} + {confirmLabel} + + + + +) interface Props { title: string diff --git a/frontend/src/wails.ts b/frontend/src/wails.ts index 184007d..182aaa8 100644 --- a/frontend/src/wails.ts +++ b/frontend/src/wails.ts @@ -180,6 +180,7 @@ export const events = { // Tray menu (internal/app/app.go trayVMAction): "Show in Reims-Go" and "New VM…". onTraySelectVM: (cb: (name: string) => void) => eventsOn('reims:tray-select-vm', cb), onTrayNewVM: (cb: () => void) => eventsOn('reims:tray-new-vm', cb), + onTrayDiscardSuspend: (cb: (name: string) => void) => eventsOn('reims:tray-discard-suspend', cb), // Renderer health watchdog & crash reporting (internal/app/ui_health.go). onUIPing: (cb: () => void) => eventsOn('reims:ui-ping', cb), emitUIPong: () => eventsEmit('reims:ui-pong'), diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index bd48390..2423b4e 100644 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -6,6 +6,7 @@ export namespace app { optimizations: host.Optimization[]; runtimes: runtime.Installed[]; active_runtime?: runtime.Installed; + can_suspend: boolean; vms: reims.VMListItem[]; transitions: Record; pending_changes: Record>; @@ -30,6 +31,7 @@ export namespace app { this.optimizations = this.convertValues(source["optimizations"], host.Optimization); this.runtimes = this.convertValues(source["runtimes"], runtime.Installed); this.active_runtime = this.convertValues(source["active_runtime"], runtime.Installed); + this.can_suspend = source["can_suspend"]; this.vms = this.convertValues(source["vms"], reims.VMListItem); this.transitions = source["transitions"]; this.pending_changes = this.convertValues(source["pending_changes"], Array, true); diff --git a/internal/app/app.go b/internal/app/app.go index f9a0183..9c035eb 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -43,6 +43,7 @@ type AppState struct { Optimizations []host.Optimization `json:"optimizations"` Runtimes []rt.Installed `json:"runtimes"` ActiveRuntime *rt.Installed `json:"active_runtime,omitempty"` + CanSuspend bool `json:"can_suspend"` VMs []reims.VMListItem `json:"vms"` Transitions map[string]string `json:"transitions"` PendingChanges map[string][]PendingChange `json:"pending_changes"` @@ -658,6 +659,7 @@ func (a *App) GetState() AppState { Optimizations: opts, Runtimes: runtimes, ActiveRuntime: active, + CanSuspend: active != nil && active.Manifest.HasCapability("vm-suspend"), VMs: vms, Transitions: trCopy, PendingChanges: pcCopy, @@ -852,7 +854,10 @@ func (a *App) trayVMAction(name string, act tray.Action) { case tray.ActResume: err, failTitle = a.ResumeVM(name), i18n.M(loc, "tray.notify.resume_fail", vars) case tray.ActDiscardSuspend: - err, failTitle = a.DiscardSuspend(name), i18n.M(loc, "tray.notify.discard_suspend_fail", vars) + a.ShowMainWindow() + if a.ctx != nil { + wailsRuntime.EventsEmit(a.ctx, "reims:tray-discard-suspend", name) + } case tray.ActStop: err, failTitle = a.StopVM(name, false), i18n.M(loc, "tray.notify.stop_fail", vars) case tray.ActForceStop: diff --git a/internal/i18n/catalog_gen.go b/internal/i18n/catalog_gen.go index edc8c67..61dcba3 100644 --- a/internal/i18n/catalog_gen.go +++ b/internal/i18n/catalog_gen.go @@ -440,13 +440,14 @@ var catalog = map[Locale]map[string]string{ "toastSSHUserSaved": "已保存 SSH 用户名", "toastSaved": "已保存", "toastSavedNextStart": "已保存,下次启动生效", - "tray.menu.discard_suspend": "放弃挂起状态(&X)", + "tray.menu.discard_suspend": "放弃挂起状态…(&X)", "tray.menu.force_stop": "强制关机(&F)", "tray.menu.new_vm": "新建虚拟机(&N)…", "tray.menu.open_in_app": "在 Reims-Go 中查看(&V)", "tray.menu.quit": "退出 Reims-Go(&Q)", "tray.menu.restart": "重启(&R)", "tray.menu.resume": "恢复(&U)", + "tray.menu.resume_unavailable": "恢复(当前内核不支持挂起)", "tray.menu.screenshot": "复制屏幕截图(&C)", "tray.menu.shared_folder": "打开共享文件夹(&H)", "tray.menu.show": "显示 Reims-Go(&O)", @@ -973,13 +974,14 @@ var catalog = map[Locale]map[string]string{ "toastSSHUserSaved": "Saved SSH username", "toastSaved": "Saved", "toastSavedNextStart": "Saved — applies on next start", - "tray.menu.discard_suspend": "Discard Saved Stat&e", + "tray.menu.discard_suspend": "Discard Saved Stat&e…", "tray.menu.force_stop": "&Force Shut Down", "tray.menu.new_vm": "&New Virtual Machine…", "tray.menu.open_in_app": "Show in &Reims-Go", "tray.menu.quit": "&Quit Reims-Go", "tray.menu.restart": "&Restart", "tray.menu.resume": "Res&ume", + "tray.menu.resume_unavailable": "Resume (runtime lacks suspend support)", "tray.menu.screenshot": "&Copy Screenshot", "tray.menu.shared_folder": "Open S&hared Folder", "tray.menu.show": "&Show Reims-Go", diff --git a/internal/tray/tray.go b/internal/tray/tray.go index 4523320..41f3cbc 100644 --- a/internal/tray/tray.go +++ b/internal/tray/tray.go @@ -94,15 +94,17 @@ type menuEntry struct { } type texts struct { - show, newVM, quit string - start, stop, forceStop, restart, showWindow, shot string - suspend, resume, discardSuspend string - shared, openInApp string - running, stopped, suspended string - starting, stopping, suspending, resuming string - broken, unknown string + show, newVM, quit string + start, stop, forceStop, restart, showWindow, shot string + suspend, resume, discardSuspend string + shared, openInApp string + running, stopped, suspended string + starting, stopping, suspending, resuming string + broken, unknown string toggleFullscreen string + + resumeUnavailable string } func menuTexts(snap Snapshot) texts { @@ -140,6 +142,8 @@ func menuTexts(snap Snapshot) texts { unknown: i18n.T(loc, "tray.state.unknown"), toggleFullscreen: i18n.T(loc, "tray.menu.toggle_fullscreen"), + + resumeUnavailable: i18n.T(loc, "tray.menu.resume_unavailable"), } } @@ -199,7 +203,11 @@ func buildMenu(snap Snapshot) []menuEntry { case "suspended": dot, state = dotSuspended, t.suspended resume := cmd(ActResume, t.resume) - resume.Default = true + resume.Default = snap.CanSuspend + if !snap.CanSuspend { + resume.Label = t.resumeUnavailable + resume.Disabled = true + } sub = []menuEntry{ resume, cmd(ActDiscardSuspend, t.discardSuspend), sep, cmd(ActSharedFolder, t.shared), sep, diff --git a/internal/tray/tray_test.go b/internal/tray/tray_test.go index ced0237..b08ff95 100644 --- a/internal/tray/tray_test.go +++ b/internal/tray/tray_test.go @@ -72,6 +72,21 @@ func TestBuildMenuPerState(t *testing.T) { } } +func TestSuspendedVMWithoutCompatibleRuntime(t *testing.T) { + menu := buildMenu(Snapshot{LocaleZh: true, VMs: []VMItem{{Name: "macos-sleep", State: "suspended"}}}) + vm := findEntry(menu, "macos-sleep\t已挂起") + if vm == nil { + t.Fatal("suspended VM is missing from the tray menu") + } + resume := vm.Sub[0] + if resume.ID != vmCmd(0, ActResume) || !resume.Disabled || resume.Default || resume.Label != "恢复(当前内核不支持挂起)" { + t.Fatalf("resume should be disabled and explain why: %+v", resume) + } + if discard := vm.Sub[1]; discard.ID != vmCmd(0, ActDiscardSuspend) || discard.Disabled { + t.Fatalf("discard should remain available: %+v", discard) + } +} + func TestDecodeVMCmdRoundTrip(t *testing.T) { for i := 0; i < maxTrayVMs; i++ { for act := ActStart; act <= ActDiscardSuspend; act++ { diff --git a/locales/en-US/native.json b/locales/en-US/native.json index 0b80880..0fdcee5 100644 --- a/locales/en-US/native.json +++ b/locales/en-US/native.json @@ -409,7 +409,8 @@ "tray.menu.start": "&Start", "tray.menu.suspend": "Sus&pend", "tray.menu.resume": "Res&ume", - "tray.menu.discard_suspend": "Discard Saved Stat&e", + "tray.menu.resume_unavailable": "Resume (runtime lacks suspend support)", + "tray.menu.discard_suspend": "Discard Saved Stat&e…", "tray.menu.stop": "Shut &Down", "tray.menu.force_stop": "&Force Shut Down", "tray.menu.restart": "&Restart", diff --git a/locales/en-US/vm.json b/locales/en-US/vm.json index f5bfc2c..6f2f87e 100644 --- a/locales/en-US/vm.json +++ b/locales/en-US/vm.json @@ -51,6 +51,7 @@ "state_broken": "Error", "suspend": "Suspend", "resume": "Resume", + "resumeUnavailable": "Switch to a runtime that supports suspend to resume this VM", "discardSuspend": "Discard saved state", "discardSuspendTitle": "Discard saved state for “{name}”?", "discardSuspendDesc": "Removes the saved memory and device state and returns the VM to powered off. Any unsaved work inside macOS will be lost and can’t be undone.", @@ -59,6 +60,7 @@ "suspendedNoticeDesc": "Resuming restores your desktop and running apps ({size}). Resume or discard the saved state before changing settings or managing disks.", "suspendedNoticeDescWithTime": "Suspended {time} ({size}) · Resuming restores your desktop and running apps. Resume or discard before changing settings or disks.", "suspendedSettingsHint": "Resume or discard saved state before changing settings", + "suspendedGuestToolsHint": "Resume or discard saved state to make changes", "toastSuspended": "{name} suspended", "toastResumed": "{name} resumed", "toastDiscardSuspend": "Discarded saved state for {name}", diff --git a/locales/zh-CN/native.json b/locales/zh-CN/native.json index b36a181..91ce361 100644 --- a/locales/zh-CN/native.json +++ b/locales/zh-CN/native.json @@ -409,7 +409,8 @@ "tray.menu.start": "启动(&S)", "tray.menu.suspend": "挂起(&P)", "tray.menu.resume": "恢复(&U)", - "tray.menu.discard_suspend": "放弃挂起状态(&X)", + "tray.menu.resume_unavailable": "恢复(当前内核不支持挂起)", + "tray.menu.discard_suspend": "放弃挂起状态…(&X)", "tray.menu.stop": "关机(&D)", "tray.menu.force_stop": "强制关机(&F)", "tray.menu.restart": "重启(&R)", diff --git a/locales/zh-CN/vm.json b/locales/zh-CN/vm.json index 3a68042..a8ab8f3 100644 --- a/locales/zh-CN/vm.json +++ b/locales/zh-CN/vm.json @@ -51,6 +51,7 @@ "state_broken": "出错", "suspend": "挂起", "resume": "恢复", + "resumeUnavailable": "切换到支持挂起的内核后可恢复", "discardSuspend": "放弃挂起状态", "discardSuspendTitle": "放弃「{name}」的挂起状态?", "discardSuspendDesc": "将删除已保存的内存与设备状态并回到关机状态,macOS 中尚未保存的工作会丢失,且无法撤销。", @@ -59,6 +60,7 @@ "suspendedNoticeDesc": "恢复后将回到挂起前的桌面与应用状态({size});修改硬件配置或管理磁盘前请先恢复或放弃挂起状态。", "suspendedNoticeDescWithTime": "挂起于 {time}({size})· 恢复后将回到原桌面与应用状态;修改硬件配置或管理磁盘前请先恢复或放弃挂起状态。", "suspendedSettingsHint": "请先恢复或放弃挂起状态后再修改配置", + "suspendedGuestToolsHint": "恢复或放弃挂起状态后可更改", "toastSuspended": "{name} 已挂起", "toastResumed": "{name} 已恢复", "toastDiscardSuspend": "已放弃 {name} 的挂起状态",
{tr('discardSuspendDesc')}