Skip to content

Commit 1f46785

Browse files
committed
修复 DependencyControl Toolbox 补丁丢行并增强 Install Script 体验
- 修复 $ToolboxPatchEmpty 替换文本漏带 buildDlgList macros 行, 导致 getScriptListDlg 内 unpack(nil) 运行时错误 - 空列表判断对齐上游 PR TypesettingTools/DependencyControl#44 评审意见:改为 buildDlgList 展平后长度, 并区分部分 feed 未抓取场景(不再误报全部已安装) - FeedInventory 增加 crawl 进度回调(可选 onProgress 参数), Install Script 爬取期间显示动态进度条并收尾满格 - 支持下载期间取消:回调检查 aegisub.progress.is_cancelled 中断 crawl, crawlWithPrompt 以 pcall 捕获静默退出并保证 prompter 复位 实测通过:进度反馈、下载中取消、空列表提示、正常安装四场景
1 parent a685d01 commit 1f46785

1 file changed

Lines changed: 44 additions & 7 deletions

File tree

tools/setup-automation.ps1

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env powershell
1+
#!/usr/bin/env powershell
22
<#
33
.SYNOPSIS
44
安装 automation 脚本到指定目录,供开发环境运行时使用。
@@ -273,21 +273,58 @@ try
273273
$ToolboxPatchScanning = @"
274274
macros, modules = {}, {}
275275
aegisub.progress.task "Scanning available feeds..."
276-
entries = crawlWithPrompt buildFeedInventory!
276+
entries = crawlWithPrompt buildFeedInventory!, (fetched, known) ->
277+
aegisub.progress.set math.floor fetched * 100 / known
278+
-- 用户取消时中断 crawl,error 穿透到 crawlWithPrompt 的 pcall 静默退出
279+
error "cancelled", 0 if aegisub.progress.is_cancelled!
280+
-- 收尾到满格,抓取失败或被预算截断的 feed 不触发回调,进度会停在最后一次成功回调的值
281+
aegisub.progress.set 100
282+
return unless entries
277283
"@
278284
$ToolboxPatchLoading = @"
279285
aegisub.progress.task "Loading feed data..."
280286
logger\log msgs.install.scanning, #entries
287+
"@
288+
# FeedInventory 进度回调(crawl 每抓取一个 feed 通知调用方,
289+
# known 随 BFS 发现新 feed 动态增长,进度可能小幅回退属预期)
290+
$FeedInventoryPatchCrawl = @"
291+
crawl: (onProgress) =>
292+
inventoryEntriesByUrl = @__collectConfigFeeds!
293+
stats = @__crawlKnownFeeds inventoryEntriesByUrl, onProgress
294+
"@
295+
$FeedInventoryPatchSink = @"
296+
__crawlKnownFeeds: (inventoryEntriesByUrl, onProgress) =>
297+
"@
298+
$FeedInventoryPatchNotify = @"
299+
stats.fetched += 1
300+
inventoryEntriesByUrl[feedUrl].fetched = true
301+
onProgress stats.fetched, #queue - head + 1 + stats.fetched if onProgress
302+
"@
303+
$ToolboxPatchCrawlWithPrompt = @"
304+
crawlWithPrompt = (inventory, onProgress) ->
305+
feedTrust = DepCtrl.updater.feedTrust
306+
feedTrust\setPrompter promptUntrustedFeed
307+
ok, entries = pcall inventory.crawl, inventory, onProgress
308+
feedTrust\setPrompter nil
309+
if not ok and entries != "cancelled"
310+
error entries, 0
311+
return nil unless ok
312+
entries
281313
"@
282314
$ToolboxPatchEmpty = @"
283-
unless next(macros) or next(modules)
284-
aegisub.log 0, "All available scripts are already installed; nothing new to install."
285-
return
286-
287315
moduleList, moduleMap = buildDlgList modules
288316
macroList, macroMap = buildDlgList macros
317+
318+
if #moduleList == 0 and #macroList == 0
319+
unfetched = #[entry for entry in *entries when not entry.fetched]
320+
message = unfetched > 0 and ("No scripts are available to install (%d of %d known feeds could not be fetched).")\format(unfetched, #entries) or "All available scripts are already installed."
321+
aegisub.dialog.display {{class: "label", x: 0, y: 0, width: 1, height: 1, label: message}},
322+
{buttons.close}, {ok: buttons.close, cancel: buttons.close}
323+
return
324+
325+
btn, res = aegisub.dialog.display getScriptListDlg macroList, moduleList
289326
"@
290-
Install-ReleaseScript -Name "DependencyControl" -Repo "TypesettingTools/DependencyControl" -Pattern "\.zip$" -PatchTag "v0.9.0" -PatchFiles @("autoload/l0.DependencyControl.Toolbox.moon", "autoload/l0.DependencyControl.Toolbox.moon", "autoload/l0.DependencyControl.Toolbox.moon") -PatchFroms @(" macros, modules = {}, {}`n entries = crawlWithPrompt buildFeedInventory!", " logger\log msgs.install.scanning, #entries", " moduleList, moduleMap = buildDlgList modules`n macroList, macroMap = buildDlgList macros") -PatchTos @($ToolboxPatchScanning, $ToolboxPatchLoading, $ToolboxPatchEmpty)
327+
Install-ReleaseScript -Name "DependencyControl" -Repo "TypesettingTools/DependencyControl" -Pattern "\.zip$" -PatchTag "v0.9.0" -PatchFiles @("autoload/l0.DependencyControl.Toolbox.moon", "autoload/l0.DependencyControl.Toolbox.moon", "autoload/l0.DependencyControl.Toolbox.moon", "autoload/l0.DependencyControl.Toolbox.moon", "include/l0/DependencyControl/FeedInventory.moon", "include/l0/DependencyControl/FeedInventory.moon", "include/l0/DependencyControl/FeedInventory.moon") -PatchFroms @(" macros, modules = {}, {}`n entries = crawlWithPrompt buildFeedInventory!", " logger\log msgs.install.scanning, #entries", "crawlWithPrompt = (inventory) ->`n feedTrust = DepCtrl.updater.feedTrust`n feedTrust\setPrompter promptUntrustedFeed`n entries = inventory\crawl!`n feedTrust\setPrompter nil`n entries", " moduleList, moduleMap = buildDlgList modules`n macroList, macroMap = buildDlgList macros`n`n btn, res = aegisub.dialog.display getScriptListDlg macroList, moduleList", " crawl: =>`n inventoryEntriesByUrl = @__collectConfigFeeds!`n stats = @__crawlKnownFeeds inventoryEntriesByUrl", " __crawlKnownFeeds: (inventoryEntriesByUrl) =>", " stats.fetched += 1`n inventoryEntriesByUrl[feedUrl].fetched = true") -PatchTos @($ToolboxPatchScanning, $ToolboxPatchLoading, $ToolboxPatchCrawlWithPrompt, $ToolboxPatchEmpty, $FeedInventoryPatchCrawl, $FeedInventoryPatchSink, $FeedInventoryPatchNotify)
291328

292329
# Aegisub-Motion(DepCtrl 分支)
293330
Install-GitScript -Name "Aegisub-Motion" -Repo "https://github.com/TypesettingTools/Aegisub-Motion.git" -Branch "DepCtrl" -Copy @("a-mo.Aegisub-Motion.moon=autoload", "src=include/a-mo")

0 commit comments

Comments
 (0)