diff --git a/PUBLICATION-AUDIT.json b/PUBLICATION-AUDIT.json index fb26032..27d139b 100644 --- a/PUBLICATION-AUDIT.json +++ b/PUBLICATION-AUDIT.json @@ -475,5 +475,146 @@ ], "SourceOnly": true, "Version": "0.3.1" + }, + "Windows032ConnectCompactDelta": { + "CandidateSha256": "85fac03989c71cbc61bdf756ac7e7194ac9cd003533c0aa6bc1c355eeb375813", + "ExampleEndpointChanges": [ + { + "Count": 4, + "Path": "windows/KnownTailnetEndpoints.cs" + }, + { + "Count": 3, + "Path": "windows/LearningSelfTest.cs" + }, + { + "Count": 1, + "Path": "windows/LearningTransportSelfTest.cs" + }, + { + "Count": 1, + "Path": "windows/NetworkHandoverSelfTest.cs" + }, + { + "Count": 1, + "Path": "windows/PlatformBootstrapTransport.cs" + }, + { + "Count": 5, + "Path": "windows/PlatformBootstrapTransportSelfTest.cs" + }, + { + "Count": 4, + "Path": "windows/PrivateAuxiliaryRouting.cs" + }, + { + "Count": 25, + "Path": "windows/PrivateAuxiliaryRoutingSelfTest.cs" + }, + { + "Count": 1, + "Path": "windows/PublicTailnetSelectionSelfTest.cs" + }, + { + "Count": 65, + "Path": "windows/TailnetTransportSelfTest.cs" + }, + { + "Count": 1, + "Path": "windows/ConnectionSelfTest.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 1, + "Path": "windows/GitReleasePolicySelfTest.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 1, + "Path": "windows/InstallationIntegration.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 2, + "Path": "windows/LearningSelfTest.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 1, + "Path": "windows/MainForm.Dashboard.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 2, + "Path": "windows/MainForm.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 1, + "Path": "windows/PlatformBootstrapTransport.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 6, + "Path": "windows/PlatformBootstrapTransportSelfTest.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 1, + "Path": "windows/PrivateAuxiliaryRouting.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 7, + "Path": "windows/PrivateAuxiliaryRoutingSelfTest.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 2, + "Path": "windows/TailnetTransportProbe.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 1, + "Path": "windows/TailnetTransportSelfTest.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 2, + "Path": "windows/TunConfigBuilder.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 1, + "Path": "windows/VpnApiClient.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 1, + "Path": "windows/XrayManager.cs", + "RuleSet": "windows-monitor-20261027" + }, + { + "Count": 1, + "Path": "windows/installer/VPNPlus.nsi", + "RuleSet": "windows-monitor-20261027" + } + ], + "FrozenSha256": "18d98d6e58c67ecf6d0293668eaeaa6946e2a2e7b879177f1410e7bf08503f7f", + "Omitted": [ + "windows/assets/login-cloud-scene-v1.jpg" + ], + "OptionalUnlicensedSceneRemainsOmitted": true, + "OriginalAcceptanceTransferred": false, + "OriginalSourceManifestSha256": "bf4a9f7360d2d44b11a8e94db881cc60d7234d2db7a3e89bffef0515ad244991", + "OtherComponentsModified": false, + "PrivateHistoryIncluded": false, + "ProductionAccepted": false, + "PublicBaseCommit": "1cf54a46e495d6f0f74b7b4b67e1786b2c51d5a2", + "PublicDownloadDomainsRetained": [ + "pro.ucvl.cn" + ], + "SourceOnly": true, + "Version": "0.3.2" } } diff --git a/README.md b/README.md index 8fe5516..a102039 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 纵横家开源源码 -此仓库是无私有 Git 历史的清洁源码快照:Windows 0.3.1、Django 后台及 iPhone/iPad 1.0.2。公司自有代码按 MIT 开源;第三方组件遵守原许可,公司商标及 Logo 不在 MIT 授权范围。Android 保留原 GPL-3.0 公开仓库,不重复拷贝或改换许可。 +此仓库是无私有 Git 历史的清洁源码快照:Windows 0.3.2、Django 后台及 iPhone/iPad 1.0.2。公司自有代码按 MIT 开源;第三方组件遵守原许可,公司商标及 Logo 不在 MIT 授权范围。Android 保留原 GPL-3.0 公开仓库,不重复拷贝或改换许可。 | 目录 | 内容与状态 | | --- | --- | diff --git a/SOURCE-PROVENANCE.json b/SOURCE-PROVENANCE.json index 40804f0..49e6816 100644 --- a/SOURCE-PROVENANCE.json +++ b/SOURCE-PROVENANCE.json @@ -4,7 +4,7 @@ "ExportDiffersFromOriginalCandidates": true, "FilesBeforeProvenanceAndAudit": { "LICENSE": "b7e94910b8dc377b0a05ccde3c6e5941838dfc15c9dd790078d11728205b524e", - "README.md": "c2c081754048ff7561f65eb5a471c08e7293acaddbbe48839ab302a3ec37b6d7", + "README.md": "bdaeafc190ac7c8bde109937d37c9f0437b044c9be78dc9dabcb13a2cb56d13c", "SECURITY.md": "34e56cd9b8f6aa5fee45921c6eb831a542e05e76e41850fc31c44e09de088b3c", "THIRD_PARTY_NOTICES.md": "8c862f2f6b71440616a887e6deb7444a1262cf7d9f144208cc04041c3f9a3371", "android/README.md": "bb4387da9a055e97f33bb29a883c543e0938fa858df3fd744abc80553a5ec65c", @@ -190,13 +190,13 @@ "windows/ConnectionHealthSelfTest.cs": "5a483194f754ad51366acd9df00554c8ceecaa5dadba73972c4922b72dc7e2fe", "windows/ConnectionRecoveryPolicy.cs": "860bd4cedf393f157fc1dd68e407776e1fe0fa1cc6cef7e99cd5581b64c6f5f6", "windows/ConnectionSelection.cs": "def94b338b9e1fd940c19b8991e4268a4e59bec741ea624f5a6e4fb7a7d3bbcc", - "windows/ConnectionSelectionSelfTest.cs": "12bd82071989c5e539031f6e7921660edb4eb10a4136ac332cc84eca2e2d96de", + "windows/ConnectionSelectionSelfTest.cs": "0d8f131cf461648aa91651a9790924b6da9cedd1801ef44cc79852164bc9f0d5", "windows/ConnectionSelfTest.cs": "6ad3f227cec3e26514d833ec1cb996818597a0cb27901053362faa45e3c1c9b3", "windows/DailyTrafficChart.cs": "4af8d8a91559e6a3fc1dd56db11f3534606aeb486ff918b2b301db0b82e4c716", - "windows/DashboardControls.cs": "1be17efd73acec775aade94461e59c7255a988bd46d056ad8613fdc3e4bd126d", + "windows/DashboardControls.cs": "d1ced56aa6e7b1a896fecaf23249adbd7c9c9ba7ba3f6ea20e171b9b96886d72", "windows/DashboardInteractionSelfTest.cs": "ad4845d14b5b5db4d91a180f95536dd1093458fab86ec8767b74983891a456b4", - "windows/DashboardLayout.cs": "a07985d84c69ed68783068d847059452db889ee244a98d7ab4e02ace4a5528ba", - "windows/DashboardTailnetLayoutSelfTest.cs": "64ed480d434f673137c5edc5b2b1a5d51f8aa31f8440efb734c052a472bf81d6", + "windows/DashboardLayout.cs": "e30bb9b0f3bc6038f482a4be7b3daab04f34a96a7d367a4ac47a29f692c981d7", + "windows/DashboardTailnetLayoutSelfTest.cs": "ff632fc070ec04a4a47a350f2ba0d543c4895423f88db64f38b53519dc82cd47", "windows/DashboardWheelRouter.cs": "d903097a5febbff296febb65855dc10b4e056ea5bb54d2df71b5d1f0297dcc1f", "windows/GitReleasePolicySelfTest.cs": "9e49ba957ab15a5c23d889004b171856c3d523f98cecf10088df4fcd8b577c61", "windows/GitReleaseUpdater.cs": "dcd00a0feca6801aad4e346c7565d8bcd80b3fd24a4accbe5cd4643d04264b9b", @@ -220,13 +220,14 @@ "windows/LearningSyncCoordinatorSelfTest.cs": "471ec344130fe74d892c1115637bd98c517084fc309e982d4d11d3f0ee19403c", "windows/LearningTransportSelfTest.cs": "05dcfd3fcfc6f25e20612c020583eb6c36934c1b251e50e70fcd29501ad0efe7", "windows/MainForm.Chrome.cs": "30dc6520a44a5120c78c472c9fb053e2e4dea8e254b5531d04a5342964969c7a", - "windows/MainForm.Dashboard.cs": "1e081c6039eac155e87c057919d7381eecdc2388615b9d56f211de0e379386f4", + "windows/MainForm.Compact.cs": "45599d3d795a14c031be051abff4b039480df5e6867aba57c3724488950d280d", + "windows/MainForm.Dashboard.cs": "0b8c2489483dd221d4b94f21f14058d8b4bda28a4326f89c8cc612c6dac05421", "windows/MainForm.Handover.cs": "4a914f4de335331f1f9d2397407328f17ae372e9119329e534af218555dc92e6", "windows/MainForm.NextGeneration.cs": "b560218aed601359310e9ee57f9628d28432be046342748931253c22dbc2d8b5", "windows/MainForm.Selection.cs": "d872004a98fc634e40c5edebf85eac7f3dfbb62fad8cafaae66a5c8470cfdaf3", "windows/MainForm.TailnetTraffic.cs": "432ea16a7f5fe66006530b5b90af6eab59362a2b02685ec2130dadfd43c1652b", "windows/MainForm.TransportSelection.cs": "92e1dd715f39cc40f217e65125d89747bb8c9bedf9a11f70bcd577926e75b995", - "windows/MainForm.cs": "0c202d8c136fc8ae5ed812582bff5d9177c14d009b27e47bd24f5ea518f8c9dd", + "windows/MainForm.cs": "9bea6d7edfa294cb620398e0199379c91a2483fed5ddf882406292efe5f504e2", "windows/NOTICE.md": "8c862f2f6b71440616a887e6deb7444a1262cf7d9f144208cc04041c3f9a3371", "windows/NetworkHandover.cs": "b43548be0051cf92dfd332e537951e4b5083f2a123be8021994513bbc3748d46", "windows/NetworkHandoverSelfTest.cs": "681d0154dc0aa5f49d7ce1f3088b465eea3ed82571b464951df8d4c89cecdf73", @@ -237,11 +238,12 @@ "windows/NetworkRecoveryTool.cs": "2dec1406ca0719af3eacedf2d8f83659927c44bc4a1eaccc1babe84c0d3d99cc", "windows/NetworkRouteLease.cs": "0b57aa0e3499ec3f9f7f7a4c683cecca0f6d7f275734e126a5da4f7849cd7ae3", "windows/NextGenerationSelfTest.cs": "a92cbbf4c8ba0cde0ec12faf2e1cdbcd2c86f758d440d677471968569030f8f1", - "windows/NodeHealthProbe.cs": "c49e5cf6b3a62242ae0e486aa3fd267d50485269ec0bd769cf140e743850fec7", + "windows/NodeHealthProbe.cs": "5c501094402010d2f8ecdc4145f1084ef084b749c2b47794fca0c0f60c4441fb", + "windows/NodeHealthProbeSelfTest.cs": "85d645160ed53f2646b58ba29d2ec17d6ff8fa54b658dc15e15c9609514c16ea", "windows/NodeMatrixSelfTest.cs": "eed8e56036d300fdffd82b83cca87ea6b2806e8598b2c4fc916aded15197f20d", "windows/NodePresentation.cs": "c70a8be06cce937f309fd10531d97b02b675a72509fff2419e412fbdf84977c0", - "windows/NodeTrafficMonitor.cs": "365c821eb9fc08f33e9387369c9f985f31992470214a5a13758f51dc3c84f0b8", - "windows/NodeTrafficSelfTest.cs": "33d7c8e16d23d19396f60e36d3204196e9499546022c09b3a8aaca9b957e01f2", + "windows/NodeTrafficMonitor.cs": "6e04288302ebe2cad0e15fd77ea22e13fa8f06998af079a303e66a7fe1ae4170", + "windows/NodeTrafficSelfTest.cs": "0d11d2d1c4b04f50449487af5948960f282c9b58651c233a06def5d93ce34b48", "windows/NodeTransportConnector.cs": "91d53471f35470fc9a4578e2819863e56a790cda62a7dbfe891a71149d2386e1", "windows/PhysicalUplink.cs": "b0a0eca6b9f724972d0e445c2dc352326ea4d7357317b98639972d60dadc2e63", "windows/PlatformBootstrapTransport.cs": "0eef4a4272449c0e2adfac2e4652bd9cff9c1b2bc11011ca2049dde2f97e4e2b", @@ -250,18 +252,19 @@ "windows/PrivateAuxiliaryRoutingSelfTest.cs": "8b2e867f562017e680def8f74c7fba972404442816abae7bf54fcab5d47339df", "windows/PrivateAuxiliaryRuntime.cs": "dcfb406508e3d7e9a9163163cfe5e2724a6955a18ae4604e2d9f890da61308cf", "windows/PrivateTransportProbe.cs": "e29e9bd0180a37bdcecf7104fde5069be799aca92b747881d0485a62d382d9b3", - "windows/Program.cs": "632a984e5c971b016a5f15b2ff1804b99cfd279661bd637a45f40dcd42e68ecd", + "windows/Program.cs": "c5fba480cc2f8864862205a8beaf99e4daae15b90ac966ca768528a60ff6474f", "windows/ProxyDnsPolicy.cs": "997e2e922ad43956932c1bd0a6da3457bc308ee723f4f77ff8e52aa23fa954c0", "windows/ProxyProbe.cs": "5d27b5a6c6b192a0c0f3ec4637c5a876a71130497af57f7cb4a04ab4735ca1ec", "windows/PublicTailnetSelection.cs": "cdd6e9195e678bd29dcef96aa9d16ffac9bf42bfe1a10ef293aefd31a2c4a68a", "windows/PublicTailnetSelectionSelfTest.cs": "aed90554aa88aa7701eaccc925307a48d4a79e244c40d0c456b88f1207b540c0", - "windows/README.md": "7296f084849469b2420a091cbee1ed381986d95956dd79d94338b4b924167671", + "windows/README.md": "5e4cff115fd3a8e2270d026ae9e37b913479ee620baa8350126819b2365e04af", "windows/ReplacementContinuitySelfTest.cs": "107878ab2b367f1812377c0b209f6d620da390091c3882e4be53a48e517d86a1", "windows/RouteLeaseSelfTest.cs": "6189c66b9f66c58bed26de4441c58a9ec02b67257bfa04ed66d702acfcd054d9", "windows/RoutingRuleBatches.cs": "9997bfa766fffe7bed7352f307c1f6f118a9be9aa86653eaefae3b2bdaa26c1e", "windows/RoutingUpdateSelfTest.cs": "48c99fc7a01037aa0368c53ccdb7eec0fea1edfac3bb2532c0de89631343206d", "windows/ScenicTheme.cs": "da0ec888a65216b57f881cf5bbc2ed551a07363afae9f2b6a54f22c6502169c7", "windows/SessionOperationFence.cs": "86e8dff164dc7f6f45ba3a41126b8e2e36af9de098479a08a9007604ff112277", + "windows/StartupLearningWarmup.cs": "137041f1c1f83147ce50b824208470832c58db775a9b72197d1d106316466f8b", "windows/StartupSelfTest.cs": "cb035bf5d22624ed5034b719f0c52a4c1527ace4c371e966f15f7c25c8126013", "windows/SystemPowerShell.cs": "1f9247d2e4f8c9bad1d71105886d2ab33d8958006dcff7fadc63f27502eda6fe", "windows/SystemProxy.cs": "beaf443f1e285e227e0c390d8e9114d5cf8464e0078a8bb842efa9eeb2b5e916", @@ -272,7 +275,7 @@ "windows/TailnetTransportProbe.cs": "c71a0d946cbefb2713e0b564ea95ae99cbd70f0ec19c8cfc416a12e16589f99a", "windows/TailnetTransportSelfTest.cs": "8ace8cc2f443c1ce576bbb9471cb46f107ac28f999090baa30431412d8a263f3", "windows/TokenStore.cs": "e07cf7d1a4cf7a1bba871c19e50b9d6355cb8c1546657346b0256c8215fed8bb", - "windows/TrafficChart.cs": "9b2b42761d9f636cd3be3d6015ce4eff73bf7c0645105c7679f1987b1f5571a0", + "windows/TrafficChart.cs": "c7bd65735ffaaace1a8b5075e6e977d7449b481858f4130d42da70069c34c883", "windows/TunConfigBuilder.cs": "35a17b9da204e338dde5ed6cd4f2e979d94ad73c4c01cc0001fc582e94b67194", "windows/TunConnectivitySelfTest.cs": "a7d7aff1d03e45dff921807cbfb8f83b5013c9df5c7e06b6662d84a8686b2f86", "windows/TunRouting.cs": "c6b3e1070a0ba0a3c42dbd12becba55404e540d06aba03cb1cc1053fa426a4c1", @@ -280,11 +283,11 @@ "windows/UpdateSelfTest.cs": "453165bb611efb8db0d8a8c9ea13f3553e0047aa22b838c43096e3d83fe18771", "windows/UpdateStreamSelfTest.cs": "ad059016c0197f33582b1969ab3280c5b9589a28d659613b3e97ce4a357d38c1", "windows/UsageHistorySeries.cs": "9e7515ceede1899e06116352de79edd6252c921048bcae9958bf9358d93b3069", - "windows/VPNPlus.csproj": "cc59524a6a01f8a606bece97ae45ca6cf25f9fb5ec83b36372d68a0f02f76cab", + "windows/VPNPlus.csproj": "6ace89a08e32b1527bcebf5d9406451ab4e00a8e0b2448a3dbf7290cfcbe9555", "windows/VpnApiClient.cs": "187829698d9f26b896dbfef596bc71b12a9ed4e014261abde0497e6763e40ae3", "windows/WindowChrome.cs": "0eceea0879e792b8ae83a74eaf5658d4a7be6a798fbdb026ff8d19fa9aa6af2c", "windows/WindowChromeSelfTest.cs": "c17dd805a0102d12b71a3e32c77ceeb45e303e08612de5d3c5259c78327532be", - "windows/XrayManager.cs": "024178506c01a7fe6074c4a05973125338999862e3b52181a0a0ce7399209375", + "windows/XrayManager.cs": "b6422093815b939b5a9c4cdbf7ba95fddeb6e32831e427aab074858606101146", "windows/XrayRoutingUpdater.cs": "91fd2b5db25477dbe4de7118faef79f9c51f9a8a3dd86e8b26c676092de3bca5", "windows/app.manifest": "4c9a2e8e2056c3bb0ae45a5f7b2e223298ee683a82b70ba4910e17f5728cf5b6", "windows/assets/company-logo-original.png": "04cf7f754a5353b96cddbed4a57a557154342c190a1785487e3bfb36cab04163", @@ -304,6 +307,8 @@ "windows/build/OwnedProcessGroup.cs": "00fc73e00dbc25bdf5ff6557f0d81786ba1ef235822ea290bead9b8a5ac66618", "windows/build/ProductionInstallationBaseline.ps1": "1079dcc459af2b217d7cbddb81d286888d1210f1069cada6272d3b79a531062a", "windows/build/ProductionNetworkBaseline.ps1": "aa3600f92ba19d3041b0c50696d1035efe68013dec7ae3f7973e75b5fc17f9b1", + "windows/build/StartupLearningWarmupHarness.cs": "1d5266159f1e8426dafd2e035a85644d03a9ed15c9207e7cd629e0fc03a3e310", + "windows/build/StartupLearningWarmupHarness.csproj": "2fee8f47a9b6b3cffcee0689fae4960525a2beadad73c5c3a4146e292f30bee2", "windows/build/Test-InstallerGuardianGate.ps1": "5289a4643cc41279eae8d32a7cfdabfdd528506b03cc9fadaf33880dea996694", "windows/build/Test-ProductionInstallationBaseline.ps1": "7d5afbffd8e4ed595917fdc8054469cdf071cfe4c932955bb84840d867eec0f0", "windows/build/Test-ProductionNetworkBaseline.ps1": "842d84027e8ec68e94ab860500a176b8d8f284b7ca0d4e55751d0e81818742ac", @@ -322,7 +327,8 @@ "windows/release/RELEASE-NOTES-0.2.22.md": "bf6c8b448481f59a05e8653fbaa1356d986d2d481c3cbaf02fe6402dcf55d499", "windows/release/RELEASE-NOTES-0.2.23.md": "2f8aea1ec4d4f1bcc9860d8945dc6266be6ea924ff9958c589a6e4eb0550dc76", "windows/release/RELEASE-NOTES-0.3.0.md": "cc1e398354ffb562c0647dbe91ffd3f43e614f3923298005c76999c457b77bf2", - "windows/release/RELEASE-NOTES-0.3.1.md": "e28a99d049842adc34f593e39bbc33484dd4dfc9e31568cbcb1aef1f3bcd4132" + "windows/release/RELEASE-NOTES-0.3.1.md": "e28a99d049842adc34f593e39bbc33484dd4dfc9e31568cbcb1aef1f3bcd4132", + "windows/release/RELEASE-NOTES-0.3.2.md": "29f2030b0be583a541dc0289ee9916d42156cf3bbd823bd5cf7867f097fb2abd" }, "IosSourceCommit": "b07d085413b1b6370245866fd82271b76590b6d6", "Kind": "clean-history-free-open-source-export", @@ -557,5 +563,18 @@ "SourceOnly": true, "Version": "0.3.1" }, + "Windows032ConnectCompactDelta": { + "CandidateSha256": "85fac03989c71cbc61bdf756ac7e7194ac9cd003533c0aa6bc1c355eeb375813", + "FrozenSha256": "18d98d6e58c67ecf6d0293668eaeaa6946e2a2e7b879177f1410e7bf08503f7f", + "OptionalUnlicensedSceneRemainsOmitted": true, + "OriginalAcceptanceTransferred": false, + "OriginalSourceManifestSha256": "bf4a9f7360d2d44b11a8e94db881cc60d7234d2db7a3e89bffef0515ad244991", + "OtherComponentsModified": false, + "PrivateHistoryIncluded": false, + "ProductionAccepted": false, + "PublicBaseCommit": "1cf54a46e495d6f0f74b7b4b67e1786b2c51d5a2", + "SourceOnly": true, + "Version": "0.3.2" + }, "WindowsSourceCommit": "0d463e6af91a3802c564b06dabb6bf86ebff5a38" } diff --git a/windows/ConnectionSelectionSelfTest.cs b/windows/ConnectionSelectionSelfTest.cs index ddcc401..b07438a 100644 --- a/windows/ConnectionSelectionSelfTest.cs +++ b/windows/ConnectionSelectionSelfTest.cs @@ -1,120 +1,136 @@ -using System.Text.Json; - -namespace UCVL.VPNPlus; - -internal static class ConnectionSelectionSelfTest -{ - internal static int Run() - { - var checks = new Dictionary(); - bool Rejected(Action action) - { - try { action(); return false; } - catch (InvalidOperationException) { return true; } - } - string[] authorized = ["office-test", "remote-test"]; - var auto = ConnectionSelection.Create(false, "office-test", authorized); - checks["default_auto_ignores_previous_manual_choice"] = auto.NodeSlug == "auto" && !auto.Manual; - checks["auto_attempts_are_bounded"] = auto.Attempts(12) == 8 && auto.Attempts(2) == 2; - var manual = ConnectionSelection.Create(true, "office-test", authorized); - checks["manual_uses_exact_authorized_node"] = manual.Manual && manual.NodeSlug == "office-test"; - checks["manual_has_no_fallback_attempt"] = manual.Attempts(12) == 1; - checks["missing_choice_rejected"] = Rejected(() => ConnectionSelection.Create(true, null, authorized)); - checks["removed_permission_rejected"] = Rejected(() => ConnectionSelection.Create(true, "removed", authorized)); - checks["manual_auto_slug_rejected"] = Rejected(() => ConnectionSelection.Create(true, "auto", ["auto"])); - checks["different_server_node_rejected"] = Rejected(() => manual.ValidateResponse("remote-test")); - checks["empty_server_node_rejected"] = Rejected(() => auto.ValidateResponse("")); - checks["manual_exact_response_accepted"] = !Rejected(() => manual.ValidateResponse("office-test")); - checks["auto_concrete_response_accepted"] = !Rejected(() => auto.ValidateResponse("remote-test")); - var siteName = NodePresentation.Name(NodePresentation.JinanSlug, "济南(博翠明湖)", true); - checks["private_connected_name_follows_registered_site"] = siteName == "济南(博翠明湖)"; - checks["legacy_private_empty_name_keeps_zero3_fallback"] = NodePresentation.Name(NodePresentation.JinanSlug, "", true) == NodePresentation.JinanName; - checks["public_node_not_relabelled_as_zero3"] = NodePresentation.Name(NodePresentation.JinanSlug, "VPN002", false) == "VPN002"; - checks["fallback_shows_actual_public_node"] = NodePresentation.Name("aliyun-tokyo-002", "VPN002", false) == "VPN002"; - checks["learning_keeps_connected_node_name"] = NodePresentation.LearningDetail(true, siteName, "规则已更新") == siteName + " · 规则已更新"; - checks["learning_after_fallback_names_public_node"] = NodePresentation.LearningDetail(true, "VPN002", "规则已更新") == "VPN002 · 规则已更新"; - checks["unconnected_selection_does_not_claim_actual_node"] = NodePresentation.LearningDetail(false, siteName, "正在验证") == "正在验证"; - checks["public_transport_has_no_suffix"] = NodePresentation.WithTransport("VPN002", false) == "VPN002"; - checks["tailnet_transport_has_explicit_suffix"] = NodePresentation.WithTransport("VPN002", true) == "VPN002 + Tailscale"; - checks["second_node_uses_same_transport_format"] = NodePresentation.WithTransport("VPN003", true) == "VPN003 + Tailscale"; - using (var form = new MainForm(preview: true, uiOnly: true)) - foreach (var check in form.CheckSelectionUi()) checks.Add(check.Key, check.Value); - var passed = checks.Values.All(v => v); - File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "connection-selection-self-test.json"), - JsonSerializer.Serialize(new { passed, network_modified = false, local_office_gateway_tested = false, checks }, - new JsonSerializerOptions { WriteIndented = true })); - return passed ? 0 : 18; - } -} - -internal sealed partial class MainForm -{ - internal Dictionary CheckSelectionUi() - { - var result = new Dictionary(); - var profile = new Profile { Nodes = [new() { Slug = "office-test", Name = "优创未来·济南办" }, new() { Slug = "remote-test", Name = "远程测试" }] }; - _availableNodeCount = 2; - UpdateSelectionNodes(profile, false); - result["ui_defaults_to_auto"] = !ManualSelection; - _connectionModeCombo.SelectedIndex = 1; - _manualNodeCombo.SelectedIndex = 0; - result["ui_manual_has_authorized_choices"] = ManualSelection && _manualNodeCombo.Items.Count == 2; - SetBusy(true); - result["ui_locked_during_connect"] = !_connectionModeCombo.Enabled && !_manualNodeCombo.Enabled; - SetBusy(false); - _wantConnected = true; - RefreshSelectionControls(); - result["ui_locked_during_connection_or_recovery"] = !_connectionModeCombo.Enabled && !_manualNodeCombo.Enabled; - _wantConnected = false; - RefreshSelectionControls(); - result["ui_editable_after_disconnect"] = _connectionModeCombo.Enabled && _manualNodeCombo.Enabled; - UpdateSelectionNodes(profile, true); - result["profile_refresh_keeps_exact_manual_choice"] = (_manualNodeCombo.SelectedItem as NodeInfo)?.Slug == "office-test"; - UpdateSelectionNodes(new Profile { Nodes = [profile.Nodes[1]] }, true); - result["removed_node_not_silently_replaced"] = ManualSelection && _manualNodeCombo.SelectedItem is null; - UpdateSelectionNodes(profile, false); - result["new_login_resets_to_auto"] = !ManualSelection && _manualNodeCombo.SelectedItem is null; - var nodeCount = _manualNodeCombo.Items.Count; - _currentNodeSlug = "office-test"; - _currentNodeBaseName = "VPN002"; - _currentNodeIsPrivateAuxiliary = false; - UpdateConnectedTransportPresentation(false); - result["connected_public_name_is_plain_node"] = _currentNodeName == "VPN002" && !_currentNodeUsesTailnet; - UpdateConnectedTransportPresentation(true); - result["connected_tailnet_name_marks_actual_transport"] = _currentNodeName == "VPN002 + Tailscale" && _currentNodeUsesTailnet; - UpdateConnectedTransportPresentation(true); - result["tailnet_refresh_does_not_duplicate_suffix"] = _currentNodeName == "VPN002 + Tailscale"; - UpdateConnectedTransportPresentation(false); - result["tailnet_fallback_removes_suffix_keeps_node"] = _currentNodeName == "VPN002" && _currentNodeSlug == "office-test" && !_currentNodeUsesTailnet; - result["transport_does_not_duplicate_node_choices"] = _manualNodeCombo.Items.Count == nodeCount && nodeCount == 2; - _currentNodeIsPrivateAuxiliary = true; - _currentNodeBaseName = NodePresentation.JinanName; - UpdateConnectedTransportPresentation(true); - result["private_tailnet_connection_shows_actual_transport"] = _currentNodeName == NodePresentation.JinanName + " + Tailscale" && _currentNodeUsesTailnet; - _currentNodeBaseName = null; - UpdateConnectedTransportPresentation(false); - result["cleared_connection_does_not_claim_tailnet"] = _currentNodeName is null && !_currentNodeUsesTailnet; - // Exercise real dashboard layout, not the hidden login page's stale bounds. - Opacity = 0; - ShowInTaskbar = false; - Show(); - ShowDashboard(profile); - _refreshTimer.Stop(); - PerformLayout(); - Application.DoEvents(); - _currentNodeName = NodePresentation.JinanName; - _currentNodeLabel.Text = _currentNodeName; - SetConnectionState(true, "已安全连接", _currentNodeName); - LayoutDashboard(); - result["connected_node_gets_full_width"] = _currentNodeLabel.Right == _nodeCard.Width - ScaleLogical(14); - result["connected_mode_badge_does_not_cover_name"] = !_scheduleBadge.Visible; - result["zero3_name_fits_connected_row"] = TextRenderer.MeasureText(_currentNodeName, _currentNodeLabel.Font).Width <= _currentNodeLabel.Width; - Size = MinimumSize; - PerformLayout(); - LayoutDashboard(); - Application.DoEvents(); - result["zero3_name_fits_compact_connected_row"] = TextRenderer.MeasureText(_currentNodeName, _currentNodeLabel.Font).Width <= _currentNodeLabel.Width; - RequestExit(); - return result; - } -} +using System.Text.Json; + +namespace UCVL.VPNPlus; + +internal static class ConnectionSelectionSelfTest +{ + internal static int Run() + { + var checks = new Dictionary(); + bool Rejected(Action action) + { + try { action(); return false; } + catch (InvalidOperationException) { return true; } + } + string[] authorized = ["office-test", "remote-test"]; + var auto = ConnectionSelection.Create(false, "office-test", authorized); + checks["default_auto_ignores_previous_manual_choice"] = auto.NodeSlug == "auto" && !auto.Manual; + checks["auto_attempts_are_bounded"] = auto.Attempts(12) == 8 && auto.Attempts(2) == 2; + var manual = ConnectionSelection.Create(true, "office-test", authorized); + checks["manual_uses_exact_authorized_node"] = manual.Manual && manual.NodeSlug == "office-test"; + checks["manual_has_no_fallback_attempt"] = manual.Attempts(12) == 1; + checks["missing_choice_rejected"] = Rejected(() => ConnectionSelection.Create(true, null, authorized)); + checks["removed_permission_rejected"] = Rejected(() => ConnectionSelection.Create(true, "removed", authorized)); + checks["manual_auto_slug_rejected"] = Rejected(() => ConnectionSelection.Create(true, "auto", ["auto"])); + checks["different_server_node_rejected"] = Rejected(() => manual.ValidateResponse("remote-test")); + checks["empty_server_node_rejected"] = Rejected(() => auto.ValidateResponse("")); + checks["manual_exact_response_accepted"] = !Rejected(() => manual.ValidateResponse("office-test")); + checks["auto_concrete_response_accepted"] = !Rejected(() => auto.ValidateResponse("remote-test")); + var siteName = NodePresentation.Name(NodePresentation.JinanSlug, "济南(博翠明湖)", true); + checks["private_connected_name_follows_registered_site"] = siteName == "济南(博翠明湖)"; + checks["legacy_private_empty_name_keeps_zero3_fallback"] = NodePresentation.Name(NodePresentation.JinanSlug, "", true) == NodePresentation.JinanName; + checks["public_node_not_relabelled_as_zero3"] = NodePresentation.Name(NodePresentation.JinanSlug, "VPN002", false) == "VPN002"; + checks["fallback_shows_actual_public_node"] = NodePresentation.Name("aliyun-tokyo-002", "VPN002", false) == "VPN002"; + checks["learning_keeps_connected_node_name"] = NodePresentation.LearningDetail(true, siteName, "规则已更新") == siteName + " · 规则已更新"; + checks["learning_after_fallback_names_public_node"] = NodePresentation.LearningDetail(true, "VPN002", "规则已更新") == "VPN002 · 规则已更新"; + checks["unconnected_selection_does_not_claim_actual_node"] = NodePresentation.LearningDetail(false, siteName, "正在验证") == "正在验证"; + checks["public_transport_has_no_suffix"] = NodePresentation.WithTransport("VPN002", false) == "VPN002"; + checks["tailnet_transport_has_explicit_suffix"] = NodePresentation.WithTransport("VPN002", true) == "VPN002 + Tailscale"; + checks["second_node_uses_same_transport_format"] = NodePresentation.WithTransport("VPN003", true) == "VPN003 + Tailscale"; + using (var form = new MainForm(preview: true, uiOnly: true)) + foreach (var check in form.CheckSelectionUi()) checks.Add(check.Key, check.Value); + var passed = checks.Values.All(v => v); + File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "connection-selection-self-test.json"), + JsonSerializer.Serialize(new { passed, network_modified = false, local_office_gateway_tested = false, checks }, + new JsonSerializerOptions { WriteIndented = true })); + return passed ? 0 : 18; + } +} + +internal sealed partial class MainForm +{ + internal Dictionary CheckSelectionUi() + { + var result = new Dictionary(); + var profile = new Profile { Nodes = [new() { Slug = "office-test", Name = "优创未来·济南办" }, new() { Slug = "remote-test", Name = "远程测试" }] }; + _availableNodeCount = 2; + UpdateSelectionNodes(profile, false); + result["ui_defaults_to_auto"] = !ManualSelection; + _connectionModeCombo.SelectedIndex = 1; + _manualNodeCombo.SelectedIndex = 0; + result["ui_manual_has_authorized_choices"] = ManualSelection && _manualNodeCombo.Items.Count == 2; + SetBusy(true); + result["ui_locked_during_connect"] = !_connectionModeCombo.Enabled && !_manualNodeCombo.Enabled; + SetBusy(false); + _wantConnected = true; + RefreshSelectionControls(); + result["ui_locked_during_connection_or_recovery"] = !_connectionModeCombo.Enabled && !_manualNodeCombo.Enabled; + _wantConnected = false; + RefreshSelectionControls(); + result["ui_editable_after_disconnect"] = _connectionModeCombo.Enabled && _manualNodeCombo.Enabled; + UpdateSelectionNodes(profile, true); + result["profile_refresh_keeps_exact_manual_choice"] = (_manualNodeCombo.SelectedItem as NodeInfo)?.Slug == "office-test"; + UpdateSelectionNodes(new Profile { Nodes = [profile.Nodes[1]] }, true); + result["removed_node_not_silently_replaced"] = ManualSelection && _manualNodeCombo.SelectedItem is null; + UpdateSelectionNodes(profile, false); + result["new_login_resets_to_auto"] = !ManualSelection && _manualNodeCombo.SelectedItem is null; + var nodeCount = _manualNodeCombo.Items.Count; + _currentNodeSlug = "office-test"; + _currentNodeBaseName = "VPN002"; + _currentNodeIsPrivateAuxiliary = false; + UpdateConnectedTransportPresentation(false); + result["connected_public_name_is_plain_node"] = _currentNodeName == "VPN002" && !_currentNodeUsesTailnet; + UpdateConnectedTransportPresentation(true); + result["connected_tailnet_name_marks_actual_transport"] = _currentNodeName == "VPN002 + Tailscale" && _currentNodeUsesTailnet; + UpdateConnectedTransportPresentation(true); + result["tailnet_refresh_does_not_duplicate_suffix"] = _currentNodeName == "VPN002 + Tailscale"; + UpdateConnectedTransportPresentation(false); + result["tailnet_fallback_removes_suffix_keeps_node"] = _currentNodeName == "VPN002" && _currentNodeSlug == "office-test" && !_currentNodeUsesTailnet; + result["transport_does_not_duplicate_node_choices"] = _manualNodeCombo.Items.Count == nodeCount && nodeCount == 2; + _currentNodeIsPrivateAuxiliary = true; + _currentNodeBaseName = NodePresentation.JinanName; + UpdateConnectedTransportPresentation(true); + result["private_tailnet_connection_shows_actual_transport"] = _currentNodeName == NodePresentation.JinanName + " + Tailscale" && _currentNodeUsesTailnet; + _currentNodeBaseName = null; + UpdateConnectedTransportPresentation(false); + result["cleared_connection_does_not_claim_tailnet"] = _currentNodeName is null && !_currentNodeUsesTailnet; + // Exercise real dashboard layout, not the hidden login page's stale bounds. + Opacity = 0; + ShowInTaskbar = false; + Show(); + ShowDashboard(profile); + _refreshTimer.Stop(); + PerformLayout(); + Application.DoEvents(); + _currentNodeName = NodePresentation.JinanName; + _currentNodeLabel.Text = _currentNodeName; + SetConnectionState(true, "已安全连接", _currentNodeName); + LayoutDashboard(); + var fullConnectedRow = true; + foreach (var (size, label) in new[] { (new Size(480, 360), "compact"), (new Size(960, 720), "wide") }) + { + ClientSize = new Size(ScaleLogical(size.Width), ScaleLogical(size.Height)); + PerformLayout(); LayoutDashboard(); Application.DoEvents(); + var rightInset = _nodeCard.ClientSize.Width - _currentNodeLabel.Right; + // The node keeps the available row, with only a small edge inset. + // Exact decorative padding can differ between compact and wide UI. + var usesRow = _currentNodeLabel.Visible && _currentNodeLabel.Left >= 0 + && rightInset >= 0 && rightInset <= ScaleLogical(16) + && _currentNodeLabel.Width >= _nodeCard.ClientSize.Width * .75; + result["connected_node_full_row_" + label] = usesRow; + result["connected_node_name_fits_" + label] = TextRenderer.MeasureText(_currentNodeName, + _currentNodeLabel.Font).Width <= _currentNodeLabel.Width; + fullConnectedRow &= usesRow; + } + result["connected_node_gets_full_width"] = fullConnectedRow; + result["connected_mode_badge_does_not_cover_name"] = !_scheduleBadge.Visible; + result["zero3_name_fits_connected_row"] = TextRenderer.MeasureText(_currentNodeName, _currentNodeLabel.Font).Width <= _currentNodeLabel.Width; + Size = MinimumSize; + PerformLayout(); + LayoutDashboard(); + Application.DoEvents(); + result["zero3_name_fits_compact_connected_row"] = TextRenderer.MeasureText(_currentNodeName, _currentNodeLabel.Font).Width <= _currentNodeLabel.Width; + RequestExit(); + return result; + } +} diff --git a/windows/DashboardControls.cs b/windows/DashboardControls.cs index b9b5471..12fbb8d 100644 --- a/windows/DashboardControls.cs +++ b/windows/DashboardControls.cs @@ -1,177 +1,185 @@ -using System.Drawing.Drawing2D; - -namespace UCVL.VPNPlus; - -internal enum DashboardIcon { Server, Settings, Database, Upload, Download, Document, Chart, History, Shield } - -// Code-drawn icons keep the existing brand assets and remain crisp at high DPI. -internal static class DashboardDrawing -{ - internal static void Icon(Graphics g, DashboardIcon icon, Rectangle bounds, Color color) - { - var state = g.Save(); - g.SmoothingMode = SmoothingMode.AntiAlias; - g.TranslateTransform(bounds.Left, bounds.Top); - g.ScaleTransform(bounds.Width / 24f, bounds.Height / 24f); - using var pen = new Pen(color, 1.8f) { StartCap = LineCap.Round, EndCap = LineCap.Round, LineJoin = LineJoin.Round }; - switch (icon) - { - case DashboardIcon.Server: - g.DrawRectangle(pen, 2, 3, 20, 7); g.DrawRectangle(pen, 2, 14, 20, 7); - g.DrawLine(pen, 6, 6, 6, 7); g.DrawLine(pen, 6, 17, 6, 18); - g.DrawLine(pen, 15, 6.5f, 18, 6.5f); g.DrawLine(pen, 15, 17.5f, 18, 17.5f); break; - case DashboardIcon.Settings: - g.DrawEllipse(pen, 5, 5, 14, 14); g.DrawEllipse(pen, 9, 9, 6, 6); - for (var i = 0; i < 8; i++) { var a = i * Math.PI / 4; g.DrawLine(pen, 12 + (float)Math.Cos(a) * 8, 12 + (float)Math.Sin(a) * 8, 12 + (float)Math.Cos(a) * 10, 12 + (float)Math.Sin(a) * 10); } break; - case DashboardIcon.Database: - g.DrawEllipse(pen, 3, 3, 18, 6); g.DrawLine(pen, 3, 6, 3, 18); g.DrawLine(pen, 21, 6, 21, 18); - g.DrawArc(pen, 3, 9, 18, 6, 0, 180); g.DrawArc(pen, 3, 15, 18, 6, 0, 180); break; - case DashboardIcon.Upload: - case DashboardIcon.Download: - var up = icon == DashboardIcon.Upload; - g.DrawLine(pen, 12, 3, 12, 16); - g.DrawLines(pen, up ? [new PointF(7, 8), new(12, 3), new(17, 8)] : [new PointF(7, 11), new(12, 16), new(17, 11)]); - g.DrawLines(pen, [new PointF(3, 16), new(3, 21), new(21, 21), new(21, 16)]); break; - case DashboardIcon.Document: - g.DrawLines(pen, [new PointF(5, 2), new(15, 2), new(20, 7), new(20, 22), new(5, 22), new(5, 2)]); - g.DrawLines(pen, [new PointF(15, 2), new(15, 7), new(20, 7)]); - g.DrawLine(pen, 9, 12, 16, 12); g.DrawLine(pen, 9, 16, 16, 16); break; - case DashboardIcon.Chart: - for (var i = 0; i < 4; i++) g.DrawLine(pen, 4 + i * 5, 21, 4 + i * 5, 16 - i * 4); break; - case DashboardIcon.History: - g.DrawArc(pen, 2, 2, 20, 20, -85, 350); g.DrawLine(pen, 12, 2, 12, 12); g.DrawLine(pen, 12, 12, 22, 12); break; - case DashboardIcon.Shield: - using (var shield = new GraphicsPath()) - { - shield.AddLines([new PointF(12, 1), new(22, 5), new(22, 12)]); - shield.AddBezier(22, 12, 22, 18, 15, 22, 12, 24); - shield.AddBezier(12, 24, 9, 22, 2, 18, 2, 12); - shield.AddLine(2, 12, 2, 5); shield.CloseFigure(); - using var fill = new LinearGradientBrush(new Point(2, 2), new Point(22, 24), Color.FromArgb(100, color), color); - g.FillPath(fill, shield); - } - using (var check = new Pen(Color.White, 2.4f) { StartCap = LineCap.Round, EndCap = LineCap.Round, LineJoin = LineJoin.Round }) - g.DrawLines(check, [new PointF(7, 12), new(10.5f, 15.5f), new(17, 9)]); - break; - } - g.Restore(state); - } -} - -internal sealed class DashboardGlyph : Control -{ - internal DashboardIcon Glyph { get; set; } - internal DashboardGlyph(DashboardIcon glyph) { Glyph = glyph; DoubleBuffered = true; SetStyle(ControlStyles.SupportsTransparentBackColor, true); BackColor = Color.Transparent; ForeColor = Brand.RoyalBlue; } - protected override void OnPaint(PaintEventArgs e) - { - base.OnPaint(e); - var side = Math.Min(Width, Height) - 4; - if (side > 0) DashboardDrawing.Icon(e.Graphics, Glyph, new((Width - side) / 2, (Height - side) / 2, side, side), ForeColor); - } -} - -internal sealed class BrandHeaderPanel : Panel -{ - internal BrandHeaderPanel() { DoubleBuffered = true; ResizeRedraw = true; } - protected override void OnPaintBackground(PaintEventArgs e) - { - ScenicTheme.Backdrop(e.Graphics, ClientSize, DeviceDpi, header: true); - } -} - -internal sealed class MetricCard : CardPanel -{ - internal DashboardIcon Glyph { get; } - internal string Heading { get; } - internal string ValueText { get; private set; } = "—"; - internal string UnitText { get; private set; } = ""; - internal string Hint { get; private set; } = "仅代理流量"; - internal MetricCard(string heading, DashboardIcon glyph) { Heading = heading; Glyph = glyph; AccessibleName = heading; } - internal void SetBytes(double? bytes, bool speed = false, string? hint = null) - { - string[] units = ["B", "KB", "MB", "GB", "TB"]; - var value = bytes.HasValue && double.IsFinite(bytes.Value) ? Math.Max(0, bytes.Value) : (double?)null; - var unit = 0; - while (value >= 1024 && unit < units.Length - 1) { value /= 1024; unit++; } - ValueText = value.HasValue ? (value == 0 ? "0" : value.Value.ToString("0.##")) : "—"; - UnitText = value.HasValue ? units[unit] + (speed ? "/s" : "") : ""; - Hint = hint ?? "仅代理流量"; - AccessibleDescription = $"{Heading} {ValueText} {UnitText},{Hint}"; - Invalidate(); - } - protected override void OnPaint(PaintEventArgs e) - { - base.OnPaint(e); - var s = DeviceDpi / 96f; - int S(int n) => (int)Math.Round(n * s); - var g = e.Graphics; - var narrow = Width < S(180); - var shortCard = Height < S(75); - if (!narrow) DashboardDrawing.Icon(g, Glyph, new(S(10), S(18), S(22), S(22)), Glyph == DashboardIcon.Download ? Brand.Cyan : Brand.RoyalBlue); - var x = S(narrow ? 8 : 49); var right = Width - S(8); var available = Math.Max(1, right - x); - using var headingFont = Brand.Font(shortCard || narrow ? 8 : 9); - using var unitFont = Brand.Font(shortCard || narrow ? 8 : 9); - using var hintFont = Brand.Font(7.2f); - var paintFlags = TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping; - var headingHeight = Math.Min(S(22), Math.Max(S(14), Height / 3)); - TextRenderer.DrawText(g, Heading, headingFont, new Rectangle(x, 0, available, headingHeight), Brand.Text, paintFlags | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); - var flags = TextFormatFlags.NoPadding | TextFormatFlags.SingleLine | paintFlags; - var unitWidth = TextRenderer.MeasureText(g, UnitText, unitFont, Size.Empty, flags).Width; - var size = shortCard ? 17f : 22f; - Font valueFont; - while (true) - { - valueFont = Brand.Font(size, FontStyle.Bold); - if (TextRenderer.MeasureText(g, ValueText, valueFont, Size.Empty, flags).Width + unitWidth + S(5) <= available || size <= 10) break; - valueFont.Dispose(); size--; - } - using (valueFont) - { - var valueWidth = TextRenderer.MeasureText(g, ValueText, valueFont, Size.Empty, flags).Width; - var valueHeight = Math.Max(1, Height - headingHeight - (shortCard ? 0 : S(18))); - TextRenderer.DrawText(g, ValueText, valueFont, new Rectangle(x, headingHeight, Math.Max(1, available - unitWidth - S(4)), valueHeight), Brand.Navy, flags | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); - TextRenderer.DrawText(g, UnitText, unitFont, new Rectangle(x + Math.Min(valueWidth, available - unitWidth - S(4)) + S(4), headingHeight, unitWidth, valueHeight), Brand.Muted, flags | TextFormatFlags.VerticalCenter); - } - if (!shortCard) TextRenderer.DrawText(g, Hint, hintFont, new Rectangle(x, Height - S(17), available, S(17)), Brand.Muted, paintFlags | TextFormatFlags.EndEllipsis); - } -} - -internal sealed class BadgeLabel : Label -{ - internal BadgeLabel() { DoubleBuffered = true; ResizeRedraw = true; } - protected override void OnPaint(PaintEventArgs e) - { - if (Width < 4 || Height < 4) return; - if (Parent is { } parent) - { - var state = e.Graphics.Save(); - e.Graphics.TranslateTransform(-Left, -Top); - InvokePaintBackground(parent, new PaintEventArgs(e.Graphics, parent.ClientRectangle)); - e.Graphics.Restore(state); - } - else e.Graphics.Clear(Brand.Surface); - e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; - using var path = UiGeometry.RoundedRectangle(new(0, 0, Width - 1, Height - 1), (Height - 1) / 2); - using var fill = new SolidBrush(BackColor); - e.Graphics.FillPath(fill, path); - TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, ForeColor, - TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); - } -} - -internal sealed class ReadOnlyModeLabel : Control -{ - internal ReadOnlyModeLabel() { DoubleBuffered = true; ResizeRedraw = true; BackColor = Color.White; Font = Brand.Font(9.5f); AccessibleName = "当前代理模式(连接中不可修改)"; } - protected override void OnTextChanged(EventArgs e) { base.OnTextChanged(e); Invalidate(); } - protected override void OnPaint(PaintEventArgs e) - { - if (Width < 10 || Height < 10) return; - e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; - using var path = UiGeometry.RoundedRectangle(new(1, 1, Width - 3, Height - 3), Math.Max(3, DeviceDpi / 24)); - using var border = new Pen(Color.FromArgb(204, 219, 237)); - e.Graphics.DrawPath(border, path); - var pad = DeviceDpi / 12; - TextRenderer.DrawText(e.Graphics, Text, Font, new Rectangle(pad, 0, Width - pad * 2, Height), Brand.Text, - TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); - } -} +using System.Drawing.Drawing2D; + +namespace UCVL.VPNPlus; + +internal enum DashboardIcon { Server, Settings, Database, Upload, Download, Document, Chart, History, Shield } + +// Code-drawn icons keep the existing brand assets and remain crisp at high DPI. +internal static class DashboardDrawing +{ + internal static void Icon(Graphics g, DashboardIcon icon, Rectangle bounds, Color color) + { + var state = g.Save(); + g.SmoothingMode = SmoothingMode.AntiAlias; + g.TranslateTransform(bounds.Left, bounds.Top); + g.ScaleTransform(bounds.Width / 24f, bounds.Height / 24f); + using var pen = new Pen(color, 1.8f) { StartCap = LineCap.Round, EndCap = LineCap.Round, LineJoin = LineJoin.Round }; + switch (icon) + { + case DashboardIcon.Server: + g.DrawRectangle(pen, 2, 3, 20, 7); g.DrawRectangle(pen, 2, 14, 20, 7); + g.DrawLine(pen, 6, 6, 6, 7); g.DrawLine(pen, 6, 17, 6, 18); + g.DrawLine(pen, 15, 6.5f, 18, 6.5f); g.DrawLine(pen, 15, 17.5f, 18, 17.5f); break; + case DashboardIcon.Settings: + g.DrawEllipse(pen, 5, 5, 14, 14); g.DrawEllipse(pen, 9, 9, 6, 6); + for (var i = 0; i < 8; i++) { var a = i * Math.PI / 4; g.DrawLine(pen, 12 + (float)Math.Cos(a) * 8, 12 + (float)Math.Sin(a) * 8, 12 + (float)Math.Cos(a) * 10, 12 + (float)Math.Sin(a) * 10); } break; + case DashboardIcon.Database: + g.DrawEllipse(pen, 3, 3, 18, 6); g.DrawLine(pen, 3, 6, 3, 18); g.DrawLine(pen, 21, 6, 21, 18); + g.DrawArc(pen, 3, 9, 18, 6, 0, 180); g.DrawArc(pen, 3, 15, 18, 6, 0, 180); break; + case DashboardIcon.Upload: + case DashboardIcon.Download: + var up = icon == DashboardIcon.Upload; + g.DrawLine(pen, 12, 3, 12, 16); + g.DrawLines(pen, up ? [new PointF(7, 8), new(12, 3), new(17, 8)] : [new PointF(7, 11), new(12, 16), new(17, 11)]); + g.DrawLines(pen, [new PointF(3, 16), new(3, 21), new(21, 21), new(21, 16)]); break; + case DashboardIcon.Document: + g.DrawLines(pen, [new PointF(5, 2), new(15, 2), new(20, 7), new(20, 22), new(5, 22), new(5, 2)]); + g.DrawLines(pen, [new PointF(15, 2), new(15, 7), new(20, 7)]); + g.DrawLine(pen, 9, 12, 16, 12); g.DrawLine(pen, 9, 16, 16, 16); break; + case DashboardIcon.Chart: + for (var i = 0; i < 4; i++) g.DrawLine(pen, 4 + i * 5, 21, 4 + i * 5, 16 - i * 4); break; + case DashboardIcon.History: + g.DrawArc(pen, 2, 2, 20, 20, -85, 350); g.DrawLine(pen, 12, 2, 12, 12); g.DrawLine(pen, 12, 12, 22, 12); break; + case DashboardIcon.Shield: + using (var shield = new GraphicsPath()) + { + shield.AddLines([new PointF(12, 1), new(22, 5), new(22, 12)]); + shield.AddBezier(22, 12, 22, 18, 15, 22, 12, 24); + shield.AddBezier(12, 24, 9, 22, 2, 18, 2, 12); + shield.AddLine(2, 12, 2, 5); shield.CloseFigure(); + using var fill = new LinearGradientBrush(new Point(2, 2), new Point(22, 24), Color.FromArgb(100, color), color); + g.FillPath(fill, shield); + } + using (var check = new Pen(Color.White, 2.4f) { StartCap = LineCap.Round, EndCap = LineCap.Round, LineJoin = LineJoin.Round }) + g.DrawLines(check, [new PointF(7, 12), new(10.5f, 15.5f), new(17, 9)]); + break; + } + g.Restore(state); + } +} + +internal sealed class DashboardGlyph : Control +{ + internal DashboardIcon Glyph { get; set; } + internal DashboardGlyph(DashboardIcon glyph) { Glyph = glyph; DoubleBuffered = true; SetStyle(ControlStyles.SupportsTransparentBackColor, true); BackColor = Color.Transparent; ForeColor = Brand.RoyalBlue; } + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + var side = Math.Min(Width, Height) - 4; + if (side > 0) DashboardDrawing.Icon(e.Graphics, Glyph, new((Width - side) / 2, (Height - side) / 2, side, side), ForeColor); + } +} + +internal sealed class BrandHeaderPanel : Panel +{ + internal BrandHeaderPanel() { DoubleBuffered = true; ResizeRedraw = true; } + protected override void OnPaintBackground(PaintEventArgs e) + { + ScenicTheme.Backdrop(e.Graphics, ClientSize, DeviceDpi, header: true); + } +} + +internal sealed class MetricCard : CardPanel +{ + internal DashboardIcon Glyph { get; } + internal string Heading { get; } + internal string ValueText { get; private set; } = "—"; + internal string UnitText { get; private set; } = ""; + internal string Hint { get; private set; } = "仅代理流量"; + internal MetricCard(string heading, DashboardIcon glyph) { Heading = heading; Glyph = glyph; AccessibleName = heading; } + internal void SetBytes(double? bytes, bool speed = false, string? hint = null) + { + string[] units = ["B", "KB", "MB", "GB", "TB"]; + var value = bytes.HasValue && double.IsFinite(bytes.Value) ? Math.Max(0, bytes.Value) : (double?)null; + var unit = 0; + while (value >= 1024 && unit < units.Length - 1) { value /= 1024; unit++; } + ValueText = value.HasValue ? (value == 0 ? "0" : value.Value.ToString("0.##")) : "—"; + UnitText = value.HasValue ? units[unit] + (speed ? "/s" : "") : ""; + Hint = hint ?? "仅代理流量"; + AccessibleDescription = $"{Heading} {ValueText} {UnitText},{Hint}"; + Invalidate(); + } + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + var s = DeviceDpi / 96f; + int S(int n) => (int)Math.Round(n * s); + var g = e.Graphics; + if(Height (int)Math.Round(n * scale); - // Tailnet is a subdivision of the existing speed area, not another - // dashboard row. Fit the complete canvas even on a small/high-DPI screen. - var verticalScale = Math.Min(1f, Math.Max(1, viewport.Height) / ((showServerTraffic ? 718f : 614f) * scale)); - int Y(int n) => Math.Max(1, (int)Math.Floor(n * scale * verticalScale)); - var margin = S(20); - var gap = Y(10); - var columnGap = S(10); - var width = Math.Max(1, viewport.Width - margin * 2); - var compact = width < S(720); - var half = (width - columnGap) / 2; - var welcome = new Rectangle(margin, Y(8), width - S(132), Y(30)); - var account = new Rectangle(margin, Y(38), Math.Min(S(275), width - S(230)), Y(24)); - var identity = new Rectangle(account.Right + S(10), Y(38), S(92), Y(23)); - var logout = new Rectangle(margin + width - S(104), Y(16), S(104), Y(34)); - var status = new Rectangle(margin, Y(72), width, Y(76)); - var node = new Rectangle(margin, status.Bottom + gap, half, Y(72)); - var mode = new Rectangle(node.Right + columnGap, node.Top, width - half - columnGap, node.Height); - var analyticsTop = mode.Bottom + gap; - var analyticsHeight = Y(276); - var leftHeight = showTailnet ? (analyticsHeight - gap) / 2 : analyticsHeight; - var traffic = new Rectangle(margin, analyticsTop, half, leftHeight); - var tailnet = showTailnet ? new Rectangle(traffic.Left, traffic.Bottom + gap, half, analyticsHeight - leftHeight - gap) : Rectangle.Empty; - var daily = new Rectangle(traffic.Right + columnGap, analyticsTop, width - half - columnGap, analyticsHeight); - Rectangle Metric(Rectangle parent, int column, bool speed) => new( - S(10) + column * ((parent.Width - S(20)) / 2), - speed ? Math.Max(Y(38), (parent.Height - Y(82)) / 2) : Y(40), - (parent.Width - S(20)) / 2 - S(1), - speed ? Math.Min(Y(82), parent.Height - Y(44)) : Y(82)); - // Relative to their matching chart card: totals together; speeds together. - Rectangle[] metrics = [Metric(daily, 0, false), Metric(traffic, 0, true), Metric(traffic, 1, true), Metric(daily, 1, false)]; - var serverTraffic = showServerTraffic ? new Rectangle(margin, daily.Bottom + gap, width, Y(94)) : Rectangle.Empty; - var footer = new Rectangle(margin, (showServerTraffic ? serverTraffic.Bottom : daily.Bottom) + gap, width, Y(76)); - return new(welcome, account, identity, logout, status, node, mode, metrics, traffic, - tailnet, daily, serverTraffic, footer, Math.Min(viewport.Height, footer.Bottom + Y(12)), compact, verticalScale); - } - - internal static bool SelfTest() - { - foreach (var dpi in new[] { 96, 120, 144, 168, 192, 240, 288, 336, 384 }) - foreach (var width in new[] { 600, 620, 739, 760, 780, 900, 1100, 1600 }) - foreach (var height in new[] { 350, 418, 560, 720 }) - foreach (var showTailnet in new[] { false, true }) - foreach (var showServers in new[] { false, true }) - { - var viewport = new Size(width * dpi / 96, height * dpi / 96); - var p = Calculate(viewport, dpi, showTailnet, showServers); - Rectangle[] cards = showTailnet - ? [p.StatusCard, p.NodeCard, p.ModeCard, p.TrafficCard, p.TailnetTrafficCard, p.DailyCard, p.Footer] - : [p.StatusCard, p.NodeCard, p.ModeCard, p.TrafficCard, p.DailyCard, p.Footer]; - if (showServers) cards = [..cards, p.ServerTrafficCard]; - if (cards.Any(c => c.Left < 0 || c.Right > viewport.Width || c.Bottom > p.ContentHeight || c.Width <= 0)) return false; - for (var i = 0; i < cards.Length; i++) - for (var j = i + 1; j < cards.Length; j++) - if (cards[i].IntersectsWith(cards[j])) return false; - if (p.WelcomeLabel.IntersectsWith(p.LogoutButton) || p.AccountLabel.IntersectsWith(p.IdentityBadge)) return false; - if (p.Metrics[0].IntersectsWith(p.Metrics[3]) || p.Metrics[1].IntersectsWith(p.Metrics[2])) return false; - for (var i = 0; i < p.Metrics.Length; i++) - if (p.Metrics[i].Right > (i == 0 || i == 3 ? p.DailyCard.Width : p.TrafficCard.Width)) return false; - if (!showTailnet && p.TailnetTrafficCard != Rectangle.Empty) return false; - if (p.ContentHeight > viewport.Height || p.Footer.Bottom > viewport.Height) return false; - var baseline = Calculate(viewport, dpi, false, showServers); - if (p.DailyCard != baseline.DailyCard || p.Footer != baseline.Footer || p.ContentHeight != baseline.ContentHeight) return false; - if (showTailnet && (p.TailnetTrafficCard.Top <= p.TrafficCard.Bottom - || p.DailyCard.Top != p.TrafficCard.Top || p.DailyCard.Bottom != p.TailnetTrafficCard.Bottom)) return false; - if (showServers && (p.ServerTrafficCard.Top <= p.DailyCard.Bottom || p.ServerTrafficCard.Bottom >= p.Footer.Top)) return false; - } - return true; - } -} +namespace UCVL.VPNPlus; + +internal readonly record struct DashboardGeometry( + Rectangle WelcomeLabel, Rectangle AccountLabel, Rectangle IdentityBadge, + Rectangle LogoutButton, Rectangle StatusCard, Rectangle NodeCard, Rectangle ModeCard, + Rectangle[] Metrics, Rectangle TrafficCard, Rectangle TailnetTrafficCard, Rectangle SpeedTrendCard, Rectangle DailyCard, Rectangle ServerTrafficCard, Rectangle Footer, + int ContentHeight, bool Compact, float VerticalScale); + +// Logical pixels converted once, independent of WinForms autoscaling. +internal static class DashboardLayout +{ + internal static DashboardGeometry Calculate(Size viewport, int dpi, bool showTailnet = false, bool showServerTraffic = false, bool preferCompact = false) + { + if (preferCompact || viewport.Width < 720f * dpi / 96f || viewport.Height < 442f * dpi / 96f) return CalculateCompact(viewport, dpi, showTailnet, showServerTraffic); + var scale = Math.Max(1f, dpi / 96f); + int S(int n) => (int)Math.Round(n * scale); + // Tailnet is a subdivision of the existing speed area, not another + // dashboard row. Fit the complete canvas even on a small/high-DPI screen. + var verticalScale = Math.Min(1f, Math.Max(1, viewport.Height) / ((showServerTraffic ? 718f : 614f) * scale)); + int Y(int n) => Math.Max(1, (int)Math.Floor(n * scale * verticalScale)); + var margin = S(20); + var gap = Y(10); + var columnGap = S(10); + var width = Math.Max(1, viewport.Width - margin * 2); + var compact = width < S(720); + var half = (width - columnGap) / 2; + var welcome = new Rectangle(margin, Y(8), width - S(132), Y(30)); + var account = new Rectangle(margin, Y(38), Math.Min(S(275), width - S(230)), Y(24)); + var identity = new Rectangle(account.Right + S(10), Y(38), S(92), Y(23)); + var logout = new Rectangle(margin + width - S(104), Y(16), S(104), Y(34)); + var status = new Rectangle(margin, Y(72), width, Y(76)); + var node = new Rectangle(margin, status.Bottom + gap, half, Y(72)); + var mode = new Rectangle(node.Right + columnGap, node.Top, width - half - columnGap, node.Height); + var analyticsTop = mode.Bottom + gap; + var analyticsHeight = Y(276); + var trendHeight = Y(120); + var figuresHeight = analyticsHeight - trendHeight - gap; + var leftHeight = showTailnet ? (figuresHeight - gap) / 2 : figuresHeight; + var traffic = new Rectangle(margin, analyticsTop, half, leftHeight); + var tailnet = showTailnet ? new Rectangle(traffic.Left, traffic.Bottom + gap, half, figuresHeight - leftHeight - gap) : Rectangle.Empty; + var trend = new Rectangle(margin, analyticsTop + figuresHeight + gap, half, trendHeight); + var daily = new Rectangle(traffic.Right + columnGap, analyticsTop, width - half - columnGap, analyticsHeight); + Rectangle Metric(Rectangle parent, int column, bool speed) => new( + S(10) + column * ((parent.Width - S(20)) / 2), + speed ? Math.Max(Y(38), (parent.Height - Y(82)) / 2) : Y(40), + (parent.Width - S(20)) / 2 - S(1), + speed ? Math.Min(Y(82), parent.Height - Y(44)) : Y(82)); + // Relative to their matching chart card: totals together; speeds together. + Rectangle Total(int row) => new(S(14), Y(40 + row * 112), daily.Width - S(28), Y(98)); + Rectangle[] metrics = [Total(0), Metric(traffic, 0, true), Metric(traffic, 1, true), Total(1)]; + var serverTraffic = showServerTraffic ? new Rectangle(margin, daily.Bottom + gap, width, Y(94)) : Rectangle.Empty; + var footer = new Rectangle(margin, (showServerTraffic ? serverTraffic.Bottom : daily.Bottom) + gap, width, Y(76)); + return new(welcome, account, identity, logout, status, node, mode, metrics, traffic, + tailnet, trend, daily, serverTraffic, footer, Math.Min(viewport.Height, footer.Bottom + Y(12)), compact, verticalScale); + } + + private static DashboardGeometry CalculateCompact(Size viewport, int dpi, bool showTailnet, bool showServers) + { + var scale = Math.Max(1f, dpi / 96f); + int S(int n) => (int)Math.Round(n * scale); + var margin = S(8); var gap = S(4); + var width = Math.Max(S(400), viewport.Width - margin * 2); + var leftWidth = (int)Math.Round((width-gap)*.61); + var welcome = new Rectangle(margin, S(1), width-S(90), S(15)); + var account = new Rectangle(margin, S(16), S(175), S(12)); + var identity = new Rectangle(account.Right+gap, S(16), S(58), S(12)); + var logout = new Rectangle(margin+width-S(70), S(3), S(70), S(23)); + var status = new Rectangle(margin, S(30), width, S(40)); + var node = new Rectangle(margin, S(74), leftWidth, S(42)); + var mode = new Rectangle(node.Right+gap,node.Top,width-leftWidth-gap,node.Height); + var footer = new Rectangle(margin, viewport.Height-S(26), width, S(22)); + var server = showServers ? new Rectangle(margin,footer.Top-gap-S(34),width,S(34)) : Rectangle.Empty; + var bottom = (showServers?server.Top:footer.Top)-gap; + var analyticsTop=S(120); + var height=Math.Max(S(112),bottom-analyticsTop); + var statsHeight=showTailnet?S(30):S(60); + var traffic=new Rectangle(margin,analyticsTop,leftWidth,statsHeight); + var tailnet=showTailnet?new Rectangle(margin,traffic.Bottom+gap,leftWidth,S(30)):Rectangle.Empty; + var trendTop=(showTailnet?tailnet.Bottom:traffic.Bottom)+gap; + var trend=new Rectangle(margin,trendTop,leftWidth,analyticsTop+height-trendTop); + var daily=new Rectangle(mode.Left,analyticsTop,mode.Width,height); + var totalHeight=(daily.Height-S(22))/2; + Rectangle Total(int row)=>new(S(5),S(20)+row*totalHeight,daily.Width-S(10),totalHeight-S(2)); + var metricWidth=(traffic.Width-S(8))/2; + var metricTop=showTailnet?S(11):S(15); + var metricHeight=traffic.Height-metricTop-S(1); + Rectangle Speed(int col)=>new(S(4)+col*metricWidth,metricTop,metricWidth-S(1),metricHeight); + Rectangle[] metrics=[Total(0),Speed(0),Speed(1),Total(1)]; + return new(welcome,account,identity,logout,status,node,mode,metrics,traffic,tailnet,trend,daily,server,footer, + viewport.Height,true,1f); + } + + internal static bool SelfTest() + { + foreach (var dpi in new[] { 96, 120, 144, 168, 192, 240, 288, 336, 384 }) + foreach (var width in new[] { 480, 600, 620, 739, 760, 780, 900, 1100, 1600 }) + foreach (var height in new[] { 312, 350, 418, 560, 720 }) + foreach (var showTailnet in new[] { false, true }) + foreach (var showServers in new[] { false, true }) + { + var viewport = new Size(width * dpi / 96, height * dpi / 96); + var p = Calculate(viewport, dpi, showTailnet, showServers); + Rectangle[] cards = [p.StatusCard,p.NodeCard,p.ModeCard,p.TrafficCard,p.SpeedTrendCard,p.DailyCard,p.Footer]; + if(showTailnet)cards=[..cards,p.TailnetTrafficCard]; + if(showServers)cards=[..cards,p.ServerTrafficCard]; + if (cards.Any(c => c.Left < 0 || c.Right > viewport.Width || c.Bottom > p.ContentHeight || c.Width <= 0 || c.Height<=0)) return false; + for (var i = 0; i < cards.Length; i++) + for (var j = i + 1; j < cards.Length; j++) + if (cards[i].IntersectsWith(cards[j])) return false; + if (p.WelcomeLabel.IntersectsWith(p.LogoutButton) || p.AccountLabel.IntersectsWith(p.IdentityBadge)) return false; + if (p.Metrics[0].IntersectsWith(p.Metrics[3]) || p.Metrics[1].IntersectsWith(p.Metrics[2])) return false; + for (var i = 0; i < p.Metrics.Length; i++) + { + var parent=i==0||i==3?p.DailyCard:p.TrafficCard; + if(p.Metrics[i].Left<0||p.Metrics[i].Top<0||p.Metrics[i].Right>parent.Width||p.Metrics[i].Bottom>parent.Height)return false; + } + if (!showTailnet && p.TailnetTrafficCard != Rectangle.Empty) return false; + if (p.ContentHeight > viewport.Height || p.Footer.Bottom > viewport.Height) return false; + var baseline = Calculate(viewport, dpi, false, showServers); + if (p.DailyCard != baseline.DailyCard || p.Footer != baseline.Footer || p.ContentHeight != baseline.ContentHeight) return false; + if (showTailnet && (p.TailnetTrafficCard.Top <= p.TrafficCard.Bottom || p.SpeedTrendCard.Top<=p.TailnetTrafficCard.Bottom)) return false; + if(p.SpeedTrendCard.Bottom!=p.DailyCard.Bottom)return false; + if (showServers && (p.ServerTrafficCard.Top <= p.DailyCard.Bottom || p.ServerTrafficCard.Bottom >= p.Footer.Top)) return false; + } + return true; + } +} diff --git a/windows/DashboardTailnetLayoutSelfTest.cs b/windows/DashboardTailnetLayoutSelfTest.cs index c201dab..5926eb0 100644 --- a/windows/DashboardTailnetLayoutSelfTest.cs +++ b/windows/DashboardTailnetLayoutSelfTest.cs @@ -1,83 +1,92 @@ -namespace UCVL.VPNPlus; - -internal sealed partial class MainForm -{ - // UI fixture only: independent supplied values, no adapter/core/route reads. - internal Dictionary CheckTailnetTrafficUi() - { - var checks = new Dictionary(); - var originalSize = ClientSize; - foreach (var size in new[] { new Size(960, 720), new Size(620, 550), new Size(900, 640) }) - { - ClientSize = new Size(ScaleLogical(size.Width), ScaleLogical(size.Height)); - SetTailnetTrafficVisibility(false); LayoutDashboard(); - var baseline = (_trafficCard.Bounds, _dailyCard.Bounds, _footer.Bounds, _dashboardBody.Size); - checks[$"no_tailnet_single_left_{size.Width}"] = !_tailnetTrafficCard.Visible - && _trafficCard.Top == _dailyCard.Top && _trafficCard.Bottom == _dailyCard.Bottom; - SetTailnetTrafficVisibility(true); - checks[$"tailnet_only_subdivides_left_{size.Width}"] = _tailnetTrafficCard.Left == _trafficCard.Left - && _tailnetTrafficCard.Width == _trafficCard.Width && _tailnetTrafficCard.Top > _trafficCard.Bottom - && _dailyCard.Top == _trafficCard.Top && _dailyCard.Bottom == _tailnetTrafficCard.Bottom; - checks[$"tailnet_never_increases_page_{size.Width}"] = _dailyCard.Bounds == baseline.Item2 - && _footer.Bounds == baseline.Item3 && _dashboardBody.Size == baseline.Item4 - && !_dashboardScrollBar.Visible && _dashboardBody.Location == Point.Empty; - checks[$"all_card_controls_fit_{size.Width}"] = DashboardControlsFit(); - SetTailnetTrafficVisibility(false); - checks[$"tailnet_hide_restores_geometry_{size.Width}"] = _trafficCard.Bounds == baseline.Item1 - && _dailyCard.Bounds == baseline.Item2 && _footer.Bounds == baseline.Item3; - } - SetTailnetTrafficVisibility(true); - var proxyValue = _uploadMetric.ValueText; - var session = (_sessionUp, _sessionDown); - var curveCount = _trafficChart.PointCount; - DisplayTailnetTraffic(12345, 67890, "独立 UI 样本"); - checks["tailnet_never_double_counts_session_or_curve"] = session == (_sessionUp, _sessionDown) - && _trafficChart.PointCount == curveCount; - checks["tailnet_values_are_independent_controls"] = _tailnetUploadMetric.ValueText == "12.06" - && _tailnetDownloadMetric.ValueText == "66.3" && _uploadMetric.ValueText == proxyValue; - checks["tailnet_scope_and_already_accounted_are_explicit"] = _tailnetSampleLabel.Text.StartsWith("仅纵横家链路 · ") - && _tailnetUploadMetric.Hint == "已计入代理总流量"; - DisplayTailnetTraffic(null, double.NaN, "采样不可用"); - checks["tailnet_missing_samples_not_fake_zero"] = _tailnetUploadMetric.ValueText == "—" - && _tailnetDownloadMetric.ValueText == "—"; - DisplayTailnetTraffic(1, 2, "独立 UI 样本"); - SetTailnetTrafficVisibility(false); SetTailnetTrafficVisibility(true); - checks["tailnet_hide_clears_previous_numbers"] = _tailnetUploadMetric.ValueText == "—" - && _tailnetDownloadMetric.ValueText == "—"; - checks["only_one_speed_curve_on_right"] = !_trafficCard.Controls.OfType().Any() - && !_tailnetTrafficCard.Controls.OfType().Any() - && _dailyCard.Controls.OfType().Single() == _trafficChart - && _dailyChart.Parent is null && !_dailyChart.Visible; - UpdateConnectedTransportPresentation(true); - DisplayTraffic(1024, 2048, "互斥入口样本"); - DisplayTailnetTraffic(1024, 2048, "互斥入口样本"); - checks["tailnet_sample_is_not_duplicated_as_public_speed"] = _uploadMetric.ValueText == "—" - && _downloadMetric.ValueText == "—" && _uploadMetric.Hint == "未使用公网入口" - && _tailnetUploadMetric.ValueText == "1" && _tailnetDownloadMetric.ValueText == "2"; - checks["actual_tailnet_transport_shows_section"] = _currentNodeUsesTailnet && _tailnetTrafficVisible; - UpdateConnectedTransportPresentation(false); - DisplayTraffic(3072, 4096, "公网样本"); - checks["public_sample_uses_only_public_speed_section"] = _uploadMetric.ValueText == "3" && _downloadMetric.ValueText == "4"; - checks["public_transport_hides_section"] = !_currentNodeUsesTailnet && !_tailnetTrafficVisible; - using var curve = new TrafficChart(); - var end = DateTimeOffset.Now; - for (var i = 0; i <= 720; i++) curve.Add(i, i * 2, end.AddSeconds((i - 720) * 5)); - checks["speed_history_retains_actual_one_hour"] = curve.PointCount == 721; - curve.SetPeriodMinutes(1); - checks["one_minute_filter_uses_actual_samples"] = curve.VisiblePointCount == 13 && curve.PointCount == 721; - curve.SetPeriodMinutes(5); - checks["five_minute_filter_uses_actual_samples"] = curve.VisiblePointCount == 61; - curve.SetPeriodMinutes(15); - checks["fifteen_minute_filter_uses_actual_samples"] = curve.VisiblePointCount == 181; - curve.SetPeriodMinutes(60); - checks["hour_filter_preserves_available_samples"] = curve.VisiblePointCount == 721; - curve.Add(1, 2, end.AddSeconds(5)); - checks["old_samples_expire_at_one_hour"] = curve.PointCount == 721; - curve.Reset(); - checks["speed_history_reset_has_no_fabricated_samples"] = curve.PointCount == 0 && curve.VisiblePointCount == 0; - ClientSize = originalSize; LayoutDashboard(); - checks["fitted_geometry_448_viewport_dpi_cases"] = DashboardLayout.SelfTest(); - checks["card_surface_remains_half_transparent"] = CardPanel.SurfaceAlpha == 128; - return checks; - } -} +namespace UCVL.VPNPlus; + +internal sealed partial class MainForm +{ + // UI fixture only: independent supplied values, no adapter/core/route reads. + internal Dictionary CheckTailnetTrafficUi() + { + var checks = new Dictionary(); + var originalSize = ClientSize; + foreach (var size in new[] { new Size(480, 360), new Size(900, 360), new Size(960, 720), new Size(620, 550), new Size(900, 640) }) + { + ClientSize = new Size(ScaleLogical(size.Width), ScaleLogical(size.Height)); + SetTailnetTrafficVisibility(false); LayoutDashboard(); + var baseline = (_trafficCard.Bounds, _dailyCard.Bounds, _footer.Bounds, _dashboardBody.Size); + checks[$"no_tailnet_single_left_{size.Width}"] = !_tailnetTrafficCard.Visible + && _trafficCard.Top == _dailyCard.Top && _speedTrendCard.Bottom == _dailyCard.Bottom; + SetTailnetTrafficVisibility(true); + checks[$"tailnet_only_subdivides_left_{size.Width}"] = _tailnetTrafficCard.Left == _trafficCard.Left + && _tailnetTrafficCard.Width == _trafficCard.Width && _tailnetTrafficCard.Top > _trafficCard.Bottom + && _dailyCard.Top == _trafficCard.Top && _dailyCard.Bottom == _speedTrendCard.Bottom; + checks[$"tailnet_never_increases_page_{size.Width}"] = _dailyCard.Bounds == baseline.Item2 + && _footer.Bounds == baseline.Item3 && _dashboardBody.Size == baseline.Item4 + && !_dashboardScrollBar.Visible && _dashboardBody.Location == Point.Empty; + checks[$"all_card_controls_fit_{size.Width}"] = DashboardControlsFit(); + SetTailnetTrafficVisibility(false); + checks[$"tailnet_hide_restores_geometry_{size.Width}"] = _trafficCard.Bounds == baseline.Item1 + && _dailyCard.Bounds == baseline.Item2 && _footer.Bounds == baseline.Item3; + } + ClientSize=new Size(ScaleLogical(480),ScaleLogical(360)); + _connectionModeCombo.SelectedIndex=1; + if(_manualNodeCombo.Items.Count>0)_manualNodeCombo.SelectedIndex=0; + RefreshSelectionControls(); LayoutDashboard(); + checks["half_size_manual_node_does_not_overlap_mode_selector"] = !_manualNodeCombo.Visible + || (!_manualNodeCombo.Bounds.IntersectsWith(_connectionModeCombo.Bounds) + && _manualNodeCombo.Bottom<=_nodeCard.Height); + _connectionModeCombo.SelectedIndex=0; + SetTailnetTrafficVisibility(true); + var proxyValue = _uploadMetric.ValueText; + var session = (_sessionUp, _sessionDown); + var curveCount = _trafficChart.PointCount; + DisplayTailnetTraffic(12345, 67890, "独立 UI 样本"); + checks["tailnet_never_double_counts_session_or_curve"] = session == (_sessionUp, _sessionDown) + && _trafficChart.PointCount == curveCount; + checks["tailnet_values_are_independent_controls"] = _tailnetUploadMetric.ValueText == "12.06" + && _tailnetDownloadMetric.ValueText == "66.3" && _uploadMetric.ValueText == proxyValue; + checks["tailnet_scope_and_already_accounted_are_explicit"] = _tailnetSampleLabel.Text.StartsWith("仅纵横家链路 · ") + && _tailnetUploadMetric.Hint == "已计入代理总流量"; + DisplayTailnetTraffic(null, double.NaN, "采样不可用"); + checks["tailnet_missing_samples_not_fake_zero"] = _tailnetUploadMetric.ValueText == "—" + && _tailnetDownloadMetric.ValueText == "—"; + DisplayTailnetTraffic(1, 2, "独立 UI 样本"); + SetTailnetTrafficVisibility(false); SetTailnetTrafficVisibility(true); + checks["tailnet_hide_clears_previous_numbers"] = _tailnetUploadMetric.ValueText == "—" + && _tailnetDownloadMetric.ValueText == "—"; + checks["cumulative_is_numeric_only_proxy_has_speed_curve"] = !_dailyCard.Controls.OfType().Any() + && !_trafficCard.Controls.OfType().Any() + && !_tailnetTrafficCard.Controls.OfType().Any() + && _speedTrendCard.Controls.OfType().Single() == _trafficChart + && _dailyChart.Parent is null && !_dailyChart.Visible; + UpdateConnectedTransportPresentation(true); + DisplayTraffic(1024, 2048, "互斥入口样本"); + DisplayTailnetTraffic(1024, 2048, "互斥入口样本"); + checks["tailnet_sample_is_not_duplicated_as_public_speed"] = _uploadMetric.ValueText == "—" + && _downloadMetric.ValueText == "—" && _uploadMetric.Hint == "未使用公网入口" + && _tailnetUploadMetric.ValueText == "1" && _tailnetDownloadMetric.ValueText == "2"; + checks["actual_tailnet_transport_shows_section"] = _currentNodeUsesTailnet && _tailnetTrafficVisible; + UpdateConnectedTransportPresentation(false); + DisplayTraffic(3072, 4096, "公网样本"); + checks["public_sample_uses_only_public_speed_section"] = _uploadMetric.ValueText == "3" && _downloadMetric.ValueText == "4"; + checks["public_transport_hides_section"] = !_currentNodeUsesTailnet && !_tailnetTrafficVisible; + using var curve = new TrafficChart(); + var end = DateTimeOffset.Now; + for (var i = 0; i <= 720; i++) curve.Add(i, i * 2, end.AddSeconds((i - 720) * 5)); + checks["speed_history_retains_actual_one_hour"] = curve.PointCount == 721; + curve.SetPeriodMinutes(1); + checks["one_minute_filter_uses_actual_samples"] = curve.VisiblePointCount == 13 && curve.PointCount == 721; + curve.SetPeriodMinutes(5); + checks["five_minute_filter_uses_actual_samples"] = curve.VisiblePointCount == 61; + curve.SetPeriodMinutes(15); + checks["fifteen_minute_filter_uses_actual_samples"] = curve.VisiblePointCount == 181; + curve.SetPeriodMinutes(60); + checks["hour_filter_preserves_available_samples"] = curve.VisiblePointCount == 721; + curve.Add(1, 2, end.AddSeconds(5)); + checks["old_samples_expire_at_one_hour"] = curve.PointCount == 721; + curve.Reset(); + checks["speed_history_reset_has_no_fabricated_samples"] = curve.PointCount == 0 && curve.VisiblePointCount == 0; + ClientSize = originalSize; LayoutDashboard(); + checks["fitted_geometry_448_viewport_dpi_cases"] = DashboardLayout.SelfTest(); + checks["card_surface_remains_half_transparent"] = CardPanel.SurfaceAlpha == 128; + return checks; + } +} diff --git a/windows/MainForm.Compact.cs b/windows/MainForm.Compact.cs new file mode 100644 index 0000000..0d8d394 --- /dev/null +++ b/windows/MainForm.Compact.cs @@ -0,0 +1,135 @@ +namespace UCVL.VPNPlus; + +internal sealed partial class MainForm +{ + // A compact logical canvas; native DPI scaling still happens exactly once. + private bool CompactPresentation => ClientSize.Width < ScaleLogical(720) || ClientSize.Height < ScaleLogical(550); + private readonly Font _compactStatusFont=Brand.Font(10,FontStyle.Bold); + private readonly Font _compactChartFont=Brand.Font(6.5f); + private readonly Dictionary _presentationFonts = new(); + private bool _presentationFontsDisposed; + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if(!disposing || _presentationFontsDisposed)return; + _presentationFontsDisposed=true; + foreach(var fonts in _presentationFonts.Values)fonts.Compact?.Dispose(); + _presentationFonts.Clear(); + _compactStatusFont.Dispose(); + _compactChartFont.Dispose(); + } + private void SetStatusTitleFont(float size) + { + if(CompactPresentation && ReferenceEquals(_statusTitle.Font,_compactStatusFont))return; + if(!CompactPresentation && !ReferenceEquals(_statusTitle.Font,_compactStatusFont) + && Math.Abs(_statusTitle.Font.SizeInPoints-size)<.1f)return; + var previous=_statusTitle.Font; + _statusTitle.Font=CompactPresentation?_compactStatusFont:Brand.Font(size,FontStyle.Bold); + if(!ReferenceEquals(previous,_compactStatusFont))previous.Dispose(); + } + private void ApplyCompactTypography() + { + void Visit(Control parent) + { + foreach (Control control in parent.Controls) + { + if (control is CaptionButton || ReferenceEquals(control,_statusTitle)) continue; + if (!_presentationFonts.TryGetValue(control, out var fonts)) + { + var original = control.Font; + fonts = (original, new Font(original.FontFamily, Math.Max(6.5f, original.SizeInPoints * .78f), original.Style)); + _presentationFonts.Add(control, fonts); + } + control.Font = CompactPresentation ? fonts.Compact! : fonts.Original; + Visit(control); + } + } + Visit(this); + } + + private void LayoutCompactHeader() + { + int S(int n) => ScaleLogical(n); + _brandHeader.Height=S(48); + foreach(Control control in _brandHeader.Controls) + { + if(control.Tag is not Rectangle)continue; + if(control is PictureBox)control.Bounds=new(S(10),S(5),S(34),S(37)); + else if(control is Label label && label.Text=="纵横家")control.Bounds=new(S(52),S(5),S(180),S(25)); + else control.Bounds=new(S(53),S(28),S(260),S(15)); + } + _headerPoem.Visible=false; + LayoutWindowChrome(); + } + + private void LayoutCompactLogin() + { + int S(int n)=>ScaleLogical(n); + _loginView.Size=new(S(400),S(280)); + foreach(Control control in _loginView.Controls) + if(control.Tag is Rectangle r) + control.Bounds=new(S((int)Math.Round(r.X*400d/440)),S((int)Math.Round(r.Y*.72)), + S((int)Math.Round(r.Width*400d/440)),S(Math.Max(14,(int)Math.Round(r.Height*.72)))); + // Text boxes and the primary action keep comfortable compact hit areas. + _loginText.Parent!.Bounds=new(S(25),S(65),S(350),S(29)); + _passwordText.Parent!.Bounds=new(S(25),S(117),S(350),S(29)); + _loginButton.Bounds=new(S(25),S(160),S(350),S(31)); + var flags=TextFormatFlags.SingleLine; + var prompt=TextRenderer.MeasureText(_registerPrompt.Text,_registerPrompt.Font,Size.Empty,flags); + var link=TextRenderer.MeasureText(_registerLink.Text,_registerLink.Font,Size.Empty,flags); + var rowWidth=prompt.Width+link.Width+S(16); + var left=(_loginView.Width-rowWidth)/2; + _registerPrompt.Bounds=new(left,S(199),prompt.Width+S(4),S(20)); + _registerLink.Bounds=new(_registerPrompt.Right+S(8),S(199),link.Width+S(4),S(20)); + foreach(Control control in _loginView.Controls) + { + if(control is Label label && label.Text.StartsWith("浏览器完成注册"))control.Bounds=new(S(20),S(226),S(360),S(18)); + } + _loginError.Bounds=new(S(20),S(248),S(360),S(24)); + _loginView.Left=Math.Max(S(8),(_content.Width-_loginView.Width)/2); + _loginView.Top=Math.Max(S(8),(_content.Height-_loginView.Height)/2); + } + + private void LayoutCompactDashboard(DashboardGeometry layout) + { + int S(int n)=>ScaleLogical(n); + Rectangle R(int x,int y,int w,int h)=>new(S(x),S(y),S(w),S(h)); + _statusDot.Bounds=R(10,8,24,24); + _connectButton.Bounds=new(_statusCard.Width-S(68),S(7),S(60),S(26)); + _statusTitle.Bounds=new(S(42),S(1),_statusCard.Width-S(116),S(21)); + _statusDetail.Bounds=new(S(42),S(22),_statusCard.Width-S(116),S(15)); + _nodeIcon.Visible=_modeIcon.Visible=false; + _nodeHeading.Bounds=R(8,0,122,15); + _nodeHeading.Text="工作节点"; + _connectionModeCombo.Bounds=new(_nodeCard.Width-S(102),S(1),S(96),S(18)); + _manualNodeCombo.Bounds=new(S(8),S(22),_nodeCard.Width-S(16),S(19)); + _currentNodeLabel.Bounds=new(S(8),S(23),_nodeCard.Width-S(16),S(17)); + _scheduleBadge.Visible=false; + _routeHeading.Bounds=new(S(8),0,_modeCard.Width-S(16),S(14)); + _routeCombo.Bounds=new(S(8),S(14),_modeCard.Width-S(16),S(20)); + _routeReadOnly.Bounds=_routeCombo.Bounds; + _trafficIcon.Visible=_dailyIcon.Visible=_tailnetTrafficIcon.Visible=false; + _trafficHeading.Bounds=new(S(6),0,_trafficCard.Width-S(12),S(13)); + _dailyHeading.Bounds=new(S(7),S(2),_dailyCard.Width-S(14),S(17)); + _tailnetTrafficHeading.Bounds=new(S(6),0,_tailnetTrafficCard.Width-S(12),S(13)); + if(_tailnetTrafficVisible) + { + var width=(_tailnetTrafficCard.Width-S(8))/2; + _tailnetUploadMetric.Bounds=new(S(4),S(11),width-S(1),S(18)); + _tailnetDownloadMetric.Bounds=new(S(4)+width,S(11),width-S(1),S(18)); + } + _trendHeading.Bounds=new(S(6),0,_speedTrendCard.Width-S(88),S(15)); + _historyRangeCombo.Bounds=new(_speedTrendCard.Width-S(82),0,S(77),S(19)); + _trafficChart.Font=_compactChartFont; + _trafficChart.Bounds=new(S(1),S(18),_speedTrendCard.Width-S(3),Math.Max(S(30),_speedTrendCard.Height-S(19))); + _uploadLegend.Visible=_downloadLegend.Visible=_historyStatus.Visible=false; + _sampleLabel.Visible=false; + _planLabel.Bounds=new(0,0,_footer.Width-S(75),S(11)); + _expiryLabel.Bounds=new(_footer.Width-S(72),0,S(72),S(11)); + _footerCompanySite.Bounds=new(0,S(11),S(210),S(11)); + _footerHint.Bounds=new(_footer.Width-S(205),S(11),S(205),S(11)); + _footerPoem.Visible=false; + _dashboardBody.Size=_dashboardView.ClientSize; + _dashboardBody.Location=Point.Empty; + } +} diff --git a/windows/MainForm.Dashboard.cs b/windows/MainForm.Dashboard.cs index 58e37e8..8e961f9 100644 --- a/windows/MainForm.Dashboard.cs +++ b/windows/MainForm.Dashboard.cs @@ -1,422 +1,441 @@ -using System.Text.Json; - -namespace UCVL.VPNPlus; - -internal sealed partial class MainForm -{ - private readonly BadgeLabel _identityBadge = new(); - private readonly BadgeLabel _scheduleBadge = new(); - private readonly Label _sampleLabel = new(); - private readonly Label _uploadLegend = new(); - private readonly Label _downloadLegend = new(); - private readonly Label _historyStatus = new(); - private readonly ReadOnlyModeLabel _routeReadOnly = new(); - private readonly ComboBox _historyRangeCombo = new(); - private readonly Label _footerHint = new(); - private readonly Label _footerPoem = new(); - private readonly PictureBox _footerCompanyLogo = new(); - private readonly Label _footerCompanySite = new(); - private readonly CardPanel _nodeCard = new(), _modeCard = new(), _trafficCard = new(), _dailyCard = new(); - private readonly ScenicPanel _footer = new() { FooterArtwork = true }; - private readonly ScenicPanel _dashboardBody = new(); - private readonly VScrollBar _dashboardScrollBar = new(); - private readonly MetricCard _usageMetric = new("本期代理流量", DashboardIcon.Database); - private readonly MetricCard _uploadMetric = new("上传速度", DashboardIcon.Upload); - private readonly MetricCard _downloadMetric = new("下载速度", DashboardIcon.Download); - private readonly MetricCard _sessionMetric = new("本次代理流量", DashboardIcon.Document); - private readonly DashboardGlyph _nodeIcon = new(DashboardIcon.Server), _modeIcon = new(DashboardIcon.Settings); - private readonly DashboardGlyph _trafficIcon = new(DashboardIcon.Chart), _dailyIcon = new(DashboardIcon.History); - private readonly Label _trafficHeading = new(), _dailyHeading = new(); - private bool _layingOutDashboard; - private sealed record SpeedHistoryPeriod(int Minutes, string Label) - { - public override string ToString() => Label; - internal static readonly SpeedHistoryPeriod[] All = [new(1, "近 1 分钟"), new(5, "近 5 分钟"), new(15, "近 15 分钟"), new(60, "近 1 小时")]; - } - - private void BuildDashboardView() - { - _dashboardView.Dock = DockStyle.Fill; - _dashboardView.BackColor = Brand.Surface; - _dashboardView.LoginArtwork = true; - _dashboardView.AutoScroll = false; - _dashboardView.Visible = false; - _dashboardView.Resize += (_, _) => LayoutDashboard(); - _content.Controls.Add(_dashboardView); - _dashboardBody.BackColor = Brand.Surface; - _dashboardBody.ParentArtwork = true; - _dashboardView.Controls.Add(_dashboardBody); - _dashboardView.Controls.Add(_dashboardScrollBar); - _dashboardScrollBar.AccessibleName = "主界面垂直滚动"; - _dashboardScrollBar.ValueChanged += (_, _) => - { - _dashboardBody.Top = -_dashboardScrollBar.Value; - // Child surfaces use the viewport's fixed backdrop coordinates. - // Moving a canvas must repaint them, not bit-blit old transparent pixels. - _dashboardBody.Invalidate(true); - }; - ConfigureLabel(_welcomeLabel, "", Brand.Font(15, FontStyle.Bold), Brand.Navy); - ConfigureLabel(_accountLabel, "", Brand.Font(9.5f), Brand.Muted); - ConfigureLabel(_identityBadge, "", Brand.Font(8.5f), Brand.RoyalBlue); - ConfigureLabel(_scheduleBadge, "AI 自动调度", Brand.Font(8, FontStyle.Bold), Brand.RoyalBlue); - foreach (var badge in new[] { _identityBadge, _scheduleBadge }) - { - badge.BackColor = Color.FromArgb(226, 239, 255); - badge.TextAlign = ContentAlignment.MiddleCenter; - } - ConfigureSecondaryButton(_logoutButton, "退出账号", Point.Empty, new(104, 34)); - _logoutButton.ForeColor = Brand.RoyalBlue; - _logoutButton.Click += async (_, _) => await LogoutAsync(); - _dashboardBody.Controls.AddRange([_welcomeLabel, _accountLabel, _identityBadge, _logoutButton]); - - ConfigureLabel(_statusTitle, "未连接", Brand.Font(17, FontStyle.Bold), Brand.Text); - ConfigureLabel(_statusDetail, "点击连接,自动选择工作节点", Brand.Font(9.5f), Brand.Muted); - _statusDot.ForeColor = Brand.Muted; - _statusCard.ScenicStatus = true; - _nodeCard.AccentBar = _modeCard.AccentBar = true; - _trafficCard.MetricBand = _dailyCard.MetricBand = false; - ConfigurePrimaryButton(_connectButton, "连接", Point.Empty, new(130, 42)); - _connectButton.Click += async (_, _) => - { - if (!_busy && !_wantConnected && !_handoverOperating) - _tailnetPreference.ResetForUserConnect(); - await ToggleConnectionAsync(); - }; - _statusCard.Controls.AddRange([_statusDot, _statusTitle, _statusDetail, _connectButton]); - ConfigureLabel(_nodeHeading, "当前工作节点", Brand.Font(9), Brand.Text); - ConfigureLabel(_routeHeading, "代理模式", Brand.Font(9), Brand.Text); - ConfigureLabel(_currentNodeLabel, "连接后自动分配", Brand.Font(12, FontStyle.Bold), Brand.RoyalBlue); - _nodeCard.Controls.AddRange([_nodeIcon, _nodeHeading, _currentNodeLabel, _scheduleBadge]); - BuildConnectionSelection(); - ConfigureCombo(_routeCombo, Point.Empty, new(220, 30)); - _routeCombo.BackColor = Color.White; - _routeCombo.AccessibleName = "代理模式(连接时不可更改)"; - _routeReadOnly.Visible = false; - _modeCard.Controls.AddRange([_modeIcon, _routeHeading, _routeCombo, _routeReadOnly]); - - ConfigureLabel(_trafficHeading, "公网入口速度", Brand.Font(9.5f, FontStyle.Bold), Brand.Text); - _trafficCard.AccessibleDescription = "仅当前纵横家使用域名或公网入口的代理速度;Tailscale 入口速度另列,非整机流量。"; - ConfigureLabel(_dailyHeading, "速度与累计", Brand.Font(9.5f, FontStyle.Bold), Brand.Text); - ConfigureLabel(_sampleLabel, "仅代理流量 · 近 5 分钟", Brand.Font(7.5f), Brand.Muted); - _sampleLabel.TextAlign = ContentAlignment.MiddleRight; - ConfigureLabel(_uploadLegend, "● 上传 —", Brand.Font(8), Brand.RoyalBlue); - ConfigureLabel(_downloadLegend, "● 下载 —", Brand.Font(8), Brand.Cyan); - ConfigureLabel(_historyStatus, "仅本次运行采样 · B/s", Brand.Font(7), Brand.Muted); - _historyStatus.AutoEllipsis = true; - _historyStatus.TextAlign = ContentAlignment.MiddleRight; - _historyStatus.AccessibleDescription = "右侧曲线仅为当前客户端实际采集的代理速度。累计数值来自套餐和本次连接,不随速度时间范围改变。"; - _trafficCard.Controls.AddRange([_trafficIcon, _trafficHeading]); - _dailyCard.Controls.AddRange([_dailyIcon, _dailyHeading, _trafficChart, _uploadLegend, _downloadLegend]); - // Keep backend accounting data available to UpdateProfile, but daily - // byte totals are no longer drawn as a misleading speed history. - _dailyChart.Visible = false; - ConfigureCombo(_historyRangeCombo, Point.Empty, new(120, 28)); - _historyRangeCombo.BackColor = Color.White; - _historyRangeCombo.Font = Brand.Font(8.5f); - _historyRangeCombo.DrawMode = DrawMode.OwnerDrawFixed; - _historyRangeCombo.DrawItem += (_, e) => - { - if (e.Index < 0) return; - var highlight = _historyRangeCombo.DroppedDown && (e.State & DrawItemState.Selected) != 0; - using var fill = new SolidBrush(highlight ? Brand.PaleBlue : Color.White); - e.Graphics.FillRectangle(fill, e.Bounds); - TextRenderer.DrawText(e.Graphics, _historyRangeCombo.Items[e.Index]?.ToString() ?? "", _historyRangeCombo.Font, - e.Bounds, Brand.Text, TextFormatFlags.VerticalCenter | TextFormatFlags.Left | TextFormatFlags.EndEllipsis); - e.DrawFocusRectangle(); - }; - _historyRangeCombo.AccessibleName = "代理实时速度时间范围"; - _historyRangeCombo.Items.AddRange(SpeedHistoryPeriod.All); - _historyRangeCombo.SelectedItem = SpeedHistoryPeriod.All[1]; - _historyRangeCombo.SelectedIndexChanged += (_, _) => - { - if (_historyRangeCombo.SelectedItem is SpeedHistoryPeriod period) _trafficChart.SetPeriodMinutes(period.Minutes); - }; - _dailyCard.Controls.AddRange([_historyRangeCombo, _historyStatus]); - ConfigureLabel(_planLabel, "", Brand.Font(8.5f), Brand.Muted); - ConfigureLabel(_expiryLabel, "", Brand.Font(8.5f), Brand.Muted); - ConfigureLabel(_footerHint, "仅限内部使用,不作商业使用。", Brand.Font(9, FontStyle.Bold), Brand.DeepBlue); - _footerHint.TextAlign = ContentAlignment.MiddleRight; - ConfigureLabel(_footerPoem, "— 科技守护连接 · 让世界更近 —", new Font("KaiTi", 11.5f), Brand.Muted); - _footerPoem.TextAlign = ContentAlignment.MiddleRight; - _footerCompanyLogo.Image = LoadCompanyLogo(); - _footerCompanyLogo.SizeMode = PictureBoxSizeMode.Zoom; - ConfigureLabel(_footerCompanySite, "vpn.example.invalid", Brand.Font(8), Brand.Muted); - _footerCompanyLogo.BackColor = Color.Transparent; - _footer.Controls.AddRange([_planLabel, _expiryLabel, _footerHint, _footerPoem, _footerCompanyLogo, _footerCompanySite]); - foreach (var card in new CardPanel[] { _statusCard, _nodeCard, _modeCard, _trafficCard, _dailyCard }) - { - card.BackColor = Color.White; - _dashboardBody.Controls.Add(card); - } - foreach (var metric in new[] { _usageMetric, _sessionMetric, _uploadMetric, _downloadMetric }) metric.Embedded = true; - _trafficCard.Controls.AddRange([_uploadMetric, _downloadMetric]); - _dailyCard.Controls.AddRange([_usageMetric, _sessionMetric]); - BuildTailnetTrafficCard(); - BuildNodeTrafficMonitor(); - _dashboardBody.Controls.Add(_footer); - foreach (var label in new[] { _welcomeLabel, _accountLabel, _statusTitle, _statusDetail, _currentNodeLabel, _planLabel, _expiryLabel }) - { - label.AutoEllipsis = true; - label.TextAlign = ContentAlignment.MiddleLeft; - } - _sessionMetric.SetBytes(0, hint: "本次连接累计"); - DisplayTraffic(null, null, "仅代理流量 · 近 5 分钟"); - // The dashboard is one fitted page; no hidden vertical or horizontal - // canvas is introduced by Tailnet, and mouse-wheel cannot shift it. - LayoutDashboard(); - } - - private void DisplayTraffic(double? upload, double? download, string sampling) - { - var publicUpload = _currentNodeUsesTailnet ? null : upload; - var publicDownload = _currentNodeUsesTailnet ? null : download; - var hint = _currentNodeUsesTailnet ? "未使用公网入口" : ""; - _uploadMetric.SetBytes(publicUpload, speed: true, hint: hint); - _downloadMetric.SetBytes(publicDownload, speed: true, hint: hint); - _sampleLabel.Text = sampling; - _uploadLegend.Text = upload.HasValue ? $"● 上传 {FormatBytes((long)upload.Value)}/s" : "● 上传 —"; - _downloadLegend.Text = download.HasValue ? $"● 下载 {FormatBytes((long)download.Value)}/s" : "● 下载 —"; - // Waiting/handover/error paths also invalidate the separate transport - // view. Valid samples are supplied once by the existing traffic reader. - if (!upload.HasValue || !download.HasValue) DisplayTailnetTraffic(null, null, sampling); - } - - private void LayoutDashboard() - { - if (_layingOutDashboard || _dashboardView.ClientSize.Width <= 0) return; - _layingOutDashboard = true; - Control[] layoutContainers = [_dashboardView, _dashboardBody, _statusCard, _nodeCard, _modeCard, _trafficCard, _tailnetTrafficCard, _dailyCard, _nodeTrafficPanel, _footer]; - foreach (var container in layoutContainers) container.SuspendLayout(); - try - { - var viewport = _dashboardView.ClientSize; - var layout = DashboardLayout.Calculate(viewport, DeviceDpi, _tailnetTrafficVisible, _canViewNodeTraffic); - var titleSize = 17f * Math.Max(.7f, layout.VerticalScale); - if (Math.Abs(_statusTitle.Font.Size - titleSize) > .1f) - { - var previousTitleFont = _statusTitle.Font; - _statusTitle.Font = Brand.Font(titleSize, FontStyle.Bold); - previousTitleFont.Dispose(); - } - _dashboardScrollBar.Visible = false; - _dashboardScrollBar.Value = 0; - _dashboardScrollBar.Maximum = 0; - int Y(int value) => Math.Max(0, (int)Math.Floor(ScaleLogical(value) * layout.VerticalScale)); - void Place(Control c, Rectangle r) { c.Bounds = r; } - Rectangle R(int x, int y, int w, int h) => new(ScaleLogical(x), Y(y), ScaleLogical(w), Y(h)); - Place(_welcomeLabel, layout.WelcomeLabel); Place(_accountLabel, layout.AccountLabel); - Place(_identityBadge, layout.IdentityBadge); Place(_logoutButton, layout.LogoutButton); - Place(_statusCard, layout.StatusCard); Place(_nodeCard, layout.NodeCard); Place(_modeCard, layout.ModeCard); - var metrics = new[] { _usageMetric, _uploadMetric, _downloadMetric, _sessionMetric }; - for (var i = 0; i < 4; i++) Place(metrics[i], layout.Metrics[i]); - Place(_trafficCard, layout.TrafficCard); Place(_dailyCard, layout.DailyCard); Place(_footer, layout.Footer); - Place(_nodeTrafficPanel, layout.ServerTrafficCard); - LayoutTailnetTrafficCard(layout.TailnetTrafficCard, layout.VerticalScale); - - _statusDot.Bounds = R(24, 15, 42, 46); - _connectButton.Bounds = new(_statusCard.Width - ScaleLogical(148), Y(17), ScaleLogical(130), Y(42)); - var textWidth = _connectButton.Left - ScaleLogical(100); - _statusTitle.Bounds = new(ScaleLogical(84), Y(10), textWidth, Y(33)); - _statusDetail.Bounds = new(ScaleLogical(85), Y(43), textWidth, Y(25)); - _nodeIcon.Bounds = R(26, 23, 24, 24); _modeIcon.Bounds = R(26, 23, 24, 24); - _nodeHeading.Bounds = new(ScaleLogical(54), Y(9), Math.Max(0, _nodeCard.Width - ScaleLogical(205)), Y(23)); - _nodeHeading.Text = layout.Compact ? "工作节点" : "当前工作节点"; - _connectionModeCombo.Bounds = new(_nodeCard.Width - ScaleLogical(144), Y(6), ScaleLogical(130), Y(28)); - _manualNodeCombo.Bounds = new(ScaleLogical(54), Y(34), _nodeCard.Width - ScaleLogical(68), Y(28)); - var badgeWidth = ScaleLogical(88); - var badgeX = _nodeCard.Width - badgeWidth - ScaleLogical(14); - _currentNodeLabel.Bounds = new(ScaleLogical(54), Y(34), - _selectionUiConnected ? _nodeCard.Width - ScaleLogical(68) : badgeX - ScaleLogical(60), Y(27)); - _scheduleBadge.Bounds = new(badgeX, Y(35), badgeWidth, Y(23)); - _routeHeading.Bounds = new(ScaleLogical(54), Y(8), _modeCard.Width - ScaleLogical(70), Y(22)); - _routeCombo.Bounds = new(ScaleLogical(54), Y(33), _modeCard.Width - ScaleLogical(70), Y(28)); - _routeReadOnly.Bounds = new(_routeCombo.Left, _routeCombo.Top, _routeCombo.Width, Y(28)); - _trafficIcon.Bounds = R(15, 10, 20, 20); _dailyIcon.Bounds = R(15, 10, 20, 20); - _trafficHeading.Bounds = R(42, 8, 150, 26); - _dailyHeading.Bounds = new(ScaleLogical(42), Y(8), Math.Max(1, _dailyCard.Width - ScaleLogical(166)), Y(26)); - _historyRangeCombo.Bounds = new(_dailyCard.Width - ScaleLogical(120), Y(8), ScaleLogical(106), Y(26)); - _trafficChart.Bounds = new(ScaleLogical(10), Y(127), _dailyCard.Width - ScaleLogical(20), Y(105)); - var legendWidth = (_dailyCard.Width - ScaleLogical(28)) / 2; - _uploadLegend.Bounds = new(ScaleLogical(14), Y(234), legendWidth, Y(19)); - _downloadLegend.Bounds = new(ScaleLogical(14) + legendWidth, Y(234), legendWidth, Y(19)); - _historyStatus.Bounds = new(ScaleLogical(14), Y(255), _dailyCard.Width - ScaleLogical(28), Y(17)); - _planLabel.Bounds = R(0, 4, 300, 26); - _expiryLabel.Bounds = R(306, 4, 132, 26); - _footerCompanyLogo.Bounds = R(0, 34, 32, 34); - _footerCompanySite.Bounds = R(0, 41, 220, 22); - _footerHint.Visible = true; - _footerHint.Bounds = new(ScaleLogical(232), Y(39), Math.Max(1, _footer.Width - ScaleLogical(232)), Y(28)); - _footerPoem.Visible = !layout.Compact && _footer.Width >= ScaleLogical(780); - _footerPoem.Bounds = new(_footer.Width - ScaleLogical(322), Y(5), ScaleLogical(322), Y(29)); - _dashboardBody.Size = viewport; - _dashboardBody.Location = Point.Empty; - } - finally - { - foreach (var container in layoutContainers.Reverse()) container.ResumeLayout(false); - _layingOutDashboard = false; - } - } - - // Isolated synthetic fixture: no stored account, core, system proxy, update query or installation. - internal static void RenderPreview() - { - using var form = new MainForm(preview: true) { Opacity = 0, ShowInTaskbar = false }; - form.Show(); - form.ShowDashboard(new Profile - { - DisplayName = "示例用户", Email = "demo@example.com", IdentityType = "employee", - Subscription = new SubscriptionInfo { Plan = "员工福利", UsedBytes = 17480516895, DeviceLimit = 3 }, - Nodes = [new NodeInfo { Name = "VPN003", Slug = "preview", Status = "online" }], - RouteModes = [new RouteModeInfo { Id = "smart", Name = "AI 智能代理" }], - UsageHistory = Enumerable.Range(0, 7).Select(i => new DailyUsage { Day = DateTime.Today.AddDays(i - 6).ToString("yyyy-MM-dd"), UploadBytes = new long[] { 14000000, 0, 0, 0, 3000000, 35000000, 196000000 }[i], DownloadBytes = new long[] { 28000000, 0, 0, 0, 26000000, 158000000, 126000000 }[i] }).ToList() - }); - form._refreshTimer.Stop(); - var fixtureRanges = UsageHistoryPeriod.All.ToDictionary(p => p.Key, p => new UsageHistorySeries - { - Bucket = p.Bucket, Note = p.Bucket == "hour" ? "演示数据 · 按上报入账小时;缺口为无明细" : "演示数据 · 月筛选为近30个自然日", - Points = Enumerable.Range(0, p.Count).Select(i => new UsageHistoryPoint - { - Time = p.Bucket == "hour" ? new DateTimeOffset(2026, 9, 9, 21, 0, 0, TimeSpan.FromHours(8)).AddHours(i - p.Count + 1).ToString("O") - : new DateOnly(2026, 9, 9).AddDays(i - p.Count + 1).ToString("yyyy-MM-dd"), - UploadBytes = p.Bucket == "hour" && i == 3 ? null : (long)((Math.Sin(i * .72) + 1.1) * 60_000_000), - DownloadBytes = p.Bucket == "hour" && i == 3 ? null : (long)((Math.Cos(i * .81) + 1.1) * 84_000_000) - }).ToList() - }); - form._currentNodeLabel.Text = "VPN003"; - form.SetConnectionState(true, "已安全连接", "VPN003 · AI 智能代理"); - form.DisplayTraffic(91975, 23357, "21:13:00 · 近 5 分钟"); - form._sessionMetric.SetBytes(130180710, hint: "本次连接累计"); - for (var i = 0; i < 60; i++) form._trafficChart.Add((i % 13 == 0 ? 72 : 8 + Math.Sin(i * 1.8) * 4) * 1024, - (i % 9 == 2 ? 130 : 10 + Math.Sin(i * 2.4) * 8) * 1024, DateTimeOffset.Now.AddSeconds((i - 59) * 5)); - form.LayoutBrandHeader(); form.LayoutDashboard(); - var checks = new Dictionary { ["geometry_112_viewport_dpi_cases"] = DashboardLayout.SelfTest() }; - foreach (var check in UsageHistorySeries.SelfTest()) checks[check.Key] = check.Value; - void Capture(string suffix) - { - form.PerformLayout(); form.LayoutDashboard(); Application.DoEvents(); - using var image = new Bitmap(form.Width, form.Height); - form.DrawToBitmap(image, new Rectangle(Point.Empty, image.Size)); - image.Save(Path.Combine(AppContext.BaseDirectory, $"preview-{GetDisplayVersion()}-{suffix}.png")); - } - Capture("dashboard"); - form._currentNodeName = NodePresentation.JinanName; - form._currentNodeLabel.Text = form._currentNodeName; - form.SetConnectionState(true, "已安全连接", form._currentNodeName + " · AI 智能代理"); - Capture("zero3-connected"); - checks["zero3_connected_name_fits"] = TextRenderer.MeasureText(form._currentNodeName, form._currentNodeLabel.Font).Width <= form._currentNodeLabel.Width; - checks["dashboard_controls_within_cards"] = form.DashboardControlsFit(); - checks["footer_slogan_displays_without_company_brand"] = !form._brandHeader.Controls.Contains(form._footerCompanyLogo) - && form._footerCompanyLogo.Parent == form._footer && !form._footerCompanyLogo.Visible; - checks["footer_slogan_text_has_no_url"] = form._footerCompanySite.Visible && form._footerCompanySite.Text == "智能连接 · 高效办公" - && !form._footerCompanySite.Text.Contains("vpn.", StringComparison.OrdinalIgnoreCase) - && !form._footerCompanySite.Text.Contains("://", StringComparison.OrdinalIgnoreCase); - checks["official_header_logo_preserved"] = form._brandHeader.Controls.OfType().Any(logo => logo.Visible && logo.Image is not null - && logo.SizeMode == PictureBoxSizeMode.Zoom && logo.Tag is Rectangle bounds && bounds == new Rectangle(20, 29, 62, 67) - && logo.Bounds == new Rectangle(form.ScaleLogical(20), form.ScaleLogical(29), form.ScaleLogical(62), form.ScaleLogical(67))); - checks["product_header_named_zonghengjia"] = form.Text == "纵横家" && form._brandHeader.Controls.OfType