From a853460fc38702ce30ff743fd66bd1becbd848cb Mon Sep 17 00:00:00 2001 From: hanyewei <139319228@qq.com> Date: Fri, 4 Dec 2026 15:44:03 +0800 Subject: [PATCH] fix(plugins): show active runtime compatibility in plugin settings --- changes/plugin-runtime-compatibility.json | 7 ++++ frontend/src/App.tsx | 1 + frontend/src/components/PluginsPage.tsx | 18 +++++++- frontend/wailsjs/go/models.ts | 2 + internal/app/plugins_flow.go | 27 +++++++++++- internal/plugin/rule_settings_test.go | 39 +++++++++++++++++ internal/plugin/rules.go | 51 +++++++++++++++++++++++ internal/plugin/types.go | 1 + locales/en-US/native.json | 1 + locales/zh-CN/native.json | 1 + 10 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 changes/plugin-runtime-compatibility.json diff --git a/changes/plugin-runtime-compatibility.json b/changes/plugin-runtime-compatibility.json new file mode 100644 index 0000000..d2ef969 --- /dev/null +++ b/changes/plugin-runtime-compatibility.json @@ -0,0 +1,7 @@ +{ + "group": "fixes", + "order": 0, + "authors": ["cosimawei"], + "zh": "在插件列表和设置中提示当前运行时不支持的插件设置。", + "en": "Show which settings the active runtime does not support in the plugin list and settings dialog." +} diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 868e486..13cea07 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1212,6 +1212,7 @@ export const App: React.FC = () => { locale={locale} appearance={theme} safeMode={state.safe_mode} + runtimeCommit={state.active_runtime?.commit} onRefresh={refresh} onError={fail} onThemeChanged={() => setThemeRevision((r) => r + 1)} diff --git a/frontend/src/components/PluginsPage.tsx b/frontend/src/components/PluginsPage.tsx index 47454fd..359a555 100644 --- a/frontend/src/components/PluginsPage.tsx +++ b/frontend/src/components/PluginsPage.tsx @@ -27,6 +27,7 @@ interface Props { locale: Locale appearance: 'light' | 'dark' safeMode?: boolean + runtimeCommit?: string onRefresh: () => void onError: (title: string, e: unknown) => void onThemeChanged?: () => void @@ -46,7 +47,7 @@ function hasAppSettings(p: PluginInfo): boolean { /** Top-level Plugins & Themes management page. */ export const PluginsPage: React.FC = ({ - locale, appearance, safeMode, onRefresh, onError, onThemeChanged, onLocaleSwitch, + locale, appearance, safeMode, runtimeCommit, onRefresh, onError, onThemeChanged, onLocaleSwitch, }) => { const tr = (k: I18nKey, v?: Record) => t(locale, k, v) const [activeTab, setActiveTab] = useState<'installed' | 'market'>('installed') @@ -61,6 +62,7 @@ export const PluginsPage: React.FC = ({ const [approveChecked, setApproveChecked] = useState(false) const approveTargetIDRef = useRef('') const [settingsTarget, setSettingsTarget] = useState(null) + const settingsRuntimeWarning = plugins.find((p) => p.id === settingsTarget?.id)?.runtime_warning const [settingsValues, setSettingsValues] = useState>({}) const [logTarget, setLogTarget] = useState<{ id: string; text: string } | null>(null) const [removeTarget, setRemoveTarget] = useState(null) @@ -151,7 +153,7 @@ export const PluginsPage: React.FC = ({ onThemeChanged?.() } - useEffect(() => { void reload() }, [safeMode]) + useEffect(() => { void reload() }, [safeMode, runtimeCommit, locale]) useEffect(() => { if (activeTab === 'market') setMarketOpened(true) }, [activeTab]) @@ -429,6 +431,12 @@ export const PluginsPage: React.FC = ({ {alert} )} + {p.runtime_warning && ( +
+
+ )}
{!isBuiltin && ( @@ -868,6 +876,12 @@ export const PluginsPage: React.FC = ({ onClose={() => setSettingsTarget(null)} >
+ {settingsRuntimeWarning && ( +
+
+ )} 0 { + info.RuntimeWarning = i18n.M(locale, "plugin.runtime_settings_skipped", i18n.Vars{ + "settings": strings.Join(settings, ", "), + }) + } + } + return infos } func (a *App) InstallPluginArchive(archivePath string) (*plugin.PluginInfo, error) { diff --git a/internal/plugin/rule_settings_test.go b/internal/plugin/rule_settings_test.go index 4a34062..2ee5441 100644 --- a/internal/plugin/rule_settings_test.go +++ b/internal/plugin/rule_settings_test.go @@ -3,6 +3,8 @@ package plugin import ( "reflect" "testing" + + "github.com/Nwflower/reims-go/internal/i18n" ) func TestRuleEnvironmentUsesVisiblePluginSettings(t *testing.T) { @@ -32,3 +34,40 @@ func TestRuleEnvironmentUsesVisiblePluginSettings(t *testing.T) { t.Fatalf("unexpected environment: %#v", intent.Env) } } + +func TestRuntimeUnavailableSettings(t *testing.T) { + const capability = "window-release-shortcut" + manifest := Manifest{ + ID: "local.capture-shortcut", + Settings: &SettingsSchema{Properties: map[string]SettingProperty{ + "releaseKeys": {Title: LocalizedText{ZhCN: "释放快捷键"}}, + "releaseOnLeave": {Title: LocalizedText{ZhCN: "鼠标移出时释放"}}, + "private": {Secret: true}, + }}, + Contributes: Contributes{RuleHooks: []RuleHook{{ + Event: EventVMBeforeStart, + Conditions: []RuleCondition{{Fact: "runtime.capabilities", Operator: "contains", Value: capability}}, + Actions: []RuleAction{{Kind: "set_env", EnvFromSettings: map[string]string{ + "REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_KEYS": "releaseKeys", + "REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_RELEASE_ON_LEAVE": "releaseOnLeave", + "REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_PRIVATE": "private", + }}}, + }}}, + } + locale := i18n.Locale("zh-CN") + if got := RuntimeUnavailableSettings(manifest, nil, locale); !reflect.DeepEqual(got, []string{"释放快捷键", "鼠标移出时释放"}) { + t.Fatalf("unexpected settings for incompatible runtime: %v", got) + } + if got := RuntimeUnavailableSettings(manifest, []string{capability}, locale); len(got) != 0 { + t.Fatalf("compatible runtime should have no warning: %v", got) + } + manifest.Contributes.RuleHooks = append(manifest.Contributes.RuleHooks, RuleHook{ + Event: EventVMBeforeStart, + Actions: []RuleAction{{Kind: "set_env", EnvFromSettings: map[string]string{ + "REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_KEYS": "releaseKeys", + }}}, + }) + if got := RuntimeUnavailableSettings(manifest, nil, locale); !reflect.DeepEqual(got, []string{"鼠标移出时释放"}) { + t.Fatalf("settings covered by a fallback should have no warning: %v", got) + } +} diff --git a/internal/plugin/rules.go b/internal/plugin/rules.go index 73b589c..418b884 100644 --- a/internal/plugin/rules.go +++ b/internal/plugin/rules.go @@ -3,7 +3,10 @@ package plugin import ( "context" "fmt" + "slices" "strings" + + "github.com/Nwflower/reims-go/internal/i18n" ) // RuleCondition is a declarative, non-Turing-complete predicate over host, VM, @@ -145,6 +148,54 @@ func (r *Registry) registerRuleHooks(sc *Scope, pluginID string, rules []RuleHoo } } +// RuntimeUnavailableSettings reports settings guarded by rules that depend only +// on runtime capabilities. VM-specific rules cannot be assessed on the plugin page. +func RuntimeUnavailableSettings(m Manifest, caps []string, loc i18n.Locale) []string { + if m.Settings == nil { + return nil + } + facts := map[string]any{"runtime.capabilities": caps} + unavailable := make(map[string]bool) + available := make(map[string]bool) + for _, rule := range m.Contributes.RuleHooks { + if rule.Event != EventVMBeforeStart || slices.ContainsFunc(rule.Conditions, func(c RuleCondition) bool { + return c.Fact != "runtime.capabilities" + }) { + continue + } + matches := EvaluateRuleConditions(rule.Conditions, facts) + for _, action := range rule.Actions { + if action.Kind != "set_env" { + continue + } + for envKey, settingKey := range action.EnvFromSettings { + prop, ok := m.Settings.Properties[settingKey] + if !ok || prop.Secret || !ValidateEnvKey(m.ID, envKey) { + continue + } + if matches { + available[settingKey] = true + } else { + unavailable[settingKey] = true + } + } + } + } + var labels []string + for key := range unavailable { + if available[key] { + continue + } + label := m.Settings.Properties[key].Title.Get(string(loc)) + if label == "" { + label = key + } + labels = append(labels, label) + } + slices.Sort(labels) + return slices.Compact(labels) +} + func (r *Registry) applyRuleEnvSettings(intent *StartIntent, rule RuleHook, schema *SettingsSchema, vmName string) { if schema == nil || r.ruleSettings == nil { return diff --git a/internal/plugin/types.go b/internal/plugin/types.go index a002fe0..cb3ce98 100644 --- a/internal/plugin/types.go +++ b/internal/plugin/types.go @@ -773,6 +773,7 @@ type PluginInfo struct { InUse bool `json:"in_use"` Error string `json:"error,omitempty"` DegradedReason string `json:"degraded_reason,omitempty"` + RuntimeWarning string `json:"runtime_warning,omitempty"` Permissions []PermissionSpec `json:"permissions,omitempty"` ApprovedPermissions []string `json:"approved_permissions,omitempty"` NeedsApproval bool `json:"needs_approval"` diff --git a/locales/en-US/native.json b/locales/en-US/native.json index 804377d..8ade5b7 100644 --- a/locales/en-US/native.json +++ b/locales/en-US/native.json @@ -1,4 +1,5 @@ { + "plugin.runtime_settings_skipped": "The current runtime cannot apply these settings: {settings}. Switch to a runtime that supports them.", "network.log.create_network_prepare": "Preparing network dependencies and checking the uplink", "network.log.mode_applied": "Network mode applied: {mode}", "network.log.uplink_switched": "Bridged uplink changed. The main adapter was notified to reconnect and renew DHCP", diff --git a/locales/zh-CN/native.json b/locales/zh-CN/native.json index 909a776..fa8bdd9 100644 --- a/locales/zh-CN/native.json +++ b/locales/zh-CN/native.json @@ -1,4 +1,5 @@ { + "plugin.runtime_settings_skipped": "当前运行时无法应用以下设置:{settings}。切换到支持这些功能的运行时即可使用。", "network.log.create_network_prepare": "正在准备网络依赖并检查出口", "network.log.mode_applied": "网络模式已应用:{mode}", "network.log.uplink_switched": "桥接出口已更换,已通知主网卡重新连接并续租 DHCP",