getaimeter 0.7.4 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/tray.ps1 +52 -29
package/package.json
CHANGED
package/tray.ps1
CHANGED
|
@@ -78,40 +78,63 @@ $aboutItem.Add_Click({
|
|
|
78
78
|
$helpMenu.DropDownItems.Add($aboutItem) | Out-Null
|
|
79
79
|
|
|
80
80
|
$checkUpdateItem = New-Object System.Windows.Forms.ToolStripMenuItem("Check for Updates")
|
|
81
|
+
$script:updateJob = $null
|
|
81
82
|
$checkUpdateItem.Add_Click({
|
|
82
83
|
$checkUpdateItem.Text = "Checking..."
|
|
83
84
|
$checkUpdateItem.Enabled = $false
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
$
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
[System.Windows.Forms.MessageBoxIcon]::Information
|
|
93
|
-
)
|
|
94
|
-
if ($result -eq [System.Windows.Forms.DialogResult]::Yes) {
|
|
95
|
-
Start-Process "cmd.exe" -ArgumentList "/k npm install -g getaimeter@latest && echo. && echo Update complete. Restart the watcher with: aimeter stop && aimeter start"
|
|
96
|
-
}
|
|
97
|
-
} else {
|
|
98
|
-
[System.Windows.Forms.MessageBox]::Show(
|
|
99
|
-
"You are running the latest version (v$Version).",
|
|
100
|
-
"No Updates",
|
|
101
|
-
[System.Windows.Forms.MessageBoxButtons]::OK,
|
|
102
|
-
[System.Windows.Forms.MessageBoxIcon]::Information
|
|
103
|
-
)
|
|
85
|
+
|
|
86
|
+
# Run HTTP request in a background job to avoid freezing the UI
|
|
87
|
+
$script:updateJob = Start-Job -ScriptBlock {
|
|
88
|
+
try {
|
|
89
|
+
$r = Invoke-RestMethod -Uri "https://registry.npmjs.org/getaimeter/latest" -TimeoutSec 10
|
|
90
|
+
return $r.version
|
|
91
|
+
} catch {
|
|
92
|
+
return "ERROR"
|
|
104
93
|
}
|
|
105
|
-
} catch {
|
|
106
|
-
[System.Windows.Forms.MessageBox]::Show(
|
|
107
|
-
"Could not check for updates. Please check your internet connection.",
|
|
108
|
-
"Update Check Failed",
|
|
109
|
-
[System.Windows.Forms.MessageBoxButtons]::OK,
|
|
110
|
-
[System.Windows.Forms.MessageBoxIcon]::Warning
|
|
111
|
-
)
|
|
112
94
|
}
|
|
113
|
-
|
|
114
|
-
|
|
95
|
+
|
|
96
|
+
# Timer polls for job completion (every 500ms)
|
|
97
|
+
$updateTimer = New-Object System.Windows.Forms.Timer
|
|
98
|
+
$updateTimer.Interval = 500
|
|
99
|
+
$updateTimer.Add_Tick({
|
|
100
|
+
if ($script:updateJob.State -eq "Completed") {
|
|
101
|
+
$updateTimer.Stop()
|
|
102
|
+
$updateTimer.Dispose()
|
|
103
|
+
$latest = Receive-Job $script:updateJob
|
|
104
|
+
Remove-Job $script:updateJob
|
|
105
|
+
$script:updateJob = $null
|
|
106
|
+
|
|
107
|
+
$checkUpdateItem.Text = "Check for Updates"
|
|
108
|
+
$checkUpdateItem.Enabled = $true
|
|
109
|
+
|
|
110
|
+
if ($latest -eq "ERROR") {
|
|
111
|
+
[System.Windows.Forms.MessageBox]::Show(
|
|
112
|
+
"Could not check for updates. Please check your internet connection.",
|
|
113
|
+
"Update Check Failed",
|
|
114
|
+
[System.Windows.Forms.MessageBoxButtons]::OK,
|
|
115
|
+
[System.Windows.Forms.MessageBoxIcon]::Warning
|
|
116
|
+
) | Out-Null
|
|
117
|
+
} elseif ($latest -and $latest -ne $Version) {
|
|
118
|
+
$result = [System.Windows.Forms.MessageBox]::Show(
|
|
119
|
+
"Update available: v$Version -> v$latest`n`nClick Yes to open a terminal and run the update command.",
|
|
120
|
+
"Update Available",
|
|
121
|
+
[System.Windows.Forms.MessageBoxButtons]::YesNo,
|
|
122
|
+
[System.Windows.Forms.MessageBoxIcon]::Information
|
|
123
|
+
)
|
|
124
|
+
if ($result -eq [System.Windows.Forms.DialogResult]::Yes) {
|
|
125
|
+
Start-Process "cmd.exe" -ArgumentList "/k echo Updating AIMeter... && npm install -g getaimeter@latest && echo. && echo Done! Now restart: aimeter stop ^&^& aimeter start"
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
[System.Windows.Forms.MessageBox]::Show(
|
|
129
|
+
"You are running the latest version (v$Version).",
|
|
130
|
+
"No Updates",
|
|
131
|
+
[System.Windows.Forms.MessageBoxButtons]::OK,
|
|
132
|
+
[System.Windows.Forms.MessageBoxIcon]::Information
|
|
133
|
+
) | Out-Null
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
$updateTimer.Start()
|
|
115
138
|
})
|
|
116
139
|
$helpMenu.DropDownItems.Add($checkUpdateItem) | Out-Null
|
|
117
140
|
|