Skip to content

Commit b61ac2f

Browse files
committed
Improve init visibility with step counter and download substage
1 parent 0ec862b commit b61ac2f

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

crabshell-gui/src-tauri/src/main.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ fn parse_progress(output: &str) -> Option<HardeningProgress> {
594594
.unwrap_or("dependency");
595595
return Some(HardeningProgress {
596596
stage: "init".to_string(),
597-
substage: None,
597+
substage: Some("toolchain.download".to_string()),
598598
progress: 3,
599599
message: format!("Downloading dependency: {file_name}"),
600600
});
@@ -614,7 +614,7 @@ fn parse_progress(output: &str) -> Option<HardeningProgress> {
614614
}
615615
return Some(HardeningProgress {
616616
stage: "init".to_string(),
617-
substage: None,
617+
substage: Some("toolchain.download".to_string()),
618618
progress,
619619
message: format!("Downloading {file_name} ({progress}%)"),
620620
});
@@ -623,7 +623,7 @@ fn parse_progress(output: &str) -> Option<HardeningProgress> {
623623
if output.contains("[toolchain] download-retry") {
624624
return Some(HardeningProgress {
625625
stage: "init".to_string(),
626-
substage: None,
626+
substage: Some("toolchain.download".to_string()),
627627
progress: 6,
628628
message: "Network unstable, retrying dependency download...".to_string(),
629629
});
@@ -636,7 +636,7 @@ fn parse_progress(output: &str) -> Option<HardeningProgress> {
636636
.unwrap_or("dependency");
637637
return Some(HardeningProgress {
638638
stage: "init".to_string(),
639-
substage: None,
639+
substage: Some("toolchain.download".to_string()),
640640
progress: 30,
641641
message: format!("Dependency ready: {file_name}"),
642642
});
@@ -785,4 +785,33 @@ mod tests {
785785
assert_eq!(progress.progress, 90);
786786
assert_eq!(progress.message, "Signing package");
787787
}
788+
789+
#[test]
790+
fn parse_progress_maps_toolchain_download_start_to_substage() {
791+
let line = "[toolchain] download-start commandlinetools.zip 12345";
792+
let progress = super::parse_progress(line).expect("progress should parse");
793+
assert_eq!(progress.stage, "init");
794+
assert_eq!(progress.substage.as_deref(), Some("toolchain.download"));
795+
}
796+
797+
#[test]
798+
fn parse_progress_maps_toolchain_download_progress_to_substage() {
799+
let line = "[toolchain] download-progress commandlinetools.zip 37%";
800+
let progress = super::parse_progress(line).expect("progress should parse");
801+
assert_eq!(progress.stage, "init");
802+
assert_eq!(progress.substage.as_deref(), Some("toolchain.download"));
803+
}
804+
805+
#[test]
806+
fn parse_progress_maps_toolchain_download_retry_and_done_to_substage() {
807+
let retry = "[toolchain] download-retry commandlinetools.zip";
808+
let retry_progress = super::parse_progress(retry).expect("retry should parse");
809+
assert_eq!(retry_progress.stage, "init");
810+
assert_eq!(retry_progress.substage.as_deref(), Some("toolchain.download"));
811+
812+
let done = "[toolchain] download-done commandlinetools.zip";
813+
let done_progress = super::parse_progress(done).expect("done should parse");
814+
assert_eq!(done_progress.stage, "init");
815+
assert_eq!(done_progress.substage.as_deref(), Some("toolchain.download"));
816+
}
788817
}

crabshell-gui/src/renderer/App.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,31 @@ const SUBSTAGE_TRANSLATION_KEYS: Record<string, string> = {
8181
'manifest.cache-hit': 'progress.substage.manifestCacheHit',
8282
'manifest.cache-store': 'progress.substage.manifestCacheStore',
8383
'manifest.done': 'progress.substage.manifestDone',
84+
'toolchain.download': 'progress.substage.toolchainDownload',
8485
'toolchain.reuse': 'progress.substage.toolchainReuse',
8586
'toolchain.build': 'progress.substage.toolchainBuild',
8687
'rules.resolve': 'progress.substage.rulesResolve',
8788
'signing.resolve': 'progress.substage.signingResolve',
8889
};
8990

91+
const INIT_SUBSTAGE_STEP_INDEX: Record<string, number> = {
92+
'env.runtime': 1,
93+
'env.java': 2,
94+
'config.load': 3,
95+
'paths.resolve': 4,
96+
'keys.prepare': 5,
97+
'manifest.prepare': 6,
98+
'manifest.cache-hit': 7,
99+
'manifest.cache-store': 7,
100+
'manifest.done': 8,
101+
'toolchain.download': 9,
102+
'toolchain.reuse': 10,
103+
'toolchain.build': 10,
104+
'rules.resolve': 11,
105+
'signing.resolve': 12,
106+
};
107+
const INIT_SUBSTAGE_TOTAL_STEPS = 12;
108+
90109
const formatSubstageFallback = (substage: string) =>
91110
substage
92111
.replace(/-/g, ' ')
@@ -172,6 +191,22 @@ const App: React.FC = () => {
172191
return t('app.stageOnly', { stage: stageLabel });
173192
}, [progress.stage, stageLabel, substageLabel, t]);
174193

194+
const initStepText = useMemo(() => {
195+
if (progress.stage !== 'init' || !progress.substage) {
196+
return '';
197+
}
198+
199+
const currentStep = INIT_SUBSTAGE_STEP_INDEX[progress.substage];
200+
if (!currentStep) {
201+
return '';
202+
}
203+
204+
return t('app.initStepCounter', {
205+
current: currentStep,
206+
total: INIT_SUBSTAGE_TOTAL_STEPS,
207+
});
208+
}, [progress.stage, progress.substage, t]);
209+
175210
const etaText = useMemo(() => {
176211
if (!isProcessing || !runStartedAt || progress.stage !== 'init') {
177212
return '';
@@ -544,7 +579,7 @@ const App: React.FC = () => {
544579
</Typography>
545580
{stageContextText ? (
546581
<Typography variant="caption" sx={{ color: '#334155', mb: 0.5, display: 'block' }}>
547-
{etaText ? `${stageContextText} · ${etaText}` : stageContextText}
582+
{[stageContextText, initStepText, etaText].filter(Boolean).join(' · ')}
548583
</Typography>
549584
) : null}
550585
<LinearProgress

crabshell-gui/src/renderer/i18n.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const resources = {
1515
statusLoading: '{{message}}',
1616
stageOnly: 'Stage: {{stage}}',
1717
stageWithSubstage: 'Stage: {{stage}} / {{substage}}',
18+
initStepCounter: 'Init steps: {{current}}/{{total}}',
1819
etaSeconds: '~{{seconds}}s remaining',
1920
},
2021
messages: {
@@ -101,6 +102,7 @@ const resources = {
101102
manifestCacheHit: 'Manifest cache hit',
102103
manifestCacheStore: 'Manifest cache update',
103104
manifestDone: 'Manifest patch complete',
105+
toolchainDownload: 'Toolchain download',
104106
toolchainReuse: 'Reuse existing artifacts',
105107
toolchainBuild: 'Build toolchain',
106108
rulesResolve: 'Runtime rules resolve',
@@ -120,6 +122,7 @@ const resources = {
120122
statusLoading: '{{message}}',
121123
stageOnly: '阶段:{{stage}}',
122124
stageWithSubstage: '阶段:{{stage}} / {{substage}}',
125+
initStepCounter: '初始化步骤:{{current}}/{{total}}',
123126
etaSeconds: '预计剩余 ~{{seconds}} 秒',
124127
},
125128
messages: {
@@ -206,6 +209,7 @@ const resources = {
206209
manifestCacheHit: '清单缓存命中',
207210
manifestCacheStore: '清单缓存更新',
208211
manifestDone: '清单补丁完成',
212+
toolchainDownload: '工具链下载',
209213
toolchainReuse: '复用现有构建产物',
210214
toolchainBuild: '构建工具链',
211215
rulesResolve: '运行时规则解析',

0 commit comments

Comments
 (0)