fix: preserve plugin secret settings (#132)

This commit is contained in:
bvz rays authored and GitHub committed 2026-12-03 21:53:47 +08:00
1 parent 4d47638b7f
commit dfb0c9aa46
4 files changed
+35 -4

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
{
"group": "fixes",
"order": 0,
"authors": ["bvzrays"],
"zh": "修复插件设置中的已保存密钥在清空后仍显示旧掩码,以及连续修改同一设置时保存顺序错乱的问题。",
"en": "Fix saved plugin secrets remaining masked after being cleared and preserve save order when the same setting is edited repeatedly."
}
+13 -2
View File
@@ -64,6 +64,7 @@ export const PluginsPage: React.FC<Props> = ({
const approveTargetIDRef = useRef('')
const [settingsTarget, setSettingsTarget] = useState<PluginInfo | null>(null)
const [settingsValues, setSettingsValues] = useState<Record<string, unknown>>({})
const settingsSaveQueuesRef = useRef(new Map<string, Promise<void>>())
const [logTarget, setLogTarget] = useState<{ id: string; text: string } | null>(null)
const [removeTarget, setRemoveTarget] = useState<PluginInfo | null>(null)
const [disableTarget, setDisableTarget] = useState<PluginInfo | null>(null)
@@ -294,12 +295,22 @@ export const PluginsPage: React.FC<Props> = ({
const savePluginSettings = async (patch: Record<string, unknown>) => {
setSettingsValues((current) => ({ ...current, ...patch }))
if (!settingsTarget) return
const target = settingsTarget
if (!target) return
const previous = settingsSaveQueuesRef.current.get(target.id) ?? Promise.resolve()
const save = previous.catch((error) => {
console.warn('[plugins] previous settings save failed:', error)
}).then(() => api.SetPluginSettings(target.id, '', patch))
settingsSaveQueuesRef.current.set(target.id, save)
try {
await api.SetPluginSettings(settingsTarget.id, '', patch)
await save
onRefresh()
} catch (e) {
onError(tr('pluginFailSaveSettings'), e)
} finally {
if (settingsSaveQueuesRef.current.get(target.id) === save) {
settingsSaveQueuesRef.current.delete(target.id)
}
}
}
+3 -1
View File
@@ -111,9 +111,11 @@ export const SchemaForm: React.FC<Props> = ({
if (prop['x-secret']) {
const isMasked = cur === SECRET_MASK
const hasSecret = isMasked || String(cur ?? '') !== ''
return (
<div className="input-group">
<input
key={`${k}:${hasSecret ? 'present' : 'empty'}`}
type="password"
className="input rg-p-input"
aria-label={label}
@@ -125,7 +127,7 @@ export const SchemaForm: React.FC<Props> = ({
if (next !== (isMasked ? '' : String(cur ?? ''))) setKey(k, next)
}}
/>
{isMasked && (
{hasSecret && (
<button type="button" className="btn rg-p-button btn-ghost" onClick={() => setKey(k, '')}>
{t(locale, 'pluginClearSecret')}
</button>
+12 -1
View File
@@ -225,6 +225,7 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, driverID, stats
(patch) => setKeymapState((state) => ({ ...state, ...patch }))))
const [vmPlugins, setVmPlugins] = useState<PluginInfo[]>([])
const [vmPluginVals, setVmPluginVals] = useState<Record<string, Record<string, unknown>>>({})
const vmPluginSettingsSaveQueues = useRef(new Map<string, Promise<void>>())
const vmSettingsKey = `${driverID}:${detail.name}`
const activeVMKeyRef = useRef(vmSettingsKey)
activeVMKeyRef.current = vmSettingsKey
@@ -259,7 +260,17 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, driverID, stats
const updateVMPluginSetting = (pluginID: string, patch: Record<string, unknown>) => {
setVmPluginVals((prev) => ({ ...prev, [pluginID]: { ...prev[pluginID], ...patch } }))
void api.SetPluginSettings(pluginID, vmSettingsKey, patch).catch((e) => setErr(parseAppError(e).summary))
const queueKey = JSON.stringify([pluginID, vmSettingsKey])
const previous = vmPluginSettingsSaveQueues.current.get(queueKey) ?? Promise.resolve()
const save = previous.catch((error) => {
console.warn('[settings] previous plugin save failed:', error)
}).then(() => api.SetPluginSettings(pluginID, vmSettingsKey, patch))
vmPluginSettingsSaveQueues.current.set(queueKey, save)
void save.catch((e) => setErr(parseAppError(e).summary)).finally(() => {
if (vmPluginSettingsSaveQueues.current.get(queueKey) === save) {
vmPluginSettingsSaveQueues.current.delete(queueKey)
}
})
}
const renderVMPluginGroup = (group: string) => {