forked from JayQueue/MyWhoosh2Garmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyWhooshMonitor.ps1
83 lines (72 loc) · 3.03 KB
/
MyWhooshMonitor.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Validate path or search if not found
if (-not $myWhooshPath -or -not (Test-Path $myWhooshPath)) {
if ([System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Unix) {
# macOS search
$myWhooshApp = "myWhoosh Indoor Cycling App.app"
Write-Host "Searching for $myWhooshApp..."
$appBundle = Get-ChildItem -Path "/Applications" -Filter $myWhooshApp -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
if ($appBundle) {
$myWhooshPath = "$($appBundle.FullName)/Contents/MacOS/myWhoosh"
}
} elseif ([System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT) {
# Windows search
$myWhooshApp = "MyWhoosh"
Write-Host "Searching for $myWhooshApp App.."
$appxPackage = Get-AppxPackage | Where-Object { $_.Name -like "*$myWhooshApp*" }
if ($appxPackage) {
$installLocation = $appxPackage.InstallLocation
Write-Host "Found install location: $installLocation"
# Search for MyWhoosh.exe in the correct subdirectory
# $myWhooshPath = Get-ChildItem -Path $installLocation -Filter $myWhooshApp -Recurse -ErrorAction SilentlyContinue |
# Select-Object -First 1 -ExpandProperty FullName
$startApp = (Get-StartApps | Where-Object { $_.Name -like "*$myWhooshApp*" })
if($startApp) {
$appId = $startApp.AppID
$myWhooshPath = "shell:AppsFolder\$appId"
}
}
}
if (-not $myWhooshPath) {
Write-Error "MyWhoosh.exe not found!"
exit 1
}
}
Write-Host "Starting $myWhooshApp : $myWhooshPath"
# Start the application
if ([System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT) {
Start-Process -FilePath "explorer.exe" -ArgumentList $myWhooshPath -NoNewWindow -PassThru
} else {
Start-Process -FilePath $myWhooshPath -NoNewWindow -PassThru
}
Start-Sleep -Seconds 10
# Wait for the app to finish
$processName = if ([System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Unix) {
"myWhoosh"
} else {
"MyWhoosh"
}
Write-Host "Waiting for $processName to finish..."
while (Get-Process -Name $processName -ErrorAction SilentlyContinue) {
Start-Sleep -Seconds 5
}
# Run the Python script after MyWhoosh exits
$venvPath = if ([System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Unix) {
"./.venv/bin/python"
} else {
".\.venv\Scripts\python.exe"
}
if (Test-Path $venvPath) {
Write-Host "Running Python script in VENV..."
& $venvPath myWhoosh2Garmin.py
} else {
Write-Host "VENV not found. Creating VENV..."
python -m venv .venv
Write-Host "VENV created. Installing required packages..."
if ([System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Unix) {
& ./.venv/bin/python -m pip install -r requirements.txt
} else {
& .\.venv\Scripts\python.exe -m pip install -r requirements.txt
}
Write-Host "Running Python script in VENV..."
& $venvPath myWhoosh2Garmin.py
}