panrouter 2.0.0 → 2.0.1
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-daemon.ps1 +23 -10
package/package.json
CHANGED
package/tray-daemon.ps1
CHANGED
|
@@ -32,7 +32,6 @@ if ([string]::IsNullOrWhiteSpace($nodePath)) {
|
|
|
32
32
|
function Restart-Server {
|
|
33
33
|
"Executing Restart-Server..." | Out-File $logFile -Append
|
|
34
34
|
try {
|
|
35
|
-
# 使用更为稳健的 WMI 查询关闭进程
|
|
36
35
|
Get-WmiObject Win32_Process -Filter "Name = 'node.exe'" |
|
|
37
36
|
Where-Object { $_.CommandLine -match "server\.mjs" } |
|
|
38
37
|
ForEach-Object { Stop-Process -Id $_.ProcessId -Force }
|
|
@@ -63,7 +62,7 @@ if (-not $isRunning) {
|
|
|
63
62
|
Restart-Server
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
# ─── 绘制托盘图标
|
|
65
|
+
# ─── 绘制托盘图标 (增加极强容错) ──────────────────────────
|
|
67
66
|
try {
|
|
68
67
|
$bmp = New-Object System.Drawing.Bitmap(16, 16)
|
|
69
68
|
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
|
@@ -71,17 +70,31 @@ try {
|
|
|
71
70
|
$g.Clear([System.Drawing.Color]::Transparent)
|
|
72
71
|
$brush = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::FromArgb(0, 120, 215))
|
|
73
72
|
$g.FillEllipse($brush, 0, 0, 15, 15)
|
|
74
|
-
|
|
73
|
+
|
|
74
|
+
# 【修复1】改用通用系统字体,防止系统中缺少 Segoe UI 导致报错闪退
|
|
75
|
+
$font = New-Object System.Drawing.Font([System.Drawing.FontFamily]::GenericSansSerif, 8, [System.Drawing.FontStyle]::Bold)
|
|
75
76
|
$fg = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::White)
|
|
76
77
|
$g.DrawString("P", $font, $fg, 3, 2)
|
|
77
78
|
|
|
78
79
|
$hIcon = $bmp.GetHicon()
|
|
79
80
|
$icon = [System.Drawing.Icon]::FromHandle($hIcon)
|
|
81
|
+
"Custom icon drawn." | Out-File $logFile -Append
|
|
80
82
|
} catch {
|
|
81
|
-
"Icon drawing error: $($_.Exception.Message)" | Out-File $logFile -Append
|
|
82
|
-
Exit
|
|
83
|
+
"Icon drawing error: $($_.Exception.Message). Using fallback icon." | Out-File $logFile -Append
|
|
84
|
+
# 【修复2】万一画图依然失败绝对不能 Exit,用系统自带程序图标兜底显示
|
|
85
|
+
$icon = [System.Drawing.SystemIcons]::Application
|
|
83
86
|
}
|
|
84
87
|
|
|
88
|
+
# ─── 创建隐藏主窗口 (防止消息循环异常退出) ─────────────────
|
|
89
|
+
# 【修复3】提供一个实质性的隐藏窗体,避免部分系统回收无窗体的托盘进程
|
|
90
|
+
$mainForm = New-Object System.Windows.Forms.Form
|
|
91
|
+
$mainForm.Text = "PanRouterHidden"
|
|
92
|
+
$mainForm.ShowInTaskbar = $false
|
|
93
|
+
$mainForm.WindowState = [System.Windows.Forms.FormWindowState]::Minimized
|
|
94
|
+
$mainForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedToolWindow
|
|
95
|
+
$mainForm.Opacity = 0
|
|
96
|
+
$mainForm.Add_Load({ $mainForm.Hide() })
|
|
97
|
+
|
|
85
98
|
# ─── 初始化托盘菜单 ────────────────────────────────────────
|
|
86
99
|
$notifyIcon = New-Object System.Windows.Forms.NotifyIcon
|
|
87
100
|
$notifyIcon.Icon = $icon
|
|
@@ -91,7 +104,7 @@ $menu = New-Object System.Windows.Forms.ContextMenuStrip
|
|
|
91
104
|
|
|
92
105
|
$titleItem = New-Object System.Windows.Forms.ToolStripMenuItem("Pan Router | :50816")
|
|
93
106
|
$titleItem.Enabled = $false
|
|
94
|
-
$titleItem.Font = New-Object System.Drawing.Font(
|
|
107
|
+
$titleItem.Font = New-Object System.Drawing.Font([System.Drawing.FontFamily]::GenericSansSerif, 9, [System.Drawing.FontStyle]::Bold)
|
|
95
108
|
$menu.Items.Add($titleItem) | Out-Null
|
|
96
109
|
$menu.Items.Add((New-Object System.Windows.Forms.ToolStripSeparator)) | Out-Null
|
|
97
110
|
|
|
@@ -128,7 +141,7 @@ $exitItem.Add_Click({
|
|
|
128
141
|
try {
|
|
129
142
|
Get-WmiObject Win32_Process -Filter "Name = 'node.exe'" | Where-Object { $_.CommandLine -match "server\.mjs" } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }
|
|
130
143
|
} catch {}
|
|
131
|
-
|
|
144
|
+
$mainForm.Close()
|
|
132
145
|
})
|
|
133
146
|
$menu.Items.Add($exitItem) | Out-Null
|
|
134
147
|
|
|
@@ -143,10 +156,10 @@ $notifyIcon.Add_MouseClick({
|
|
|
143
156
|
|
|
144
157
|
$notifyIcon.Visible = $true
|
|
145
158
|
|
|
146
|
-
"UI setup completed, entering
|
|
159
|
+
"UI setup completed, entering Application loop." | Out-File $logFile -Append
|
|
147
160
|
|
|
148
|
-
|
|
149
|
-
[System.Windows.Forms.Application]::Run($
|
|
161
|
+
# 运行消息循环,绑定到隐藏窗体以锁死进程不被误杀
|
|
162
|
+
[System.Windows.Forms.Application]::Run($mainForm)
|
|
150
163
|
|
|
151
164
|
"Exiting..." | Out-File $logFile -Append
|
|
152
165
|
$notifyIcon.Visible = $false
|