cortico-world-bottle 0.1.2 → 0.2.0
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/CHANGELOG.md +140 -0
- package/README.md +284 -284
- package/describe.json +9 -2
- package/package.json +1 -1
- package/server/app.ts +67 -9
- package/server/db.ts +31 -6
- package/server/quota.ts +6 -1
- package/server/tuning.ts +9 -0
- package/shared/contract.ts +41 -2
- package/world/ENV_PROMPT.md +17 -20
- package/world/card-host.ps1 +375 -375
- package/world/cards.ts +30 -10
- package/world/config.ts +10 -0
- package/world/definition.ts +7 -0
- package/world/page.ts +137 -29
- package/world/store.ts +96 -25
- package/world/tools.ts +1 -1
- package/world/world.ts +233 -38
package/world/card-host.ps1
CHANGED
|
@@ -1,375 +1,375 @@
|
|
|
1
|
-
# 漂流瓶 · 原生卡片
|
|
2
|
-
#
|
|
3
|
-
# 由 World 启动,读一份 JSON,画一张纸,按钮把动作回传给本地信箱服务,然后自己关。
|
|
4
|
-
# 只做三件事:显示、回传、关闭。不读网络上的任何东西。
|
|
5
|
-
param(
|
|
6
|
-
[Parameter(Mandatory = $true)][string]$Data,
|
|
7
|
-
[Parameter(Mandatory = $true)][string]$Base,
|
|
8
|
-
# 没人理它时多久自己收起;调试时可以传小一点。
|
|
9
|
-
[int]$AutoCloseMs = 300000,
|
|
10
|
-
# 开发用:把窗口真实的样子截一张 PNG,然后照常运行。
|
|
11
|
-
[string]$Shot = '',
|
|
12
|
-
# 开发用:起来后自动触发一个动作,用来验证回传链路。
|
|
13
|
-
[string]$AutoAction = ''
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
$ErrorActionPreference = 'Stop'
|
|
17
|
-
Add-Type -AssemblyName PresentationFramework
|
|
18
|
-
Add-Type -AssemblyName PresentationCore
|
|
19
|
-
Add-Type -AssemblyName WindowsBase
|
|
20
|
-
|
|
21
|
-
# 150% 缩放下也别糊;老系统上失败就算了。
|
|
22
|
-
try {
|
|
23
|
-
Add-Type -Namespace BottleNative -Name Dpi -MemberDefinition '[DllImport("user32.dll")] public static extern bool SetProcessDpiAwarenessContext(IntPtr ctx);' -ErrorAction Stop
|
|
24
|
-
[BottleNative.Dpi]::SetProcessDpiAwarenessContext([IntPtr]::new(-4)) | Out-Null
|
|
25
|
-
} catch { }
|
|
26
|
-
|
|
27
|
-
function Brush([string]$hex) {
|
|
28
|
-
$color = [System.Windows.Media.Color][System.Windows.Media.ColorConverter]::ConvertFromString($hex)
|
|
29
|
-
return [System.Windows.Media.SolidColorBrush]::new($color)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
$spec = Get-Content -LiteralPath $Data -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
33
|
-
$script:baseUrl = $Base.TrimEnd('/')
|
|
34
|
-
$script:busy = $false
|
|
35
|
-
$script:closeTimer = $null
|
|
36
|
-
$script:buttons = New-Object System.Collections.ArrayList
|
|
37
|
-
|
|
38
|
-
$win = New-Object System.Windows.Window
|
|
39
|
-
$win.Title = '漂流瓶'
|
|
40
|
-
$win.Width = 460
|
|
41
|
-
$win.SizeToContent = 'Height'
|
|
42
|
-
$win.WindowStyle = 'None'
|
|
43
|
-
$win.ResizeMode = 'NoResize'
|
|
44
|
-
$win.AllowsTransparency = $true
|
|
45
|
-
$win.Background = [System.Windows.Media.Brushes]::Transparent
|
|
46
|
-
$win.Topmost = $true
|
|
47
|
-
$win.ShowInTaskbar = $false
|
|
48
|
-
$win.ShowActivated = $false
|
|
49
|
-
$win.WindowStartupLocation = 'Manual'
|
|
50
|
-
$win.Left = -4000
|
|
51
|
-
$win.Top = -4000
|
|
52
|
-
$win.Opacity = 0
|
|
53
|
-
$script:win = $win
|
|
54
|
-
|
|
55
|
-
$shell = New-Object System.Windows.Controls.Grid
|
|
56
|
-
$shell.Margin = [System.Windows.Thickness]::new(26)
|
|
57
|
-
|
|
58
|
-
$card = New-Object System.Windows.Controls.Border
|
|
59
|
-
$card.Background = Brush '#FFFDF7'
|
|
60
|
-
$card.CornerRadius = [System.Windows.CornerRadius]::new(14)
|
|
61
|
-
$card.BorderBrush = Brush '#E2D8C7'
|
|
62
|
-
$card.BorderThickness = [System.Windows.Thickness]::new(1)
|
|
63
|
-
$card.Padding = [System.Windows.Thickness]::new(24, 20, 24, 18)
|
|
64
|
-
$shadow = New-Object System.Windows.Media.Effects.DropShadowEffect
|
|
65
|
-
$shadow.BlurRadius = 22
|
|
66
|
-
$shadow.ShadowDepth = 6
|
|
67
|
-
$shadow.Direction = 270
|
|
68
|
-
$shadow.Opacity = 0.17
|
|
69
|
-
$shadow.Color = [System.Windows.Media.Color][System.Windows.Media.ColorConverter]::ConvertFromString('#3C2D19')
|
|
70
|
-
$card.Effect = $shadow
|
|
71
|
-
$slide = [System.Windows.Media.TranslateTransform]::new(0, 10)
|
|
72
|
-
$card.RenderTransform = $slide
|
|
73
|
-
|
|
74
|
-
$stack = New-Object System.Windows.Controls.StackPanel
|
|
75
|
-
|
|
76
|
-
$head = New-Object System.Windows.Controls.Grid
|
|
77
|
-
$head.ColumnDefinitions.Add((New-Object System.Windows.Controls.ColumnDefinition)) | Out-Null
|
|
78
|
-
$auto = New-Object System.Windows.Controls.ColumnDefinition
|
|
79
|
-
$auto.Width = [System.Windows.GridLength]::Auto
|
|
80
|
-
$head.ColumnDefinitions.Add($auto) | Out-Null
|
|
81
|
-
|
|
82
|
-
$eyebrow = New-Object System.Windows.Controls.TextBlock
|
|
83
|
-
$eyebrow.Text = [string]$spec.eyebrow
|
|
84
|
-
$eyebrow.FontFamily = 'Microsoft YaHei'
|
|
85
|
-
$eyebrow.FontSize = 11
|
|
86
|
-
$eyebrow.Foreground = Brush '#8A6540'
|
|
87
|
-
$eyebrow.VerticalAlignment = 'Center'
|
|
88
|
-
$head.Children.Add($eyebrow) | Out-Null
|
|
89
|
-
|
|
90
|
-
$close = New-Object System.Windows.Controls.TextBlock
|
|
91
|
-
$close.Text = '×'
|
|
92
|
-
$close.FontFamily = 'Segoe UI'
|
|
93
|
-
$close.FontSize = 15
|
|
94
|
-
$close.Foreground = Brush '#C4B9A6'
|
|
95
|
-
$close.Cursor = 'Hand'
|
|
96
|
-
$close.Margin = [System.Windows.Thickness]::new(10, -4, 0, 0)
|
|
97
|
-
$close.VerticalAlignment = 'Top'
|
|
98
|
-
[System.Windows.Controls.Grid]::SetColumn($close, 1)
|
|
99
|
-
$script:brushInk = Brush '#2F2A23'
|
|
100
|
-
$script:brushInkHover = Brush '#443C31'
|
|
101
|
-
$script:brushGhost = Brush '#00FFFFFF'
|
|
102
|
-
$script:brushGhostHover = Brush '#F4EEE2'
|
|
103
|
-
$script:brushMuted = Brush '#8B8375'
|
|
104
|
-
$script:brushFaint = Brush '#C4B9A6'
|
|
105
|
-
|
|
106
|
-
$close.Add_MouseLeftButtonUp({ param($s, $e) $script:win.Close() })
|
|
107
|
-
$close.Add_MouseEnter({ param($s, $e) $s.Foreground = $script:brushMuted })
|
|
108
|
-
$close.Add_MouseLeave({ param($s, $e) $s.Foreground = $script:brushFaint })
|
|
109
|
-
$head.Children.Add($close) | Out-Null
|
|
110
|
-
$stack.Children.Add($head) | Out-Null
|
|
111
|
-
|
|
112
|
-
if ($spec.from) {
|
|
113
|
-
$from = New-Object System.Windows.Controls.TextBlock
|
|
114
|
-
$from.Text = [string]$spec.from
|
|
115
|
-
$from.FontFamily = 'Microsoft YaHei'
|
|
116
|
-
$from.FontSize = 12
|
|
117
|
-
$from.Foreground = Brush '#8B8375'
|
|
118
|
-
$from.Margin = [System.Windows.Thickness]::new(0, 3, 0, 12)
|
|
119
|
-
$stack.Children.Add($from) | Out-Null
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
# 标题:来自谁之后、正文之前。和网页上的 .mail-topic / h2.title 同一个位置。
|
|
123
|
-
if ($spec.title) {
|
|
124
|
-
$title = New-Object System.Windows.Controls.TextBlock
|
|
125
|
-
$title.Text = [string]$spec.title
|
|
126
|
-
$title.FontFamily = 'Microsoft YaHei'
|
|
127
|
-
$title.FontSize = 15
|
|
128
|
-
$title.FontWeight = 'SemiBold'
|
|
129
|
-
$title.Foreground = Brush '#2F2A23'
|
|
130
|
-
$title.TextWrapping = 'Wrap'
|
|
131
|
-
$title.Margin = [System.Windows.Thickness]::new(0, 0, 0, 10)
|
|
132
|
-
$stack.Children.Add($title) | Out-Null
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if ($spec.quote) {
|
|
136
|
-
$quote = New-Object System.Windows.Controls.Border
|
|
137
|
-
$quote.Background = Brush '#FAF6EC'
|
|
138
|
-
$quote.CornerRadius = [System.Windows.CornerRadius]::new(10)
|
|
139
|
-
$quote.Padding = [System.Windows.Thickness]::new(13, 10, 13, 10)
|
|
140
|
-
$quote.Margin = [System.Windows.Thickness]::new(0, 0, 0, 14)
|
|
141
|
-
$quoteStack = New-Object System.Windows.Controls.StackPanel
|
|
142
|
-
$quoteLabel = New-Object System.Windows.Controls.TextBlock
|
|
143
|
-
$quoteLabel.Text = [string]$spec.quote.label
|
|
144
|
-
$quoteLabel.FontFamily = 'Microsoft YaHei'
|
|
145
|
-
$quoteLabel.FontSize = 10.5
|
|
146
|
-
$quoteLabel.Foreground = Brush '#A39A8A'
|
|
147
|
-
$quoteLabel.Margin = [System.Windows.Thickness]::new(0, 0, 0, 4)
|
|
148
|
-
$quoteStack.Children.Add($quoteLabel) | Out-Null
|
|
149
|
-
$quoteBody = New-Object System.Windows.Controls.TextBlock
|
|
150
|
-
$quoteBody.Text = [string]$spec.quote.body
|
|
151
|
-
$quoteBody.FontFamily = 'Microsoft YaHei'
|
|
152
|
-
$quoteBody.FontSize = 12.5
|
|
153
|
-
$quoteBody.LineHeight = 21
|
|
154
|
-
$quoteBody.LineStackingStrategy = 'BlockLineHeight'
|
|
155
|
-
$quoteBody.TextWrapping = 'Wrap'
|
|
156
|
-
$quoteBody.TextTrimming = 'CharacterEllipsis'
|
|
157
|
-
$quoteBody.MaxHeight = 86
|
|
158
|
-
$quoteBody.Foreground = Brush '#5B5449'
|
|
159
|
-
$quoteStack.Children.Add($quoteBody) | Out-Null
|
|
160
|
-
$quote.Child = $quoteStack
|
|
161
|
-
$stack.Children.Add($quote) | Out-Null
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
$body = New-Object System.Windows.Controls.TextBlock
|
|
165
|
-
$body.Text = [string]$spec.body
|
|
166
|
-
$body.FontFamily = 'Microsoft YaHei'
|
|
167
|
-
$body.FontSize = 15.5
|
|
168
|
-
$body.LineHeight = 27
|
|
169
|
-
$body.LineStackingStrategy = 'BlockLineHeight'
|
|
170
|
-
$body.TextWrapping = 'Wrap'
|
|
171
|
-
$body.Foreground = Brush '#2F2A23'
|
|
172
|
-
$stack.Children.Add($body) | Out-Null
|
|
173
|
-
|
|
174
|
-
if ($spec.hints) {
|
|
175
|
-
foreach ($hint in @($spec.hints)) {
|
|
176
|
-
$hintBorder = New-Object System.Windows.Controls.Border
|
|
177
|
-
$hintBorder.Background = Brush '#FBF3E2'
|
|
178
|
-
$hintBorder.BorderBrush = Brush '#EFE0C6'
|
|
179
|
-
$hintBorder.BorderThickness = [System.Windows.Thickness]::new(1)
|
|
180
|
-
$hintBorder.CornerRadius = [System.Windows.CornerRadius]::new(9)
|
|
181
|
-
$hintBorder.Padding = [System.Windows.Thickness]::new(11, 7, 11, 7)
|
|
182
|
-
$hintBorder.Margin = [System.Windows.Thickness]::new(0, 10, 0, 0)
|
|
183
|
-
$hintText = New-Object System.Windows.Controls.TextBlock
|
|
184
|
-
$hintText.Text = [string]$hint
|
|
185
|
-
$hintText.FontFamily = 'Microsoft YaHei'
|
|
186
|
-
$hintText.FontSize = 11.5
|
|
187
|
-
$hintText.TextWrapping = 'Wrap'
|
|
188
|
-
$hintText.Foreground = Brush '#7A5B3A'
|
|
189
|
-
$hintBorder.Child = $hintText
|
|
190
|
-
$stack.Children.Add($hintBorder) | Out-Null
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if ($spec.meta) {
|
|
195
|
-
$meta = New-Object System.Windows.Controls.TextBlock
|
|
196
|
-
$meta.Text = [string]$spec.meta
|
|
197
|
-
$meta.FontFamily = 'Microsoft YaHei'
|
|
198
|
-
$meta.FontSize = 11
|
|
199
|
-
$meta.Foreground = Brush '#A39A8A'
|
|
200
|
-
$meta.Margin = [System.Windows.Thickness]::new(0, 12, 0, 0)
|
|
201
|
-
$stack.Children.Add($meta) | Out-Null
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
$status = New-Object System.Windows.Controls.TextBlock
|
|
205
|
-
$status.FontFamily = 'Microsoft YaHei'
|
|
206
|
-
$status.FontSize = 11.5
|
|
207
|
-
$status.TextWrapping = 'Wrap'
|
|
208
|
-
$status.Foreground = Brush '#5F5E5A'
|
|
209
|
-
$status.Margin = [System.Windows.Thickness]::new(0, 10, 0, 0)
|
|
210
|
-
$status.Visibility = 'Collapsed'
|
|
211
|
-
$script:status = $status
|
|
212
|
-
$stack.Children.Add($status) | Out-Null
|
|
213
|
-
|
|
214
|
-
function Close-Soon([int]$ms) {
|
|
215
|
-
if ($script:closeTimer) { $script:closeTimer.Stop() }
|
|
216
|
-
$script:closeTimer = New-Object System.Windows.Threading.DispatcherTimer
|
|
217
|
-
$script:closeTimer.Interval = [TimeSpan]::FromMilliseconds($ms)
|
|
218
|
-
$script:closeTimer.Add_Tick({
|
|
219
|
-
$script:closeTimer.Stop()
|
|
220
|
-
$fade = [System.Windows.Media.Animation.DoubleAnimation]::new(1, 0, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(150)))
|
|
221
|
-
$script:win.BeginAnimation([System.Windows.Window]::OpacityProperty, $fade)
|
|
222
|
-
$script:late = New-Object System.Windows.Threading.DispatcherTimer
|
|
223
|
-
$script:late.Interval = [TimeSpan]::FromMilliseconds(170)
|
|
224
|
-
$script:late.Add_Tick({ $script:late.Stop(); $script:win.Close() })
|
|
225
|
-
$script:late.Start()
|
|
226
|
-
})
|
|
227
|
-
$script:closeTimer.Start()
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function Invoke-CardAction([string]$id) {
|
|
231
|
-
if ($script:busy) { return }
|
|
232
|
-
if ($id -eq 'close') { Close-Soon 0; return }
|
|
233
|
-
|
|
234
|
-
$script:busy = $true
|
|
235
|
-
foreach ($b in $script:buttons) { $b.IsEnabled = $false }
|
|
236
|
-
try {
|
|
237
|
-
# 不用 Invoke-RestMethod:它可能走系统代理,回环地址不该经过代理。
|
|
238
|
-
$client = New-Object System.Net.WebClient
|
|
239
|
-
$client.Proxy = $null
|
|
240
|
-
$client.Encoding = [System.Text.Encoding]::UTF8
|
|
241
|
-
$client.Headers.Add('x-bottle', '1')
|
|
242
|
-
$client.Headers.Add('x-bottle-surface', 'card')
|
|
243
|
-
$raw = $client.UploadString("$($script:baseUrl)/$id", 'POST', '')
|
|
244
|
-
$res = $raw | ConvertFrom-Json
|
|
245
|
-
if ($res.message) {
|
|
246
|
-
$script:status.Text = [string]$res.message
|
|
247
|
-
$script:status.Visibility = 'Visible'
|
|
248
|
-
}
|
|
249
|
-
if ($res.ok -eq $true -and $res.close -eq $true) {
|
|
250
|
-
Close-Soon 950
|
|
251
|
-
return
|
|
252
|
-
}
|
|
253
|
-
if ($res.ok -ne $true) {
|
|
254
|
-
foreach ($b in $script:buttons) { $b.IsEnabled = $true }
|
|
255
|
-
$script:busy = $false
|
|
256
|
-
return
|
|
257
|
-
}
|
|
258
|
-
foreach ($b in $script:buttons) { $b.IsEnabled = $true }
|
|
259
|
-
$script:busy = $false
|
|
260
|
-
} catch {
|
|
261
|
-
$script:status.Text = '信箱没回音,稍后再试。'
|
|
262
|
-
$script:status.Visibility = 'Visible'
|
|
263
|
-
foreach ($b in $script:buttons) { $b.IsEnabled = $true }
|
|
264
|
-
$script:busy = $false
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function New-Pill([string]$label, [string]$tone, [string]$id) {
|
|
269
|
-
$pill = New-Object System.Windows.Controls.Border
|
|
270
|
-
$pill.Tag = $id
|
|
271
|
-
$pill.Uid = $tone
|
|
272
|
-
$pill.CornerRadius = [System.Windows.CornerRadius]::new(17)
|
|
273
|
-
$pill.Padding = [System.Windows.Thickness]::new(18, 8, 18, 8)
|
|
274
|
-
$pill.Margin = [System.Windows.Thickness]::new(0, 0, 8, 0)
|
|
275
|
-
$pill.BorderThickness = [System.Windows.Thickness]::new(1)
|
|
276
|
-
$pill.Cursor = 'Hand'
|
|
277
|
-
if ($tone -eq 'primary') {
|
|
278
|
-
$pill.Background = $script:brushInk
|
|
279
|
-
$pill.BorderBrush = $script:brushInk
|
|
280
|
-
$fg = '#FDFAF2'
|
|
281
|
-
} else {
|
|
282
|
-
$pill.Background = $script:brushGhost
|
|
283
|
-
$pill.BorderBrush = Brush '#E2D8C7'
|
|
284
|
-
$fg = '#8B8375'
|
|
285
|
-
}
|
|
286
|
-
$text = New-Object System.Windows.Controls.TextBlock
|
|
287
|
-
$text.Text = $label
|
|
288
|
-
$text.FontFamily = 'Microsoft YaHei'
|
|
289
|
-
$text.FontSize = 13
|
|
290
|
-
$text.Foreground = Brush $fg
|
|
291
|
-
$pill.Child = $text
|
|
292
|
-
$pill.Add_MouseLeftButtonUp({ param($s, $e) Invoke-CardAction ([string]$s.Tag) })
|
|
293
|
-
$pill.Add_MouseEnter({ param($s, $e)
|
|
294
|
-
if ($script:busy) { return }
|
|
295
|
-
if ($s.Uid -eq 'primary') { $s.Background = $script:brushInkHover } else { $s.Background = $script:brushGhostHover }
|
|
296
|
-
})
|
|
297
|
-
$pill.Add_MouseLeave({ param($s, $e)
|
|
298
|
-
if ($script:busy) { return }
|
|
299
|
-
if ($s.Uid -eq 'primary') { $s.Background = $script:brushInk } else { $s.Background = $script:brushGhost }
|
|
300
|
-
})
|
|
301
|
-
[void]$script:buttons.Add($pill)
|
|
302
|
-
return $pill
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
$actions = New-Object System.Windows.Controls.StackPanel
|
|
306
|
-
$actions.Orientation = 'Horizontal'
|
|
307
|
-
$actions.Margin = [System.Windows.Thickness]::new(0, 16, 0, 0)
|
|
308
|
-
foreach ($action in @($spec.actions)) {
|
|
309
|
-
if (-not $action) { continue }
|
|
310
|
-
$actions.Children.Add((New-Pill ([string]$action.label) ([string]$action.tone) ([string]$action.id))) | Out-Null
|
|
311
|
-
}
|
|
312
|
-
$stack.Children.Add($actions) | Out-Null
|
|
313
|
-
|
|
314
|
-
$card.Child = $stack
|
|
315
|
-
$shell.Children.Add($card) | Out-Null
|
|
316
|
-
$win.Content = $shell
|
|
317
|
-
|
|
318
|
-
$win.Add_KeyDown({ param($s, $e) if ($e.Key -eq 'Escape') { $script:win.Close() } })
|
|
319
|
-
|
|
320
|
-
$win.Add_ContentRendered({
|
|
321
|
-
$wa = [System.Windows.SystemParameters]::WorkArea
|
|
322
|
-
$script:win.Left = [Math]::Max($wa.Left + 12, $wa.Right - $script:win.ActualWidth - 20)
|
|
323
|
-
$script:win.Top = [Math]::Max($wa.Top + 12, $wa.Bottom - $script:win.ActualHeight - 20)
|
|
324
|
-
|
|
325
|
-
$fade = [System.Windows.Media.Animation.DoubleAnimation]::new(0, 1, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(180)))
|
|
326
|
-
$script:win.BeginAnimation([System.Windows.Window]::OpacityProperty, $fade)
|
|
327
|
-
|
|
328
|
-
$ease = New-Object System.Windows.Media.Animation.CubicEase
|
|
329
|
-
$ease.EasingMode = 'EaseOut'
|
|
330
|
-
$rise = [System.Windows.Media.Animation.DoubleAnimation]::new(10, 0, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(240)))
|
|
331
|
-
$rise.EasingFunction = $ease
|
|
332
|
-
$slide.BeginAnimation([System.Windows.Media.TranslateTransform]::YProperty, $rise)
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
# 人类一直不理它也别永远压在最上面:默认五分钟自己收起。
|
|
336
|
-
Close-Soon $AutoCloseMs
|
|
337
|
-
|
|
338
|
-
if ($Shot) {
|
|
339
|
-
Add-Type -AssemblyName System.Drawing -ErrorAction SilentlyContinue
|
|
340
|
-
$script:shotTimer = New-Object System.Windows.Threading.DispatcherTimer
|
|
341
|
-
$script:shotTimer.Interval = [TimeSpan]::FromMilliseconds(500)
|
|
342
|
-
$script:shotTimer.Add_Tick({
|
|
343
|
-
$script:shotTimer.Stop()
|
|
344
|
-
try {
|
|
345
|
-
$screenDc = [System.Drawing.Graphics]::FromHwnd([IntPtr]::Zero)
|
|
346
|
-
$scale = $screenDc.DpiX / 96.0
|
|
347
|
-
$screenDc.Dispose()
|
|
348
|
-
$x = [int][Math]::Round($script:win.Left * $scale)
|
|
349
|
-
$y = [int][Math]::Round($script:win.Top * $scale)
|
|
350
|
-
$w = [int][Math]::Round($script:win.ActualWidth * $scale)
|
|
351
|
-
$h = [int][Math]::Round($script:win.ActualHeight * $scale)
|
|
352
|
-
$bmp = New-Object System.Drawing.Bitmap($w, $h)
|
|
353
|
-
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
|
354
|
-
$g.CopyFromScreen($x, $y, 0, 0, (New-Object System.Drawing.Size($w, $h)))
|
|
355
|
-
$bmp.Save($Shot, [System.Drawing.Imaging.ImageFormat]::Png)
|
|
356
|
-
$g.Dispose()
|
|
357
|
-
$bmp.Dispose()
|
|
358
|
-
} catch { }
|
|
359
|
-
})
|
|
360
|
-
$script:shotTimer.Start()
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
if ($AutoAction) {
|
|
364
|
-
$script:autoTimer = New-Object System.Windows.Threading.DispatcherTimer
|
|
365
|
-
$script:autoTimer.Interval = [TimeSpan]::FromMilliseconds(700)
|
|
366
|
-
$script:autoTimer.Add_Tick({
|
|
367
|
-
$script:autoTimer.Stop()
|
|
368
|
-
Invoke-CardAction $AutoAction
|
|
369
|
-
})
|
|
370
|
-
$script:autoTimer.Start()
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
$app = New-Object System.Windows.Application
|
|
374
|
-
$app.ShutdownMode = 'OnMainWindowClose'
|
|
375
|
-
$app.Run($win) | Out-Null
|
|
1
|
+
# 漂流瓶 · 原生卡片
|
|
2
|
+
#
|
|
3
|
+
# 由 World 启动,读一份 JSON,画一张纸,按钮把动作回传给本地信箱服务,然后自己关。
|
|
4
|
+
# 只做三件事:显示、回传、关闭。不读网络上的任何东西。
|
|
5
|
+
param(
|
|
6
|
+
[Parameter(Mandatory = $true)][string]$Data,
|
|
7
|
+
[Parameter(Mandatory = $true)][string]$Base,
|
|
8
|
+
# 没人理它时多久自己收起;调试时可以传小一点。
|
|
9
|
+
[int]$AutoCloseMs = 300000,
|
|
10
|
+
# 开发用:把窗口真实的样子截一张 PNG,然后照常运行。
|
|
11
|
+
[string]$Shot = '',
|
|
12
|
+
# 开发用:起来后自动触发一个动作,用来验证回传链路。
|
|
13
|
+
[string]$AutoAction = ''
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
$ErrorActionPreference = 'Stop'
|
|
17
|
+
Add-Type -AssemblyName PresentationFramework
|
|
18
|
+
Add-Type -AssemblyName PresentationCore
|
|
19
|
+
Add-Type -AssemblyName WindowsBase
|
|
20
|
+
|
|
21
|
+
# 150% 缩放下也别糊;老系统上失败就算了。
|
|
22
|
+
try {
|
|
23
|
+
Add-Type -Namespace BottleNative -Name Dpi -MemberDefinition '[DllImport("user32.dll")] public static extern bool SetProcessDpiAwarenessContext(IntPtr ctx);' -ErrorAction Stop
|
|
24
|
+
[BottleNative.Dpi]::SetProcessDpiAwarenessContext([IntPtr]::new(-4)) | Out-Null
|
|
25
|
+
} catch { }
|
|
26
|
+
|
|
27
|
+
function Brush([string]$hex) {
|
|
28
|
+
$color = [System.Windows.Media.Color][System.Windows.Media.ColorConverter]::ConvertFromString($hex)
|
|
29
|
+
return [System.Windows.Media.SolidColorBrush]::new($color)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
$spec = Get-Content -LiteralPath $Data -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
33
|
+
$script:baseUrl = $Base.TrimEnd('/')
|
|
34
|
+
$script:busy = $false
|
|
35
|
+
$script:closeTimer = $null
|
|
36
|
+
$script:buttons = New-Object System.Collections.ArrayList
|
|
37
|
+
|
|
38
|
+
$win = New-Object System.Windows.Window
|
|
39
|
+
$win.Title = '漂流瓶'
|
|
40
|
+
$win.Width = 460
|
|
41
|
+
$win.SizeToContent = 'Height'
|
|
42
|
+
$win.WindowStyle = 'None'
|
|
43
|
+
$win.ResizeMode = 'NoResize'
|
|
44
|
+
$win.AllowsTransparency = $true
|
|
45
|
+
$win.Background = [System.Windows.Media.Brushes]::Transparent
|
|
46
|
+
$win.Topmost = $true
|
|
47
|
+
$win.ShowInTaskbar = $false
|
|
48
|
+
$win.ShowActivated = $false
|
|
49
|
+
$win.WindowStartupLocation = 'Manual'
|
|
50
|
+
$win.Left = -4000
|
|
51
|
+
$win.Top = -4000
|
|
52
|
+
$win.Opacity = 0
|
|
53
|
+
$script:win = $win
|
|
54
|
+
|
|
55
|
+
$shell = New-Object System.Windows.Controls.Grid
|
|
56
|
+
$shell.Margin = [System.Windows.Thickness]::new(26)
|
|
57
|
+
|
|
58
|
+
$card = New-Object System.Windows.Controls.Border
|
|
59
|
+
$card.Background = Brush '#FFFDF7'
|
|
60
|
+
$card.CornerRadius = [System.Windows.CornerRadius]::new(14)
|
|
61
|
+
$card.BorderBrush = Brush '#E2D8C7'
|
|
62
|
+
$card.BorderThickness = [System.Windows.Thickness]::new(1)
|
|
63
|
+
$card.Padding = [System.Windows.Thickness]::new(24, 20, 24, 18)
|
|
64
|
+
$shadow = New-Object System.Windows.Media.Effects.DropShadowEffect
|
|
65
|
+
$shadow.BlurRadius = 22
|
|
66
|
+
$shadow.ShadowDepth = 6
|
|
67
|
+
$shadow.Direction = 270
|
|
68
|
+
$shadow.Opacity = 0.17
|
|
69
|
+
$shadow.Color = [System.Windows.Media.Color][System.Windows.Media.ColorConverter]::ConvertFromString('#3C2D19')
|
|
70
|
+
$card.Effect = $shadow
|
|
71
|
+
$slide = [System.Windows.Media.TranslateTransform]::new(0, 10)
|
|
72
|
+
$card.RenderTransform = $slide
|
|
73
|
+
|
|
74
|
+
$stack = New-Object System.Windows.Controls.StackPanel
|
|
75
|
+
|
|
76
|
+
$head = New-Object System.Windows.Controls.Grid
|
|
77
|
+
$head.ColumnDefinitions.Add((New-Object System.Windows.Controls.ColumnDefinition)) | Out-Null
|
|
78
|
+
$auto = New-Object System.Windows.Controls.ColumnDefinition
|
|
79
|
+
$auto.Width = [System.Windows.GridLength]::Auto
|
|
80
|
+
$head.ColumnDefinitions.Add($auto) | Out-Null
|
|
81
|
+
|
|
82
|
+
$eyebrow = New-Object System.Windows.Controls.TextBlock
|
|
83
|
+
$eyebrow.Text = [string]$spec.eyebrow
|
|
84
|
+
$eyebrow.FontFamily = 'Microsoft YaHei'
|
|
85
|
+
$eyebrow.FontSize = 11
|
|
86
|
+
$eyebrow.Foreground = Brush '#8A6540'
|
|
87
|
+
$eyebrow.VerticalAlignment = 'Center'
|
|
88
|
+
$head.Children.Add($eyebrow) | Out-Null
|
|
89
|
+
|
|
90
|
+
$close = New-Object System.Windows.Controls.TextBlock
|
|
91
|
+
$close.Text = '×'
|
|
92
|
+
$close.FontFamily = 'Segoe UI'
|
|
93
|
+
$close.FontSize = 15
|
|
94
|
+
$close.Foreground = Brush '#C4B9A6'
|
|
95
|
+
$close.Cursor = 'Hand'
|
|
96
|
+
$close.Margin = [System.Windows.Thickness]::new(10, -4, 0, 0)
|
|
97
|
+
$close.VerticalAlignment = 'Top'
|
|
98
|
+
[System.Windows.Controls.Grid]::SetColumn($close, 1)
|
|
99
|
+
$script:brushInk = Brush '#2F2A23'
|
|
100
|
+
$script:brushInkHover = Brush '#443C31'
|
|
101
|
+
$script:brushGhost = Brush '#00FFFFFF'
|
|
102
|
+
$script:brushGhostHover = Brush '#F4EEE2'
|
|
103
|
+
$script:brushMuted = Brush '#8B8375'
|
|
104
|
+
$script:brushFaint = Brush '#C4B9A6'
|
|
105
|
+
|
|
106
|
+
$close.Add_MouseLeftButtonUp({ param($s, $e) $script:win.Close() })
|
|
107
|
+
$close.Add_MouseEnter({ param($s, $e) $s.Foreground = $script:brushMuted })
|
|
108
|
+
$close.Add_MouseLeave({ param($s, $e) $s.Foreground = $script:brushFaint })
|
|
109
|
+
$head.Children.Add($close) | Out-Null
|
|
110
|
+
$stack.Children.Add($head) | Out-Null
|
|
111
|
+
|
|
112
|
+
if ($spec.from) {
|
|
113
|
+
$from = New-Object System.Windows.Controls.TextBlock
|
|
114
|
+
$from.Text = [string]$spec.from
|
|
115
|
+
$from.FontFamily = 'Microsoft YaHei'
|
|
116
|
+
$from.FontSize = 12
|
|
117
|
+
$from.Foreground = Brush '#8B8375'
|
|
118
|
+
$from.Margin = [System.Windows.Thickness]::new(0, 3, 0, 12)
|
|
119
|
+
$stack.Children.Add($from) | Out-Null
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# 标题:来自谁之后、正文之前。和网页上的 .mail-topic / h2.title 同一个位置。
|
|
123
|
+
if ($spec.title) {
|
|
124
|
+
$title = New-Object System.Windows.Controls.TextBlock
|
|
125
|
+
$title.Text = [string]$spec.title
|
|
126
|
+
$title.FontFamily = 'Microsoft YaHei'
|
|
127
|
+
$title.FontSize = 15
|
|
128
|
+
$title.FontWeight = 'SemiBold'
|
|
129
|
+
$title.Foreground = Brush '#2F2A23'
|
|
130
|
+
$title.TextWrapping = 'Wrap'
|
|
131
|
+
$title.Margin = [System.Windows.Thickness]::new(0, 0, 0, 10)
|
|
132
|
+
$stack.Children.Add($title) | Out-Null
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if ($spec.quote) {
|
|
136
|
+
$quote = New-Object System.Windows.Controls.Border
|
|
137
|
+
$quote.Background = Brush '#FAF6EC'
|
|
138
|
+
$quote.CornerRadius = [System.Windows.CornerRadius]::new(10)
|
|
139
|
+
$quote.Padding = [System.Windows.Thickness]::new(13, 10, 13, 10)
|
|
140
|
+
$quote.Margin = [System.Windows.Thickness]::new(0, 0, 0, 14)
|
|
141
|
+
$quoteStack = New-Object System.Windows.Controls.StackPanel
|
|
142
|
+
$quoteLabel = New-Object System.Windows.Controls.TextBlock
|
|
143
|
+
$quoteLabel.Text = [string]$spec.quote.label
|
|
144
|
+
$quoteLabel.FontFamily = 'Microsoft YaHei'
|
|
145
|
+
$quoteLabel.FontSize = 10.5
|
|
146
|
+
$quoteLabel.Foreground = Brush '#A39A8A'
|
|
147
|
+
$quoteLabel.Margin = [System.Windows.Thickness]::new(0, 0, 0, 4)
|
|
148
|
+
$quoteStack.Children.Add($quoteLabel) | Out-Null
|
|
149
|
+
$quoteBody = New-Object System.Windows.Controls.TextBlock
|
|
150
|
+
$quoteBody.Text = [string]$spec.quote.body
|
|
151
|
+
$quoteBody.FontFamily = 'Microsoft YaHei'
|
|
152
|
+
$quoteBody.FontSize = 12.5
|
|
153
|
+
$quoteBody.LineHeight = 21
|
|
154
|
+
$quoteBody.LineStackingStrategy = 'BlockLineHeight'
|
|
155
|
+
$quoteBody.TextWrapping = 'Wrap'
|
|
156
|
+
$quoteBody.TextTrimming = 'CharacterEllipsis'
|
|
157
|
+
$quoteBody.MaxHeight = 86
|
|
158
|
+
$quoteBody.Foreground = Brush '#5B5449'
|
|
159
|
+
$quoteStack.Children.Add($quoteBody) | Out-Null
|
|
160
|
+
$quote.Child = $quoteStack
|
|
161
|
+
$stack.Children.Add($quote) | Out-Null
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
$body = New-Object System.Windows.Controls.TextBlock
|
|
165
|
+
$body.Text = [string]$spec.body
|
|
166
|
+
$body.FontFamily = 'Microsoft YaHei'
|
|
167
|
+
$body.FontSize = 15.5
|
|
168
|
+
$body.LineHeight = 27
|
|
169
|
+
$body.LineStackingStrategy = 'BlockLineHeight'
|
|
170
|
+
$body.TextWrapping = 'Wrap'
|
|
171
|
+
$body.Foreground = Brush '#2F2A23'
|
|
172
|
+
$stack.Children.Add($body) | Out-Null
|
|
173
|
+
|
|
174
|
+
if ($spec.hints) {
|
|
175
|
+
foreach ($hint in @($spec.hints)) {
|
|
176
|
+
$hintBorder = New-Object System.Windows.Controls.Border
|
|
177
|
+
$hintBorder.Background = Brush '#FBF3E2'
|
|
178
|
+
$hintBorder.BorderBrush = Brush '#EFE0C6'
|
|
179
|
+
$hintBorder.BorderThickness = [System.Windows.Thickness]::new(1)
|
|
180
|
+
$hintBorder.CornerRadius = [System.Windows.CornerRadius]::new(9)
|
|
181
|
+
$hintBorder.Padding = [System.Windows.Thickness]::new(11, 7, 11, 7)
|
|
182
|
+
$hintBorder.Margin = [System.Windows.Thickness]::new(0, 10, 0, 0)
|
|
183
|
+
$hintText = New-Object System.Windows.Controls.TextBlock
|
|
184
|
+
$hintText.Text = [string]$hint
|
|
185
|
+
$hintText.FontFamily = 'Microsoft YaHei'
|
|
186
|
+
$hintText.FontSize = 11.5
|
|
187
|
+
$hintText.TextWrapping = 'Wrap'
|
|
188
|
+
$hintText.Foreground = Brush '#7A5B3A'
|
|
189
|
+
$hintBorder.Child = $hintText
|
|
190
|
+
$stack.Children.Add($hintBorder) | Out-Null
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if ($spec.meta) {
|
|
195
|
+
$meta = New-Object System.Windows.Controls.TextBlock
|
|
196
|
+
$meta.Text = [string]$spec.meta
|
|
197
|
+
$meta.FontFamily = 'Microsoft YaHei'
|
|
198
|
+
$meta.FontSize = 11
|
|
199
|
+
$meta.Foreground = Brush '#A39A8A'
|
|
200
|
+
$meta.Margin = [System.Windows.Thickness]::new(0, 12, 0, 0)
|
|
201
|
+
$stack.Children.Add($meta) | Out-Null
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
$status = New-Object System.Windows.Controls.TextBlock
|
|
205
|
+
$status.FontFamily = 'Microsoft YaHei'
|
|
206
|
+
$status.FontSize = 11.5
|
|
207
|
+
$status.TextWrapping = 'Wrap'
|
|
208
|
+
$status.Foreground = Brush '#5F5E5A'
|
|
209
|
+
$status.Margin = [System.Windows.Thickness]::new(0, 10, 0, 0)
|
|
210
|
+
$status.Visibility = 'Collapsed'
|
|
211
|
+
$script:status = $status
|
|
212
|
+
$stack.Children.Add($status) | Out-Null
|
|
213
|
+
|
|
214
|
+
function Close-Soon([int]$ms) {
|
|
215
|
+
if ($script:closeTimer) { $script:closeTimer.Stop() }
|
|
216
|
+
$script:closeTimer = New-Object System.Windows.Threading.DispatcherTimer
|
|
217
|
+
$script:closeTimer.Interval = [TimeSpan]::FromMilliseconds($ms)
|
|
218
|
+
$script:closeTimer.Add_Tick({
|
|
219
|
+
$script:closeTimer.Stop()
|
|
220
|
+
$fade = [System.Windows.Media.Animation.DoubleAnimation]::new(1, 0, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(150)))
|
|
221
|
+
$script:win.BeginAnimation([System.Windows.Window]::OpacityProperty, $fade)
|
|
222
|
+
$script:late = New-Object System.Windows.Threading.DispatcherTimer
|
|
223
|
+
$script:late.Interval = [TimeSpan]::FromMilliseconds(170)
|
|
224
|
+
$script:late.Add_Tick({ $script:late.Stop(); $script:win.Close() })
|
|
225
|
+
$script:late.Start()
|
|
226
|
+
})
|
|
227
|
+
$script:closeTimer.Start()
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function Invoke-CardAction([string]$id) {
|
|
231
|
+
if ($script:busy) { return }
|
|
232
|
+
if ($id -eq 'close') { Close-Soon 0; return }
|
|
233
|
+
|
|
234
|
+
$script:busy = $true
|
|
235
|
+
foreach ($b in $script:buttons) { $b.IsEnabled = $false }
|
|
236
|
+
try {
|
|
237
|
+
# 不用 Invoke-RestMethod:它可能走系统代理,回环地址不该经过代理。
|
|
238
|
+
$client = New-Object System.Net.WebClient
|
|
239
|
+
$client.Proxy = $null
|
|
240
|
+
$client.Encoding = [System.Text.Encoding]::UTF8
|
|
241
|
+
$client.Headers.Add('x-bottle', '1')
|
|
242
|
+
$client.Headers.Add('x-bottle-surface', 'card')
|
|
243
|
+
$raw = $client.UploadString("$($script:baseUrl)/$id", 'POST', '')
|
|
244
|
+
$res = $raw | ConvertFrom-Json
|
|
245
|
+
if ($res.message) {
|
|
246
|
+
$script:status.Text = [string]$res.message
|
|
247
|
+
$script:status.Visibility = 'Visible'
|
|
248
|
+
}
|
|
249
|
+
if ($res.ok -eq $true -and $res.close -eq $true) {
|
|
250
|
+
Close-Soon 950
|
|
251
|
+
return
|
|
252
|
+
}
|
|
253
|
+
if ($res.ok -ne $true) {
|
|
254
|
+
foreach ($b in $script:buttons) { $b.IsEnabled = $true }
|
|
255
|
+
$script:busy = $false
|
|
256
|
+
return
|
|
257
|
+
}
|
|
258
|
+
foreach ($b in $script:buttons) { $b.IsEnabled = $true }
|
|
259
|
+
$script:busy = $false
|
|
260
|
+
} catch {
|
|
261
|
+
$script:status.Text = '信箱没回音,稍后再试。'
|
|
262
|
+
$script:status.Visibility = 'Visible'
|
|
263
|
+
foreach ($b in $script:buttons) { $b.IsEnabled = $true }
|
|
264
|
+
$script:busy = $false
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function New-Pill([string]$label, [string]$tone, [string]$id) {
|
|
269
|
+
$pill = New-Object System.Windows.Controls.Border
|
|
270
|
+
$pill.Tag = $id
|
|
271
|
+
$pill.Uid = $tone
|
|
272
|
+
$pill.CornerRadius = [System.Windows.CornerRadius]::new(17)
|
|
273
|
+
$pill.Padding = [System.Windows.Thickness]::new(18, 8, 18, 8)
|
|
274
|
+
$pill.Margin = [System.Windows.Thickness]::new(0, 0, 8, 0)
|
|
275
|
+
$pill.BorderThickness = [System.Windows.Thickness]::new(1)
|
|
276
|
+
$pill.Cursor = 'Hand'
|
|
277
|
+
if ($tone -eq 'primary') {
|
|
278
|
+
$pill.Background = $script:brushInk
|
|
279
|
+
$pill.BorderBrush = $script:brushInk
|
|
280
|
+
$fg = '#FDFAF2'
|
|
281
|
+
} else {
|
|
282
|
+
$pill.Background = $script:brushGhost
|
|
283
|
+
$pill.BorderBrush = Brush '#E2D8C7'
|
|
284
|
+
$fg = '#8B8375'
|
|
285
|
+
}
|
|
286
|
+
$text = New-Object System.Windows.Controls.TextBlock
|
|
287
|
+
$text.Text = $label
|
|
288
|
+
$text.FontFamily = 'Microsoft YaHei'
|
|
289
|
+
$text.FontSize = 13
|
|
290
|
+
$text.Foreground = Brush $fg
|
|
291
|
+
$pill.Child = $text
|
|
292
|
+
$pill.Add_MouseLeftButtonUp({ param($s, $e) Invoke-CardAction ([string]$s.Tag) })
|
|
293
|
+
$pill.Add_MouseEnter({ param($s, $e)
|
|
294
|
+
if ($script:busy) { return }
|
|
295
|
+
if ($s.Uid -eq 'primary') { $s.Background = $script:brushInkHover } else { $s.Background = $script:brushGhostHover }
|
|
296
|
+
})
|
|
297
|
+
$pill.Add_MouseLeave({ param($s, $e)
|
|
298
|
+
if ($script:busy) { return }
|
|
299
|
+
if ($s.Uid -eq 'primary') { $s.Background = $script:brushInk } else { $s.Background = $script:brushGhost }
|
|
300
|
+
})
|
|
301
|
+
[void]$script:buttons.Add($pill)
|
|
302
|
+
return $pill
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
$actions = New-Object System.Windows.Controls.StackPanel
|
|
306
|
+
$actions.Orientation = 'Horizontal'
|
|
307
|
+
$actions.Margin = [System.Windows.Thickness]::new(0, 16, 0, 0)
|
|
308
|
+
foreach ($action in @($spec.actions)) {
|
|
309
|
+
if (-not $action) { continue }
|
|
310
|
+
$actions.Children.Add((New-Pill ([string]$action.label) ([string]$action.tone) ([string]$action.id))) | Out-Null
|
|
311
|
+
}
|
|
312
|
+
$stack.Children.Add($actions) | Out-Null
|
|
313
|
+
|
|
314
|
+
$card.Child = $stack
|
|
315
|
+
$shell.Children.Add($card) | Out-Null
|
|
316
|
+
$win.Content = $shell
|
|
317
|
+
|
|
318
|
+
$win.Add_KeyDown({ param($s, $e) if ($e.Key -eq 'Escape') { $script:win.Close() } })
|
|
319
|
+
|
|
320
|
+
$win.Add_ContentRendered({
|
|
321
|
+
$wa = [System.Windows.SystemParameters]::WorkArea
|
|
322
|
+
$script:win.Left = [Math]::Max($wa.Left + 12, $wa.Right - $script:win.ActualWidth - 20)
|
|
323
|
+
$script:win.Top = [Math]::Max($wa.Top + 12, $wa.Bottom - $script:win.ActualHeight - 20)
|
|
324
|
+
|
|
325
|
+
$fade = [System.Windows.Media.Animation.DoubleAnimation]::new(0, 1, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(180)))
|
|
326
|
+
$script:win.BeginAnimation([System.Windows.Window]::OpacityProperty, $fade)
|
|
327
|
+
|
|
328
|
+
$ease = New-Object System.Windows.Media.Animation.CubicEase
|
|
329
|
+
$ease.EasingMode = 'EaseOut'
|
|
330
|
+
$rise = [System.Windows.Media.Animation.DoubleAnimation]::new(10, 0, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(240)))
|
|
331
|
+
$rise.EasingFunction = $ease
|
|
332
|
+
$slide.BeginAnimation([System.Windows.Media.TranslateTransform]::YProperty, $rise)
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
# 人类一直不理它也别永远压在最上面:默认五分钟自己收起。
|
|
336
|
+
Close-Soon $AutoCloseMs
|
|
337
|
+
|
|
338
|
+
if ($Shot) {
|
|
339
|
+
Add-Type -AssemblyName System.Drawing -ErrorAction SilentlyContinue
|
|
340
|
+
$script:shotTimer = New-Object System.Windows.Threading.DispatcherTimer
|
|
341
|
+
$script:shotTimer.Interval = [TimeSpan]::FromMilliseconds(500)
|
|
342
|
+
$script:shotTimer.Add_Tick({
|
|
343
|
+
$script:shotTimer.Stop()
|
|
344
|
+
try {
|
|
345
|
+
$screenDc = [System.Drawing.Graphics]::FromHwnd([IntPtr]::Zero)
|
|
346
|
+
$scale = $screenDc.DpiX / 96.0
|
|
347
|
+
$screenDc.Dispose()
|
|
348
|
+
$x = [int][Math]::Round($script:win.Left * $scale)
|
|
349
|
+
$y = [int][Math]::Round($script:win.Top * $scale)
|
|
350
|
+
$w = [int][Math]::Round($script:win.ActualWidth * $scale)
|
|
351
|
+
$h = [int][Math]::Round($script:win.ActualHeight * $scale)
|
|
352
|
+
$bmp = New-Object System.Drawing.Bitmap($w, $h)
|
|
353
|
+
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
|
354
|
+
$g.CopyFromScreen($x, $y, 0, 0, (New-Object System.Drawing.Size($w, $h)))
|
|
355
|
+
$bmp.Save($Shot, [System.Drawing.Imaging.ImageFormat]::Png)
|
|
356
|
+
$g.Dispose()
|
|
357
|
+
$bmp.Dispose()
|
|
358
|
+
} catch { }
|
|
359
|
+
})
|
|
360
|
+
$script:shotTimer.Start()
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if ($AutoAction) {
|
|
364
|
+
$script:autoTimer = New-Object System.Windows.Threading.DispatcherTimer
|
|
365
|
+
$script:autoTimer.Interval = [TimeSpan]::FromMilliseconds(700)
|
|
366
|
+
$script:autoTimer.Add_Tick({
|
|
367
|
+
$script:autoTimer.Stop()
|
|
368
|
+
Invoke-CardAction $AutoAction
|
|
369
|
+
})
|
|
370
|
+
$script:autoTimer.Start()
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
$app = New-Object System.Windows.Application
|
|
374
|
+
$app.ShutdownMode = 'OnMainWindowClose'
|
|
375
|
+
$app.Run($win) | Out-Null
|