@aivin-labs/cli 1.0.57 → 1.0.60

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.
@@ -1,138 +1,158 @@
1
- /** Chữ trên menu khay hệ thống (Aivin.exe) — ghi vào launch.cfg theo ngôn ngữ máy (mascotLang). */
2
- export const TRAY_STRINGS = Object.freeze({
3
- vi: {
4
- running: 'Đang chạy — sẵn sàng nhận việc',
5
- paused: 'Đang tạm dừng — từ chối mọi việc từ xa',
6
- stopped: 'Đang không chạy',
7
- notPaired: 'Chưa kết nối với Aivin',
8
- connecting: 'Đang kết nối…',
9
- open: 'Mở Aivin',
10
- quickChat: 'Quick chat',
11
- quickVoice: 'Quick voice',
12
- terminal: 'Mở Terminal',
13
- server: 'Máy chủ',
14
- serverCloud: 'Cloud',
15
- serverVn: 'VN',
16
- serverLocal: 'Local',
17
- serverConfirm: 'Đổi máy chủ sang {server}? Việc đang chạy trên máy này sẽ bị dừng.',
18
- connect: 'Đăng nhập để kết nối…',
19
- pause: 'Tạm dừng nhận việc',
20
- resume: 'Tiếp tục nhận việc',
21
- startup: 'Khởi động cùng Windows',
22
- mascot: 'Linh vật trên màn hình',
23
- mascotShow: 'Hiện linh vật',
24
- mascotHide: 'Ẩn linh vật',
25
- version: 'Phiên bản: {version}',
26
- updateUpToDate: 'Đã là bản mới nhất',
27
- updateAvailable: 'Có bản mới ({version}) — Bấm cập nhật',
28
- updateChecking: 'Đang kiểm tra cập nhật...',
29
- updateCheckNow: 'Kiểm tra cập nhật',
30
- updateUpdating: 'Đang tải bản cập nhật...',
31
- quit: 'Thoát Aivin',
32
- firstRun: 'Aivin đang chạy ở khay hệ thống — bấm biểu tượng để mở.',
33
- connectHint: 'Aivin đang ở khay hệ thống — bấm biểu tượng rồi chọn “Đăng nhập để kết nối”.',
34
- connected: 'Đã kết nối máy này với Aivin.',
35
- pairFailed: 'Không kết nối được — mã sai hoặc đã hết hạn. Tạo mã mới trong Aivin rồi thử lại.',
36
- pairPrompt: 'Nhập mã kết nối từ Aivin (khung chat → Browser ▾ → Thêm máy tính này):',
37
- pairOk: 'Kết nối',
38
- pairCancel: 'Huỷ',
39
- connectCode: 'Tôi có mã kết nối',
40
- connectBrowserHint: 'Đang mở trang đăng nhập. Sau khi bạn cấp quyền, Aivin sẽ tự kết nối máy tính này.',
41
- connectPairing: 'Đăng nhập thành công. Đang liên kết máy tính…',
42
- connectFailed: 'Chưa kết nối được. Hãy thử lại hoặc dùng mã kết nối.',
43
- connectDone: 'Đã kết nối máy tính này với Aivin Cloud.',
44
- shortcut: 'Aivin — cho các agent Aivin làm việc trên máy tính này',
45
- openWith: 'Mở bằng AIVIN Office Suite',
46
- share: 'Gửi cho AIVIN Bot',
47
- workHere: 'Làm việc ở đây với AIVIN Bot',
48
- uninstallPrompt: 'Gỡ AIVIN Bot khỏi máy này?\n\nỨng dụng, lệnh aivin và kết nối của máy với tài khoản sẽ bị xoá.\nCó xoá luôn dữ liệu (ghi nhớ của bot, bản sao tệp để hoàn tác, phiên đăng nhập trình duyệt)? Xoá rồi không lấy lại được.\n\nYes = gỡ và xoá dữ liệu\nNo = gỡ, giữ dữ liệu\nCancel = không gỡ',
49
- uninstallFailed: 'Không gỡ tự động được. Mở Terminal và chạy: aivin uninstall',
50
- stopCast: 'Ngưng kết nối cast ({device})',
51
- trustedDevices: 'Thiết bị tin cậy',
52
- trustedRemove: 'Gỡ {device} · tin từ {date}',
53
- trustedRemoveAll: 'Gỡ tất cả',
54
- castDisconnected: 'Đã ngưng kết nối từ {device}. Thiết bị này sẽ cần xác nhận nếu muốn kết nối lại.',
55
- fileType: 'Tài liệu mở bằng AIVIN Office Suite',
56
- },
57
- en: {
58
- running: 'Running — ready for work',
59
- paused: 'Paused — refusing all remote work',
60
- stopped: 'Not running',
61
- notPaired: 'Not connected to Aivin',
62
- connecting: 'Connecting…',
63
- open: 'Open Aivin',
64
- quickChat: 'Quick chat',
65
- quickVoice: 'Quick voice',
66
- terminal: 'Open Terminal',
67
- server: 'Server',
68
- serverCloud: 'Cloud',
69
- serverVn: 'VN',
70
- serverLocal: 'Local',
71
- serverConfirm: 'Switch to {server}? Current work on this computer will be stopped.',
72
- connect: 'Sign in to connect…',
73
- pause: 'Pause work',
74
- resume: 'Resume work',
75
- startup: 'Start with Windows',
76
- mascot: 'Desktop mascot',
77
- mascotShow: 'Show mascot',
78
- mascotHide: 'Hide mascot',
79
- version: 'Version: {version}',
80
- updateUpToDate: 'Up to date',
81
- updateAvailable: 'New version available ({version}) — Click to update',
82
- updateChecking: 'Checking for updates...',
83
- updateCheckNow: 'Check for updates',
84
- updateUpdating: 'Downloading update...',
85
- quit: 'Quit Aivin',
86
- firstRun: 'Aivin is running in the system tray — click the icon to open it.',
87
- connectHint: 'Aivin is in the system tray — click the icon, then choose “Sign in to connect”.',
88
- connected: 'This computer is now connected to Aivin.',
89
- pairFailed: 'Could not connect — the code is wrong or expired. Create a new code in Aivin and try again.',
90
- pairPrompt: 'Enter the connect code from Aivin (chat box → Browser ▾ → Add this computer):',
91
- pairOk: 'Connect',
92
- pairCancel: 'Cancel',
93
- connectCode: 'I have a connect code',
94
- connectBrowserHint: 'Opening sign-in. Aivin will connect this computer after you grant access.',
95
- connectPairing: 'Signed in. Linking this computer…',
96
- connectFailed: 'Could not connect. Try again or use a connect code.',
97
- connectDone: 'This computer is connected to Aivin Cloud.',
98
- shortcut: 'Aivin — lets your Aivin agents work on this computer',
99
- openWith: 'Open with AIVIN Office Suite',
100
- share: 'Share with AIVIN Bot',
101
- workHere: 'Work here with AIVIN Bot',
102
- uninstallPrompt: 'Remove AIVIN Bot from this computer?\n\nThe app, the aivin command and this computer\'s connection to your account will be removed.\nAlso delete your data (the bot\'s memory, file copies kept for undo, browser sign-ins)? This cannot be undone.\n\nYes = remove and delete data\nNo = remove, keep data\nCancel = do not remove',
103
- uninstallFailed: 'Could not remove it automatically. Open a terminal and run: aivin uninstall',
104
- stopCast: 'Disconnect cast from {device}',
105
- trustedDevices: 'Trusted devices',
106
- trustedRemove: 'Remove {device} · trusted since {date}',
107
- trustedRemoveAll: 'Remove all',
108
- castDisconnected: 'Disconnected cast from {device}. Future casts will require confirmation.',
109
- fileType: 'Document opened with AIVIN Office Suite',
110
- },
111
- });
112
-
113
- /** Chữ khác đi theo hệ điều hành (macOS: thanh menu; macOS / Linux: khởi động cùng máy thay vì cùng Windows). */
114
- const PLATFORM_STRINGS = Object.freeze({
115
- darwin: {
116
- vi: {
117
- startup: 'Mở khi đăng nhập',
118
- firstRun: 'Aivin đang chạy trên thanh menu — bấm biểu tượng để xem.',
119
- connectHint: 'Aivin đang ở khay hệ thống — bấm biểu tượng rồi chọn “Đăng nhập để kết nối”.',
120
- folder: 'Mở thư mục Aivin trong Finder',
121
- },
122
- en: {
123
- startup: 'Open at login',
124
- firstRun: 'Aivin is running in the menu bar — click its icon to see it.',
125
- connectHint: 'Aivin is in the system tray — click its icon, then choose “Sign in to connect”.',
126
- folder: 'Show Aivin folder in Finder',
127
- },
128
- },
129
- linux: {
130
- vi: { startup: 'Khởi động cùng máy' },
131
- en: { startup: 'Start at login' },
132
- },
133
- });
134
-
135
- export function trayStrings(lang, platform = 'win32') {
136
- const code = TRAY_STRINGS[lang] ? lang : 'en';
137
- return { ...TRAY_STRINGS[code], ...(PLATFORM_STRINGS[platform]?.[code] || {}) };
138
- }
1
+ /** Chữ trên menu khay hệ thống (Aivin.exe) — ghi vào launch.cfg theo ngôn ngữ máy (mascotLang). */
2
+ export const TRAY_STRINGS = Object.freeze({
3
+ vi: {
4
+ running: 'Đang chạy — sẵn sàng nhận việc',
5
+ paused: 'Đang tạm dừng — từ chối mọi việc từ xa',
6
+ stopped: 'Đang không chạy',
7
+ notPaired: 'Chưa kết nối với Aivin',
8
+ connecting: 'Đang kết nối…',
9
+ open: 'Mở Aivin',
10
+ quickChat: 'Quick chat',
11
+ quickVoice: 'Quick voice',
12
+ terminal: 'Mở Terminal',
13
+ server: 'Máy chủ',
14
+ serverCloud: 'Cloud',
15
+ serverVn: 'VN',
16
+ serverLocal: 'Local',
17
+ serverConfirm: 'Đổi máy chủ sang {server}? Việc đang chạy trên máy này sẽ bị dừng.',
18
+ connect: 'Đăng nhập để kết nối…',
19
+ pause: 'Tạm dừng nhận việc',
20
+ resume: 'Tiếp tục nhận việc',
21
+ startup: 'Khởi động cùng Windows',
22
+ mascot: 'Linh vật trên màn hình',
23
+ mascotShow: 'Hiện linh vật',
24
+ mascotHide: 'Ẩn linh vật',
25
+ version: 'Phiên bản: {version}',
26
+ updateUpToDate: 'Đã là bản mới nhất',
27
+ updateAvailable: 'Có bản mới ({version}) — Bấm cập nhật',
28
+ updateChecking: 'Đang kiểm tra cập nhật...',
29
+ updateCheckNow: 'Kiểm tra cập nhật',
30
+ updateUpdating: 'Đang tải bản cập nhật...',
31
+ quit: 'Thoát Aivin',
32
+ firstRun: 'Aivin đang chạy ở khay hệ thống — bấm biểu tượng để mở.',
33
+ connectHint: 'Aivin đang ở khay hệ thống — bấm biểu tượng rồi chọn “Đăng nhập để kết nối”.',
34
+ connected: 'Đã kết nối máy này với Aivin.',
35
+ pairFailed: 'Không kết nối được — mã sai hoặc đã hết hạn. Tạo mã mới trong Aivin rồi thử lại.',
36
+ pairPrompt: 'Nhập mã kết nối từ Aivin (khung chat → Browser ▾ → Thêm máy tính này):',
37
+ pairOk: 'Kết nối',
38
+ pairCancel: 'Huỷ',
39
+ connectCode: 'Tôi có mã kết nối',
40
+ connectBrowserHint: 'Đang mở trang đăng nhập. Sau khi bạn cấp quyền, Aivin sẽ tự kết nối máy tính này.',
41
+ connectPairing: 'Đăng nhập thành công. Đang liên kết máy tính…',
42
+ connectFailed: 'Chưa kết nối được. Hãy thử lại hoặc dùng mã kết nối.',
43
+ connectDone: 'Đã kết nối máy tính này với Aivin Cloud.',
44
+ shortcut: 'Aivin — cho các agent Aivin làm việc trên máy tính này',
45
+ openWith: 'Mở bằng AIVIN Office Suite',
46
+ share: 'Gửi cho AIVIN Bot',
47
+ workHere: 'Làm việc ở đây với AIVIN Bot',
48
+ uninstallPrompt: 'Gỡ AIVIN Bot khỏi máy này?\n\nỨng dụng, lệnh aivin và kết nối của máy với tài khoản sẽ bị xoá.\nCó xoá luôn dữ liệu (ghi nhớ của bot, bản sao tệp để hoàn tác, phiên đăng nhập trình duyệt)? Xoá rồi không lấy lại được.\n\nYes = gỡ và xoá dữ liệu\nNo = gỡ, giữ dữ liệu\nCancel = không gỡ',
49
+ uninstallFailed: 'Không gỡ tự động được. Mở Terminal và chạy: aivin uninstall',
50
+ stopCast: 'Ngưng kết nối cast ({device})',
51
+ trustedDevices: 'Thiết bị vào thẳng không cần hỏi',
52
+ trustedAccount: 'Chỉ tài khoản {account} mới vào được',
53
+ trustedLastUsed: 'Dùng lần cuối: {when}',
54
+ trustedPlace: 'Vị trí: {place}',
55
+ trustedIp: 'IP: {ip}',
56
+ trustedSince: 'Cho vào thẳng từ {date}',
57
+ trustedRemove: 'Gỡ thiết bị này',
58
+ trustedRemoveAll: 'Gỡ tất cả',
59
+ trustedHint: 'Thấy thiết bị lạ: gỡ đi và đổi mật khẩu',
60
+ agoNow: 'vừa xong',
61
+ agoMin: '{n} phút trước',
62
+ agoHour: '{n} giờ trước',
63
+ agoDay: '{n} ngày trước',
64
+ castDisconnected: 'Đã ngưng kết nối từ {device}. Thiết bị này sẽ cần xác nhận nếu muốn kết nối lại.',
65
+ fileType: 'Tài liệu mở bằng AIVIN Office Suite',
66
+ },
67
+ en: {
68
+ running: 'Running — ready for work',
69
+ paused: 'Paused — refusing all remote work',
70
+ stopped: 'Not running',
71
+ notPaired: 'Not connected to Aivin',
72
+ connecting: 'Connecting…',
73
+ open: 'Open Aivin',
74
+ quickChat: 'Quick chat',
75
+ quickVoice: 'Quick voice',
76
+ terminal: 'Open Terminal',
77
+ server: 'Server',
78
+ serverCloud: 'Cloud',
79
+ serverVn: 'VN',
80
+ serverLocal: 'Local',
81
+ serverConfirm: 'Switch to {server}? Current work on this computer will be stopped.',
82
+ connect: 'Sign in to connect…',
83
+ pause: 'Pause work',
84
+ resume: 'Resume work',
85
+ startup: 'Start with Windows',
86
+ mascot: 'Desktop mascot',
87
+ mascotShow: 'Show mascot',
88
+ mascotHide: 'Hide mascot',
89
+ version: 'Version: {version}',
90
+ updateUpToDate: 'Up to date',
91
+ updateAvailable: 'New version available ({version}) — Click to update',
92
+ updateChecking: 'Checking for updates...',
93
+ updateCheckNow: 'Check for updates',
94
+ updateUpdating: 'Downloading update...',
95
+ quit: 'Quit Aivin',
96
+ firstRun: 'Aivin is running in the system tray — click the icon to open it.',
97
+ connectHint: 'Aivin is in the system tray — click the icon, then choose “Sign in to connect”.',
98
+ connected: 'This computer is now connected to Aivin.',
99
+ pairFailed: 'Could not connect — the code is wrong or expired. Create a new code in Aivin and try again.',
100
+ pairPrompt: 'Enter the connect code from Aivin (chat box → Browser ▾ → Add this computer):',
101
+ pairOk: 'Connect',
102
+ pairCancel: 'Cancel',
103
+ connectCode: 'I have a connect code',
104
+ connectBrowserHint: 'Opening sign-in. Aivin will connect this computer after you grant access.',
105
+ connectPairing: 'Signed in. Linking this computer…',
106
+ connectFailed: 'Could not connect. Try again or use a connect code.',
107
+ connectDone: 'This computer is connected to Aivin Cloud.',
108
+ shortcut: 'Aivin — lets your Aivin agents work on this computer',
109
+ openWith: 'Open with AIVIN Office Suite',
110
+ share: 'Share with AIVIN Bot',
111
+ workHere: 'Work here with AIVIN Bot',
112
+ uninstallPrompt: 'Remove AIVIN Bot from this computer?\n\nThe app, the aivin command and this computer\'s connection to your account will be removed.\nAlso delete your data (the bot\'s memory, file copies kept for undo, browser sign-ins)? This cannot be undone.\n\nYes = remove and delete data\nNo = remove, keep data\nCancel = do not remove',
113
+ uninstallFailed: 'Could not remove it automatically. Open a terminal and run: aivin uninstall',
114
+ stopCast: 'Disconnect cast from {device}',
115
+ trustedDevices: 'Devices allowed without asking',
116
+ trustedAccount: 'Only account {account} can connect',
117
+ trustedLastUsed: 'Last used: {when}',
118
+ trustedPlace: 'Location: {place}',
119
+ trustedIp: 'IP: {ip}',
120
+ trustedSince: 'Allowed since {date}',
121
+ trustedRemove: 'Remove this device',
122
+ trustedRemoveAll: 'Remove all',
123
+ trustedHint: "Don't recognize one? Remove it and change your password",
124
+ agoNow: 'just now',
125
+ agoMin: '{n} min ago',
126
+ agoHour: '{n} h ago',
127
+ agoDay: '{n} days ago',
128
+ castDisconnected: 'Disconnected cast from {device}. Future casts will require confirmation.',
129
+ fileType: 'Document opened with AIVIN Office Suite',
130
+ },
131
+ });
132
+
133
+ /** Chữ khác đi theo hệ điều hành (macOS: thanh menu; macOS / Linux: khởi động cùng máy thay vì cùng Windows). */
134
+ const PLATFORM_STRINGS = Object.freeze({
135
+ darwin: {
136
+ vi: {
137
+ startup: 'Mở khi đăng nhập',
138
+ firstRun: 'Aivin đang chạy trên thanh menu — bấm biểu tượng để xem.',
139
+ connectHint: 'Aivin đang ở khay hệ thống — bấm biểu tượng rồi chọn “Đăng nhập để kết nối”.',
140
+ folder: 'Mở thư mục Aivin trong Finder',
141
+ },
142
+ en: {
143
+ startup: 'Open at login',
144
+ firstRun: 'Aivin is running in the menu bar — click its icon to see it.',
145
+ connectHint: 'Aivin is in the system tray — click its icon, then choose “Sign in to connect”.',
146
+ folder: 'Show Aivin folder in Finder',
147
+ },
148
+ },
149
+ linux: {
150
+ vi: { startup: 'Khởi động cùng máy' },
151
+ en: { startup: 'Start at login' },
152
+ },
153
+ });
154
+
155
+ export function trayStrings(lang, platform = 'win32') {
156
+ const code = TRAY_STRINGS[lang] ? lang : 'en';
157
+ return { ...TRAY_STRINGS[code], ...(PLATFORM_STRINGS[platform]?.[code] || {}) };
158
+ }
@@ -830,6 +830,9 @@ namespace AivinDesktop {
830
830
  Match mDev = Regex.Match(castTxt, "\"viewer_device\"\\s*:\\s*\"([^\"]+)\"");
831
831
  if (mDev.Success && !string.IsNullOrEmpty(mDev.Groups[1].Value)) {
832
832
  castDevice = mDev.Groups[1].Value;
833
+ // Nơi theo IP: chủ máy biết ai đang điều khiển, không chỉ tên máy (tên do trình duyệt tự khai).
834
+ string place = JsonText(castTxt, "viewer_place");
835
+ if (place.Length > 0) castDevice += " · " + place.Split(',')[0].Trim();
833
836
  } else {
834
837
  Match mId = Regex.Match(castTxt, "\"viewer_id\"\\s*:\\s*\"([^\"]+)\"");
835
838
  castDevice = mId.Success ? mId.Groups[1].Value : "Remote device";
@@ -851,40 +854,111 @@ namespace AivinDesktop {
851
854
  }
852
855
 
853
856
  /** Danh sách chỉ để hiện và gỡ — daemon mới là bên kiểm chữ ký và cho vào. Rỗng / daemon không chạy thì ẩn cả mục, menu giữ gọn. */
857
+ static string JsonText(string obj, string field) {
858
+ Match m = Regex.Match(obj, "\"" + field + "\"\\s*:\\s*\"([^\"]*)\"");
859
+ return m.Success ? m.Groups[1].Value : "";
860
+ }
861
+
862
+ static double JsonNumber(string obj, string field) {
863
+ Match m = Regex.Match(obj, "\"" + field + "\"\\s*:\\s*([0-9]+)");
864
+ double v;
865
+ return m.Success && double.TryParse(m.Groups[1].Value, out v) ? v : 0;
866
+ }
867
+
868
+ /** "2 giờ trước" — chủ máy nhận ra thiết bị theo lần dùng gần nhất dễ hơn ngày được tin. */
869
+ string Ago(double nowMs, double atMs) {
870
+ double min = Math.Max(0, (nowMs - atMs) / 60000);
871
+ if (min < 1) return cfg.T("agoNow");
872
+ if (min < 60) return cfg.T("agoMin").Replace("{n}", ((int)min).ToString());
873
+ if (min < 1440) return cfg.T("agoHour").Replace("{n}", ((int)(min / 60)).ToString());
874
+ return cfg.T("agoDay").Replace("{n}", ((int)(min / 1440)).ToString());
875
+ }
876
+
877
+ ToolStripMenuItem InfoItem(string text) {
878
+ ToolStripMenuItem item = Item(text, delegate { });
879
+ item.Enabled = false;
880
+ return item;
881
+ }
882
+
883
+ static void StyleDropDown(ToolStripMenuItem item) {
884
+ ToolStripDropDownMenu drop = item.DropDown as ToolStripDropDownMenu;
885
+ if (drop != null) { drop.ShowImageMargin = false; drop.ShowCheckMargin = false; }
886
+ item.DropDown.BackColor = Color.White;
887
+ item.DropDown.Font = new Font("Segoe UI", 9.5f, FontStyle.Regular);
888
+ item.DropDown.Padding = new Padding(2, 6, 2, 6);
889
+ }
890
+
891
+ /**
892
+ * Danh sách chỉ để hiện và gỡ — daemon mới là bên kiểm chữ ký và cho vào. Rỗng / daemon không chạy thì ẩn cả mục, menu giữ gọn.
893
+ * Mỗi thiết bị là một menu con: dòng chính "tên · nơi · lần dùng cuối", bên trong là tài khoản / IP / ngày được tin và nút gỡ.
894
+ * Chỉ tài khoản chủ máy xem được (BE chặn), nên tài khoản hiện một lần ở đầu: thấy thiết bị lạ nghĩa là tài khoản đã lộ.
895
+ */
854
896
  void RefreshTrustedDevices(bool running) {
897
+ // key, name, place, ip, account, lastUsed(ms), added date
855
898
  var rows = new List<string[]>();
899
+ var lastUsed = new List<double>();
900
+ double nowMs = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
856
901
  try {
857
902
  if (running && File.Exists(TrustedDevicesFile)) {
858
- double nowMs = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
859
903
  foreach (Match row in Regex.Matches(File.ReadAllText(TrustedDevicesFile), "\\{[^{}]*\\}")) {
860
- Match key = Regex.Match(row.Value, "\"key\"\\s*:\\s*\"([A-Za-z0-9+/=]+)\"");
861
- Match name = Regex.Match(row.Value, "\"name\"\\s*:\\s*\"([^\"]*)\"");
862
- Match added = Regex.Match(row.Value, "\"added_at\"\\s*:\\s*\"([^\"]*)\"");
863
- Match expires = Regex.Match(row.Value, "\"expires_at\"\\s*:\\s*([0-9]+)");
864
- if (!key.Success || !expires.Success || double.Parse(expires.Groups[1].Value) < nowMs) continue;
904
+ string obj = row.Value;
905
+ Match key = Regex.Match(obj, "\"key\"\\s*:\\s*\"([A-Za-z0-9+/=]+)\"");
906
+ double expires = JsonNumber(obj, "expires_at");
907
+ if (!key.Success || expires < nowMs) continue;
865
908
  DateTime when;
866
- string date = DateTime.TryParse(added.Groups[1].Value, out when) ? when.ToString("dd/MM/yyyy") : "";
867
- rows.Add(new string[] { key.Groups[1].Value, name.Groups[1].Value, date });
909
+ string date = DateTime.TryParse(JsonText(obj, "added_at"), out when) ? when.ToString("dd/MM/yyyy") : "";
910
+ double used = JsonNumber(obj, "last_used_at");
911
+ int at = 0;
912
+ while (at < lastUsed.Count && lastUsed[at] >= used) at++;
913
+ lastUsed.Insert(at, used);
914
+ rows.Insert(at, new string[] { key.Groups[1].Value, JsonText(obj, "name"), JsonText(obj, "place"), JsonText(obj, "ip"), JsonText(obj, "account"), date });
868
915
  }
869
916
  }
870
917
  } catch { }
871
918
 
872
919
  trustedMenu.Visible = rows.Count > 0;
873
- var shown = new StringBuilder();
874
- foreach (string[] row in rows) shown.Append(row[0]).Append('|');
920
+ // Chữ "x phút trước" đổi theo thời gian: dựng lại khi chữ hiện ra đổi, không chỉ khi danh sách đổi.
921
+ var texts = new List<string>();
922
+ for (int i = 0; i < rows.Count; i++) {
923
+ string[] row = rows[i];
924
+ string where = row[2].Length > 0 ? row[2].Split(',')[0].Trim() : "";
925
+ texts.Add(row[1] + (where.Length > 0 ? " · " + where : "") + (lastUsed[i] > 0 ? " · " + Ago(nowMs, lastUsed[i]) : ""));
926
+ }
927
+ string account = "";
928
+ foreach (string[] row in rows) { if (row[4].Length > 0) { account = row[4]; break; } }
929
+ var shown = new StringBuilder(account);
930
+ for (int i = 0; i < rows.Count; i++) shown.Append('|').Append(rows[i][0]).Append('|').Append(texts[i]).Append('|').Append(rows[i][2]).Append('|').Append(rows[i][3]);
875
931
  if (shown.ToString() == trustedShown) return;
876
932
  trustedShown = shown.ToString();
877
933
 
878
934
  trustedMenu.DropDownItems.Clear();
879
- foreach (string[] row in rows) {
935
+ if (account.Length > 0) {
936
+ trustedMenu.DropDownItems.Add(InfoItem(cfg.T("trustedAccount").Replace("{account}", account)));
937
+ trustedMenu.DropDownItems.Add(new ToolStripSeparator());
938
+ }
939
+ for (int i = 0; i < rows.Count; i++) {
940
+ string[] row = rows[i];
880
941
  string key = row[0];
881
- trustedMenu.DropDownItems.Add(Item(cfg.T("trustedRemove").Replace("{device}", row[1]).Replace("{date}", row[2]),
882
- delegate { SendTrustAction("{\"action\":\"untrust\",\"key\":\"" + key + "\"}"); }));
942
+ SubmenuItem device = new SubmenuItem(texts[i]);
943
+ device.Padding = new Padding(16, 6, 24, 6);
944
+ StyleDropDown(device);
945
+ if (lastUsed[i] > 0) device.DropDownItems.Add(InfoItem(cfg.T("trustedLastUsed").Replace("{when}", Ago(nowMs, lastUsed[i]))));
946
+ if (row[2].Length > 0) device.DropDownItems.Add(InfoItem(cfg.T("trustedPlace").Replace("{place}", row[2])));
947
+ if (row[3].Length > 0) device.DropDownItems.Add(InfoItem(cfg.T("trustedIp").Replace("{ip}", row[3])));
948
+ if (row[5].Length > 0) device.DropDownItems.Add(InfoItem(cfg.T("trustedSince").Replace("{date}", row[5])));
949
+ device.DropDownItems.Add(new ToolStripSeparator());
950
+ ToolStripMenuItem remove = Item(cfg.T("trustedRemove"), delegate { SendTrustAction("{\"action\":\"untrust\",\"key\":\"" + key + "\"}"); });
951
+ remove.ForeColor = Color.FromArgb(210, 45, 45);
952
+ device.DropDownItems.Add(remove);
953
+ trustedMenu.DropDownItems.Add(device);
883
954
  }
955
+ trustedMenu.DropDownItems.Add(new ToolStripSeparator());
884
956
  if (rows.Count > 1) {
885
- trustedMenu.DropDownItems.Add(new ToolStripSeparator());
886
957
  trustedMenu.DropDownItems.Add(Item(cfg.T("trustedRemoveAll"), delegate { SendTrustAction("{\"action\":\"untrust_all\"}"); }));
887
958
  }
959
+ ToolStripMenuItem hint = InfoItem(cfg.T("trustedHint"));
960
+ hint.Font = new Font("Segoe UI", 8.5f, FontStyle.Regular);
961
+ trustedMenu.DropDownItems.Add(hint);
888
962
  }
889
963
 
890
964
  void SendTrustAction(string json) {
@@ -1238,7 +1312,7 @@ namespace AivinDesktop {
1238
1312
  Refresh();
1239
1313
  Balloon(cfg.T("connectBrowserHint"), ToolTipIcon.Info);
1240
1314
  ThreadPool.QueueUserWorkItem(delegate {
1241
- int loginResult = RunCliAndWait("login");
1315
+ int loginResult = RunCliAndWait("login --app desktop");
1242
1316
  if (quitting) return;
1243
1317
  if (loginResult != 0) {
1244
1318
  UI(delegate {
@@ -1,4 +1,5 @@
1
1
  import net from 'net';
2
+ import os from 'os';
2
3
  import readline from 'readline';
3
4
  import { spawn } from 'child_process';
4
5
  import { createDesktopWebRtc } from './desktopWebRtc.mjs';
@@ -24,6 +25,9 @@ export const DESKTOP_WEBRTC_WORKER_ARG = '__desktop-webrtc-worker';
24
25
  const VIDEO_LIVE_MS = 3000;
25
26
 
26
27
  export async function runDesktopWebRtcWorker({ input = process.stdin, output = process.stdout } = {}) {
28
+ // Bộ mã hoá hình chạy bằng CPU: máy bận mà ở mức thường thì có lượt đứng hình vài giây (đo 13/11/2026, 24 luồng đốt CPU: trung vị
29
+ // 104 ms, lượt tệ nhất 3 s; trên mức thường: 94 ms, tệ nhất 106 ms). Không lên High để không giành ứng dụng người dùng đang dùng.
30
+ try { os.setPriority(process.pid, os.constants.priority.PRIORITY_ABOVE_NORMAL); } catch { /* không đổi được thì chạy mức thường */ }
27
31
  const send = (msg) => { try { output.write(JSON.stringify(msg) + '\n'); } catch { /* daemon đã đóng */ } };
28
32
  let lastRawAt = 0;
29
33
  let lastState = '';
@@ -0,0 +1,91 @@
1
+ import { createHash } from 'crypto';
2
+ import { execFileSync } from 'child_process';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { REMOTE_CONFIG_DIR } from './constants.mjs';
6
+
7
+ /**
8
+ * DPAPI nhanh trên Windows (13/11/2026): tệp exe nhỏ biên dịch một lần bằng csc của .NET Framework có sẵn trong Windows, đặt trong
9
+ * `~/.aivin/bin` (thư mục bị chặn với mọi công cụ từ xa). Mỗi lần giải ~0,1 s thay vì ~1–4 s của PowerShell — đủ nhanh để CLI giải khoá
10
+ * API ở MỖI lệnh. Không biên dịch được (máy chặn csc, diệt virus xoá tệp) → `null`, tokenStore lùi về PowerShell như cũ.
11
+ * Định dạng bản mã giống hệt bản PowerShell (UTF-8, entropy, CurrentUser, base64) nên đọc được bản mã cũ.
12
+ */
13
+
14
+ const SOURCE = `using System; using System.Text; using System.Security.Cryptography;
15
+ class AivinDpapi {
16
+ static int Main(string[] a) {
17
+ try {
18
+ if (a.Length < 2) return 2;
19
+ string input = Console.In.ReadToEnd();
20
+ byte[] entropy = Encoding.UTF8.GetBytes(a[1]);
21
+ if (a[0] == "protect") {
22
+ Console.Out.Write(Convert.ToBase64String(ProtectedData.Protect(Encoding.UTF8.GetBytes(input), entropy, DataProtectionScope.CurrentUser)));
23
+ return 0;
24
+ }
25
+ if (a[0] == "unprotect") {
26
+ Console.Out.Write(Encoding.UTF8.GetString(ProtectedData.Unprotect(Convert.FromBase64String(input.Trim()), entropy, DataProtectionScope.CurrentUser)));
27
+ return 0;
28
+ }
29
+ return 2;
30
+ } catch { return 1; }
31
+ }
32
+ }
33
+ `;
34
+
35
+ const VERSION = createHash('sha256').update(SOURCE).digest('hex').slice(0, 10);
36
+ const BIN_DIR = path.join(REMOTE_CONFIG_DIR, 'bin');
37
+ export const DPAPI_HELPER_PATH = path.join(BIN_DIR, `aivin-dpapi-${VERSION}.exe`);
38
+ const FAILED_MARK = path.join(BIN_DIR, `aivin-dpapi-${VERSION}.failed`);
39
+ /** Biên dịch hỏng thì thôi thử lại trong ngần này — không bắt mọi lệnh chờ csc. */
40
+ const RETRY_AFTER_FAIL_MS = 24 * 3600_000;
41
+ const RUN_TIMEOUT_MS = 10_000;
42
+
43
+ export const DpapiMode = Object.freeze({ PROTECT: 'protect', UNPROTECT: 'unprotect' });
44
+
45
+ let resolved; // undefined = chưa dò; null = không dùng được; chuỗi = đường dẫn exe
46
+
47
+ function cscPath(env = process.env) {
48
+ const windir = env.WINDIR || env.SystemRoot || 'C:\\Windows';
49
+ return ['Framework64', 'Framework'].map((d) => path.join(windir, 'Microsoft.NET', d, 'v4.0.30319', 'csc.exe')).find((p) => fs.existsSync(p)) || null;
50
+ }
51
+
52
+ function recentlyFailed() {
53
+ try { return Date.now() - fs.statSync(FAILED_MARK).mtimeMs < RETRY_AFTER_FAIL_MS; } catch { return false; }
54
+ }
55
+
56
+ function build() {
57
+ const csc = cscPath();
58
+ if (!csc) return null;
59
+ fs.mkdirSync(BIN_DIR, { recursive: true });
60
+ const src = path.join(BIN_DIR, `aivin-dpapi-${VERSION}.cs`);
61
+ const tmp = `${DPAPI_HELPER_PATH}.${process.pid}.tmp`;
62
+ try {
63
+ fs.writeFileSync(src, SOURCE, 'utf8');
64
+ execFileSync(csc, ['-nologo', '-target:exe', '-optimize+', '-r:System.Security.dll', `-out:${tmp}`, src], { timeout: 60_000, windowsHide: true, stdio: 'ignore' });
65
+ fs.renameSync(tmp, DPAPI_HELPER_PATH);
66
+ return DPAPI_HELPER_PATH;
67
+ } catch {
68
+ try { fs.rmSync(tmp, { force: true }); } catch { /* không có thì thôi */ }
69
+ try { fs.writeFileSync(FAILED_MARK, new Date().toISOString()); } catch { /* chỉ là dấu */ }
70
+ return fs.existsSync(DPAPI_HELPER_PATH) ? DPAPI_HELPER_PATH : null;
71
+ } finally {
72
+ try { fs.rmSync(src, { force: true }); } catch { /* không có thì thôi */ }
73
+ }
74
+ }
75
+
76
+ /** Đường dẫn exe (biên dịch lần đầu nếu cần); `null` khi không phải Windows hoặc không dựng được. */
77
+ export function dpapiHelper({ platform = process.platform } = {}) {
78
+ if (resolved !== undefined) return resolved;
79
+ if (platform !== 'win32' || process.env.AIVIN_DPAPI_HELPER === '0') return (resolved = null);
80
+ if (fs.existsSync(DPAPI_HELPER_PATH)) return (resolved = DPAPI_HELPER_PATH);
81
+ if (recentlyFailed()) return (resolved = null);
82
+ return (resolved = build());
83
+ }
84
+
85
+ /** Chạy exe; lỗi (bản mã của máy / tài khoản khác…) → ném lỗi như nhánh PowerShell. */
86
+ export function runDpapiHelper(exe, mode, input, entropy) {
87
+ return execFileSync(exe, [mode, entropy], { input, encoding: 'utf8', timeout: RUN_TIMEOUT_MS, windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] }).trim();
88
+ }
89
+
90
+ /** Chỉ cho test: quên kết quả dò. */
91
+ export function resetDpapiHelperForTest() { resolved = undefined; }