fix: 插件外部dll授权弹窗逻辑优化 - #612
Conversation
🤖 Augment PR SummarySummary: This PR refines external-DLL authorization during plugin loading.
🤖 Was this summary useful? React with 👍 or 👎 |
| { | ||
| if (!sessionAllowed) return false; | ||
| // 用户已对该插件本次会话授权,持久化当前 DLL 的授权记录。 | ||
| PersistAuthorization(plugin, assemblyPath); |
There was a problem hiding this comment.
Once the first dependency is approved, normal ALC resolution is still blocked in that call, so later dependencies have not yet been added to _sessionPendingFiles or shown in the dialog. This branch then silently persists and loads those unlisted DLLs, so the single confirmation does not disclose the full set of assemblies being authorized.
Severity: medium
Other Locations
Ink Canvas/Plugins/PluginAuthorizationService.cs:134
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| { | ||
| _authorizations[key] = hash; | ||
| } | ||
| Save(); |
There was a problem hiding this comment.
PersistAuthorization releases _authorizations before Save, while a session-cached request can enter this method concurrently with the gate-holder. JsonSerializer.Serialize(_authorizations) may enumerate while the other call mutates the dictionary; the swallowed exception then leaves one or more grants unsaved and causes later re-prompts.
Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
本pr代码为AI生成,我已初步审查确认没有问题。
以下为修复总结:
问题根因
外部插件引用多个 DLL 时,
PluginLoadContext的Load/LoadUnmanagedDll对每个依赖 DLL 逐个调用RequestExternalAuthorization,而原实现存在三个问题:_authorizations是普通 Dictionary,无锁、无 in-flight 去重,并发解析时同一 DLL 可能弹多个框MessageBox.Show未切 Dispatcher,后台线程创建无 owner 窗口,与启动期工具栏重建队列交错导致渲染错乱RegisterBoardToolbarItem每注册一个组件就排队一次RebuildBoardToolbar,多个组件 = 多次清空/重建控件修复内容
[PluginAuthorizationService.cs](./Ink Canvas/Plugins/PluginAuthorizationService.cs)
SemaphoreSlim:同一时刻只允许一个授权对话框BeginSession/EndSession:一次加载会话内,同一插件的首次"允许/拒绝"复用到该插件其余 DLL,不再逐个弹窗;多文件时在消息中列出完整清单MessageBox.Show强制切到Application.Current.Dispatcher,并传入MainWindow作为 owner_authorizations读写加锁[PluginManager.cs](./Ink Canvas/Plugins/PluginManager.cs)
LoadAllAsync和InstallPendingPackages加载循环外包裹BeginSession/EndSession(finally 保证释放)_isLoadingBatch标志:批量加载期间RegisterBoardToolbarItem不逐项排队重建,只设_boardToolbarRebuildPendingFlushPendingBoardToolbarRebuild:加载结束后统一排队一次RebuildBoardToolbar