getaimeter 0.3.3 → 0.3.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/cli.js +3 -3
- package/package.json +1 -1
- package/tray.ps1 +72 -1
package/cli.js
CHANGED
|
@@ -335,11 +335,11 @@ function runLogs() {
|
|
|
335
335
|
const tail = allLines.slice(-lines).join('\n');
|
|
336
336
|
console.log(tail);
|
|
337
337
|
|
|
338
|
-
// Follow mode
|
|
338
|
+
// Follow mode — poll every second (fs.watch is unreliable on Windows)
|
|
339
339
|
console.log('\n--- Watching for new entries (Ctrl+C to stop) ---\n');
|
|
340
340
|
|
|
341
341
|
let fileSize = fs.statSync(logFile).size;
|
|
342
|
-
|
|
342
|
+
setInterval(() => {
|
|
343
343
|
try {
|
|
344
344
|
const newSize = fs.statSync(logFile).size;
|
|
345
345
|
if (newSize > fileSize) {
|
|
@@ -351,7 +351,7 @@ function runLogs() {
|
|
|
351
351
|
fileSize = newSize;
|
|
352
352
|
}
|
|
353
353
|
} catch {}
|
|
354
|
-
});
|
|
354
|
+
}, 1000);
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
// ---------------------------------------------------------------------------
|
package/package.json
CHANGED
package/tray.ps1
CHANGED
|
@@ -42,7 +42,78 @@ $dashboard = $menu.Items.Add("Open Dashboard")
|
|
|
42
42
|
$dashboard.Add_Click({ Start-Process "https://getaimeter.com/dashboard" })
|
|
43
43
|
|
|
44
44
|
$logs = $menu.Items.Add("View Logs")
|
|
45
|
-
$logs.Add_Click({
|
|
45
|
+
$logs.Add_Click({
|
|
46
|
+
# Build a self-contained live-tail window in a separate runspace so it
|
|
47
|
+
# doesn't block the tray message loop.
|
|
48
|
+
$rs = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
|
|
49
|
+
$rs.ApartmentState = 'STA'
|
|
50
|
+
$rs.ThreadOptions = 'ReuseThread'
|
|
51
|
+
$rs.Open()
|
|
52
|
+
$rs.SessionStateProxy.SetVariable('LogPath', $LogPath)
|
|
53
|
+
|
|
54
|
+
$ps = [System.Management.Automation.PowerShell]::Create()
|
|
55
|
+
$ps.Runspace = $rs
|
|
56
|
+
$null = $ps.AddScript({
|
|
57
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
58
|
+
Add-Type -AssemblyName System.Drawing
|
|
59
|
+
|
|
60
|
+
$form = New-Object System.Windows.Forms.Form
|
|
61
|
+
$form.Text = 'AIMeter — Live Logs'
|
|
62
|
+
$form.Size = New-Object System.Drawing.Size(860, 520)
|
|
63
|
+
$form.BackColor = [System.Drawing.Color]::FromArgb(15, 15, 15)
|
|
64
|
+
$form.StartPosition = 'CenterScreen'
|
|
65
|
+
|
|
66
|
+
$rtb = New-Object System.Windows.Forms.RichTextBox
|
|
67
|
+
$rtb.Dock = 'Fill'
|
|
68
|
+
$rtb.BackColor = [System.Drawing.Color]::FromArgb(15, 15, 15)
|
|
69
|
+
$rtb.ForeColor = [System.Drawing.Color]::FromArgb(200, 200, 200)
|
|
70
|
+
$rtb.Font = New-Object System.Drawing.Font('Consolas', 9)
|
|
71
|
+
$rtb.ReadOnly = $true
|
|
72
|
+
$rtb.ScrollBars = 'Vertical'
|
|
73
|
+
$rtb.WordWrap = $false
|
|
74
|
+
$form.Controls.Add($rtb)
|
|
75
|
+
|
|
76
|
+
# Seed with last 200 lines
|
|
77
|
+
$fileSize = 0
|
|
78
|
+
if (Test-Path $LogPath) {
|
|
79
|
+
$all = Get-Content $LogPath -Raw -ErrorAction SilentlyContinue
|
|
80
|
+
if ($all) {
|
|
81
|
+
$lines = $all -split "`n"
|
|
82
|
+
$seed = ($lines | Select-Object -Last 200) -join "`n"
|
|
83
|
+
$rtb.Text = $seed.TrimEnd() + "`n"
|
|
84
|
+
$rtb.SelectionStart = $rtb.Text.Length
|
|
85
|
+
$rtb.ScrollToCaret()
|
|
86
|
+
}
|
|
87
|
+
$fileSize = (Get-Item $LogPath).Length
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
# Poll for new bytes every 500 ms
|
|
91
|
+
$timer = New-Object System.Windows.Forms.Timer
|
|
92
|
+
$timer.Interval = 500
|
|
93
|
+
$timer.Add_Tick({
|
|
94
|
+
if (-not (Test-Path $LogPath)) { return }
|
|
95
|
+
$newSize = (Get-Item $LogPath).Length
|
|
96
|
+
if ($newSize -le $fileSize) { return }
|
|
97
|
+
try {
|
|
98
|
+
$fs = [System.IO.File]::Open($LogPath, 'Open', 'Read', 'ReadWrite')
|
|
99
|
+
$null = $fs.Seek($fileSize, 'Begin')
|
|
100
|
+
$buf = New-Object byte[] ($newSize - $fileSize)
|
|
101
|
+
$null = $fs.Read($buf, 0, $buf.Length)
|
|
102
|
+
$fs.Close()
|
|
103
|
+
$chunk = [System.Text.Encoding]::UTF8.GetString($buf)
|
|
104
|
+
$rtb.AppendText($chunk)
|
|
105
|
+
$rtb.SelectionStart = $rtb.Text.Length
|
|
106
|
+
$rtb.ScrollToCaret()
|
|
107
|
+
$fileSize = $newSize
|
|
108
|
+
} catch {}
|
|
109
|
+
})
|
|
110
|
+
$timer.Start()
|
|
111
|
+
|
|
112
|
+
$form.Add_FormClosed({ $timer.Stop(); $timer.Dispose() })
|
|
113
|
+
[System.Windows.Forms.Application]::Run($form)
|
|
114
|
+
})
|
|
115
|
+
$null = $ps.BeginInvoke()
|
|
116
|
+
})
|
|
46
117
|
|
|
47
118
|
$menu.Items.Add("-")
|
|
48
119
|
|