Skip to content

fix: 插件外部dll授权弹窗逻辑优化 - #612

Merged
CJKmkp merged 1 commit into
net6from
fix/authorization-dialog-queue
Aug 9, 2026
Merged

fix: 插件外部dll授权弹窗逻辑优化#612
CJKmkp merged 1 commit into
net6from
fix/authorization-dialog-queue

Conversation

@2-2-3-trimethylpentane

Copy link
Copy Markdown
Collaborator

本pr代码为AI生成,我已初步审查确认没有问题。
以下为修复总结:

问题根因

外部插件引用多个 DLL 时,PluginLoadContextLoad / LoadUnmanagedDll 对每个依赖 DLL 逐个调用 RequestExternalAuthorization,而原实现存在三个问题:

  1. 逐 DLL 弹窗:同一插件的 N 个依赖就弹 N 次确认框
  2. 无并发去重_authorizations 是普通 Dictionary,无锁、无 in-flight 去重,并发解析时同一 DLL 可能弹多个框
  3. 非 UI 线程创建窗口MessageBox.Show 未切 Dispatcher,后台线程创建无 owner 窗口,与启动期工具栏重建队列交错导致渲染错乱
  4. 工具栏重复重建RegisterBoardToolbarItem 每注册一个组件就排队一次 RebuildBoardToolbar,多个组件 = 多次清空/重建控件

修复内容

[PluginAuthorizationService.cs](./Ink Canvas/Plugins/PluginAuthorizationService.cs)

  • 串行锁 SemaphoreSlim:同一时刻只允许一个授权对话框
  • 会话级决定缓存 BeginSession/EndSession:一次加载会话内,同一插件的首次"允许/拒绝"复用到该插件其余 DLL,不再逐个弹窗;多文件时在消息中列出完整清单
  • Dispatcher 切换:所有 MessageBox.Show 强制切到 Application.Current.Dispatcher,并传入 MainWindow 作为 owner
  • 持久化授权线程安全_authorizations 读写加锁

[PluginManager.cs](./Ink Canvas/Plugins/PluginManager.cs)

  • LoadAllAsyncInstallPendingPackages 加载循环外包裹 BeginSession/EndSession(finally 保证释放)
  • 新增 _isLoadingBatch 标志:批量加载期间 RegisterBoardToolbarItem 不逐项排队重建,只设 _boardToolbarRebuildPending
  • 新增 FlushPendingBoardToolbarRebuild:加载结束后统一排队一次 RebuildBoardToolbar

@augmentcode

augmentcode Bot commented Aug 9, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR refines external-DLL authorization during plugin loading.

Changes:

  • Adds a semaphore to serialize authorization dialogs.
  • Adds begin/end loading sessions and caches a per-plugin allow/deny decision.
  • Persists hashes for additional DLLs allowed within a session.
  • Moves authorization dialogs onto the WPF application dispatcher.
  • Uses the loaded main window as the dialog owner when available.
  • Protects authorization-dictionary lookup and writes with a lock.
  • Wraps startup and hot-install loading loops in authorization sessions.
  • Batches whiteboard-toolbar rebuild requests during plugin loading.
  • Flushes one deferred rebuild after normal startup loading.
Technical notes: The change aims to prevent repeated dialogs and toolbar reconstruction from interleaving with modal UI during plugin initialization.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

{
if (!sessionAllowed) return false;
// 用户已对该插件本次会话授权,持久化当前 DLL 的授权记录。
PersistAuthorization(plugin, assemblyPath);

@augmentcode augmentcode Bot Aug 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

{
_authorizations[key] = hash;
}
Save();

@augmentcode augmentcode Bot Aug 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@CJKmkp
CJKmkp merged commit d6853d7 into net6 Aug 9, 2026
3 checks passed
@CJKmkp
CJKmkp deleted the fix/authorization-dialog-queue branch August 9, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants