vanspod 0.4.15 → 0.4.16
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/README.md +4 -4
- package/dist/classroomApp.js +55 -11
- package/dist/codexWebSearch.js +1 -1
- package/dist/deviceConnection.js +13 -2
- package/dist/html.js +12 -0
- package/dist/localCommands.js +82 -119
- package/dist/localToolApproval.js +81 -4
- package/dist/localTools.js +31 -8
- package/dist/modelStatus.js +8 -12
- package/dist/page.js +278 -124
- package/dist/remoteAgentLog.js +126 -0
- package/dist/remoteAgentLogView.js +421 -0
- package/dist/saveImage.js +26 -0
- package/dist/settingsActions.js +1 -1
- package/dist/start.js +59 -10
- package/dist/trayChannel.js +25 -6
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/scripts/tray.ps1 +141 -11
package/dist/start.js
CHANGED
|
@@ -9,8 +9,8 @@ const clientDetection_1 = require("./clientDetection");
|
|
|
9
9
|
const runtimeOptions_1 = require("./runtimeOptions");
|
|
10
10
|
const deviceConnection_1 = require("./deviceConnection");
|
|
11
11
|
const localTools_1 = require("./localTools");
|
|
12
|
+
const remoteAgentLog_1 = require("./remoteAgentLog");
|
|
12
13
|
const localToolApproval_1 = require("./localToolApproval");
|
|
13
|
-
const localCommands_1 = require("./localCommands");
|
|
14
14
|
const trayChannel_1 = require("./trayChannel");
|
|
15
15
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
16
16
|
const node_child_process_1 = require("node:child_process");
|
|
@@ -19,6 +19,7 @@ const node_os_1 = __importDefault(require("node:os"));
|
|
|
19
19
|
const node_path_1 = __importDefault(require("node:path"));
|
|
20
20
|
const classroomApp_1 = require("./classroomApp");
|
|
21
21
|
const page_1 = require("./page");
|
|
22
|
+
const saveImage_1 = require("./saveImage");
|
|
22
23
|
const promptCapture_1 = require("./promptCapture");
|
|
23
24
|
const clipboard_1 = require("./clipboard");
|
|
24
25
|
const folderPicker_1 = require("./folderPicker");
|
|
@@ -411,8 +412,8 @@ async function main(instance) {
|
|
|
411
412
|
});
|
|
412
413
|
// One Local Tool Approval queue for this Device. The page and the Approval Popup (tray) decide here.
|
|
413
414
|
const approvals = (0, localToolApproval_1.createApprovalQueue)();
|
|
414
|
-
// The
|
|
415
|
-
const
|
|
415
|
+
// The Remote Agent Log of this VansPod run. Only memory: a restart starts an empty log.
|
|
416
|
+
const remoteAgentLog = (0, remoteAgentLog_1.createRemoteAgentLog)();
|
|
416
417
|
let trayChannel;
|
|
417
418
|
approvals.subscribe(() => trayChannel?.update());
|
|
418
419
|
app = new classroomApp_1.ClassroomApp({
|
|
@@ -454,11 +455,11 @@ async function main(instance) {
|
|
|
454
455
|
device: (0, deviceConnection_1.createDeviceConnection)({
|
|
455
456
|
url: process.env.CLASSROOM_DEVICE_RELAY_URL ?? "wss://mcp.vanscoding.com/device",
|
|
456
457
|
device: node_os_1.default.hostname(),
|
|
457
|
-
handle: (0, localTools_1.createLocalTools)({ projectFolder: () => app.view().projectFolder, system: localTools_1.localSystem, approver: approvals,
|
|
458
|
+
handle: (0, localTools_1.createLocalTools)({ projectFolder: () => app.view().projectFolder, system: localTools_1.localSystem, approver: approvals, log: remoteAgentLog }),
|
|
458
459
|
onChange: () => trayChannel?.update(),
|
|
459
460
|
}),
|
|
460
461
|
approvals,
|
|
461
|
-
|
|
462
|
+
remoteAgentLog,
|
|
462
463
|
});
|
|
463
464
|
dispatch = async (accepted, req, res) => {
|
|
464
465
|
if (!/^(127\.0\.0\.1|localhost):\d+$/.test(req.headers.host ?? "")) {
|
|
@@ -477,6 +478,19 @@ async function main(instance) {
|
|
|
477
478
|
}
|
|
478
479
|
redirect(res);
|
|
479
480
|
};
|
|
481
|
+
const sendRemoteAgentPage = () => {
|
|
482
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
|
|
483
|
+
const html = (0, page_1.renderRemoteAgentPage)(app.view());
|
|
484
|
+
res.end(instance ? (0, lifecyclePage_1.lifecyclePage)(html, instance.token) : html);
|
|
485
|
+
};
|
|
486
|
+
// The Local Tool Access actions live on the 遠端 Agent page; its script posts them with X-Remote-Agent.
|
|
487
|
+
const goRemoteAgent = () => {
|
|
488
|
+
if (req.headers["x-remote-agent"] === "1") {
|
|
489
|
+
sendRemoteAgentPage();
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
redirect(res, "/remote-agent");
|
|
493
|
+
};
|
|
480
494
|
try {
|
|
481
495
|
if (instance && pathname.startsWith("/_vanspod/")) {
|
|
482
496
|
if (req.headers.authorization !== `Bearer ${instance.token}` || (req.headers.origin && req.headers.origin !== instance.origin)) {
|
|
@@ -567,6 +581,24 @@ async function main(instance) {
|
|
|
567
581
|
res.end(JSON.stringify(answer.body));
|
|
568
582
|
return;
|
|
569
583
|
}
|
|
584
|
+
if (req.method === "GET" && pathname === "/remote-agent-log-entry") {
|
|
585
|
+
const answer = (0, page_1.remoteAgentLogEntryResponse)(app.view(), parsed.searchParams.get("id") ?? "");
|
|
586
|
+
res.writeHead(answer.status, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" });
|
|
587
|
+
res.end(JSON.stringify(answer.body));
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
// A saved image of the Remote Agent Log, read from the disk: only from images/ in the Project Folder.
|
|
591
|
+
if (req.method === "GET" && pathname === "/remote-agent-image") {
|
|
592
|
+
const image = await (0, saveImage_1.readProjectImage)(app.view().projectFolder, parsed.searchParams.get("path") ?? "");
|
|
593
|
+
if (!image) {
|
|
594
|
+
res.writeHead(404, { "Cache-Control": "no-store" });
|
|
595
|
+
res.end();
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
res.writeHead(200, { "Content-Type": image.mimeType, "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" });
|
|
599
|
+
res.end(image.bytes);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
570
602
|
if (req.method === "GET" && pathname === "/model-status") {
|
|
571
603
|
res.writeHead(200, {
|
|
572
604
|
"Content-Type": "application/json; charset=utf-8",
|
|
@@ -589,6 +621,10 @@ async function main(instance) {
|
|
|
589
621
|
res.end(JSON.stringify({ recording: promptCapture.recording, ...promptCapture.list() }));
|
|
590
622
|
return;
|
|
591
623
|
}
|
|
624
|
+
if (req.method === "GET" && pathname === "/remote-agent") {
|
|
625
|
+
sendRemoteAgentPage();
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
592
628
|
if (req.method === "GET" && pathname === "/prompt-inspector") {
|
|
593
629
|
const html = (0, page_1.renderInspectorPage)({ recording: promptCapture.recording, ...promptCapture.list() });
|
|
594
630
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
|
|
@@ -735,7 +771,7 @@ async function main(instance) {
|
|
|
735
771
|
if (req.method === "POST" && pathname === "/local-tools") {
|
|
736
772
|
const params = new URLSearchParams(await readBody(req));
|
|
737
773
|
await app.setLocalToolAccess(params.get("on") === "1");
|
|
738
|
-
|
|
774
|
+
goRemoteAgent();
|
|
739
775
|
return;
|
|
740
776
|
}
|
|
741
777
|
if (req.method === "POST" && pathname === "/local-tool-approval") {
|
|
@@ -743,13 +779,26 @@ async function main(instance) {
|
|
|
743
779
|
const decision = params.get("decision");
|
|
744
780
|
if (decision === "approve" || decision === "deny")
|
|
745
781
|
app.decideLocalToolApproval(params.get("id") ?? "", decision);
|
|
746
|
-
|
|
782
|
+
goRemoteAgent();
|
|
747
783
|
return;
|
|
748
784
|
}
|
|
749
|
-
if (req.method === "POST" && pathname === "/
|
|
785
|
+
if (req.method === "POST" && pathname === "/auto-approval-start") {
|
|
750
786
|
const params = new URLSearchParams(await readBody(req));
|
|
751
|
-
|
|
752
|
-
|
|
787
|
+
const duration = params.get("duration");
|
|
788
|
+
if (duration && Object.hasOwn(classroomApp_1.AUTO_APPROVAL_DURATIONS, duration))
|
|
789
|
+
app.startAutoApproval(duration);
|
|
790
|
+
goRemoteAgent();
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
if (req.method === "POST" && pathname === "/auto-approval-stop") {
|
|
794
|
+
app.stopAutoApproval();
|
|
795
|
+
goRemoteAgent();
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
if (req.method === "POST" && pathname === "/remote-agent-log-stop") {
|
|
799
|
+
const params = new URLSearchParams(await readBody(req));
|
|
800
|
+
app.stopRemoteAgentCommand(params.get("id") ?? "");
|
|
801
|
+
goRemoteAgent();
|
|
753
802
|
return;
|
|
754
803
|
}
|
|
755
804
|
if (req.method === "POST" && pathname === "/clear") {
|
package/dist/trayChannel.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TRAY_BODY_CHARS = void 0;
|
|
3
|
+
exports.TRAY_BODY_CHARS = exports.AUTO_APPROVAL_NEEDS_ACCESS = void 0;
|
|
4
4
|
exports.createTrayChannel = createTrayChannel;
|
|
5
|
+
const classroomApp_1 = require("./classroomApp");
|
|
6
|
+
Object.defineProperty(exports, "AUTO_APPROVAL_NEEDS_ACCESS", { enumerable: true, get: function () { return classroomApp_1.AUTO_APPROVAL_NEEDS_ACCESS; } });
|
|
5
7
|
/** The popup shows this much of the body. On the page, 「顯示全部」 shows all of it. */
|
|
6
8
|
exports.TRAY_BODY_CHARS = 2_000;
|
|
7
9
|
function trayText(value, max) {
|
|
@@ -24,12 +26,13 @@ function createTrayChannel(options) {
|
|
|
24
26
|
}
|
|
25
27
|
catch { /* the tray has gone */ }
|
|
26
28
|
};
|
|
27
|
-
const state = () => {
|
|
28
|
-
const local = app.view().localTools;
|
|
29
|
+
const state = (local) => {
|
|
29
30
|
const shown = local?.approval;
|
|
31
|
+
const auto = local?.autoApproval;
|
|
30
32
|
return {
|
|
31
33
|
type: "state",
|
|
32
34
|
access: local?.on ?? false,
|
|
35
|
+
autoApproval: auto ? { label: auto.label, ...(auto.endsAt === undefined ? {} : { endsAt: auto.endsAt, secondsLeft: auto.secondsLeft }) } : null,
|
|
33
36
|
approval: shown ? {
|
|
34
37
|
id: shown.id,
|
|
35
38
|
tool: shown.tool,
|
|
@@ -39,15 +42,22 @@ function createTrayChannel(options) {
|
|
|
39
42
|
device: shown.device,
|
|
40
43
|
secondsLeft: shown.secondsLeft,
|
|
41
44
|
waiting: shown.waiting,
|
|
45
|
+
...(shown.exception ? { exception: shown.exception } : {}),
|
|
42
46
|
} : null,
|
|
43
47
|
};
|
|
44
48
|
};
|
|
45
49
|
const update = () => {
|
|
46
50
|
if (closed)
|
|
47
51
|
return;
|
|
48
|
-
const
|
|
52
|
+
const local = app.view().localTools;
|
|
53
|
+
const current = state(local);
|
|
49
54
|
// secondsLeft alone does not make a new state: the tray counts down itself.
|
|
50
|
-
|
|
55
|
+
// A new end time of Auto Approval does.
|
|
56
|
+
const key = JSON.stringify({
|
|
57
|
+
...current,
|
|
58
|
+
autoApproval: current.autoApproval && { ...current.autoApproval, secondsLeft: 0 },
|
|
59
|
+
approval: current.approval && { ...current.approval, secondsLeft: 0 },
|
|
60
|
+
});
|
|
51
61
|
if (key === lastState)
|
|
52
62
|
return;
|
|
53
63
|
lastState = key;
|
|
@@ -63,7 +73,7 @@ function createTrayChannel(options) {
|
|
|
63
73
|
}
|
|
64
74
|
if (!message || typeof message !== "object")
|
|
65
75
|
return;
|
|
66
|
-
const { type, id, decision, on } = message;
|
|
76
|
+
const { type, id, decision, on, duration } = message;
|
|
67
77
|
if (type === "decide" && typeof id === "string" && (decision === "approve" || decision === "deny")) {
|
|
68
78
|
app.decideLocalToolApproval(id, decision);
|
|
69
79
|
update();
|
|
@@ -80,6 +90,15 @@ function createTrayChannel(options) {
|
|
|
80
90
|
send({ type: "refused", message: local.message });
|
|
81
91
|
update();
|
|
82
92
|
}
|
|
93
|
+
else if (type === "auto_approval_start" && typeof duration === "string" && Object.hasOwn(classroomApp_1.AUTO_APPROVAL_DURATIONS, duration)) {
|
|
94
|
+
if (!app.startAutoApproval(duration))
|
|
95
|
+
send({ type: "refused", message: classroomApp_1.AUTO_APPROVAL_NEEDS_ACCESS });
|
|
96
|
+
update();
|
|
97
|
+
}
|
|
98
|
+
else if (type === "auto_approval_stop") {
|
|
99
|
+
app.stopAutoApproval();
|
|
100
|
+
update();
|
|
101
|
+
}
|
|
83
102
|
};
|
|
84
103
|
const onData = (chunk) => {
|
|
85
104
|
if (closed)
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
package/scripts/tray.ps1
CHANGED
|
@@ -128,6 +128,29 @@ if (-not $onIcon) {
|
|
|
128
128
|
$onIcon = [System.Drawing.Icon]::FromHandle($marked.GetHicon())
|
|
129
129
|
} catch { $onIcon = [System.Drawing.SystemIcons]::Shield }
|
|
130
130
|
}
|
|
131
|
+
# The third look, for Auto Approval (ADR 0014): the "on" icon with a purple badge and a white bolt.
|
|
132
|
+
$autoIcon = $null
|
|
133
|
+
try {
|
|
134
|
+
$badged = New-Object System.Drawing.Bitmap($size.Width, $size.Height)
|
|
135
|
+
$graphics = [System.Drawing.Graphics]::FromImage($badged)
|
|
136
|
+
$graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
|
|
137
|
+
$graphics.DrawIcon($onIcon, (New-Object System.Drawing.Rectangle(0, 0, $size.Width, $size.Height)))
|
|
138
|
+
$badge = [Math]::Max(8, [int]($size.Width * 0.6))
|
|
139
|
+
$bx = $size.Width - $badge
|
|
140
|
+
$by = $size.Height - $badge
|
|
141
|
+
$purple = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::FromArgb(124, 58, 237))
|
|
142
|
+
$graphics.FillEllipse([System.Drawing.Brushes]::White, $bx, $by, $badge, $badge)
|
|
143
|
+
$graphics.FillEllipse($purple, $bx + 1, $by + 1, $badge - 2, $badge - 2)
|
|
144
|
+
# The bolt, on a 24 x 24 grid: M13 2 4 14h7l-1 8 9-12h-7z
|
|
145
|
+
$unit = ($badge - 2) / 24.0
|
|
146
|
+
$bolt = @(@(13, 2), @(4, 14), @(11, 14), @(10, 22), @(19, 10), @(12, 10)) | ForEach-Object {
|
|
147
|
+
New-Object System.Drawing.PointF(($bx + 1 + $_[0] * $unit), ($by + 1 + $_[1] * $unit))
|
|
148
|
+
}
|
|
149
|
+
$graphics.FillPolygon([System.Drawing.Brushes]::White, [System.Drawing.PointF[]]$bolt)
|
|
150
|
+
$purple.Dispose()
|
|
151
|
+
$graphics.Dispose()
|
|
152
|
+
$autoIcon = [System.Drawing.Icon]::FromHandle($badged.GetHicon())
|
|
153
|
+
} catch { $autoIcon = [System.Drawing.SystemIcons]::Warning }
|
|
131
154
|
|
|
132
155
|
$notify = New-Object System.Windows.Forms.NotifyIcon
|
|
133
156
|
$notify.Icon = $offIcon
|
|
@@ -138,9 +161,14 @@ $notify.add_MouseClick({ if ($_.Button -eq [System.Windows.Forms.MouseButtons]::
|
|
|
138
161
|
$menu = New-Object System.Windows.Forms.ContextMenuStrip
|
|
139
162
|
$open = $menu.Items.Add("開啟 VansPod")
|
|
140
163
|
$open.add_Click($openPage)
|
|
141
|
-
$script:accessItem = New-Object System.Windows.Forms.ToolStripMenuItem("
|
|
164
|
+
$script:accessItem = New-Object System.Windows.Forms.ToolStripMenuItem("允許 Agent 使用這台電腦")
|
|
142
165
|
$script:accessItem.add_Click({ Send-ToVansPod @{ type = 'access'; on = (-not $script:access) } })
|
|
143
166
|
[void]$menu.Items.Add($script:accessItem)
|
|
167
|
+
# 只在 Auto Approval 期間出現。
|
|
168
|
+
$script:stopAutoItem = New-Object System.Windows.Forms.ToolStripMenuItem("停止自動允許")
|
|
169
|
+
$script:stopAutoItem.Visible = $false
|
|
170
|
+
$script:stopAutoItem.add_Click({ Send-ToVansPod @{ type = 'auto_approval_stop' } })
|
|
171
|
+
[void]$menu.Items.Add($script:stopAutoItem)
|
|
144
172
|
[void]$menu.Items.Add((New-Object System.Windows.Forms.ToolStripSeparator))
|
|
145
173
|
$stop = $menu.Items.Add("結束 VansPod")
|
|
146
174
|
$stop.add_Click({
|
|
@@ -182,11 +210,13 @@ if ($script:mascot) {
|
|
|
182
210
|
$popup.Controls.Add($picture)
|
|
183
211
|
$textLeft = 64
|
|
184
212
|
}
|
|
185
|
-
$
|
|
186
|
-
$heading
|
|
187
|
-
$heading.
|
|
188
|
-
$heading.
|
|
189
|
-
$
|
|
213
|
+
$autoColor = [System.Drawing.Color]::FromArgb(124, 58, 237)
|
|
214
|
+
$script:heading = New-Object System.Windows.Forms.Label
|
|
215
|
+
$script:heading.Text = "Agent 想要使用這台電腦"
|
|
216
|
+
$script:heading.Font = $bold
|
|
217
|
+
$script:heading.AutoEllipsis = $true
|
|
218
|
+
$script:heading.SetBounds($textLeft, 10, (388 - $textLeft), 22)
|
|
219
|
+
$popup.Controls.Add($script:heading)
|
|
190
220
|
$script:titleLabel = New-Object System.Windows.Forms.Label
|
|
191
221
|
$script:titleLabel.AutoEllipsis = $true
|
|
192
222
|
$script:titleLabel.SetBounds($textLeft, 34, (388 - $textLeft), 22)
|
|
@@ -212,10 +242,66 @@ $script:denyButton.Text = "拒絕"
|
|
|
212
242
|
$script:denyButton.SetBounds(176, 266, 100, 36)
|
|
213
243
|
$popup.Controls.Add($script:denyButton)
|
|
214
244
|
$script:approveButton = New-Object VansPodTray.MouseOnlyButton
|
|
215
|
-
$script:approveButton.Text = "
|
|
245
|
+
$script:approveButton.Text = "允許一次"
|
|
216
246
|
$script:approveButton.Font = $bold
|
|
217
247
|
$script:approveButton.SetBounds(288, 266, 100, 36)
|
|
218
248
|
$popup.Controls.Add($script:approveButton)
|
|
249
|
+
# 自動允許 ▾:選一個時間,先看提醒,按「確定打開」才打開 Auto Approval(ADR 0014)。
|
|
250
|
+
# Auto Approval 期間沒有這個按鈕。
|
|
251
|
+
$script:autoButton = New-Object VansPodTray.MouseOnlyButton
|
|
252
|
+
$script:autoButton.Text = "自動允許 ▾"
|
|
253
|
+
$script:autoButton.SetBounds(12, 266, 110, 36)
|
|
254
|
+
$popup.Controls.Add($script:autoButton)
|
|
255
|
+
$script:autoMenu = New-Object System.Windows.Forms.ContextMenuStrip
|
|
256
|
+
foreach ($choice in @(@('10', '10 分鐘'), @('30', '30 分鐘'), @('until_off', '直到關閉開關'))) {
|
|
257
|
+
$item = New-Object System.Windows.Forms.ToolStripMenuItem($choice[1])
|
|
258
|
+
$item.Tag = $choice[0]
|
|
259
|
+
$item.add_Click({ param($sender) Show-Reminder ([string]$sender.Tag) ([string]$sender.Text) })
|
|
260
|
+
[void]$script:autoMenu.Items.Add($item)
|
|
261
|
+
}
|
|
262
|
+
$script:autoButton.add_Click({ $script:autoMenu.Show($script:autoButton, (New-Object System.Drawing.Point(0, $script:autoButton.Height))) })
|
|
263
|
+
|
|
264
|
+
# 提醒:蓋在 Approval Popup 上面,同樣不搶鍵盤、沒有預設按鈕。
|
|
265
|
+
$script:reminder = New-Object System.Windows.Forms.Panel
|
|
266
|
+
$script:reminder.SetBounds(0, 0, 400, 318)
|
|
267
|
+
$script:reminder.BackColor = [System.Drawing.Color]::White
|
|
268
|
+
$script:reminder.Visible = $false
|
|
269
|
+
$popup.Controls.Add($script:reminder)
|
|
270
|
+
$script:reminderTitle = New-Object System.Windows.Forms.Label
|
|
271
|
+
$script:reminderTitle.Font = $bold
|
|
272
|
+
$script:reminderTitle.ForeColor = $autoColor
|
|
273
|
+
$script:reminderTitle.SetBounds(12, 10, 376, 22)
|
|
274
|
+
$script:reminder.Controls.Add($script:reminderTitle)
|
|
275
|
+
$reminderText = New-Object System.Windows.Forms.Label
|
|
276
|
+
$reminderText.Text = "自動允許期間,Agent 可以不經過你,直接執行指令、寫入檔案和儲存圖片。"
|
|
277
|
+
$reminderText.SetBounds(12, 38, 376, 36)
|
|
278
|
+
$script:reminder.Controls.Add($reminderText)
|
|
279
|
+
$reminderWarn = New-Object System.Windows.Forms.Label
|
|
280
|
+
$reminderWarn.Text = "如果你的 Agent 會讀網頁或電子郵件,那些內容可能藏著給 Agent 的指令。"
|
|
281
|
+
$reminderWarn.Font = New-Object System.Drawing.Font("Microsoft JhengHei UI", 9, [System.Drawing.FontStyle]::Bold)
|
|
282
|
+
$reminderWarn.ForeColor = [System.Drawing.Color]::FromArgb(192, 54, 44)
|
|
283
|
+
$reminderWarn.SetBounds(12, 80, 376, 36)
|
|
284
|
+
$script:reminder.Controls.Add($reminderWarn)
|
|
285
|
+
$reminderExceptions = New-Object System.Windows.Forms.Label
|
|
286
|
+
$reminderExceptions.Text = "下面這兩種情況仍然會問你:`r`n・碰到機密檔案,例如 .env、私密金鑰`r`n・刪除專案資料夾以外的檔案`r`n`r`n排隊中的確認也會一起允許。你隨時可以按「停止自動允許」。"
|
|
287
|
+
$reminderExceptions.ForeColor = [System.Drawing.Color]::FromArgb(90, 90, 90)
|
|
288
|
+
$reminderExceptions.SetBounds(12, 122, 376, 132)
|
|
289
|
+
$script:reminder.Controls.Add($reminderExceptions)
|
|
290
|
+
$reminderCancel = New-Object VansPodTray.MouseOnlyButton
|
|
291
|
+
$reminderCancel.Text = "取消"
|
|
292
|
+
$reminderCancel.SetBounds(176, 266, 100, 36)
|
|
293
|
+
$reminderCancel.add_Click({ Hide-Reminder })
|
|
294
|
+
$script:reminder.Controls.Add($reminderCancel)
|
|
295
|
+
$reminderOk = New-Object VansPodTray.MouseOnlyButton
|
|
296
|
+
$reminderOk.Text = "確定打開"
|
|
297
|
+
$reminderOk.Font = $bold
|
|
298
|
+
$reminderOk.SetBounds(288, 266, 100, 36)
|
|
299
|
+
$reminderOk.add_Click({
|
|
300
|
+
if ($script:reminderDuration) { Send-ToVansPod @{ type = 'auto_approval_start'; duration = $script:reminderDuration } }
|
|
301
|
+
Hide-Reminder
|
|
302
|
+
})
|
|
303
|
+
$script:reminder.Controls.Add($reminderOk)
|
|
304
|
+
$script:reminderDuration = $null
|
|
219
305
|
# 沒有預設按鈕:AcceptButton 與 CancelButton 都不設定。
|
|
220
306
|
|
|
221
307
|
$script:access = $false
|
|
@@ -242,17 +328,58 @@ function Send-Decision([string]$decision) {
|
|
|
242
328
|
$script:approveButton.add_Click({ Send-Decision 'approve' })
|
|
243
329
|
$script:denyButton.add_Click({ Send-Decision 'deny' })
|
|
244
330
|
|
|
331
|
+
function Show-Reminder([string]$duration, [string]$label) {
|
|
332
|
+
$script:reminderDuration = $duration
|
|
333
|
+
$script:reminderTitle.Text = "打開自動允許($label)"
|
|
334
|
+
$script:reminder.Visible = $true
|
|
335
|
+
$script:reminder.BringToFront()
|
|
336
|
+
}
|
|
337
|
+
function Hide-Reminder {
|
|
338
|
+
$script:reminderDuration = $null
|
|
339
|
+
$script:reminder.Visible = $false
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
# Auto Approval:$script:autoOn、結束時間($null 代表直到關閉開關)。
|
|
343
|
+
$script:autoOn = $false
|
|
344
|
+
$script:autoDeadline = $null
|
|
345
|
+
function Update-TrayText {
|
|
346
|
+
if (-not $script:access) { $notify.Text = "VansPod"; return }
|
|
347
|
+
if (-not $script:autoOn) { $notify.Text = "VansPod:Agent 可以使用這台電腦"; return }
|
|
348
|
+
if ($null -eq $script:autoDeadline) { $notify.Text = "VansPod:自動允許中,直到關閉開關"; return }
|
|
349
|
+
$left = [Math]::Max(0, [int][Math]::Ceiling(($script:autoDeadline - [DateTime]::UtcNow).TotalMinutes))
|
|
350
|
+
$notify.Text = "VansPod:自動允許中,剩 $left 分鐘"
|
|
351
|
+
}
|
|
352
|
+
|
|
245
353
|
function Show-State($state) {
|
|
246
354
|
$script:access = [bool]$state.access
|
|
247
355
|
$script:accessItem.Checked = $script:access
|
|
248
|
-
|
|
249
|
-
|
|
356
|
+
$auto = $state.autoApproval
|
|
357
|
+
$script:autoOn = [bool]$auto
|
|
358
|
+
if ($auto -and $null -ne $auto.secondsLeft) { $script:autoDeadline = [DateTime]::UtcNow.AddSeconds([int]$auto.secondsLeft) }
|
|
359
|
+
else { $script:autoDeadline = $null }
|
|
360
|
+
$script:stopAutoItem.Visible = $script:autoOn
|
|
361
|
+
if (-not $script:access) { $notify.Icon = $offIcon }
|
|
362
|
+
elseif ($script:autoOn) { $notify.Icon = $autoIcon }
|
|
363
|
+
else { $notify.Icon = $onIcon }
|
|
364
|
+
Update-TrayText
|
|
365
|
+
# Auto Approval 期間沒有「自動允許 ▾」,提醒也收起來。
|
|
366
|
+
$script:autoButton.Visible = -not $script:autoOn
|
|
367
|
+
if ($script:autoOn) { Hide-Reminder }
|
|
250
368
|
$approval = $state.approval
|
|
251
369
|
if (-not $approval) {
|
|
252
370
|
$script:shownId = $null
|
|
371
|
+
Hide-Reminder
|
|
253
372
|
$popup.Hide()
|
|
254
373
|
return
|
|
255
374
|
}
|
|
375
|
+
# Auto Approval 期間只有例外會顯示:標題寫出為什麼仍要確認。
|
|
376
|
+
if ($script:autoOn -and $approval.exception) {
|
|
377
|
+
$script:heading.Text = "自動允許期間仍要確認:$($approval.exception)"
|
|
378
|
+
$script:heading.ForeColor = $autoColor
|
|
379
|
+
} else {
|
|
380
|
+
$script:heading.Text = "Agent 想要使用這台電腦"
|
|
381
|
+
$script:heading.ForeColor = [System.Drawing.SystemColors]::ControlText
|
|
382
|
+
}
|
|
256
383
|
$script:waiting = [int]$approval.waiting
|
|
257
384
|
if ($approval.id -ne $script:shownId) {
|
|
258
385
|
$script:shownId = [string]$approval.id
|
|
@@ -291,14 +418,17 @@ $pipeTimer.add_Tick({
|
|
|
291
418
|
$pipeTimer.Start()
|
|
292
419
|
$clock = New-Object System.Windows.Forms.Timer
|
|
293
420
|
$clock.Interval = 1000
|
|
294
|
-
$clock.add_Tick({
|
|
421
|
+
$clock.add_Tick({
|
|
422
|
+
if ($script:shownId) { Update-Time }
|
|
423
|
+
if ($script:autoOn) { Update-TrayText }
|
|
424
|
+
})
|
|
295
425
|
$clock.Start()
|
|
296
426
|
|
|
297
427
|
try { [System.Windows.Forms.Application]::Run() }
|
|
298
428
|
finally {
|
|
299
429
|
$pipeTimer.Stop(); $clock.Stop()
|
|
300
430
|
$popup.Dispose()
|
|
301
|
-
$notify.Visible = $false; $notify.Dispose(); $menu.Dispose()
|
|
431
|
+
$notify.Visible = $false; $notify.Dispose(); $menu.Dispose(); $script:autoMenu.Dispose()
|
|
302
432
|
if ($offIcon) { $offIcon.Dispose() }
|
|
303
433
|
if ($script:mascot) { $script:mascot.Dispose() }
|
|
304
434
|
}
|