-
Notifications
You must be signed in to change notification settings - Fork 0
/
carousel.ps1
59 lines (48 loc) · 1.95 KB
/
carousel.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function Set-Interval {
$global:images = (Get-ChildItem -File .\images | Measure-Object).Count - 1
$global:delta = [Math]::Min($global:images, 20)
if ($global:images -le 9) {
$global:interval = if ($global:images -eq 9) { 5 } else { [Math]::Ceiling(40 / $global:images) }
} else {
$global:interval = 4
}
}
function Scrap-Images {
$StopWatchScrap = New-Object -TypeName 'System.Diagnostics.Stopwatch'
$StopWatchScrap.Start()
npm start
$global:elapsed = $StopWatchScrap.Elapsed.Seconds
Write-Output "Done with scrapping"
}
function Start-Carousel {
Start-ThreadJob -ScriptBlock {
param($interval)
ImageViewer.exe --interval=$interval --random=on --repeat=off --fullscreen=on --effect=off --stretchIn=on --stretchOut=on --includSubFolders=off --stayOnTop=on 'images'
} -ArgumentList $global:interval | Out-Null
}
Scrap-Images
Set-Interval
while($true) {
[bool] $updated = $false
$StopWatch = New-Object -TypeName 'System.Diagnostics.Stopwatch'
$StopWatch.Start()
Start-Carousel
Write-Output "Images: $($global:images)"
Write-Output "Temps d'exec total: $($global:images*$global:interval)"
Write-Output "Temps du scraping: $($global:elapsed)"
Write-Output "Delta: $($global:delta)"
Write-Output "Interval: $($global:interval)"
Write-Output "Prochain scraping dans $(($global:images*$global:interval - $global:elapsed - $global:delta)) secondes"
while($true) {
if ($StopWatch.Elapsed.TotalSeconds -ge ($global:images*$global:interval - $global:elapsed - $global:delta) -And !$updated) {
$updated = $true
Scrap-Images
Set-Interval
}
if ($StopWatch.Elapsed.TotalSeconds -ge ($global:images*$global:interval + $global:interval)) {
Write-Output "Stopping processes"
Get-job | Remove-Job -Force
break
}
}
}