Skip to content

Commit a8e0583

Browse files
committed
feat: Windows Integration progress bar
1 parent 17f3f6d commit a8e0583

2 files changed

Lines changed: 45 additions & 10 deletions

File tree

bin/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function winUIWait(text) {
2424
"-File", _winUIWait,
2525
"-Name", name__,
2626
"-Text", text
27-
], { detached: false, stdio: 'ignore' });
27+
], { detached: false, stdio: ['pipe','ignore','ignore'] });
2828
}
2929

3030
let WinUIWait = false;
@@ -387,7 +387,9 @@ const instance = windows ? new JSSC() : {
387387

388388
if (windows) {
389389
WinUIWait = winUIWait('Compressing "' + path.parse(inp).name + '"...');
390-
instance.events.onCompressProgress = (percentage) => {console.log(percentage, '%')}
390+
instance.events.onCompressProgress = (percentage) => {
391+
WinUIWait.stdin.write(percentage + "\n");
392+
};
391393
}
392394

393395
config.stringify = undefined;
@@ -456,7 +458,9 @@ const instance = windows ? new JSSC() : {
456458
console.log(prefix + e);
457459
exit(1, e);
458460
}
459-
if (windows) WinUIWait = winUIWait('Decompressing "' + path.parse(inp).name + '"...');
461+
if (windows) {
462+
WinUIWait = winUIWait('Decompressing "' + path.parse(inp).name + '"...');
463+
}
460464

461465
const raw = isFile ? fs.readFileSync(input[0]) : input[0];
462466

bin/windows/ui/wait.ps1

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
param (
22
[string]$Name = "",
3-
[string]$Text = ""
3+
[string]$Text = "",
4+
[int]$Progress = 0
45
)
56

6-
[Windows.Forms.Application]::EnableVisualStyles()
7-
87
Add-Type -AssemblyName System.Windows.Forms
98
Add-Type -AssemblyName System.Drawing
109

10+
[Windows.Forms.Application]::EnableVisualStyles()
11+
1112
$form = New-Object Windows.Forms.Form
1213
$form.Text = $Name
13-
$form.Size = New-Object Drawing.Size(400, 90)
14+
$form.Size = New-Object Drawing.Size(400, 120)
1415
$form.StartPosition = "CenterScreen"
1516
$form.FormBorderStyle = "FixedDialog"
1617
$form.MaximizeBox = $false
@@ -19,10 +20,40 @@ $form.ControlBox = $false
1920
$form.TopMost = $true
2021

2122
$label = New-Object Windows.Forms.Label
22-
$label.Text = $Text
23-
$label.Location = New-Object Drawing.Point(20, 20)
23+
$label.Text = "$Text ($Progress%)"
24+
$label.Location = New-Object Drawing.Point(20, 15)
2425
$label.AutoSize = $true
2526
$label.Font = New-Object System.Drawing.Font('Microsoft JhengHei',10)
27+
28+
$progressBar = New-Object Windows.Forms.ProgressBar
29+
$progressBar.Location = New-Object Drawing.Point(20, 50)
30+
$progressBar.Size = New-Object Drawing.Size(340, 20)
31+
$progressBar.Minimum = 0
32+
$progressBar.Maximum = 100
33+
$progressBar.Value = $Progress
34+
2635
$form.Controls.Add($label)
36+
$form.Controls.Add($progressBar)
37+
38+
$timer = New-Object Windows.Forms.Timer
39+
$timer.Interval = 100
40+
41+
$timer.Add_Tick({
42+
while ([Console]::In.Peek() -ne -1) {
43+
$line = [Console]::In.ReadLine()
44+
if ($line -ne $null) {
45+
$value = [int]$line
46+
if ($value -ge 0 -and $value -le 100) {
47+
$progressBar.Value = $value
48+
$label.Text = "$Text ($value%)"
49+
}
50+
}
51+
}
52+
})
53+
54+
$timer.Start()
55+
56+
$form.Add_Shown({ $form.Activate() })
57+
[void]$form.Show()
2758

28-
$form.ShowDialog()
59+
[Windows.Forms.Application]::Run($form)

0 commit comments

Comments
 (0)