feat: 提权会话复用,5 分钟内免密 - #2
Merged
Merged
Conversation
osascript 的 do shell script ... with administrator privileges 不做任何 缓存,每次执行都是全新的 Authorization 会话,所以每次都弹密码框。 改为持有一个 AuthorizationRef 并在 App 生命周期内复用:首次执行时 AuthorizationCopyRights 弹一次框,之后在 system.privilege.admin 的 默认有效期(5 分钟)内直接复用,不再弹。 AuthorizationExecuteWithPrivileges 在 Swift 里被标为 unavailable, 运行时用 dlsym 取函数指针调用;取不到则回退到原来的 osascript 路径。 该 API 拿不到子进程退出码,改用 shell 里的 rc 变量 + 输出标记回传。 界面在需要提权时显示授权剩余秒数,并提供「释放」按钮立即失效。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
osascript 的 do shell script ... with administrator privileges 不做任何 缓存,每次执行都是全新的 Authorization 会话,所以每次都弹密码框。
改为持有一个 AuthorizationRef 并在 App 生命周期内复用:首次执行时
AuthorizationCopyRights 弹一次框,之后在 system.privilege.admin 的 默认有效期(5 分钟)内直接复用,不再弹。
AuthorizationExecuteWithPrivileges 在 Swift 里被标为 unavailable, 运行时用 dlsym 取函数指针调用;取不到则回退到原来的 osascript 路径。
该 API 拿不到子进程退出码,改用 shell 里的 rc 变量 + 输出标记回传。
界面在需要提权时显示授权剩余秒数,并提供「释放」按钮立即失效。