-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFlutterRunAutomator.ps1
103 lines (96 loc) · 2.52 KB
/
FlutterRunAutomator.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
$logFile = "log.txt"
$platform = Read-Host -Prompt 'Enter your platform (android or web)'
function LogError {
param([string]$message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"$timestamp ERROR: $message" | Out-File -FilePath $logFile -Append
}
# function WaitForEmulatorToBeReady() {
# $isReady = $false
# while (-not $isReady) {
# $output = adb shell getprop init.svc.bootanim
# if ($output -eq 'stopped') {
# $isReady = $true
# }
# else {
# Write-Host "Waiting for emulator to be ready..."
# Start-Sleep -Seconds 10
# }
# }
# }
function WaitForEmulatorToBeReady() {
$isReady = $false
while (-not $isReady) {
try {
$output = adb shell getprop init.svc.bootanim
if ($output -eq 'stopped') {
$isReady = $true
}
else {
Write-Host "Waiting for emulator to be ready..."
Start-Sleep -Seconds 10
}
}
catch {
LogError "Failed to check emulator status: $_"
exit 1
}
}
}
function RunEmulator() {
if ($platform -eq 'android') {
try {
flutter emulator --launch Prometheus
WaitForEmulatorToBeReady
}
catch {
Write-Host "Failed to start the Prometheus emulator. Available emulators:"
LogError "Failed to start the Prometheus emulator: $_"
flutter emulators
$emulatorName = Read-Host -Prompt 'Enter the name of the emulator you want to launch'
try {
flutter emulator --launch $emulatorName
WaitForEmulatorToBeReady
}
catch {
LogError "Failed to start the emulator $emulatorName : $_"
exit 1
}
}
}
}
function cleanAndGetPackages() {
try {
flutter clean
}
catch {
LogError "Failed to clean packages: $_"
exit 1
}
try {
flutter pub get
}
catch {
LogError "Failed to get packages: $_"
exit 1
}
}
# Main Running Part
try {
if ($platform -eq 'web') {
cleanAndGetPackages
flutter run -d chrome
}
elseif ($platform -eq 'android') {
cleanAndGetPackages
RunEmulator
flutter run -d emulator
}
else {
Write-Host "Invalid platform. Please enter either 'android' or 'web'."
}
}
catch {
LogError "Failed to run the app: $_"
exit 1
}