mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 04:33:45 +08:00
Compare commits
2447 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
84fbccbfd9 | ||
|
49c81f6201 | ||
|
c894a15d13 | ||
|
196b887381 | ||
|
2ad20ed239 | ||
|
98de91771e | ||
|
9dfd9bad20 | ||
|
0b8d08d13b | ||
|
0de304d4e3 | ||
|
55f1766ebc | ||
|
6d1a8fb264 | ||
|
d3958594d9 | ||
|
b5952f320b | ||
|
98be9621a6 | ||
|
e4eb13ce22 | ||
|
ecf2da7c0a | ||
|
7d7c8988d7 | ||
|
5e11d36972 | ||
|
3039f39d40 | ||
|
7b5fd104de | ||
|
30ea408019 | ||
|
3fa130695c | ||
|
fece31438a | ||
|
ad1f2bea3b | ||
|
cd4bfdd743 | ||
|
cde8c4004f | ||
|
c53514e060 | ||
|
8e99672265 | ||
|
5b9b5cb6a8 | ||
|
62141380d8 | ||
|
52a15bb281 | ||
|
b092f74c88 | ||
|
937f43c270 | ||
|
9b02088918 | ||
|
1bd503a654 | ||
|
c6477dfda4 | ||
|
4831d88467 | ||
|
9ebde802d4 | ||
|
a9cccc7b97 | ||
|
d54a765bd6 | ||
|
5a2751162f | ||
|
492a5a6de7 | ||
|
f6c0f144a6 | ||
|
1c046f3ca3 | ||
|
4a47c5bb6f | ||
|
b7e01aefb4 | ||
|
e8e16f7d57 | ||
|
59caa22431 | ||
|
e2046f3e48 | ||
|
8fdcffc731 | ||
|
3ec77c6256 | ||
|
b09313756e | ||
|
f800e2e3b6 | ||
|
daad623855 | ||
|
7716e2bc87 | ||
|
70bd5ec03c | ||
|
ce5c86c3b0 | ||
|
a6a6d9d036 | ||
|
971dd6a2cf | ||
|
42d0ea7e36 | ||
|
006bcffe8c | ||
|
ff4101fa47 | ||
|
7280635741 | ||
|
7ede91599c | ||
|
6e40dd9862 | ||
|
42db9ea0bb | ||
|
ca0cf4552c | ||
|
d91653b218 | ||
|
1ace560531 | ||
|
81968a579d | ||
|
5a0eb56f70 | ||
|
804fad6083 | ||
|
98d3a48710 | ||
|
0ec4f46052 | ||
|
a891341e35 | ||
|
10426af3ad | ||
|
5be1d604ee | ||
|
1baa840160 | ||
|
14347f60d5 | ||
|
df5424d55e | ||
|
12065330e1 | ||
|
e054ac67fb | ||
|
31a7750482 | ||
|
2e38307f65 | ||
|
47accdd2b1 | ||
|
cb0146573f | ||
|
cf78bb3686 | ||
|
b5b5ae4e7b | ||
|
b99bc7fcd1 | ||
|
f50fe9159d | ||
|
09f6917638 | ||
|
e330d75a89 | ||
|
4f0ce7458e | ||
|
a2811c4803 | ||
|
1c233783a7 | ||
|
3e45cc4650 | ||
|
1a7c076e07 | ||
|
da4fddf150 | ||
|
970eb62aa6 | ||
|
d669650758 | ||
|
69347160e9 | ||
|
a345b54a77 | ||
|
8aabcd77a5 | ||
|
c30f54609d | ||
|
0830236a73 | ||
|
44f21444bb | ||
|
1d88d98ea1 | ||
|
86f69fd574 | ||
|
e21846a2ce | ||
|
d5981ca94f | ||
|
8c5eb3b550 | ||
|
55dc416109 | ||
|
ec30b888d1 | ||
|
2a92755e65 | ||
|
6976ea3c09 | ||
|
b07ed2dbf5 | ||
|
2ab923da87 | ||
|
9799d4f747 | ||
|
f739836891 | ||
|
a28887be8e | ||
|
0f13691ae0 | ||
|
ae72b83dbe | ||
|
2e38404434 | ||
|
11b8c8be45 | ||
|
a06597a3a6 | ||
|
108840c4be | ||
|
16c8672aeb | ||
|
167edcf8ef | ||
|
d6dd89b674 | ||
|
fac2ee6374 | ||
|
dd7876845a | ||
|
56e6139c2b | ||
|
04bdd48a2a | ||
|
5b47fe5b88 | ||
|
84a5cf6b89 | ||
|
618ba52bca | ||
|
5c0cde517f | ||
|
1b249564a3 | ||
|
81b5501b0e | ||
|
91ccb3045c | ||
|
e31f176c25 | ||
|
ad45485009 | ||
|
25e5cf2ac2 | ||
|
bd58d935c6 | ||
|
da2705ff7d | ||
|
61f019f194 | ||
|
74e441df5b | ||
|
772ecdd3b0 | ||
|
baa535b609 | ||
|
a2ff0a7e20 | ||
|
84732f9835 | ||
|
dd17bcb0d6 | ||
|
cab8e613a6 | ||
|
fe1227618a | ||
|
596c52de87 | ||
|
ba5d5e9f86 | ||
|
530669d288 | ||
|
70b0f9a03a | ||
|
105de99d06 | ||
|
6239f81f36 | ||
|
697d200ffe | ||
|
16d5077f55 | ||
|
e0e1a05448 | ||
|
bcaafa67a3 | ||
|
36142656a4 | ||
|
d6a48deb5a | ||
|
e98ce0c2ae | ||
|
8118fc754c | ||
|
1ec7a0f23c | ||
|
488e8ef1d5 | ||
|
1f99cee78b | ||
|
c25015ed54 | ||
|
aaefc5b479 | ||
|
1c58816c73 | ||
|
0fd99358aa | ||
|
d4012bace9 | ||
|
af7660686d | ||
|
b57c6e408a | ||
|
124934b012 | ||
|
1bef6d085d | ||
|
c73927c5ba | ||
|
692deb6012 | ||
|
8ec499f631 | ||
|
2bcd653a56 | ||
|
0f10952979 | ||
|
58fa67100f | ||
|
8e294916c4 | ||
|
6877e0c95d | ||
|
37a333a023 | ||
|
48f1da963a | ||
|
e1905aced4 | ||
|
f18202a3a4 | ||
|
c1a9de4d66 | ||
|
18f86874ee | ||
|
e6686e0b82 | ||
|
4bf166986d | ||
|
0f60d84f6c | ||
|
15e54df67c | ||
|
4cb6ad7736 | ||
|
e27a32395a | ||
|
eddcf209c1 | ||
|
10a151d411 | ||
|
54d5586a60 | ||
|
30ca547e50 | ||
|
a1944d1a90 | ||
|
c2b35fdaa5 | ||
|
805b54d81e | ||
|
e3579dac65 | ||
|
f80591242e | ||
|
69cb9769c1 | ||
|
efd42d9da0 | ||
|
21a6340095 | ||
|
6c96724dce | ||
|
ebb194d2a2 | ||
|
1a51a92b70 | ||
|
5760f16272 | ||
|
4ed36f6223 | ||
|
7ea7ca1415 | ||
|
1ee8786ab7 | ||
|
44ca513241 | ||
|
73310b466b | ||
|
1ba688727e | ||
|
3b69465016 | ||
|
3e53ea7209 | ||
|
07bdc108ed | ||
|
a18efb0e71 | ||
|
de1c825ad3 | ||
|
de2cff824e | ||
|
aff504bddc | ||
|
277390e597 | ||
|
fdcefe458e | ||
|
9bb2160abe | ||
|
97d683541d | ||
|
9f7ffb80e1 | ||
|
c957ea7b24 | ||
|
181fce16b1 | ||
|
825f023505 | ||
|
347ea53b32 | ||
|
d525e0dd70 | ||
|
365e844b83 | ||
|
44bdeb555a | ||
|
520c33557e | ||
|
bfad5ac091 | ||
|
3ecf4bc238 | ||
|
028e4012aa | ||
|
dc6d429b9c | ||
|
625cf1a803 | ||
|
9ee011514a | ||
|
184fd4a1ba | ||
|
23dcfd9401 | ||
|
1cdba297fb | ||
|
1ed6743bbb | ||
|
41c42bba32 | ||
|
8fb66ea32c | ||
|
51d4c1c4a5 | ||
|
86e069994e | ||
|
1cb923b6d8 | ||
|
b1d003b073 | ||
|
0fb4254481 | ||
|
ae7f456011 | ||
|
cd4bec6bfd | ||
|
5906e0126d | ||
|
dce1395af1 | ||
|
e7db13af37 | ||
|
2eee8cd7d3 | ||
|
836a2abae1 | ||
|
a68a86d6db | ||
|
ee9f0990fd | ||
|
59d0629e3f | ||
|
17af292761 | ||
|
a4dd4bcc8a | ||
|
1a9b0a476b | ||
|
bb015506e7 | ||
|
76be5d8469 | ||
|
1258e187f5 | ||
|
4056a4c35f | ||
|
b6677f0f72 | ||
|
e8c1e6f241 | ||
|
618595ac4c | ||
|
d54ba48c11 | ||
|
a489012a0c | ||
|
a5acdc04e3 | ||
|
709a20ed7b | ||
|
c88f2099c1 | ||
|
f72a2a943b | ||
|
c51199719d | ||
|
bf374f2e85 | ||
|
34f450fcdb | ||
|
23f75598e5 | ||
|
afc238d60e | ||
|
1291c38d58 | ||
|
16caccde51 | ||
|
33f199fcd2 | ||
|
2b534e0d51 | ||
|
23d1d210c7 | ||
|
39a1d6202a | ||
|
f00a5af6c9 | ||
|
48d68f5766 | ||
|
f948da748e | ||
|
8b25d45109 | ||
|
c4ddc35746 | ||
|
0122e2bdcf | ||
|
94b75f463b | ||
|
3c2e04290c | ||
|
f0331ec2d9 | ||
|
3b4013a1b0 | ||
|
31ddccd3e1 | ||
|
d29fe4cb6c | ||
|
6763537f22 | ||
|
8ab4bd6293 | ||
|
31bc644763 | ||
|
fcd672abeb | ||
|
5f550da0bb | ||
|
e865a86eef | ||
|
80ee2e4289 | ||
|
4d327594d3 | ||
|
3363c37457 | ||
|
cee9be81bf | ||
|
932d36462f | ||
|
75c930f7ef | ||
|
bdb178d893 | ||
|
3b0635e8a1 | ||
|
f5760784bf | ||
|
67f3554095 | ||
|
3bb3872e38 | ||
|
c98330ea1f | ||
|
d895b68f04 | ||
|
e230981ac4 | ||
|
20763a741a | ||
|
4babcd9442 | ||
|
d75f36066a | ||
|
26ca4670ad | ||
|
c4d6c167a2 | ||
|
e5af9541da | ||
|
89d9f47191 | ||
|
ff2cf30238 | ||
|
ebe0899eb1 | ||
|
a3d0a38b1e | ||
|
63bd0c87b2 | ||
|
db593fb188 | ||
|
67ae10b593 | ||
|
c8d91c9e14 | ||
|
6c54f5e9b4 | ||
|
8749648d97 | ||
|
0b75b5ef26 | ||
|
fbcadd0493 | ||
|
75bb7a4dd7 | ||
|
4604fe4841 | ||
|
e8badb0c0f | ||
|
8906a8f3c6 | ||
|
4e32990a5d | ||
|
9f2583d1f2 | ||
|
a9b3d8885d | ||
|
29ec4dc546 | ||
|
d0d5204cbc | ||
|
3d84acd7ac | ||
|
5057221f59 | ||
|
3ddfbc5d2f | ||
|
362270e3ea | ||
|
db91177e90 | ||
|
d2f51ce509 | ||
|
146a66fb09 | ||
|
03305f03c1 | ||
|
82e76bc58e | ||
|
e8ff6c785a | ||
|
a8fafb469a | ||
|
b9a220cb63 | ||
|
0b44d40b39 | ||
|
6b349eda45 | ||
|
ad335ba005 | ||
|
04d766884a | ||
|
44d1ec433d | ||
|
97864e8df3 | ||
|
3916293e8f | ||
|
a527177b67 | ||
|
9c027b10b2 | ||
|
5da7086475 | ||
|
0006012ae7 | ||
|
a3f46ec037 | ||
|
bfea52f9dd | ||
|
53334f05b8 | ||
|
ba195c41b6 | ||
|
cca2f1ce61 | ||
|
a51191c661 | ||
|
4cdb5f93b9 | ||
|
fae658c9c2 | ||
|
886a469634 | ||
|
c3c1394e86 | ||
|
6a00255fff | ||
|
4f0aae0879 | ||
|
4f4fe4c41c | ||
|
2a4a3c8250 | ||
|
7864acbadb | ||
|
ba18e64be0 | ||
|
ba8c1e5eb2 | ||
|
2737fb2d87 | ||
|
899285735f | ||
|
f561d12d35 | ||
|
be258b13e0 | ||
|
dbce6b5f1a | ||
|
30f0c99a58 | ||
|
49880c05d9 | ||
|
dc2fc84f58 | ||
|
78c2a1694f | ||
|
baf34dd0d3 | ||
|
48f9dede7b | ||
|
a1f2a621ef | ||
|
a1e8ddb461 | ||
|
d33d90a36e | ||
|
c3114b876f | ||
|
50285aebde | ||
|
0eb5ee6ea8 | ||
|
16c9c95e19 | ||
|
3bc4da3e85 | ||
|
a028a2e1cc | ||
|
9675a35dff | ||
|
c1546fdd64 | ||
|
a109efc1d6 | ||
|
0782b25830 | ||
|
0041ff13b8 | ||
|
4693a25aa0 | ||
|
609df5b4a6 | ||
|
6df8140cb1 | ||
|
65b4cb3191 | ||
|
e1de481349 | ||
|
6e1cc80b91 | ||
|
b658ce7e75 | ||
|
f91f374dfa | ||
|
56f6de5410 | ||
|
94d22ecfc3 | ||
|
e25d71c6c8 | ||
|
bb1b156d2f | ||
|
1b80ddf1e9 | ||
|
66d2fe9074 | ||
|
6e36910734 | ||
|
a553a33c46 | ||
|
2a6f8b401b | ||
|
fa30567140 | ||
|
243f685b83 | ||
|
6cf2373b34 | ||
|
e842ea745a | ||
|
9696c7cec0 | ||
|
c4986eec50 | ||
|
61079e769e | ||
|
00d2c915d1 | ||
|
6ad975c420 | ||
|
1cd1a2d907 | ||
|
39a3c3d3a7 | ||
|
dfefcf03ad | ||
|
825b00e618 | ||
|
ae562e1e92 | ||
|
21c7888595 | ||
|
3b87a4f9d0 | ||
|
8564a58eab | ||
|
c5d009c2cd | ||
|
c2e165d825 | ||
|
922020c57a | ||
|
8cdc33beab | ||
|
23eafdfe00 | ||
|
e72e8ea631 | ||
|
a610a43db0 | ||
|
4a90ffe619 | ||
|
18e8357b6a | ||
|
df39347b19 | ||
|
a36261d705 | ||
|
f133d22124 | ||
|
6ba276b43f | ||
|
44db98f260 | ||
|
8873526619 | ||
|
37c2599754 | ||
|
a079b470b8 | ||
|
0f9ed02bf0 | ||
|
9aeb68205c | ||
|
82b4cf259c | ||
|
566fd3e88b | ||
|
fbecf4f47b | ||
|
52899d4def | ||
|
a89a828b35 | ||
|
4d0dbdaced | ||
|
8003f9902e | ||
|
15bd7324fe | ||
|
bb44fc51bd | ||
|
67a32e60c7 | ||
|
960725777c | ||
|
98c6e0311b | ||
|
95b7641f9c | ||
|
18b0c3f7aa | ||
|
49d3644d6a | ||
|
ee9d12d933 | ||
|
5d37015f4d | ||
|
dca25637c9 | ||
|
a7020fd46c | ||
|
1ef2b1aaf1 | ||
|
a7a661e60f | ||
|
2a9e2d47f5 | ||
|
e33b3043df | ||
|
3f41618aa1 | ||
|
a507d7567f | ||
|
62a6f58705 | ||
|
77dd074fc3 | ||
|
e8c0051be3 | ||
|
b3923eafc7 | ||
|
9ebd96611a | ||
|
824325a2eb | ||
|
e8b3bd5bdc | ||
|
a59fda512c | ||
|
ae181f6835 | ||
|
67bb242778 | ||
|
2028c189aa | ||
|
ba0dc4fb81 | ||
|
c40db417d2 | ||
|
0eb776cdd3 | ||
|
c79a7a7f6f | ||
|
1e3c995e6a | ||
|
3f79e42628 | ||
|
c16ae89a3d | ||
|
7132eaeb11 | ||
|
aef96f0d27 | ||
|
b20a56f1de | ||
|
3073b4e48e | ||
|
7b53752ccd | ||
|
03eedf6175 | ||
|
2330a4bc93 | ||
|
36afae50b1 | ||
|
272ee7577c | ||
|
7f34073da6 | ||
|
f46ee2a0a3 | ||
|
4a79f0c75d | ||
|
27a78af269 | ||
|
586af67829 | ||
|
575d8c4240 | ||
|
d32734214b | ||
|
22ce5aab25 | ||
|
9f90a1c58e | ||
|
b5e0374946 | ||
|
44cb1c7f3e | ||
|
80aba859e7 | ||
|
08360edd26 | ||
|
6e69b3f032 | ||
|
19bb9c7f50 | ||
|
f5dee51e9c | ||
|
bd37fef720 | ||
|
c22e4e5e2c | ||
|
2887a2b6d3 | ||
|
01bde19701 | ||
|
792f1826ee | ||
|
c16795dce9 | ||
|
c1597a0968 | ||
|
590aa950df | ||
|
402018b95c | ||
|
d5101ac2f3 | ||
|
251942c91d | ||
|
fe86b812cd | ||
|
cb3bff589f | ||
|
ec7d7ec559 | ||
|
24c7a5b805 | ||
|
0a4ecb1507 | ||
|
d736dace50 | ||
|
70bbab909f | ||
|
6625f78e4f | ||
|
da2b4c8858 | ||
|
12df415dfd | ||
|
2493f463f3 | ||
|
f4238b1fb9 | ||
|
794783ab4e | ||
|
02634622a5 | ||
|
ac24501e76 | ||
|
e40ea38112 | ||
|
b809b9bb80 | ||
|
73bad8f355 | ||
|
ac884da56b | ||
|
c35ab2e1cd | ||
|
ed3907c273 | ||
|
5e00287045 | ||
|
95c6578911 | ||
|
d22097ee33 | ||
|
74251af163 | ||
|
7c1b11851f | ||
|
f8724c4cb9 | ||
|
3baac034e5 | ||
|
114f1426f3 | ||
|
7de63cea5c | ||
|
34e3af2b38 | ||
|
da907d0eea | ||
|
9cbc2d9206 | ||
|
db2e466d60 | ||
|
e5cdbf7361 | ||
|
a919f493d6 | ||
|
3660298683 | ||
|
c845efe475 | ||
|
38eb47132d | ||
|
b1f097f32b | ||
|
d3123253b3 | ||
|
7b1ec1ec22 | ||
|
4cefacfe73 | ||
|
978acfa471 | ||
|
fb2d138cbf | ||
|
0edd63edb5 | ||
|
97b730668c | ||
|
26b8cf6d52 | ||
|
a979638368 | ||
|
97f434ad4a | ||
|
34af040c48 | ||
|
cc81b443be | ||
|
d44f3c22c7 | ||
|
3795b537f6 | ||
|
ecb5f0885c | ||
|
86d2234713 | ||
|
62ddf26150 | ||
|
ec14b7c52f | ||
|
5f9cc38e82 | ||
|
f48c58f299 | ||
|
c2843f3c4b | ||
|
5d33df4e12 | ||
|
c030fb47ca | ||
|
964daadb18 | ||
|
71a5698ac7 | ||
|
d41d74d0f8 | ||
|
f6c7a611a3 | ||
|
06f4e79e5c | ||
|
154cf44f0a | ||
|
f6e2ff0e44 | ||
|
2aba616f7f | ||
|
95e21386b8 | ||
|
250e908d9a | ||
|
9742fb296c | ||
|
9ff3c2c0d4 | ||
|
9dd7bd9530 | ||
|
6f477b7147 | ||
|
8389826e30 | ||
|
aa31fb7470 | ||
|
a013fe663c | ||
|
89ce497431 | ||
|
60c0b649e8 | ||
|
2bbb5ea23b | ||
|
4f9c1533c1 | ||
|
a6a3847e30 | ||
|
118f38dba3 | ||
|
879f946b28 | ||
|
6acb8a5a91 | ||
|
a38f1e92e3 | ||
|
4ca977466e | ||
|
ec45dc56fb | ||
|
5686302653 | ||
|
6322773513 | ||
|
8e845fc919 | ||
|
f90c8f2ae5 | ||
|
b5af06529f | ||
|
fac3669f8e | ||
|
28ff8d6dcc | ||
|
d0e7f6673c | ||
|
800dc21202 | ||
|
f52089a674 | ||
|
82543de95e | ||
|
12db69407e | ||
|
9b2b447b8b | ||
|
35f5e4ca41 | ||
|
8a69713f6c | ||
|
efd8ef0380 | ||
|
c5eacd1627 | ||
|
5fdb52d8d0 | ||
|
7869ce060f | ||
|
e0d96c0ce1 | ||
|
30678904ee | ||
|
953be61d89 | ||
|
d8c85007d4 | ||
|
591c1cb454 | ||
|
0ca90ed082 | ||
|
4c963b3978 | ||
|
071665f0c3 | ||
|
9a7826752f | ||
|
44b4187365 | ||
|
148807543f | ||
|
2b9fa09293 | ||
|
10211d1d03 | ||
|
46811f33ad | ||
|
32b16790d3 | ||
|
10592ca5a8 | ||
|
dc5cb2e1b8 | ||
|
c10d782524 | ||
|
d73366984f | ||
|
60b1e47ae6 | ||
|
9591fb2c21 | ||
|
c3cba03ac6 | ||
|
ce7818c436 | ||
|
f367a81e44 | ||
|
de507f7ec9 | ||
|
0a8be603c8 | ||
|
d7f033bd46 | ||
|
1fb3b87697 | ||
|
b9c8fa61b2 | ||
|
99ea6d5080 | ||
|
0bacfa9286 | ||
|
b350b605a8 | ||
|
d1eeeab7b1 | ||
|
54296ba84a | ||
|
f82b0f259c | ||
|
57f1c005e6 | ||
|
d9e5387bff | ||
|
3154b8ce55 | ||
|
45b48ede44 | ||
|
961b86dcd2 | ||
|
4d57c64b0d | ||
|
1c894f3cfa | ||
|
3d6faecaed | ||
|
2263ade187 | ||
|
2cdf33d8a1 | ||
|
f6fce6bd31 | ||
|
f9f1721d66 | ||
|
0792ac7de8 | ||
|
98edb048b7 | ||
|
52fcdf28fa | ||
|
d9671faca7 | ||
|
f456004543 | ||
|
a38040d0ea | ||
|
f18cd92318 | ||
|
06e1d0f8da | ||
|
dffd663d7a | ||
|
414f9e9e96 | ||
|
c17ea74856 | ||
|
9a08740e5b | ||
|
8bea0db843 | ||
|
2c612e371f | ||
|
2f61dc9bc6 | ||
|
d18b78c11c | ||
|
95fb4f2e50 | ||
|
f31fe1440d | ||
|
10cd0a1f30 | ||
|
659f854f62 | ||
|
4a7f8dbe09 | ||
|
3e19e574e6 | ||
|
2af2d3664f | ||
|
7dad46adb4 | ||
|
b6fc6a751a | ||
|
934674a8d7 | ||
|
c66986f065 | ||
|
fc49e4a0da | ||
|
b6e1d71b81 | ||
|
b3626a786d | ||
|
a398e28ac0 | ||
|
892d4e597e | ||
|
e8311dd306 | ||
|
a0b266fef8 | ||
|
983d1ea361 | ||
|
db615b932c | ||
|
07415e512f | ||
|
0c6d417d8c | ||
|
772e01ad40 | ||
|
1b2509d5bc | ||
|
fd963a8e66 | ||
|
3c17fca369 | ||
|
4a76997044 | ||
|
894960ef5a | ||
|
3c24d4bc4e | ||
|
ed7e6a3495 | ||
|
07de032e62 | ||
|
c07165531a | ||
|
b1a22d4412 | ||
|
6734e5ef57 | ||
|
6cc81fe6b8 | ||
|
ad80d21e89 | ||
|
97689c6cbb | ||
|
41c83dabde | ||
|
f909f0dcf9 | ||
|
5c9bf30c79 | ||
|
6efc518eed | ||
|
198bd3a3dc | ||
|
7b1055702b | ||
|
d21bcce3c4 | ||
|
b5a26941ef | ||
|
6ab7131378 | ||
|
22bcc2e438 | ||
|
32edc0f1fe | ||
|
8faa0ce2c2 | ||
|
bf05e5999b | ||
|
3d7bdded31 | ||
|
7507182097 | ||
|
6853b3c531 | ||
|
f2372a13e8 | ||
|
3f321c8801 | ||
|
8b47107df8 | ||
|
97e7136293 | ||
|
c8db58150e | ||
|
5e1067df59 | ||
|
175444c59f | ||
|
b09d5ff3c9 | ||
|
43fc97137e | ||
|
c67eee57d6 | ||
|
607aa78059 | ||
|
7edbae7b4c | ||
|
232ff38084 | ||
|
d9d9ca67cd | ||
|
57fa48aef4 | ||
|
5a8e0749c2 | ||
|
f834f069cd | ||
|
9b2dc10da2 | ||
|
c3730b7efd | ||
|
23499497a3 | ||
|
3b78d609b7 | ||
|
65529c3356 | ||
|
899849d4dc | ||
|
52393206e6 | ||
|
2cd1fa6601 | ||
|
e371bbedc0 | ||
|
9dde385073 | ||
|
afa3d39cb3 | ||
|
fe41817f25 | ||
|
a865465514 | ||
|
9278e74e9e | ||
|
689a1f739f | ||
|
19dee57b7e | ||
|
8690b91632 | ||
|
fa31cab11b | ||
|
46ee783f99 | ||
|
199bba5da4 | ||
|
16e8791472 | ||
|
1728442d62 | ||
|
22f7f059ce | ||
|
97629c1fc3 | ||
|
4727d613c0 | ||
|
9ed138ea2b | ||
|
2cbd998941 | ||
|
806d70c243 | ||
|
74a1c7d489 | ||
|
f6ed5dc126 | ||
|
e25185b9b8 | ||
|
5e6d8873b9 | ||
|
951b48c337 | ||
|
7f209b76bf | ||
|
890bfbe02d | ||
|
70f8c28ca6 | ||
|
47bacdaed0 | ||
|
bcd8eb2a09 | ||
|
e4855d0143 | ||
|
94f0ff1ed1 | ||
|
b5f0243a89 | ||
|
17e59b8783 | ||
|
ffdf308b40 | ||
|
cdadc80945 | ||
|
294e1f5b10 | ||
|
1c5eab6055 | ||
|
f74f06e403 | ||
|
f04ee0baf2 | ||
|
689273fc24 | ||
|
6f4c59a15c | ||
|
dc87097dfe | ||
|
24f4ab7597 | ||
|
ad94f0a292 | ||
|
695613a063 | ||
|
6f1828eabc | ||
|
bf158b3bf0 | ||
|
13618e6a0a | ||
|
c424e9dec8 | ||
|
a2e9523707 | ||
|
606817ae06 | ||
|
7124d326fc | ||
|
f9f4653e33 | ||
|
bf8eebe537 | ||
|
bd9eef6502 | ||
|
e343b1790e | ||
|
d81ef1d67c | ||
|
6e374bcd4e | ||
|
fb4648d2af | ||
|
a63fc25f14 | ||
|
5e20e9ae1c | ||
|
7d5d604ea6 | ||
|
a722581868 | ||
|
28f3044bdd | ||
|
497804434d | ||
|
d2d6ee806d | ||
|
2e106265f9 | ||
|
28fb0b433b | ||
|
171bd6b327 | ||
|
198e215d54 | ||
|
4d424e70bc | ||
|
3efef52398 | ||
|
b85929772e | ||
|
041522f94e | ||
|
80d3c9e96f | ||
|
6ee5e560cc | ||
|
2be9eb4bae | ||
|
0a8935686a | ||
|
0109d9148b | ||
|
212518c682 | ||
|
59b4f1ebab | ||
|
ee9462c221 | ||
|
c648dc6c99 | ||
|
4f1b8094a3 | ||
|
c89ccf7185 | ||
|
753395965a | ||
|
04be747d52 | ||
|
f828ed3edf | ||
|
b98d9c2932 | ||
|
aba2ce8390 | ||
|
8bd8e149cf | ||
|
e7c359a2e7 | ||
|
d64d25380a | ||
|
6cba6166fb | ||
|
e66f5fe253 | ||
|
1d4388d444 | ||
|
28ab08a7ca | ||
|
6fa0f92ceb | ||
|
3083ab74a6 | ||
|
b6ea73af83 | ||
|
1fa3ffb1ff | ||
|
af89630095 | ||
|
18f0177fce | ||
|
d89eecacba | ||
|
a9149fb92e | ||
|
9a04208a11 | ||
|
6cdf199531 | ||
|
44dc7fe24a | ||
|
455892b414 | ||
|
4f5227782a | ||
|
481e473b60 | ||
|
2c2a1f638b | ||
|
973e269f46 | ||
|
9f76e0e056 | ||
|
3a5f1b41a4 | ||
|
e2d8369daf | ||
|
a20d4959bf | ||
|
7b887e4cdd | ||
|
bc9cbd2993 | ||
|
9baa0e247f | ||
|
2df8d2bc69 | ||
|
b8165fb06e | ||
|
c698b24e01 | ||
|
e70249cb2e | ||
|
8a9bfe8281 | ||
|
8c2a4e627e | ||
|
bf35c92c14 | ||
|
019293a034 | ||
|
46dc40149e | ||
|
444643eb6f | ||
|
2913b911e3 | ||
|
ca323371a7 | ||
|
a06cb39777 | ||
|
b0ec8767a2 | ||
|
353fb49a87 | ||
|
e453b40e0b | ||
|
0c6f8ce77d | ||
|
c0219662bb | ||
|
aae71d375c | ||
|
b6228e4c59 | ||
|
3a9a1439d9 | ||
|
7cf256dc7c | ||
|
c3c26998bf | ||
|
02e860480b | ||
|
7737b8b596 | ||
|
2725322fd5 | ||
|
6c6ccda6b3 | ||
|
d71269e223 | ||
|
36266d2b10 | ||
|
acae62de87 | ||
|
9fe4197cae | ||
|
7fa1a8d54a | ||
|
2333271c20 | ||
|
5b83149567 | ||
|
250a35baab | ||
|
d60ba95532 | ||
|
c901472198 | ||
|
2a5b70fb13 | ||
|
dc6db6e4b3 | ||
|
8df6f32314 | ||
|
a2d8c894fe | ||
|
a1996768f1 | ||
|
205587cb9e | ||
|
224b2ef952 | ||
|
90a83dc753 | ||
|
a7cf968d04 | ||
|
80ff72bae1 | ||
|
5320fc8111 | ||
|
8753531e82 | ||
|
03a845f2b3 | ||
|
25b05f127d | ||
|
073beb0135 | ||
|
ef7659691b | ||
|
e69c0c079e | ||
|
dc31269a06 | ||
|
df9eccabea | ||
|
7788f5ae4c | ||
|
ff5456c178 | ||
|
40ed702437 | ||
|
65924e9a5d | ||
|
a88d149dad | ||
|
b9ec94d835 | ||
|
fc1675575a | ||
|
2f7229720f | ||
|
0187fc7b22 | ||
|
540e1a9650 | ||
|
a371cd1d79 | ||
|
16b11fee31 | ||
|
1bc46f22b4 | ||
|
554c8fe163 | ||
|
8f6bf6e002 | ||
|
d5dd8e9346 | ||
|
4a67e1021a | ||
|
c97061770a | ||
|
55b331511e | ||
|
4b9b5e861f | ||
|
b8599a0642 | ||
|
ae6530585a | ||
|
39aa1fa2a4 | ||
|
4f740acabd | ||
|
2cc9b91895 | ||
|
4eedc39e97 | ||
|
b99e8d7f46 | ||
|
a8a27aeadd | ||
|
21176d2fd3 | ||
|
224c65438f | ||
|
f1c21b642f | ||
|
030d1f374a | ||
|
0b29fa2288 | ||
|
b721f148f0 | ||
|
63434a2f87 | ||
|
0d6f0e66be | ||
|
fb3f1365c5 | ||
|
8de7d5d377 | ||
|
952d7494ac | ||
|
9aeba20086 | ||
|
9150c9c40e | ||
|
3e75897154 | ||
|
b0aa4402c2 | ||
|
41f80bcafd | ||
|
c67359c49d | ||
|
2f7c3cf21e | ||
|
9731c8a750 | ||
|
8092e5c3a8 | ||
|
f7ab8cc471 | ||
|
b593f62c4f | ||
|
6905b7a410 | ||
|
402f27b2a3 | ||
|
c9c46d05d0 | ||
|
6591575d22 | ||
|
6064119779 | ||
|
00cd9b581d | ||
|
a3d7b72485 | ||
|
88c73be2f4 | ||
|
39a9181cdd | ||
|
0e5c6f56a0 | ||
|
5147a070a1 | ||
|
b11be1838a | ||
|
be99768a32 | ||
|
fe439a0cb6 | ||
|
87f49ec879 | ||
|
20f2730125 | ||
|
bc5b34db6b | ||
|
bcf9df3744 | ||
|
4d3674ee0a | ||
|
28567e4629 | ||
|
1180a4fb0b | ||
|
71928d2c9f | ||
|
3853072a2e | ||
|
0cf630ef23 | ||
|
202015fe34 | ||
|
ae43e5cae4 | ||
|
67b67bae6a | ||
|
dbb8fe15cf | ||
|
56efa10f64 | ||
|
5ff776f90d | ||
|
a25b072bf6 | ||
|
c95951c0e4 | ||
|
4c8193b801 | ||
|
598a544ff8 | ||
|
465ef3fa9a | ||
|
2f876d93e3 | ||
|
84e8c44e4f | ||
|
855d794bdb | ||
|
a3333f8fe1 | ||
|
2e64d62ca4 | ||
|
26a3dbcbe1 | ||
|
fa2e86df29 | ||
|
b4f0ece78f | ||
|
630b319a37 | ||
|
4a37e49798 | ||
|
cfbe98a39a | ||
|
91f097d514 | ||
|
c545521cd9 | ||
|
11e0f49ada | ||
|
19ce53128b | ||
|
deccff623a | ||
|
b2a210ec0d | ||
|
bdb5169a6f | ||
|
0865b702a3 | ||
|
d13b8fd486 | ||
|
494911805e | ||
|
cba3a2be24 | ||
|
0686781359 | ||
|
e5b82dca4d | ||
|
2144a42a22 | ||
|
07a989e004 | ||
|
4f7e8116cb | ||
|
c0f650d7dc | ||
|
d4a0136504 | ||
|
5f25e027c4 | ||
|
9610dcce20 | ||
|
3ee3e7c17b | ||
|
98536250bd | ||
|
e95808e6be | ||
|
9fc819a410 | ||
|
b0f1ce1fa0 | ||
|
503579a638 | ||
|
3ad216751a | ||
|
ca8e3179bb | ||
|
fd84e56c00 | ||
|
8b67fb7290 | ||
|
2d1fdb319d | ||
|
c200e18434 | ||
|
b3ffcd020f | ||
|
9258a3dcd4 | ||
|
57f5478731 | ||
|
973d75ebdd | ||
|
33519b27c8 | ||
|
7da7ff4a69 | ||
|
dbd2f697f9 | ||
|
f435762b88 | ||
|
ae46332e42 | ||
|
d003883de9 | ||
|
4e438a44f1 | ||
|
02e19b3d44 | ||
|
ccc19512e7 | ||
|
c34539e389 | ||
|
f8aeacb949 | ||
|
9940190679 | ||
|
e2498b3e91 | ||
|
82246fd9c7 | ||
|
11538552eb | ||
|
4ce28f54de | ||
|
e887ed74a3 | ||
|
28c086e97c | ||
|
11465e89a3 | ||
|
b2197187c1 | ||
|
2b26a10745 | ||
|
daf726ebbf | ||
|
88dd886687 | ||
|
609da457f7 | ||
|
363e28ff69 | ||
|
bdd6bf9020 | ||
|
5c3dab3466 | ||
|
9b2c8fa25d | ||
|
df2f102d9e | ||
|
95ebb0e6d2 | ||
|
e5d03652a9 | ||
|
56b53e2dd8 | ||
|
cf0b7b213f | ||
|
d214c8e01b | ||
|
fba0f362a5 | ||
|
ec05d0857c | ||
|
54b744b7de | ||
|
1a76780fff | ||
|
58f5c44533 | ||
|
d085da4dbf | ||
|
c4a5c356f7 | ||
|
18fdc5c6a2 | ||
|
35dabaab9c | ||
|
9bf31b10bb | ||
|
7186575cb1 | ||
|
2ecae40130 | ||
|
778ed62a90 | ||
|
5e863a87dc | ||
|
7ce8597c25 | ||
|
1992237ce5 | ||
|
8f247b0f73 | ||
|
e2159d80af | ||
|
057023531e | ||
|
dfed65bf9f | ||
|
739161849a | ||
|
c65b280020 | ||
|
d3bcf25ef0 | ||
|
f6bd3340e7 | ||
|
6a7c09bfe3 | ||
|
8b9f294a5d | ||
|
4a282d9629 | ||
|
909b88864f | ||
|
1346a7992c | ||
|
bba607e987 | ||
|
f9cc490c35 | ||
|
a5aec2d9fa | ||
|
c0df368dc6 | ||
|
aa77433523 | ||
|
44ad99f693 | ||
|
b7f7a82ea9 | ||
|
c69978c9fd | ||
|
6174aa6ee1 | ||
|
74b8d2e908 | ||
|
63a515944f | ||
|
5b5db7b860 | ||
|
b3bbacf2ef | ||
|
3a0429d049 | ||
|
ab539081fa | ||
|
f0d88d4e73 | ||
|
772cbd6ffd | ||
|
17b9dbe9d7 | ||
|
75e5d42d8b | ||
|
031c15fd7d | ||
|
de1924cefc | ||
|
66db0a4751 | ||
|
c309410965 | ||
|
7f461b99e2 | ||
|
7bfe0eeae9 | ||
|
8619bd5be3 | ||
|
56011d37d4 | ||
|
c2852c8a82 | ||
|
6f546a424e | ||
|
447f7530af | ||
|
6136f1206b | ||
|
36a3c5b501 | ||
|
dcd6c1f522 | ||
|
2b074bcdcb | ||
|
b20ec7f0eb | ||
|
58cf69a2fe | ||
|
096c148228 | ||
|
a68005d4ab | ||
|
bf3a281987 | ||
|
2965a6827d | ||
|
9f43a73c36 | ||
|
7551b45da2 | ||
|
bca3685eda | ||
|
6d20175800 | ||
|
a62dd4c020 | ||
|
d1d9620a61 | ||
|
5106d77c77 | ||
|
69cf237d7a | ||
|
7d9d1c82b6 | ||
|
228ff5edf4 | ||
|
2baac618a8 | ||
|
e8f499a938 | ||
|
96ca20d0b4 | ||
|
54acdc86e7 | ||
|
0815e02895 | ||
|
30cbb72b57 | ||
|
0b91397709 | ||
|
89934c17ca | ||
|
e4a38e62eb | ||
|
5e1e09d7bf | ||
|
51ce3a1e42 | ||
|
54b46dfad9 | ||
|
787917ac66 | ||
|
619b49bdc4 | ||
|
4b3a73d440 | ||
|
54f9c59d6e | ||
|
1d123996f6 | ||
|
c4768f6138 | ||
|
5f3551ff34 | ||
|
d3985c2e3b | ||
|
3b1843f3a3 | ||
|
2c36796362 | ||
|
655ccba89b | ||
|
150d72f0f8 | ||
|
6a316b34a2 | ||
|
8e6b600609 | ||
|
5630a4dd67 | ||
|
38ee8aedc1 | ||
|
d594615532 | ||
|
2739fa60be | ||
|
327301782d | ||
|
8781c5db8d | ||
|
31c34ea158 | ||
|
ef9bbaca19 | ||
|
02d89072bc | ||
|
4e8bd640a7 | ||
|
8c71a00600 | ||
|
3d36c70d53 | ||
|
c72479c4d6 | ||
|
4bb88d8e44 | ||
|
0ee0958539 | ||
|
b6dd6f3a94 | ||
|
d11c322e1f | ||
|
cd92b34ef1 | ||
|
b6481cfcda | ||
|
db7eb92638 | ||
|
f2d0477550 | ||
|
776e207f09 | ||
|
733e8a0043 | ||
|
4fa19006ad | ||
|
73a597e3e5 | ||
|
d776f1765d | ||
|
741b6f6f9a | ||
|
b6f4695bcd | ||
|
b7d3b807d2 | ||
|
0cc386bc28 | ||
|
cb155707cd | ||
|
9b6b250cbd | ||
|
5b7e29b8ad | ||
|
b6d748b414 | ||
|
8fc4b338c2 | ||
|
6d3ea19ac5 | ||
|
d01ef48bf0 | ||
|
71103bb7b9 | ||
|
1c9bc00acc | ||
|
bed128e8cf | ||
|
b5c3f18f24 | ||
|
cbccdf5d93 | ||
|
a46f3a31e1 | ||
|
a808f7b04e | ||
|
3a883b9e41 | ||
|
17d8691300 | ||
|
523ce1dbdd | ||
|
4a3a9bf62c | ||
|
3b30177959 | ||
|
7e66f89260 | ||
|
1a93ba634f | ||
|
d93f823fc6 | ||
|
f2198bf938 | ||
|
965f10698b | ||
|
b71367cd2a | ||
|
abe18ac825 | ||
|
bb193d3768 | ||
|
7a7f5cd4a8 | ||
|
ac9f49f8c9 | ||
|
8f53859e00 | ||
|
bfb7ff88d9 | ||
|
c36425fd3a | ||
|
981f9d0b01 | ||
|
fa89fe3e87 | ||
|
d132357c20 | ||
|
a719237556 | ||
|
8955ca5216 | ||
|
f665762cc8 | ||
|
d16fc2b68b | ||
|
e1df32c32d | ||
|
943c6f77dc | ||
|
4964382966 | ||
|
021c6fdbe2 | ||
|
711f9805c9 | ||
|
0aaae3afd6 | ||
|
eadd1042fb | ||
|
16fa2c9f5e | ||
|
d4ab1df870 | ||
|
4a5aa1bcc1 | ||
|
01a9cda99a | ||
|
dcdf606ff6 | ||
|
ea021de5eb | ||
|
5cc3526f8f | ||
|
3060fc2af4 | ||
|
e4395dfeb4 | ||
|
f65dadf1d7 | ||
|
f048762fd9 | ||
|
bb985f826e | ||
|
bb239cba2a | ||
|
e7e66e580a | ||
|
689d689d3b | ||
|
125c3d3e0d | ||
|
ffaa06560e | ||
|
f9b716201f | ||
|
8b14a5f0d8 | ||
|
c5855119d8 | ||
|
a036597f5f | ||
|
b8688e2e66 | ||
|
d8b2e08717 | ||
|
7da78d3312 | ||
|
2292b107dc | ||
|
1fcc74c658 | ||
|
73be027951 | ||
|
132d91c2ab | ||
|
f08ce82c3f | ||
|
8de2712652 | ||
|
55835785c0 | ||
|
cb711b7758 | ||
|
19c75293bf | ||
|
33219f00d5 | ||
|
4aaedbb0e6 | ||
|
ee1f14d4eb | ||
|
feac8085c9 | ||
|
0a5ec11b1b | ||
|
03937174e5 | ||
|
e00529c05f | ||
|
5dbf8e1d2b | ||
|
bebf672186 | ||
|
6d4a8f2a5a | ||
|
14db0ae663 | ||
|
88d1c1d140 | ||
|
9106055be1 | ||
|
2cf52f15ab | ||
|
b7e9d61c72 | ||
|
0bc22db296 | ||
|
6a943acc70 | ||
|
7c97416e7d | ||
|
dd75504a66 | ||
|
04c4ab2289 | ||
|
310a2e2511 | ||
|
f6314431f0 | ||
|
89100d0ca0 | ||
|
2b646636c1 | ||
|
b10c1d5006 | ||
|
225b829c1a | ||
|
5f4c7076ab | ||
|
61c9b304d7 | ||
|
789d7000cf | ||
|
d23ef2bd59 | ||
|
8a77f832a3 | ||
|
5a6d318cfb | ||
|
e9f14de05d | ||
|
2d8da45bda | ||
|
83de33f5b8 | ||
|
e63844f786 | ||
|
0a805c16fd | ||
|
653c7d4430 | ||
|
306c3bea21 | ||
|
389ce60bc9 | ||
|
2d453a1a6c | ||
|
0775560ad2 | ||
|
2680c1e8b3 | ||
|
50ba2e3ad4 | ||
|
c16875d0de | ||
|
a4205cd0c2 | ||
|
2fb3e373c6 | ||
|
ac1fa7209c | ||
|
fd820d6af8 | ||
|
b88486601b | ||
|
92e712a508 | ||
|
64a9079ce4 | ||
|
f18d0ab923 | ||
|
def49e6d20 | ||
|
f142db3d49 | ||
|
e7b04a89e2 | ||
|
1cb59f46e3 | ||
|
a604746e0b | ||
|
aba706a293 | ||
|
c1b9113347 | ||
|
5e7db2807d | ||
|
203f830a30 | ||
|
3dbe9193e2 | ||
|
717cf29595 | ||
|
72300fec5e | ||
|
ec50b1d67a | ||
|
408a4420c9 | ||
|
568218204a | ||
|
bd39e98c66 | ||
|
01be65a624 | ||
|
a59d8a6a17 | ||
|
70b71aa4f9 | ||
|
aaf7991139 | ||
|
265d579fd9 | ||
|
f6dd91e47c | ||
|
cdae552ab0 | ||
|
730e887454 | ||
|
5a3852d82c | ||
|
5b35580d2d | ||
|
4b0705fe36 | ||
|
d219b4d12a | ||
|
6e38331328 | ||
|
c4bc9aea22 | ||
|
6c692d9308 | ||
|
7ce8bd8988 | ||
|
b4ead4076a | ||
|
052893bbf8 | ||
|
a319fe8632 | ||
|
8a84e68c13 | ||
|
0ca7defe83 | ||
|
b704706ee9 | ||
|
23fb634847 | ||
|
0bd37eb8f9 | ||
|
b86294e9cc | ||
|
f11f968f99 | ||
|
ad81642954 | ||
|
ea42103ae7 | ||
|
82435e37be | ||
|
b61d29b22a | ||
|
04392a6a4c | ||
|
6e9798d596 | ||
|
bef553c9ae | ||
|
7a76efa7a0 | ||
|
c5f64374ed | ||
|
b767caa704 | ||
|
63974f97ab | ||
|
37764a7caa | ||
|
fb586f0043 | ||
|
9990f4d8cf | ||
|
80f73cc5d0 | ||
|
8775f67416 | ||
|
2ce302f6f8 | ||
|
69b9944b8e | ||
|
37f35e8b2d | ||
|
8ad9531fa6 | ||
|
5ec37c08bf | ||
|
84cb008421 | ||
|
a744cca35a | ||
|
1950cf5f99 | ||
|
fbf230cd01 | ||
|
05abf1e419 | ||
|
f0c13980ed | ||
|
d136207d2f | ||
|
b331ee5d93 | ||
|
73cd6e981a | ||
|
6826be73c7 | ||
|
0a61a607c9 | ||
|
7444e1566b | ||
|
e401661cfc | ||
|
89d32f7109 | ||
|
5b4c88f933 | ||
|
966bce973a | ||
|
69cbcae7ed | ||
|
e26cf282d6 | ||
|
6ec7d55cbc | ||
|
9888f2a322 | ||
|
15d29b2c79 | ||
|
7e768e0a17 | ||
|
affa41b5a9 | ||
|
c8cf179ed9 | ||
|
9ef7310fc2 | ||
|
cdd7d0f4c5 | ||
|
813d706dac | ||
|
223d4133c5 | ||
|
bb62ebc23e | ||
|
a4c2adf69a | ||
|
0baff0a1e1 | ||
|
51766ad72c | ||
|
bf00b42941 | ||
|
56482acfc2 | ||
|
8898b1a608 | ||
|
525bc37649 | ||
|
9d29450f47 | ||
|
26c98bdace | ||
|
19ccd35f3f | ||
|
efa7529c5c | ||
|
334c11ccd1 | ||
|
c318a5dd79 | ||
|
25d1a8957d | ||
|
9f4853b9d6 | ||
|
ac58f50b0a | ||
|
36f22b660e | ||
|
398046eca6 | ||
|
a6f2ce4bdd | ||
|
950a8ea8df | ||
|
2b6b979f88 | ||
|
4b80e5ff47 | ||
|
a14d18c6b6 | ||
|
fe88c7ce97 | ||
|
c54b00a701 | ||
|
4a4b8c2e12 | ||
|
f1770711cb | ||
|
94757f0f0c | ||
|
15cf9be90d | ||
|
cb1955c217 | ||
|
2ce944034d | ||
|
53a207e859 | ||
|
dbdd2411c3 | ||
|
4ac3fbd726 | ||
|
8f8f62555c | ||
|
73b980c6a9 | ||
|
d2cce3cc40 | ||
|
4139360788 | ||
|
ca7bb50212 | ||
|
48ebf626b8 | ||
|
564eb802b1 | ||
|
c968949f49 | ||
|
74268ecce6 | ||
|
93f9db3af4 | ||
|
4cc0a9d4a9 | ||
|
a04dfba16b | ||
|
7f83b58b92 | ||
|
ca2e6353ae | ||
|
6bf7795529 | ||
|
401f4828b6 | ||
|
7a0ce1efe7 | ||
|
cdc2550e34 | ||
|
2d760241f3 | ||
|
3748e420a0 | ||
|
031a253101 | ||
|
cfce6d548b | ||
|
038e93ea6a | ||
|
8028e145f1 | ||
|
ddfb9fd0cc | ||
|
a36ed6ab1e | ||
|
0c7fe0664e | ||
|
7ae2f1980b | ||
|
0c89583b1b | ||
|
f5ec43276a | ||
|
e55e46011c | ||
|
77c0304faf | ||
|
ea476e26ae | ||
|
2eb47aef62 | ||
|
3e4084d99c | ||
|
955ac92043 | ||
|
5a65a07a39 | ||
|
554d73c6ee | ||
|
7bc7bc7c49 | ||
|
7b8d47cdeb | ||
|
63a8509f1f | ||
|
4e69454f72 | ||
|
ec3e237093 | ||
|
edd224a185 | ||
|
b5142b8ef5 | ||
|
ddfdf1d49d | ||
|
e7675c29da | ||
|
0bf3fef431 | ||
|
8cb0e81e89 | ||
|
d468cb051d | ||
|
0b24be7532 | ||
|
6316a0ede9 | ||
|
3c9d0e02f6 | ||
|
02d4360526 | ||
|
aedf80e382 | ||
|
51b492e1e2 | ||
|
d283f236db | ||
|
371e937a0e | ||
|
5778c25477 | ||
|
d2cd3ec879 | ||
|
ba0a59629b | ||
|
03fea7558d | ||
|
4901673c4e | ||
|
a4d84bd2e8 | ||
|
0289218c92 | ||
|
c3d32e59e7 | ||
|
8cab08351b | ||
|
5de0e58d5d | ||
|
438106f42e | ||
|
6b21f38047 | ||
|
1b07a5f3c0 | ||
|
a39ec5a061 | ||
|
015df9e6dd | ||
|
bf95284b72 | ||
|
07c04f0c2f | ||
|
b9976ee68e | ||
|
c8d9951ae4 | ||
|
97339512e1 | ||
|
95682a7a0b | ||
|
87038c4c75 | ||
|
1e5b5193fe | ||
|
9cc47678a2 | ||
|
198109cd43 | ||
|
16490541e4 | ||
|
6d5ca25e03 | ||
|
0ca44bd859 | ||
|
124b5b0549 | ||
|
fed62fae3c | ||
|
9e2812d55c | ||
|
fdcbc3904a | ||
|
cc0114cd90 | ||
|
f97753c1d0 | ||
|
fcdf545a3c | ||
|
bf28f887eb | ||
|
5f1f04e486 | ||
|
2242174749 | ||
|
e8af077fe2 | ||
|
055252f746 | ||
|
8dc84d7c17 | ||
|
f140c75fb9 | ||
|
c63dd46bac | ||
|
a23b0ba945 | ||
|
7e768aa6e9 | ||
|
18765508c0 | ||
|
efb3464ee2 | ||
|
f3319c5f75 | ||
|
384623fbb7 | ||
|
3bcccdf3dd | ||
|
d9b913fa69 | ||
|
7b9a430e8a | ||
|
4f3ab0dc69 | ||
|
427caaf9aa | ||
|
85eefdebbb | ||
|
b31b70302b | ||
|
c830ea676f | ||
|
9249059cb7 | ||
|
9fee228d1a | ||
|
20718c6ec1 | ||
|
b8754f3f44 | ||
|
6f598ae59e | ||
|
ca81fcaf37 | ||
|
75867da94f | ||
|
53c11701de | ||
|
4741793bb6 | ||
|
ab161a42ee | ||
|
4642b79b5b | ||
|
1cb43fe110 | ||
|
0123135237 | ||
|
1d77f91acc | ||
|
9b89333b1b | ||
|
829361d767 | ||
|
d3fca26499 | ||
|
ff3460e100 | ||
|
1a209a54c6 | ||
|
3bf0ac087f | ||
|
96cf6215ce | ||
|
71ce6120c3 | ||
|
21e82d0daa | ||
|
8c20bb003b | ||
|
90913d2486 | ||
|
ef0de04a0f | ||
|
8879a0ce8a | ||
|
18db46800e | ||
|
955c5b5605 | ||
|
c3b2c88213 | ||
|
7412bb35ad | ||
|
2a6fbc5c5d | ||
|
90c9b87f8d | ||
|
ffe2557e84 | ||
|
a77798e5b4 | ||
|
c1fa7bfce6 | ||
|
bf50da1e6b | ||
|
2cd4aac5ce | ||
|
208b96c092 | ||
|
36a53f8134 | ||
|
e8d8a8737e | ||
|
41b9f90a0b | ||
|
5e39493e89 | ||
|
31f3c60401 | ||
|
519c74e4dd | ||
|
4419770b15 | ||
|
b7fa86c848 | ||
|
4d620c3db9 | ||
|
319c8cb54c | ||
|
868b6f141c | ||
|
589fdd4cfe | ||
|
3f36dd9a14 | ||
|
0a6568bbab | ||
|
4e26d56746 | ||
|
d4e363fbd7 | ||
|
b721b822eb | ||
|
58d6985080 | ||
|
ee2abd415e | ||
|
09c9321159 | ||
|
0900a7cf80 | ||
|
d3ec7f65fb | ||
|
b24a94d6ce | ||
|
65769c7766 | ||
|
cbeef9fe06 | ||
|
b199209d0d | ||
|
cb48545600 | ||
|
5e626e2cc5 | ||
|
2709d1ff6e | ||
|
de3ca6e237 | ||
|
c2253e868c | ||
|
3a77c6f7eb | ||
|
8e3ff7670b | ||
|
7870147c16 | ||
|
64a371e5d8 | ||
|
f837736a20 | ||
|
dec503da81 | ||
|
1328299fda | ||
|
05190a52f1 | ||
|
46cc3105c4 | ||
|
8ba5853cdd | ||
|
e5fbcc4a8c | ||
|
e559194e8e | ||
|
c0d2994b8e | ||
|
89009aa1f8 | ||
|
ee8b580a98 | ||
|
f4656fa493 | ||
|
adf9405fd7 | ||
|
f46db7ce1a | ||
|
f00d726347 | ||
|
e8d8063ebc | ||
|
b4bc4f5ddc | ||
|
0d3ffe210f | ||
|
8eb88a161a | ||
|
346c964419 | ||
|
bc8be2460f | ||
|
a33f24d19c | ||
|
8f839fbf8e | ||
|
10dd9101cd | ||
|
aa5d3af8a1 | ||
|
dace993c21 | ||
|
32b72f0ef6 | ||
|
3dbc54c8ae | ||
|
9dd3b8fd68 | ||
|
5fb1afc681 | ||
|
a4c985a219 | ||
|
a1f819a458 | ||
|
166d7ba1cf | ||
|
a089accd23 | ||
|
38546e557f | ||
|
080dca7ee0 | ||
|
a89e433f3d | ||
|
f30ef61b06 | ||
|
03a36c1100 | ||
|
546eb6e73e | ||
|
bedd3abf8a | ||
|
ce2d4498e1 | ||
|
a786023160 | ||
|
98cf8aa445 | ||
|
d733d9fd4c | ||
|
58e9cb8b93 | ||
|
bb669acf95 | ||
|
4f3751b7ce | ||
|
84c12dee80 | ||
|
f5f865a139 | ||
|
902aed671a | ||
|
1423fe7e16 | ||
|
58ed2e6f33 | ||
|
a90939f46a | ||
|
db7456b9c5 | ||
|
a964b30c34 | ||
|
d566629d51 | ||
|
837422fbb8 | ||
|
afc37c71a6 | ||
|
e8b014ea6d | ||
|
b124512020 | ||
|
158f352328 | ||
|
f1895e32fb | ||
|
6c3be01093 | ||
|
ebe548438c | ||
|
a45c61f19e | ||
|
b07a4b95aa | ||
|
777b4e13e6 | ||
|
92cfc9324d | ||
|
97dfa18b9b | ||
|
515c07ea2b | ||
|
4d17e45f86 | ||
|
32095daf90 | ||
|
aa23ed892b | ||
|
3f079c8501 | ||
|
0aaf4bfde8 | ||
|
b967cfc775 | ||
|
2ca0483bf4 | ||
|
03cedc7b35 | ||
|
35049b5830 | ||
|
b707dde4da | ||
|
1ec8339b13 | ||
|
8bbe04a174 | ||
|
0b6a173ba0 | ||
|
8b41dfe94f | ||
|
a18b1ac99b | ||
|
e007bcb640 | ||
|
1090e7ceae | ||
|
933035dd7e | ||
|
aaaac78170 | ||
|
b5d2392def | ||
|
b88a736735 | ||
|
f238da416b | ||
|
10c7e75491 | ||
|
60af0735f4 | ||
|
273cbf333e | ||
|
189b17ad8f | ||
|
1eecf26429 | ||
|
2f9a3fa942 | ||
|
f166fb132e | ||
|
0adb69139e | ||
|
ab309e4b90 | ||
|
532c6d4fa5 | ||
|
14f627d0d3 | ||
|
947c38c124 | ||
|
f991e49203 | ||
|
4fbb6ed4ff | ||
|
2fa49303de | ||
|
f9527e9d2d | ||
|
80c63cb9d6 | ||
|
a2455eeade | ||
|
5d7ad4b3bd | ||
|
f46fa61cf3 | ||
|
da24a9637b | ||
|
2cdc11c2ad | ||
|
191cd3f25c | ||
|
f158bce8bd | ||
|
94eebb2dd6 | ||
|
375b146690 | ||
|
8c13214ff2 | ||
|
681dfadb57 | ||
|
b8b5d1cb09 | ||
|
e187dd86ed | ||
|
c380d6988c | ||
|
444acc8ef5 | ||
|
068f08aa45 | ||
|
bdc101f69c | ||
|
0ece530b9e | ||
|
5853a86091 | ||
|
20ba87bc88 | ||
|
be166ec158 | ||
|
02147891c2 | ||
|
c08cd588eb | ||
|
882bb564b1 | ||
|
18edf06a20 | ||
|
68b52b6130 | ||
|
3503f3eb4b | ||
|
a75706f329 | ||
|
29fe9d973c | ||
|
87d3320fa1 | ||
|
0b96dbc04c | ||
|
55ed58c4a0 | ||
|
8503e8c9ad | ||
|
fcdf783c40 | ||
|
008b92acb2 | ||
|
baf8ef8516 | ||
|
0cf89467e3 | ||
|
37d8a563c0 | ||
|
f3de93d73a | ||
|
4de23bd160 | ||
|
29397ca04f | ||
|
6038a36532 | ||
|
186a922d06 | ||
|
be1f9e66e3 | ||
|
9ac015e550 | ||
|
f7a9ac0ba2 | ||
|
39a8ddcfec | ||
|
3a9e28ba48 | ||
|
b6a479355e | ||
|
a791c964e8 | ||
|
9686a7f9bf | ||
|
6b65b89350 | ||
|
09a1915ec6 | ||
|
3424c421a4 | ||
|
77b89b6841 | ||
|
09807cfcad | ||
|
6ca81df40c | ||
|
2d00ddad2b | ||
|
04f4934adb | ||
|
0593007fd0 | ||
|
c07cbf9dbb | ||
|
ddd60aa1ff | ||
|
b5ecdbbc48 | ||
|
0cca613b04 | ||
|
b254ad177a | ||
|
4fd9213d2c | ||
|
982d1e219c | ||
|
3923b8631d | ||
|
72dcdf4483 | ||
|
5f3a71ed5f | ||
|
000d6ebcd0 | ||
|
7f0a04e3e3 | ||
|
005c6bb9f1 | ||
|
59c856fc0e | ||
|
5bf26619ee | ||
|
676c1d560b | ||
|
5afaa7c079 | ||
|
b0b49b72b8 | ||
|
e7600458a9 | ||
|
e0fa308984 | ||
|
6ce6fed10d | ||
|
b23ca2e138 | ||
|
2798dc3d42 | ||
|
0586d4d7a9 | ||
|
d2b3a52424 | ||
|
ffb97242d9 | ||
|
13ab400d6d | ||
|
db6d47b3f3 | ||
|
393943bb9f | ||
|
4c72ac14e6 | ||
|
7156871412 | ||
|
20665a49ed | ||
|
ad1dfc3137 | ||
|
8de67411ac | ||
|
2e75c9951b | ||
|
77f66f44a4 | ||
|
3278a397f4 | ||
|
d1c2abbaf3 | ||
|
8a443013c0 | ||
|
d3735c4763 | ||
|
f9887434d1 | ||
|
12afa005d9 | ||
|
7c0129b911 | ||
|
332f92d08e | ||
|
281ac16dca | ||
|
e8a2b9446d | ||
|
4e33f3e722 | ||
|
e46e60153d | ||
|
d3559bb1b7 | ||
|
c8a046996b | ||
|
6c85b8717f | ||
|
142a62e371 | ||
|
ff6abf08b7 | ||
|
2fd921cd60 | ||
|
1d7bd57357 | ||
|
1a4d76b4c3 | ||
|
853d869086 | ||
|
c99d669b06 | ||
|
19d3921637 | ||
|
4ee716457f | ||
|
5fb19bb187 | ||
|
8b83c5349d | ||
|
ac91942452 | ||
|
5ef23ddc1d | ||
|
2ad6c66a8d | ||
|
630f877e95 | ||
|
7dd5ce1356 | ||
|
54b18d15b6 | ||
|
2b0880af80 | ||
|
786ea17f95 | ||
|
c699bae99c | ||
|
588e8e019c | ||
|
1e7a86b7c0 | ||
|
2bb18b18b7 | ||
|
da77c549a7 | ||
|
fc707c157a | ||
|
5be6f550be | ||
|
66abf27edd | ||
|
3d1b6d7de7 | ||
|
115e604627 | ||
|
f9aeec8eb5 | ||
|
acf4d15a8d | ||
|
e5e08d1762 | ||
|
178c7817fa | ||
|
a93a428a89 | ||
|
d126a361e1 | ||
|
9e42ec0c06 | ||
|
1f05654faa | ||
|
3ddef6440a | ||
|
036b47acbc | ||
|
42e585e7a2 | ||
|
93d066bef7 | ||
|
580c6fca00 | ||
|
03300da93a | ||
|
2a1fc38799 | ||
|
646afbfa36 | ||
|
45a1435ce7 | ||
|
f4d7d32fd7 | ||
|
1b00f93091 | ||
|
9c9e5a54a7 | ||
|
4cf8c9c477 | ||
|
a78e1d7f2b | ||
|
00c1d6c42c | ||
|
5d92f09449 | ||
|
ac7d820e6f | ||
|
7d752443ca | ||
|
3311b5a6e3 | ||
|
3801443c9c | ||
|
9b2a2eb229 | ||
|
d165f66815 | ||
|
6715d52b81 | ||
|
ae160556d0 | ||
|
c040e1f9b7 | ||
|
db14a8ac1a | ||
|
9beafd03ee | ||
|
4f081c5e14 | ||
|
ff4e9e42e5 | ||
|
d5e3e6f256 | ||
|
cc9660c0e7 | ||
|
90d92707c8 | ||
|
fe77bc7c37 | ||
|
54a7d8291b | ||
|
7bb924ce5b | ||
|
9f2e25309e | ||
|
b32b39579e | ||
|
00513e66bc | ||
|
8850867b82 | ||
|
d6dfbbf8dd | ||
|
6c4797bce4 | ||
|
2c97eb4115 | ||
|
54b0828c20 | ||
|
0d241a4993 | ||
|
802b0d1a75 | ||
|
e76a7716bc | ||
|
a9cc0a61d9 | ||
|
fe50e47fc6 | ||
|
0006b286ca | ||
|
17f99da45e | ||
|
f7ce03a819 | ||
|
c073501ac0 | ||
|
d4a4747c08 | ||
|
e7b19a5f66 | ||
|
0070ec09a2 | ||
|
b3ec62a3db | ||
|
34ca4ad3b0 | ||
|
e0909731a4 | ||
|
d8d1cb2eda | ||
|
2a24fbadae | ||
|
85e1c4bd47 | ||
|
09fcb0739d | ||
|
0882c2b5c7 | ||
|
bb7763d72b | ||
|
b919d7364a | ||
|
942a37290c | ||
|
ef24c6cbbd | ||
|
cf05571f1c | ||
|
0fa038b4f2 | ||
|
10a33a2978 | ||
|
60a88381cf | ||
|
48d83c7d44 | ||
|
b967b7ed6b | ||
|
b60ecb6171 | ||
|
e8b80216e8 | ||
|
69a5472a16 | ||
|
bd6eb606ca | ||
|
e7f1e83a43 | ||
|
357fe3b793 | ||
|
ad6c06409e | ||
|
2a7feba808 | ||
|
45b7e28db2 | ||
|
daa9479352 | ||
|
0f688bd71a | ||
|
ffe0843bd6 | ||
|
0ee4039853 | ||
|
a3a6e8cdf6 | ||
|
30f60f87f4 | ||
|
0d91657557 | ||
|
ec9b80a64e | ||
|
91909f8886 | ||
|
cc335dae38 | ||
|
0d6ea03ac8 | ||
|
e1370b75e8 | ||
|
c2d0ccea3c | ||
|
9319851118 | ||
|
d45ad76fbc | ||
|
d8b9c3b832 | ||
|
9f2534af3d | ||
|
2c2978b93a | ||
|
c9b0f22a2e | ||
|
2959cd140b | ||
|
7834cfe5f0 | ||
|
2b9c5d0cff | ||
|
cb3b51dcde | ||
|
0c23fe96be | ||
|
9d0bd73ee6 | ||
|
15f096f764 | ||
|
9dd41be608 | ||
|
17f8703c71 | ||
|
5edfd7b6f7 | ||
|
4371772ec7 | ||
|
8e4e08a828 | ||
|
401e6b5a57 | ||
|
01dfe83fcd | ||
|
177c5700ff | ||
|
5d401a4fbb | ||
|
c60ab97103 | ||
|
f3d7a90ac7 | ||
|
7b114f961a | ||
|
8caaf13c84 | ||
|
0218da1ee6 | ||
|
f4786755f1 | ||
|
b9b1fcb4e5 | ||
|
5bfda557bc | ||
|
6e53df403e | ||
|
4a7246ec6e | ||
|
f53a021c08 | ||
|
8fa95d06e1 | ||
|
b34bd9ffd2 | ||
|
fd1a7e34a8 | ||
|
973653a690 | ||
|
11e4dfe940 | ||
|
e7804d39b3 | ||
|
6cfbde43ab | ||
|
30421bf247 | ||
|
ab1b6b45a2 | ||
|
59366c04dd | ||
|
fac437c1ef | ||
|
797f0d92b3 | ||
|
75f3fa5144 | ||
|
6ea1b5c7c3 | ||
|
6a81cc0e83 | ||
|
d3e2c7c51a | ||
|
1c930a2eb9 | ||
|
fb1ea5b37c | ||
|
e82f344a2c | ||
|
10ba205f97 | ||
|
fbc8b97c25 | ||
|
c6a31b21e3 | ||
|
4aa8c4b79d | ||
|
04179ae833 | ||
|
205ecde505 | ||
|
7cb467c960 | ||
|
cbe7c69154 | ||
|
c93cbb614d | ||
|
42c570a6e2 | ||
|
aed47c1178 | ||
|
a1ac4784c8 | ||
|
d8b751d56b | ||
|
213eb2ae88 | ||
|
17b7265a9a | ||
|
3afdf9571e | ||
|
bb8a59d1db | ||
|
d26830d81e | ||
|
1f2c703ddc | ||
|
dd51a6e4d1 | ||
|
caa7597097 | ||
|
409996cb29 | ||
|
a15b37d177 | ||
|
a436ef2126 | ||
|
4c53e6e89d | ||
|
083eb98949 | ||
|
418951415c | ||
|
bac0d0a175 | ||
|
7bde7ebc30 | ||
|
7b7e6555c1 | ||
|
ea8565d0ca | ||
|
1ba2902618 | ||
|
e91e8d565a | ||
|
206e613ace | ||
|
9a88dcf33e | ||
|
9fc9e8972f | ||
|
4fe6703dd4 | ||
|
d613cbb68f | ||
|
be2247b36f | ||
|
66d1f49116 | ||
|
37d35bbbdb | ||
|
321d4ccc8e | ||
|
6e4338d13c | ||
|
677d15d8a7 | ||
|
a7e978dc06 | ||
|
67f5218a73 | ||
|
c2d1329b8b | ||
|
0530ec0651 | ||
|
8a6e18badc | ||
|
1a144a7070 | ||
|
e115432e11 | ||
|
145f6e2d53 | ||
|
9c62311b56 | ||
|
a150d91c48 | ||
|
4730a4e352 | ||
|
67c57be830 | ||
|
d98e72ca25 | ||
|
d81fa1e610 | ||
|
8c12de8b73 | ||
|
9b5218f85b | ||
|
a6cf5c7667 | ||
|
4fca73ffbd | ||
|
46a9023782 | ||
|
5fed443476 | ||
|
0fab0f207c | ||
|
ee67358ee6 | ||
|
cefd44304b | ||
|
2a88cdc76d | ||
|
4c39d37ad5 | ||
|
9b9865f717 | ||
|
3f0456322d | ||
|
16ac005fd6 | ||
|
003fcf446a | ||
|
39703120a4 | ||
|
656c0efc0d | ||
|
63f7c0ed69 | ||
|
5103463524 | ||
|
97254a1e3a | ||
|
9f171a01e8 | ||
|
6c9b6007a3 | ||
|
f4a7c4bd69 | ||
|
5abad18e51 | ||
|
57f70a6d35 | ||
|
cb78f3a707 | ||
|
b331db74ee | ||
|
8fb9ad3fe7 | ||
|
d4b5c55169 | ||
|
a41438d779 | ||
|
0895d8a813 | ||
|
89310d7b7c | ||
|
ca0e936f7c | ||
|
afe767e28a | ||
|
1481b011d9 | ||
|
5f1b968b60 | ||
|
5a729043ce | ||
|
2de0dfcef7 | ||
|
7cc83ed080 | ||
|
31ec03f8e5 | ||
|
0d095c4cf1 | ||
|
dbde09d008 | ||
|
43d33e21e6 | ||
|
c8cf43a255 | ||
|
b2d05672b1 | ||
|
4123c789e6 | ||
|
c65f3c7b68 | ||
|
41e3642e02 | ||
|
eae7602f80 | ||
|
fd12c73cf9 | ||
|
2ef9d70224 | ||
|
3861531fb7 | ||
|
aeff41ff41 | ||
|
b5c8283575 | ||
|
b31cdce073 | ||
|
6040aae12a | ||
|
6ba4afc5bb | ||
|
4707e2b02a | ||
|
08dd73fd72 | ||
|
83bf67b8ca | ||
|
b758ead371 | ||
|
357a0db03e | ||
|
6a3219a5e8 | ||
|
b7e7e82f85 | ||
|
e4c66c8b2b | ||
|
4d4f8b5ee8 | ||
|
5ab75f7eb9 | ||
|
8ff22bc737 | ||
|
1d65287fbb | ||
|
dc24993bf6 | ||
|
ef606d1365 | ||
|
e26ecec545 | ||
|
28e8aa9111 | ||
|
a8ff67e3b8 | ||
|
c311b92ae2 | ||
|
b04e22cd2c | ||
|
4903c70686 | ||
|
04aa963b9a | ||
|
7fdd2e81cf | ||
|
38778c8cac | ||
|
565851b113 | ||
|
cd216b0591 | ||
|
031e2acc63 | ||
|
b3afa6b0a4 | ||
|
40fc2b78d3 | ||
|
24e6c1ea36 | ||
|
275b4e2944 | ||
|
061c93cb7d | ||
|
3b91117724 | ||
|
eb4fac28c4 | ||
|
acb5fc6393 | ||
|
961ed728a1 | ||
|
678fcfc3a3 | ||
|
79d60e6b4a | ||
|
858b2ff6da | ||
|
ba3355c74c | ||
|
6e3028cf86 | ||
|
a28598630d | ||
|
36810b2d42 | ||
|
de9923f2e1 | ||
|
716b1ac528 | ||
|
77663d64a0 | ||
|
49540c7151 | ||
|
03710bc6ba | ||
|
489ae6c9b6 | ||
|
3b54eeb1c5 | ||
|
a9bd753e38 | ||
|
bf15580081 | ||
|
5b5a299b55 | ||
|
051b529c11 | ||
|
fa5fb815fb | ||
|
a4c0a61698 | ||
|
80d8a8190d | ||
|
e69a62c41a | ||
|
46183d4d43 | ||
|
4f2d3cc250 | ||
|
79daf543b0 | ||
|
5b83fb496c | ||
|
3dfe7c27cd | ||
|
e50538c634 | ||
|
92b6ecc4dd | ||
|
588ade0ab2 | ||
|
4375aefb49 | ||
|
c5cba7775a | ||
|
7cf8ec6d61 | ||
|
46cbd3ae7b | ||
|
678cf8a341 | ||
|
3a0f1f6197 | ||
|
902ff23a95 | ||
|
7e2e9aa836 | ||
|
491ef4559f | ||
|
b7bad0f585 | ||
|
ce248bc169 | ||
|
d599be7e7c | ||
|
5b1fc0e6c0 | ||
|
aeece6c201 | ||
|
d7a1b974cd | ||
|
0db1872bd2 | ||
|
4333bc7004 | ||
|
f6caac749e | ||
|
723303e1b6 | ||
|
0daf5bae96 | ||
|
6d59fe2a34 | ||
|
3ed0f005ee | ||
|
66b89ee817 | ||
|
c596c875a6 | ||
|
08c1a29383 | ||
|
ab078d1ea0 | ||
|
b028b09041 | ||
|
44c3eb7b35 | ||
|
f54052c320 | ||
|
d23a055e3b | ||
|
8f76f3184f | ||
|
619c4853fd | ||
|
58fb6ade7c | ||
|
f2c0626c68 | ||
|
3956d2bd63 | ||
|
1d851631d6 | ||
|
517e38e33f | ||
|
a2644a4ebf | ||
|
f7bf6a8080 | ||
|
681c1d9e9a | ||
|
9ab2e69f4f | ||
|
9af2ab57d1 | ||
|
f14e4dc0be | ||
|
39bd9641f4 | ||
|
177c283011 | ||
|
62ff1421e7 | ||
|
2577cbe1ac | ||
|
7542f065a1 | ||
|
aa2abb92ef | ||
|
efc00c1610 | ||
|
7585893cf0 | ||
|
4fd9019c25 | ||
|
f4990aaa95 | ||
|
834fa77385 | ||
|
3acd20c04d | ||
|
878859d7cc | ||
|
7038776ec5 | ||
|
a74001ef6a | ||
|
0bad1794c4 | ||
|
ceec72b869 | ||
|
5c1ed0ec06 | ||
|
ce00fc502b | ||
|
ab82d2af4f | ||
|
2eb3e1aef6 | ||
|
32cb0388cf | ||
|
30f9039a2c | ||
|
8bad63f72d | ||
|
aec4d89550 | ||
|
e8639a37af | ||
|
a92ab2cbe3 | ||
|
fb0bb6e7f3 | ||
|
8dbf870122 | ||
|
50dab48f25 | ||
|
e0c6354ff3 | ||
|
5b03d251fd | ||
|
9c4b69d1ae | ||
|
feba220fff | ||
|
f9efa3bf8f | ||
|
6ebf333982 | ||
|
2c7d07d606 | ||
|
b05185e7cc | ||
|
148547de95 | ||
|
fb6a97789e | ||
|
271f34c7e3 | ||
|
9309f877d1 | ||
|
88db5fb38e | ||
|
4ee0a1b8c5 | ||
|
7617d734e2 | ||
|
a15ae9badb | ||
|
97b6fed909 | ||
|
ab653afae9 | ||
|
df158a741a | ||
|
fb1371ebfa | ||
|
82d5494235 | ||
|
6b754723d9 | ||
|
e003113132 | ||
|
dda492ff87 | ||
|
2459699d27 | ||
|
989acec027 | ||
|
701ab8b24f | ||
|
ed6bfa5fa2 | ||
|
2d2899b68a | ||
|
2d8b80bfa9 | ||
|
c1cc560458 | ||
|
95fb562533 | ||
|
17853ac237 | ||
|
e064a8bbdb | ||
|
8b9e3f1b59 | ||
|
1d38739016 | ||
|
3bb46eaa6f | ||
|
3b1561a99b | ||
|
a61e5c7310 | ||
|
ef8d1ebc0e | ||
|
348b3d3738 | ||
|
3550aa10ba | ||
|
c29eadd9ee | ||
|
aecefaee8d | ||
|
3bab5ec3a7 | ||
|
3c908963ae | ||
|
cba176cdc9 | ||
|
cfdc854409 | ||
|
1d87f78088 | ||
|
63b01376d6 | ||
|
010e518adb | ||
|
6570784b46 | ||
|
63b31f41a7 | ||
|
96eca59afc | ||
|
25978bde8e | ||
|
7691d2b5db | ||
|
edb108322e | ||
|
af3936b68e | ||
|
e76c25f9d3 | ||
|
124f455be2 | ||
|
f679eefe0a |
25
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
25
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -12,14 +12,16 @@ body:
|
||||
1. 请 **确保** 您已经查阅了 [Clash Verge Rev 官方文档](https://clash-verge-rev.github.io/guide/term.html) 以及 [常见问题](https://clash-verge-rev.github.io/faq/windows.html)
|
||||
2. 请 **确保** [已有的问题](https://github.com/clash-verge-rev/clash-verge-rev/issues?q=is%3Aissue) 中没有人提交过相似issue,否则请在已有的issue下进行讨论
|
||||
3. 请 **务必** 给issue填写一个简洁明了的标题,以便他人快速检索
|
||||
4. 请 **务必** 先下载 [Alpha](https://github.com/clash-verge-rev/clash-verge-rev/releases/tag/alpha) 版本测试,确保问题依然存在
|
||||
5. 请 **务必** 按照模板规范详细描述问题,否则issue将会被关闭
|
||||
4. 请 **务必** 查看 [Alpha](https://github.com/clash-verge-rev/clash-verge-rev/releases/tag/alpha) 版本更新日志
|
||||
5. 请 **务必** 尝试 [Alpha](https://github.com/clash-verge-rev/clash-verge-rev/releases/tag/alpha) 版本,确定问题是否仍然存在
|
||||
6. 请 **务必** 按照模板规范详细描述问题以及尝试更新 Alpha 版本,否则issue将会被直接关闭
|
||||
## Before submitting the issue, please make sure of the following checklist:
|
||||
1. Please make sure you have read the [Clash Verge Rev official documentation](https://clash-verge-rev.github.io/guide/term.html) and [FAQ](https://clash-verge-rev.github.io/faq/windows.html)
|
||||
2. Please make sure there is no similar issue in the [existing issues](https://github.com/clash-verge-rev/clash-verge-rev/issues?q=is%3Aissue), otherwise please discuss under the existing issue
|
||||
3. Please be sure to fill in a concise and clear title for the issue so that others can quickly search
|
||||
4. Please be sure to download the [Alpha](https://github.com/clash-verge-rev/clash-verge-rev/releases/tag/alpha) version for testing to ensure that the problem still exists
|
||||
5. Please describe the problem in detail according to the template specification, otherwise the issue will be closed
|
||||
4. Please be sure to check out [Alpha](https://github.com/clash-verge-rev/clash-verge-rev/releases/tag/alpha) version update log
|
||||
5. Please be sure to try the [Alpha](https://github.com/clash-verge-rev/clash-verge-rev/releases/tag/alpha) version to ensure that the problem still exists
|
||||
6. Please describe the problem in detail according to the template specification and try to update the Alpha version, otherwise the issue will be closed
|
||||
|
||||
- type: textarea
|
||||
id: description
|
||||
@ -55,20 +57,9 @@ body:
|
||||
description: 请提供你的操作系统版本,Linux请额外提供桌面环境及窗口系统 / Please provide your OS version, for Linux, please also provide the desktop environment and window system
|
||||
validations:
|
||||
required: true
|
||||
- type: checkboxes
|
||||
id: os-labels
|
||||
attributes:
|
||||
label: 系统标签 / OS Labels
|
||||
description: 请选择受影响的操作系统(至少选择一个) / Please select the affected operating system(s) (select at least one)
|
||||
options:
|
||||
- label: windows
|
||||
- label: macos
|
||||
- label: linux
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: 日志 / Log
|
||||
description: 请提供完整或相关部分的Debug日志(请在“软件左侧菜单”->“设置”->“日志等级”调整到debug,Verge错误请把“杂项设置”->“app日志等级”调整到debug/trace,并重启Verge生效。日志文件在“软件左侧菜单”->“设置”->“日志目录”下) / Please provide a complete or relevant part of the Debug log (please adjust the "Log level" to debug in "Software left menu" -> "Settings" -> "Log level". If there is a Verge error, please adjust "Miscellaneous settings" -> "app log level" to trace, and restart Verge to take effect. The log file is under "Software left menu" -> "Settings" -> "Log directory")
|
||||
label: 日志(勿上传日志文件,请粘贴日志内容) / Log (Do not upload the log file, paste the log content directly)
|
||||
description: 请提供完整或相关部分的Debug日志(请在“软件左侧菜单”->“设置”->“日志等级”调整到debug,Verge错误请把“杂项设置”->“app日志等级”调整到debug,并重启Verge生效。日志文件在“软件左侧菜单”->“设置”->“日志目录”下) / Please provide a complete or relevant part of the Debug log (please adjust the "Log level" to debug in "Software left menu" -> "Settings" -> "Log level". If there is a Verge error, please adjust "Miscellaneous settings" -> "app log level" to debug, and restart Verge to take effect. The log file is under "Software left menu" -> "Settings" -> "Log directory")
|
||||
validations:
|
||||
required: true
|
||||
|
265
.github/workflows/alpha.yml
vendored
265
.github/workflows/alpha.yml
vendored
@ -3,8 +3,8 @@ name: Alpha Build
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# UTC+8 00:00 (UTC 16:00 previous day) and UTC+8 12:00 (UTC 04:00)
|
||||
- cron: "0 16,4 * * *"
|
||||
# UTC+8 0,6,12,18
|
||||
- cron: "0 16,22,4,10 * * *"
|
||||
permissions: write-all
|
||||
env:
|
||||
CARGO_INCREMENTAL: 0
|
||||
@ -25,7 +25,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: Check if commit changed
|
||||
- name: Check if version changed or src changed
|
||||
id: check
|
||||
run: |
|
||||
# For manual workflow_dispatch, always run
|
||||
@ -34,21 +34,182 @@ jobs:
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if current commit is different from the previous one
|
||||
CURRENT_COMMIT=$(git rev-parse HEAD)
|
||||
PREVIOUS_COMMIT=$(git rev-parse HEAD~1)
|
||||
# Store current version from package.json
|
||||
CURRENT_VERSION=$(cat package.json | jq -r '.version')
|
||||
echo "Current version: $CURRENT_VERSION"
|
||||
|
||||
if [ "$CURRENT_COMMIT" != "$PREVIOUS_COMMIT" ]; then
|
||||
echo "New commit detected: $CURRENT_COMMIT"
|
||||
# Get the previous commit's package.json version
|
||||
git checkout HEAD~1 package.json
|
||||
PREVIOUS_VERSION=$(cat package.json | jq -r '.version')
|
||||
echo "Previous version: $PREVIOUS_VERSION"
|
||||
|
||||
# Reset back to current commit
|
||||
git checkout HEAD package.json
|
||||
|
||||
# Check if version changed
|
||||
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
|
||||
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
|
||||
echo "should_run=true" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if src or src-tauri directories changed
|
||||
CURRENT_SRC_HASH=$(git rev-parse HEAD:src)
|
||||
PREVIOUS_SRC_HASH=$(git rev-parse HEAD~1:src 2>/dev/null || echo "")
|
||||
CURRENT_TAURI_HASH=$(git rev-parse HEAD:src-tauri 2>/dev/null || echo "")
|
||||
PREVIOUS_TAURI_HASH=$(git rev-parse HEAD~1:src-tauri 2>/dev/null || echo "")
|
||||
|
||||
echo "Current src hash: $CURRENT_SRC_HASH"
|
||||
echo "Previous src hash: $PREVIOUS_SRC_HASH"
|
||||
echo "Current tauri hash: $CURRENT_TAURI_HASH"
|
||||
echo "Previous tauri hash: $PREVIOUS_TAURI_HASH"
|
||||
|
||||
if [ "$CURRENT_SRC_HASH" != "$PREVIOUS_SRC_HASH" ] || [ "$CURRENT_TAURI_HASH" != "$PREVIOUS_TAURI_HASH" ]; then
|
||||
echo "Source directories changed"
|
||||
echo "should_run=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "No new commits since last run"
|
||||
echo "Version and source directories unchanged"
|
||||
echo "should_run=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
alpha:
|
||||
delete_old_assets:
|
||||
needs: check_commit
|
||||
if: ${{ needs.check_commit.outputs.should_run == 'true' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Delete Old Alpha Release Assets
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const releaseTag = 'alpha';
|
||||
|
||||
try {
|
||||
// Get the release by tag name
|
||||
const { data: release } = await github.rest.repos.getReleaseByTag({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
tag: releaseTag
|
||||
});
|
||||
|
||||
console.log(`Found release with ID: ${release.id}`);
|
||||
|
||||
// Delete each asset
|
||||
if (release.assets && release.assets.length > 0) {
|
||||
console.log(`Deleting ${release.assets.length} assets`);
|
||||
|
||||
for (const asset of release.assets) {
|
||||
console.log(`Deleting asset: ${asset.name} (${asset.id})`);
|
||||
await github.rest.repos.deleteReleaseAsset({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
asset_id: asset.id
|
||||
});
|
||||
}
|
||||
|
||||
console.log('All assets deleted successfully');
|
||||
} else {
|
||||
console.log('No assets found to delete');
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
console.log('Release not found, nothing to delete');
|
||||
} else {
|
||||
console.error('Error:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
update_tag:
|
||||
name: Update tag
|
||||
runs-on: ubuntu-latest
|
||||
needs: delete_old_assets
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Fetch Alpha update logs
|
||||
id: fetch_alpha_logs
|
||||
run: |
|
||||
# Check if UPDATELOG.md exists
|
||||
if [ -f "UPDATELOG.md" ]; then
|
||||
# Extract the section starting with ## and containing -alpha until the next ## or end of file
|
||||
# ALPHA_LOGS=$(awk '/^## .*-alpha/{flag=1; print; next} /^## /{flag=0} flag' UPDATELOG.md)
|
||||
ALPHA_LOGS=$(awk '/^## v/{if(flag) exit; flag=1} flag' UPDATELOG.md)
|
||||
|
||||
if [ -n "$ALPHA_LOGS" ]; then
|
||||
echo "Found alpha update logs"
|
||||
echo "ALPHA_LOGS<<EOF" >> $GITHUB_ENV
|
||||
echo "$ALPHA_LOGS" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
else
|
||||
echo "No alpha sections found in UPDATELOG.md"
|
||||
fi
|
||||
else
|
||||
echo "UPDATELOG.md file not found"
|
||||
fi
|
||||
shell: bash
|
||||
|
||||
- name: Set Env
|
||||
run: |
|
||||
echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV
|
||||
shell: bash
|
||||
|
||||
- run: |
|
||||
# 检查 ALPHA_LOGS 是否存在,如果不存在则使用默认消息
|
||||
if [ -z "$ALPHA_LOGS" ]; then
|
||||
echo "No alpha logs found, using default message"
|
||||
ALPHA_LOGS="More new features are now supported. Check for detailed changelog soon."
|
||||
else
|
||||
echo "Using found alpha logs"
|
||||
fi
|
||||
|
||||
# 生成 release.txt 文件
|
||||
cat > release.txt << EOF
|
||||
$ALPHA_LOGS
|
||||
|
||||
## 我应该下载哪个版本?
|
||||
|
||||
### MacOS
|
||||
- MacOS intel芯片: x64.dmg
|
||||
- MacOS apple M芯片: aarch64.dmg
|
||||
|
||||
### Linux
|
||||
- Linux 64位: amd64.deb/amd64.rpm
|
||||
- Linux arm64 architecture: arm64.deb/aarch64.rpm
|
||||
- Linux armv7架构: armhf.deb/armhfp.rpm
|
||||
|
||||
### Windows (不再支持Win7)
|
||||
#### 正常版本(推荐)
|
||||
- 64位: x64-setup.exe
|
||||
- arm64架构: arm64-setup.exe
|
||||
#### 便携版问题很多不再提供
|
||||
#### 内置Webview2版(体积较大,仅在企业版系统或无法安装webview2时使用)
|
||||
- 64位: x64_fixed_webview2-setup.exe
|
||||
- arm64架构: arm64_fixed_webview2-setup.exe
|
||||
|
||||
### FAQ
|
||||
|
||||
- [常见问题](https://clash-verge-rev.github.io/faq/windows.html)
|
||||
|
||||
### 稳定机场VPN推荐
|
||||
- [狗狗加速](https://verge.dginv.click/#/register?code=oaxsAGo6)
|
||||
|
||||
Created at ${{ env.BUILDTIME }}.
|
||||
EOF
|
||||
|
||||
- name: Upload Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: alpha
|
||||
name: "Clash Verge Rev Alpha"
|
||||
body_path: release.txt
|
||||
prerelease: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
generate_release_notes: true
|
||||
|
||||
alpha:
|
||||
needs: update_tag
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@ -86,7 +247,7 @@ jobs:
|
||||
if: matrix.os == 'ubuntu-22.04'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf
|
||||
sudo apt-get install -y libxslt1.1 libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf
|
||||
|
||||
- name: Install Node
|
||||
uses: actions/setup-node@v4
|
||||
@ -103,8 +264,8 @@ jobs:
|
||||
pnpm i
|
||||
pnpm check ${{ matrix.target }}
|
||||
|
||||
- name: Alpha Version update
|
||||
run: pnpm run fix-alpha-version
|
||||
- name: Release Alpha Version
|
||||
run: pnpm release-alpha-version
|
||||
|
||||
- name: Tauri build
|
||||
uses: tauri-apps/tauri-action@v0
|
||||
@ -129,8 +290,7 @@ jobs:
|
||||
args: --target ${{ matrix.target }}
|
||||
|
||||
alpha-for-linux-arm:
|
||||
needs: check_commit
|
||||
if: ${{ needs.check_commit.outputs.should_run == 'true' }}
|
||||
needs: update_tag
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@ -173,6 +333,9 @@ jobs:
|
||||
pnpm i
|
||||
pnpm check ${{ matrix.target }}
|
||||
|
||||
- name: Release Alpha Version
|
||||
run: pnpm release-alpha-version
|
||||
|
||||
- name: "Setup for linux"
|
||||
run: |-
|
||||
sudo ls -lR /etc/apt/
|
||||
@ -196,6 +359,7 @@ jobs:
|
||||
sudo apt update
|
||||
|
||||
sudo apt install -y \
|
||||
libxslt1.1:${{ matrix.arch }} \
|
||||
libwebkit2gtk-4.1-dev:${{ matrix.arch }} \
|
||||
libayatana-appindicator3-dev:${{ matrix.arch }} \
|
||||
libssl-dev:${{ matrix.arch }} \
|
||||
@ -244,7 +408,6 @@ jobs:
|
||||
with:
|
||||
tag_name: alpha
|
||||
name: "Clash Verge Rev Alpha"
|
||||
body: "More new features are now supported."
|
||||
prerelease: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
files: |
|
||||
@ -252,8 +415,7 @@ jobs:
|
||||
src-tauri/target/${{ matrix.target }}/release/bundle/rpm/*.rpm
|
||||
|
||||
alpha-for-fixed-webview2:
|
||||
needs: check_commit
|
||||
if: ${{ needs.check_commit.outputs.should_run == 'true' }}
|
||||
needs: update_tag
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@ -294,6 +456,9 @@ jobs:
|
||||
pnpm i
|
||||
pnpm check ${{ matrix.target }}
|
||||
|
||||
- name: Release Alpha Version
|
||||
run: pnpm release-alpha-version
|
||||
|
||||
- name: Download WebView2 Runtime
|
||||
run: |
|
||||
invoke-webrequest -uri https://github.com/westinyang/WebView2RuntimeArchive/releases/download/109.0.1518.78/Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.${{ matrix.arch }}.cab -outfile Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.${{ matrix.arch }}.cab
|
||||
@ -338,7 +503,6 @@ jobs:
|
||||
with:
|
||||
tag_name: alpha
|
||||
name: "Clash Verge Rev Alpha"
|
||||
body: "More new features are now supported."
|
||||
prerelease: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
files: src-tauri/target/${{ matrix.target }}/release/bundle/nsis/*setup*
|
||||
@ -347,66 +511,3 @@ jobs:
|
||||
run: pnpm portable-fixed-webview2 ${{ matrix.target }} --alpha
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
update_tag:
|
||||
name: Update tag
|
||||
runs-on: ubuntu-latest
|
||||
needs: [check_commit, alpha, alpha-for-linux-arm, alpha-for-fixed-webview2]
|
||||
if: ${{ needs.check_commit.outputs.should_run == 'true' }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set Env
|
||||
run: |
|
||||
echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV
|
||||
shell: bash
|
||||
|
||||
# - name: Update Tag
|
||||
# uses: richardsimko/update-tag@v1
|
||||
# with:
|
||||
# tag_name: alpha
|
||||
# env:
|
||||
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- run: |
|
||||
cat > release.txt << 'EOF'
|
||||
## 我应该下载哪个版本?
|
||||
|
||||
### MacOS
|
||||
- MacOS intel芯片: x64.dmg
|
||||
- MacOS apple M芯片: aarch64.dmg
|
||||
|
||||
### Linux
|
||||
- Linux 64位: amd64.deb/amd64.rpm
|
||||
- Linux arm64 architecture: arm64.deb/aarch64.rpm
|
||||
- Linux armv7架构: armhf.deb/armhfp.rpm
|
||||
|
||||
### Windows (不再支持Win7)
|
||||
#### 正常版本(推荐)
|
||||
- 64位: x64-setup.exe
|
||||
- arm64架构: arm64-setup.exe
|
||||
#### 便携版问题很多不再提供
|
||||
#### 内置Webview2版(体积较大,仅在企业版系统或无法安装webview2时使用)
|
||||
- 64位: x64_fixed_webview2-setup.exe
|
||||
- arm64架构: arm64_fixed_webview2-setup.exe
|
||||
|
||||
### FAQ
|
||||
|
||||
- [常见问题](https://clash-verge-rev.github.io/faq/windows.html)
|
||||
|
||||
### 稳定机场VPN推荐
|
||||
- [狗狗加速](https://verge.dginv.click/#/register?code=oaxsAGo6)
|
||||
|
||||
Created at ${{ env.BUILDTIME }}.
|
||||
EOF
|
||||
|
||||
- name: Upload Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: alpha
|
||||
name: "Clash Verge Rev Alpha"
|
||||
body_path: release.txt
|
||||
prerelease: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
generate_release_notes: true
|
||||
|
3
.github/workflows/release.yml
vendored
3
.github/workflows/release.yml
vendored
@ -50,7 +50,7 @@ jobs:
|
||||
if: matrix.os == 'ubuntu-22.04'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf
|
||||
sudo apt-get install -y libxslt1.1 libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf
|
||||
|
||||
- name: Install Node
|
||||
uses: actions/setup-node@v4
|
||||
@ -153,6 +153,7 @@ jobs:
|
||||
sudo apt update
|
||||
|
||||
sudo apt install -y \
|
||||
libxslt1.1:${{ matrix.arch }} \
|
||||
libwebkit2gtk-4.1-dev:${{ matrix.arch }} \
|
||||
libayatana-appindicator3-dev:${{ matrix.arch }} \
|
||||
libssl-dev:${{ matrix.arch }} \
|
||||
|
@ -1 +1,16 @@
|
||||
pnpm pretty-quick --staged
|
||||
#!/bin/bash
|
||||
|
||||
#pnpm pretty-quick --staged
|
||||
|
||||
# 运行 clippy fmt
|
||||
cargo fmt --manifest-path ./src-tauri/Cargo.toml
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "rustfmt failed to format the code. Please fix the issues and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#git add .
|
||||
|
||||
# 允许提交
|
||||
exit 0
|
||||
|
13
.husky/pre-push
Normal file
13
.husky/pre-push
Normal file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 运行 clippy
|
||||
# cargo clippy --manifest-path ./src-tauri/Cargo.toml --fix
|
||||
|
||||
# 如果 clippy 失败,阻止 push
|
||||
# if [ $? -ne 0 ]; then
|
||||
# echo "Clippy found issues in sub_crate. Please fix them before pushing."
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
# 允许 push
|
||||
exit 0
|
175
UPDATELOG.md
175
UPDATELOG.md
@ -1,3 +1,174 @@
|
||||
## v2.2.3
|
||||
|
||||
#### 已知问题
|
||||
- 仅在Ubuntu 22.04/24.04,Fedora 41 **Gnome桌面环境** 做过简单测试,不保证其他其他Linux发行版可用,将在未来做进一步适配和调优
|
||||
- MacOS 自定义图标与速率显示推荐图标尺寸为 256x256。其他尺寸(可能)会导致不正常图标和速率间隙
|
||||
- MacOS 下 墙贴主要为浅色,Tray 图标深色时图标闪烁;彩色 Tray 速率颜色淡
|
||||
- Linux 下 Clash Verge Rev 内存占用显著高于 Windows / MacOS
|
||||
|
||||
### 2.2.3 相对于 2.2.2
|
||||
#### 修复了:
|
||||
- 首页“当前代理”因为重复刷新导致的CPU占用过高的问题
|
||||
- “开机自启”和“DNS覆写”开关跳动问题
|
||||
- 自定义托盘图标未能应用更改
|
||||
- MacOS 自定义托盘图标显示速率时图标和文本间隙过大
|
||||
- MacOS 托盘速率显示不全
|
||||
- Linux 在系统服务模式下无法拉起 Mihomo 内核
|
||||
- 使用异步操作,避免获取系统信息和切换代理模式可能带来的崩溃
|
||||
- 相同节点名称可能导致的页面渲染出错
|
||||
- URL Schemes被截断的问题
|
||||
- 首页流量统计卡更好的时间戳范围
|
||||
- 静默启动无法触发自动轻量化计时器
|
||||
|
||||
#### 新增了:
|
||||
- Mihomo(Meta)内核升级至 1.19.4
|
||||
- Clash Verge Rev 从现在开始不再强依赖系统服务和管理权限
|
||||
- 支持根据用户偏好选择Sidecar(用户空间)模式或安装服务
|
||||
- 增加载入初始配置文件的错误提示,防止切换到错误的订阅配置
|
||||
- 检测是否以管理员模式运行软件,如果是提示无法使用开机自启
|
||||
- 代理组显示节点数量
|
||||
- 统一运行模式检测,支持管理员模式下开启TUN模式
|
||||
- 托盘切换代理模式会根据设置自动断开之前连接
|
||||
- 如订阅获取失败回退使用Clash内核代理再次尝试
|
||||
|
||||
#### 移除了:
|
||||
- 实时保存窗口位置和大小。这个功能可能会导致窗口异常大小和位置,还需观察。
|
||||
|
||||
#### 优化了:
|
||||
- 重构了后端内核管理逻辑,更轻量化和有效的管理内核,提高了性能和稳定性
|
||||
- 前端统一刷新应用数据,优化数据获取和刷新逻辑
|
||||
- 优化首页流量图表代码,调整图表文字边距
|
||||
- MacOS 托盘速率更好的显示样式和更新逻辑
|
||||
- 首页仅在有流量图表时显示流量图表区域
|
||||
- 更新DNS默认覆写配置
|
||||
- 移除测试目录,简化资源初始化逻辑
|
||||
|
||||
## v2.2.2
|
||||
|
||||
**发行代号:拓**
|
||||
|
||||
感谢 Tunglies 对 Verge 后端重构,性能优化做出的重大贡献!
|
||||
|
||||
代号释义: 本次发布在功能上的大幅扩展。新首页设计为用户带来全新交互体验,DNS 覆写功能增强网络控制能力,解锁测试页面助力内容访问自由度提升,轻量模式提供灵活使用选择。此外,macOS 应用菜单集成、sidecar 模式、诊断信息导出等新特性进一步丰富了软件的适用场景。这些新增功能显著拓宽了 Clash Verge 的功能边界,为用户提供了更强大的工具和可能性。
|
||||
|
||||
#### 已知问题
|
||||
- 仅在Ubuntu 22.04/24.04,Fedora 41 **Gnome桌面环境** 做过简单测试,不保证其他其他Linux发行版可用,将在未来做进一步适配和调优
|
||||
|
||||
### 2.2.2 相对于 2.2.1(已下架不再提供)
|
||||
#### 修复了:
|
||||
- 弹黑框的问题(原因是服务崩溃触发重装机制)
|
||||
- MacOS进入轻量模式以后隐藏Dock图标
|
||||
- 增加轻量模式缺失的tray翻译
|
||||
- Linux下的窗口边框被削掉的问题
|
||||
|
||||
#### 新增了:
|
||||
- 加强服务检测和重装逻辑
|
||||
- 增强内核与服务保活机制
|
||||
- 增加服务模式下的僵尸进程清理机制
|
||||
- 新增当服务模式多次尝试失败后自动回退至用户空间模式
|
||||
|
||||
### 2.2.1 相对于 2.2.0(已下架不再提供)
|
||||
#### 修复了:
|
||||
1. **首页**
|
||||
- 修复 Direct 模式首页无法渲染
|
||||
- 修复 首页启用轻量模式导致 ClashVergeRev 从托盘退出
|
||||
- 修复 系统代理标识判断不准的问题
|
||||
- 修复 系统代理地址错误的问题
|
||||
- 代理模式“多余的切换动画”
|
||||
2. **系统**
|
||||
- 修复 MacOS 无法使用快捷键粘贴/选择/复制订阅地址。
|
||||
- 修复 代理端口设置同步问题。
|
||||
- 修复 Linux 无法与 Mihomo 核心 和 ClashVergeRev 服务通信
|
||||
3. **界面**
|
||||
- 修复 连接详情卡没有跟随主题色
|
||||
4. **轻量模式**
|
||||
- 修复 MacOS 轻量模式下 Dock 栏图标无法隐藏。
|
||||
|
||||
#### 新增了:
|
||||
1. **首页**
|
||||
- 首页文本过长自动截断
|
||||
2. **轻量模式**
|
||||
- 新增托盘进入轻量模式支持
|
||||
- 新增进入轻量模式快捷键支持
|
||||
3. **系统**
|
||||
- 在 ClashVergeRev 对 Mihomo 进行操作时,总是尝试确保两者运行
|
||||
- 服务器模式下启动mihomo内核的时候查找并停止其他已经存在的内核进程,防止内核假死等问题带来的通信失败
|
||||
4. **托盘**
|
||||
- 新增 MacOS 启用托盘速率显示时,可选隐藏托盘图标显示
|
||||
|
||||
---
|
||||
|
||||
## 2.2.0(已下架不再提供)
|
||||
|
||||
#### 新增功能
|
||||
1. **首页**
|
||||
- 新增首页功能,默认启动页面改为首页。
|
||||
- 首页流量图卡片显示上传/下载名称。
|
||||
- 首页支持轻量模式切换。
|
||||
- 流量统计数据持久保存。
|
||||
- 限制首页配置文件卡片URL长度。
|
||||
|
||||
2. **DNS 设置与覆写**
|
||||
- 新增 DNS 覆写功能。
|
||||
- 默认启用 DNS 覆写。
|
||||
|
||||
3. **解锁测试**
|
||||
- 新增解锁测试页面。
|
||||
|
||||
4. **轻量模式**
|
||||
- 新增轻量模式及设置。
|
||||
- 添加自动轻量模式定时器。
|
||||
|
||||
5. **系统支持**
|
||||
- Mihomo(meta)内核升级 1.19.3
|
||||
- macOS 支持 CMD+W 关闭窗口。
|
||||
- 新增 macOS 应用菜单。
|
||||
- 添加 macOS 安装服务时候的管理员权限提示。
|
||||
- 新增 sidecar(用户空间启动内核) 模式。
|
||||
|
||||
6. **其他**
|
||||
- 增强延迟测试日志和错误处理。
|
||||
- 添加诊断信息导出。
|
||||
- 新增代理命令。
|
||||
|
||||
#### 修复
|
||||
1. **系统**
|
||||
- 修复 Windows 热键崩溃。
|
||||
- 修复 macOS 无框标题。
|
||||
- 修复 macOS 静默启动崩溃。
|
||||
- 修复 macOS tray图标错位到左上角的问题。
|
||||
- 修复 Windows/Linux 运行时崩溃。
|
||||
- 修复 Win10 阴影和边框问题。
|
||||
- 修复 升级或重装后开机自启状态检测和同步问题。
|
||||
|
||||
2. **构建**
|
||||
- 修复构建失败问题。
|
||||
|
||||
#### 优化
|
||||
1. **性能**
|
||||
- 重构后端,巨幅性能优化。
|
||||
- 优化首页组件性能。
|
||||
- 优化流量图表资源使用。
|
||||
- 提升代理组列表滚动性能。
|
||||
- 加快应用退出速度。
|
||||
- 加快进入轻量模式速度。
|
||||
- 优化小数值速度更新。
|
||||
- 增加请求超时至 60 秒。
|
||||
- 修复代理节点选择同步。
|
||||
- 优化修改verge配置性能。
|
||||
|
||||
2. **重构**
|
||||
- 重构后端,巨幅性能优化。
|
||||
- 优化定时器管理。
|
||||
- 重构 MihomoManager 处理流量。
|
||||
- 优化 WebSocket 连接。
|
||||
|
||||
3. **其他**
|
||||
- 更新依赖。
|
||||
- 默认 TUN 堆栈改为 gvisor。
|
||||
|
||||
---
|
||||
|
||||
## v2.1.2
|
||||
|
||||
**发行代号:臻**
|
||||
@ -6,14 +177,14 @@
|
||||
|
||||
感谢 Tychristine 对社区群组管理做出的重大贡献!
|
||||
|
||||
##### 2.1.2相对2.1.1(已下架不在提供)更新了:
|
||||
##### 2.1.2相对2.1.1(已下架不再提供)更新了:
|
||||
|
||||
- 无法更新和签名验证失败的问题(该死的CDN缓存)
|
||||
- 设置菜单区分Verge基本设置和高级设置
|
||||
- 增加v2 Updater的更多功能和权限
|
||||
- 退出Verge后Tun代理状态仍保留的问题
|
||||
|
||||
##### 2.1.1相对2.1.0(已下架不在提供)更新了:
|
||||
##### 2.1.1相对2.1.0(已下架不再提供)更新了:
|
||||
|
||||
- 检测所需的Clash Verge Service版本(杀毒软件误报可能与此有关,因为检测和安装新版本Service需管理员权限)
|
||||
- MacOS下支持彩色托盘图标和更好速率显示(感谢Tunglies)
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 314 KiB |
Binary file not shown.
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 274 KiB |
61
package.json
61
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "clash-verge",
|
||||
"version": "2.1.3-alpha",
|
||||
"version": "2.2.3",
|
||||
"license": "GPL-3.0-only",
|
||||
"scripts": {
|
||||
"dev": "cross-env RUST_BACKTRACE=1 tauri dev -f verge-dev -- --profile fast-dev",
|
||||
@ -16,9 +16,11 @@
|
||||
"updater-fixed-webview2": "node scripts/updater-fixed-webview2.mjs",
|
||||
"portable": "node scripts/portable.mjs",
|
||||
"portable-fixed-webview2": "node scripts/portable-fixed-webview2.mjs",
|
||||
"fix-alpha-version": "node scripts/alpha_version.mjs",
|
||||
"fix-alpha-version": "node scripts/fix-alpha_version.mjs",
|
||||
"release-version": "node scripts/release_version.mjs",
|
||||
"release-alpha-version": "node scripts/release-alpha_version.mjs",
|
||||
"prepare": "husky",
|
||||
"clean": "cd ./src-tauri && cargo clean && cd -"
|
||||
"clippy": "cargo clippy --manifest-path ./src-tauri/Cargo.toml"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dnd-kit/core": "^6.3.1",
|
||||
@ -27,46 +29,49 @@
|
||||
"@emotion/react": "^11.14.0",
|
||||
"@emotion/styled": "^11.14.0",
|
||||
"@juggle/resize-observer": "^3.4.0",
|
||||
"@mui/icons-material": "^6.4.2",
|
||||
"@mui/icons-material": "^6.4.8",
|
||||
"@mui/lab": "6.0.0-beta.25",
|
||||
"@mui/material": "^6.4.2",
|
||||
"@mui/x-data-grid": "^7.25.0",
|
||||
"@mui/material": "^6.4.8",
|
||||
"@mui/x-data-grid": "^7.28.0",
|
||||
"@tauri-apps/api": "2.2.0",
|
||||
"@tauri-apps/plugin-clipboard-manager": "^2.2.1",
|
||||
"@tauri-apps/plugin-clipboard-manager": "^2.2.2",
|
||||
"@tauri-apps/plugin-dialog": "^2.2.0",
|
||||
"@tauri-apps/plugin-fs": "^2.2.0",
|
||||
"@tauri-apps/plugin-global-shortcut": "^2.2.0",
|
||||
"@tauri-apps/plugin-notification": "^2.2.1",
|
||||
"@tauri-apps/plugin-notification": "^2.2.2",
|
||||
"@tauri-apps/plugin-process": "^2.2.0",
|
||||
"@tauri-apps/plugin-shell": "2.2.0",
|
||||
"@tauri-apps/plugin-updater": "2.3.0",
|
||||
"@types/d3-shape": "^3.1.7",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"ahooks": "^3.8.4",
|
||||
"axios": "^1.7.9",
|
||||
"axios": "^1.8.3",
|
||||
"cli-color": "^2.0.4",
|
||||
"d3-shape": "^3.2.0",
|
||||
"dayjs": "1.11.13",
|
||||
"foxact": "^0.2.43",
|
||||
"foxact": "^0.2.44",
|
||||
"glob": "^11.0.1",
|
||||
"i18next": "^24.2.2",
|
||||
"i18next": "^24.2.3",
|
||||
"js-base64": "^3.7.7",
|
||||
"js-yaml": "^4.1.0",
|
||||
"lodash-es": "^4.17.21",
|
||||
"monaco-editor": "^0.52.2",
|
||||
"monaco-yaml": "^5.2.3",
|
||||
"nanoid": "^5.0.9",
|
||||
"monaco-yaml": "^5.3.1",
|
||||
"nanoid": "^5.1.5",
|
||||
"peggy": "^4.2.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-error-boundary": "^4.0.12",
|
||||
"react-error-boundary": "^4.1.2",
|
||||
"react-hook-form": "^7.54.2",
|
||||
"react-i18next": "^13.5.0",
|
||||
"react-markdown": "^9.0.1",
|
||||
"react-monaco-editor": "^0.56.0",
|
||||
"react-router-dom": "^6.22.3",
|
||||
"react-markdown": "^9.1.0",
|
||||
"react-monaco-editor": "^0.56.2",
|
||||
"react-router-dom": "^6.30.0",
|
||||
"react-transition-group": "^4.4.5",
|
||||
"react-virtuoso": "^4.6.3",
|
||||
"react-virtuoso": "^4.12.5",
|
||||
"recharts": "^2.15.1",
|
||||
"sockette": "^2.0.6",
|
||||
"swr": "^2.3.0",
|
||||
"swr": "^2.3.3",
|
||||
"tar": "^7.4.3",
|
||||
"types-pac": "^1.0.3",
|
||||
"zustand": "^5.0.3"
|
||||
@ -80,20 +85,20 @@
|
||||
"@types/react": "^18.3.18",
|
||||
"@types/react-dom": "^18.3.5",
|
||||
"@types/react-transition-group": "^4.4.12",
|
||||
"@vitejs/plugin-legacy": "^6.0.0",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"@vitejs/plugin-legacy": "^6.0.2",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"adm-zip": "^0.5.16",
|
||||
"cross-env": "^7.0.3",
|
||||
"https-proxy-agent": "^7.0.6",
|
||||
"husky": "^9.1.7",
|
||||
"meta-json-schema": "^1.19.1",
|
||||
"meta-json-schema": "^1.19.3",
|
||||
"node-fetch": "^3.3.2",
|
||||
"prettier": "^3.4.2",
|
||||
"pretty-quick": "^4.0.0",
|
||||
"sass": "^1.83.4",
|
||||
"terser": "^5.37.0",
|
||||
"typescript": "^5.7.3",
|
||||
"vite": "^6.0.11",
|
||||
"prettier": "^3.5.3",
|
||||
"pretty-quick": "^4.1.1",
|
||||
"sass": "^1.86.0",
|
||||
"terser": "^5.39.0",
|
||||
"typescript": "^5.8.2",
|
||||
"vite": "^6.2.2",
|
||||
"vite-plugin-monaco-editor": "^1.1.0",
|
||||
"vite-plugin-svgr": "^4.3.0"
|
||||
},
|
||||
|
7608
pnpm-lock.yaml
generated
7608
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
96
scripts/release-alpha_version.mjs
Normal file
96
scripts/release-alpha_version.mjs
Normal file
@ -0,0 +1,96 @@
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
/**
|
||||
* 更新 package.json 文件中的版本号
|
||||
*/
|
||||
async function updatePackageVersion() {
|
||||
const _dirname = process.cwd();
|
||||
const packageJsonPath = path.join(_dirname, "package.json");
|
||||
try {
|
||||
const data = await fs.readFile(packageJsonPath, "utf8");
|
||||
const packageJson = JSON.parse(data);
|
||||
|
||||
let result = packageJson.version;
|
||||
if (!result.includes("alpha")) {
|
||||
result = `${result}-alpha`;
|
||||
}
|
||||
|
||||
console.log("[INFO]: Current package.json version is: ", result);
|
||||
packageJson.version = result;
|
||||
await fs.writeFile(
|
||||
packageJsonPath,
|
||||
JSON.stringify(packageJson, null, 2),
|
||||
"utf8",
|
||||
);
|
||||
console.log(`[INFO]: package.json version updated to: ${result}`);
|
||||
} catch (error) {
|
||||
console.error("Error updating package.json version:", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 Cargo.toml 文件中的版本号
|
||||
*/
|
||||
async function updateCargoVersion() {
|
||||
const _dirname = process.cwd();
|
||||
const cargoTomlPath = path.join(_dirname, "src-tauri", "Cargo.toml");
|
||||
try {
|
||||
const data = await fs.readFile(cargoTomlPath, "utf8");
|
||||
const lines = data.split("\n");
|
||||
|
||||
const updatedLines = lines.map((line) => {
|
||||
if (line.startsWith("version =")) {
|
||||
const versionMatch = line.match(/version\s*=\s*"([^"]+)"/);
|
||||
if (versionMatch && !versionMatch[1].includes("alpha")) {
|
||||
const newVersion = `${versionMatch[1]}-alpha`;
|
||||
return line.replace(versionMatch[1], newVersion);
|
||||
}
|
||||
}
|
||||
return line;
|
||||
});
|
||||
|
||||
await fs.writeFile(cargoTomlPath, updatedLines.join("\n"), "utf8");
|
||||
} catch (error) {
|
||||
console.error("Error updating Cargo.toml version:", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 tauri.conf.json 文件中的版本号
|
||||
*/
|
||||
async function updateTauriConfigVersion() {
|
||||
const _dirname = process.cwd();
|
||||
const tauriConfigPath = path.join(_dirname, "src-tauri", "tauri.conf.json");
|
||||
try {
|
||||
const data = await fs.readFile(tauriConfigPath, "utf8");
|
||||
const tauriConfig = JSON.parse(data);
|
||||
|
||||
let version = tauriConfig.version;
|
||||
if (!version.includes("alpha")) {
|
||||
version = `${version}-alpha`;
|
||||
}
|
||||
|
||||
console.log("[INFO]: Current tauri.conf.json version is: ", version);
|
||||
tauriConfig.version = version;
|
||||
await fs.writeFile(
|
||||
tauriConfigPath,
|
||||
JSON.stringify(tauriConfig, null, 2),
|
||||
"utf8",
|
||||
);
|
||||
console.log(`[INFO]: tauri.conf.json version updated to: ${version}`);
|
||||
} catch (error) {
|
||||
console.error("Error updating tauri.conf.json version:", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主函数,依次更新所有文件的版本号
|
||||
*/
|
||||
async function main() {
|
||||
await updatePackageVersion();
|
||||
await updateCargoVersion();
|
||||
await updateTauriConfigVersion();
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
197
scripts/release_version.mjs
Normal file
197
scripts/release_version.mjs
Normal file
@ -0,0 +1,197 @@
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import { program } from "commander";
|
||||
|
||||
/**
|
||||
* 验证版本号格式
|
||||
* @param {string} version
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isValidVersion(version) {
|
||||
return /^v?\d+\.\d+\.\d+(-(alpha|beta|rc)(\.\d+)?)?$/i.test(version);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标准化版本号(确保v前缀可选)
|
||||
* @param {string} version
|
||||
* @returns {string}
|
||||
*/
|
||||
function normalizeVersion(version) {
|
||||
return version.startsWith("v") ? version : `v${version}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 package.json 文件中的版本号
|
||||
* @param {string} newVersion 新版本号
|
||||
*/
|
||||
async function updatePackageVersion(newVersion) {
|
||||
const _dirname = process.cwd();
|
||||
const packageJsonPath = path.join(_dirname, "package.json");
|
||||
try {
|
||||
const data = await fs.readFile(packageJsonPath, "utf8");
|
||||
const packageJson = JSON.parse(data);
|
||||
|
||||
console.log(
|
||||
"[INFO]: Current package.json version is: ",
|
||||
packageJson.version,
|
||||
);
|
||||
packageJson.version = newVersion.startsWith("v")
|
||||
? newVersion.slice(1)
|
||||
: newVersion;
|
||||
await fs.writeFile(
|
||||
packageJsonPath,
|
||||
JSON.stringify(packageJson, null, 2),
|
||||
"utf8",
|
||||
);
|
||||
console.log(
|
||||
`[INFO]: package.json version updated to: ${packageJson.version}`,
|
||||
);
|
||||
return packageJson.version;
|
||||
} catch (error) {
|
||||
console.error("Error updating package.json version:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 Cargo.toml 文件中的版本号
|
||||
* @param {string} newVersion 新版本号
|
||||
*/
|
||||
async function updateCargoVersion(newVersion) {
|
||||
const _dirname = process.cwd();
|
||||
const cargoTomlPath = path.join(_dirname, "src-tauri", "Cargo.toml");
|
||||
try {
|
||||
const data = await fs.readFile(cargoTomlPath, "utf8");
|
||||
const lines = data.split("\n");
|
||||
|
||||
const versionWithoutV = newVersion.startsWith("v")
|
||||
? newVersion.slice(1)
|
||||
: newVersion;
|
||||
|
||||
const updatedLines = lines.map((line) => {
|
||||
if (line.trim().startsWith("version =")) {
|
||||
return line.replace(
|
||||
/version\s*=\s*"[^"]+"/,
|
||||
`version = "${versionWithoutV}"`,
|
||||
);
|
||||
}
|
||||
return line;
|
||||
});
|
||||
|
||||
await fs.writeFile(cargoTomlPath, updatedLines.join("\n"), "utf8");
|
||||
console.log(`[INFO]: Cargo.toml version updated to: ${versionWithoutV}`);
|
||||
} catch (error) {
|
||||
console.error("Error updating Cargo.toml version:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 tauri.conf.json 文件中的版本号
|
||||
* @param {string} newVersion 新版本号
|
||||
*/
|
||||
async function updateTauriConfigVersion(newVersion) {
|
||||
const _dirname = process.cwd();
|
||||
const tauriConfigPath = path.join(_dirname, "src-tauri", "tauri.conf.json");
|
||||
try {
|
||||
const data = await fs.readFile(tauriConfigPath, "utf8");
|
||||
const tauriConfig = JSON.parse(data);
|
||||
|
||||
const versionWithoutV = newVersion.startsWith("v")
|
||||
? newVersion.slice(1)
|
||||
: newVersion;
|
||||
|
||||
console.log(
|
||||
"[INFO]: Current tauri.conf.json version is: ",
|
||||
tauriConfig.version,
|
||||
);
|
||||
tauriConfig.version = versionWithoutV;
|
||||
await fs.writeFile(
|
||||
tauriConfigPath,
|
||||
JSON.stringify(tauriConfig, null, 2),
|
||||
"utf8",
|
||||
);
|
||||
console.log(
|
||||
`[INFO]: tauri.conf.json version updated to: ${versionWithoutV}`,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error updating tauri.conf.json version:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前版本号(从package.json)
|
||||
*/
|
||||
async function getCurrentVersion() {
|
||||
const _dirname = process.cwd();
|
||||
const packageJsonPath = path.join(_dirname, "package.json");
|
||||
try {
|
||||
const data = await fs.readFile(packageJsonPath, "utf8");
|
||||
const packageJson = JSON.parse(data);
|
||||
return packageJson.version;
|
||||
} catch (error) {
|
||||
console.error("Error getting current version:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主函数,更新所有文件的版本号
|
||||
* @param {string} versionArg 版本参数(可以是标签或完整版本号)
|
||||
*/
|
||||
async function main(versionArg) {
|
||||
if (!versionArg) {
|
||||
console.error("Error: Version argument is required");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
let newVersion;
|
||||
const validTags = ["alpha", "beta", "rc"];
|
||||
|
||||
// 判断参数是标签还是完整版本号
|
||||
if (validTags.includes(versionArg.toLowerCase())) {
|
||||
// 标签模式:在当前版本基础上添加标签
|
||||
const currentVersion = await getCurrentVersion();
|
||||
const baseVersion = currentVersion.replace(
|
||||
/-(alpha|beta|rc)(\.\d+)?$/i,
|
||||
"",
|
||||
);
|
||||
newVersion = `${baseVersion}-${versionArg.toLowerCase()}`;
|
||||
} else {
|
||||
// 完整版本号模式
|
||||
if (!isValidVersion(versionArg)) {
|
||||
console.error(
|
||||
"Error: Invalid version format. Expected format: vX.X.X or vX.X.X-tag (e.g. v2.2.3 or v2.2.3-alpha)",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
newVersion = normalizeVersion(versionArg);
|
||||
}
|
||||
|
||||
console.log(`[INFO]: Updating versions to: ${newVersion}`);
|
||||
await updatePackageVersion(newVersion);
|
||||
await updateCargoVersion(newVersion);
|
||||
await updateTauriConfigVersion(newVersion);
|
||||
console.log("[SUCCESS]: All version updates completed successfully!");
|
||||
} catch (error) {
|
||||
console.error("[ERROR]: Failed to update versions:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Example:
|
||||
// pnpm release-version 2.2.3-alpha
|
||||
// 设置命令行界面
|
||||
program
|
||||
.name("pnpm release-version")
|
||||
.description(
|
||||
"Update project version numbers. Can add tag (alpha/beta/rc) or set full version (e.g. v2.2.3 or v2.2.3-alpha)",
|
||||
)
|
||||
.argument(
|
||||
"<version>",
|
||||
"version tag (alpha/beta/rc) or full version (e.g. v2.2.3 or v2.2.3-alpha)",
|
||||
)
|
||||
.action(main)
|
||||
.parse(process.argv);
|
@ -43,3 +43,42 @@ export async function resolveUpdateLog(tag) {
|
||||
|
||||
return map[tag].join("\n").trim();
|
||||
}
|
||||
|
||||
export async function resolveUpdateLogDefault() {
|
||||
const cwd = process.cwd();
|
||||
const file = path.join(cwd, UPDATE_LOG);
|
||||
|
||||
if (!fs.existsSync(file)) {
|
||||
throw new Error("could not found UPDATELOG.md");
|
||||
}
|
||||
|
||||
const data = await fsp.readFile(file, "utf-8");
|
||||
|
||||
const reTitle = /^## v[\d\.]+/;
|
||||
const reEnd = /^---/;
|
||||
|
||||
let isCapturing = false;
|
||||
let content = [];
|
||||
let firstTag = "";
|
||||
|
||||
for (const line of data.split("\n")) {
|
||||
if (reTitle.test(line) && !isCapturing) {
|
||||
isCapturing = true;
|
||||
firstTag = line.slice(3).trim();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isCapturing) {
|
||||
if (reEnd.test(line)) {
|
||||
break;
|
||||
}
|
||||
content.push(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (!firstTag) {
|
||||
throw new Error("could not found any version tag in UPDATELOG.md");
|
||||
}
|
||||
|
||||
return content.join("\n").trim();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import fetch from "node-fetch";
|
||||
import { getOctokit, context } from "@actions/github";
|
||||
import { resolveUpdateLog } from "./updatelog.mjs";
|
||||
import { resolveUpdateLog, resolveUpdateLogDefault } from "./updatelog.mjs";
|
||||
|
||||
// Add stable update JSON filenames
|
||||
const UPDATE_TAG_NAME = "updater";
|
||||
@ -8,8 +8,8 @@ const UPDATE_JSON_FILE = "update.json";
|
||||
const UPDATE_JSON_PROXY = "update-proxy.json";
|
||||
// Add alpha update JSON filenames
|
||||
const ALPHA_TAG_NAME = "updater-alpha";
|
||||
const ALPHA_UPDATE_JSON_FILE = "update-alpha.json";
|
||||
const ALPHA_UPDATE_JSON_PROXY = "update-alpha-proxy.json";
|
||||
const ALPHA_UPDATE_JSON_FILE = "update.json";
|
||||
const ALPHA_UPDATE_JSON_PROXY = "update-proxy.json";
|
||||
|
||||
/// generate update.json
|
||||
/// upload to update tag's release asset
|
||||
@ -78,6 +78,7 @@ async function resolveUpdater() {
|
||||
async function processRelease(github, options, tag, isAlpha) {
|
||||
if (!tag) return;
|
||||
|
||||
try {
|
||||
const { data: release } = await github.rest.repos.getReleaseByTag({
|
||||
...options,
|
||||
tag: tag.name,
|
||||
@ -85,8 +86,8 @@ async function processRelease(github, options, tag, isAlpha) {
|
||||
|
||||
const updateData = {
|
||||
name: tag.name,
|
||||
notes: await resolveUpdateLog(tag.name).catch(
|
||||
() => "No changelog available",
|
||||
notes: await resolveUpdateLog(tag.name).catch(() =>
|
||||
resolveUpdateLogDefault().catch(() => "No changelog available"),
|
||||
),
|
||||
pub_date: new Date().toISOString(),
|
||||
platforms: {
|
||||
@ -216,10 +217,42 @@ async function processRelease(github, options, tag, isAlpha) {
|
||||
);
|
||||
|
||||
try {
|
||||
const { data: updateRelease } = await github.rest.repos.getReleaseByTag({
|
||||
let updateRelease;
|
||||
|
||||
try {
|
||||
// Try to get the existing release
|
||||
const response = await github.rest.repos.getReleaseByTag({
|
||||
...options,
|
||||
tag: releaseTag,
|
||||
});
|
||||
updateRelease = response.data;
|
||||
console.log(
|
||||
`Found existing ${releaseTag} release with ID: ${updateRelease.id}`,
|
||||
);
|
||||
} catch (error) {
|
||||
// If release doesn't exist, create it
|
||||
if (error.status === 404) {
|
||||
console.log(
|
||||
`Release with tag ${releaseTag} not found, creating new release...`,
|
||||
);
|
||||
const createResponse = await github.rest.repos.createRelease({
|
||||
...options,
|
||||
tag_name: releaseTag,
|
||||
name: isAlpha
|
||||
? "Auto-update Alpha Channel"
|
||||
: "Auto-update Stable Channel",
|
||||
body: `This release contains the update information for ${isAlpha ? "alpha" : "stable"} channel.`,
|
||||
prerelease: isAlpha,
|
||||
});
|
||||
updateRelease = createResponse.data;
|
||||
console.log(
|
||||
`Created new ${releaseTag} release with ID: ${updateRelease.id}`,
|
||||
);
|
||||
} else {
|
||||
// If it's another error, throw it
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// File names based on release type
|
||||
const jsonFile = isAlpha ? ALPHA_UPDATE_JSON_FILE : UPDATE_JSON_FILE;
|
||||
@ -265,6 +298,16 @@ async function processRelease(github, options, tag, isAlpha) {
|
||||
error.message,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
console.log(`Release not found for tag: ${tag.name}, skipping...`);
|
||||
} else {
|
||||
console.error(
|
||||
`Failed to get release for tag: ${tag.name}`,
|
||||
error.message,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get the signature file content
|
||||
|
1
src-tauri/.clippy.toml
Normal file
1
src-tauri/.clippy.toml
Normal file
@ -0,0 +1 @@
|
||||
avoid-breaking-exported-api = true
|
1702
src-tauri/Cargo.lock
generated
1702
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "clash-verge"
|
||||
version = "2.1.2"
|
||||
version = "2.2.3"
|
||||
description = "clash verge"
|
||||
authors = ["zzzgydi", "wonfen", "MystiPanda"]
|
||||
license = "GPL-3.0-only"
|
||||
@ -13,70 +13,72 @@ build = "build.rs"
|
||||
identifier = "io.github.clash-verge-rev.clash-verge-rev"
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2.0.6", features = [] }
|
||||
tauri-build = { version = "2.1.0", features = [] }
|
||||
|
||||
[dependencies]
|
||||
warp = "0.3"
|
||||
anyhow = "1.0.97"
|
||||
dirs = "6.0"
|
||||
open = "5.1"
|
||||
open = "5.3"
|
||||
log = "0.4"
|
||||
dunce = "1.0"
|
||||
log4rs = "1"
|
||||
nanoid = "0.4"
|
||||
chrono = "0.4.40"
|
||||
sysinfo = "0.33.1"
|
||||
sysinfo = "0.34"
|
||||
boa_engine = "0.20.0"
|
||||
serde_json = "1.0"
|
||||
serde_yaml = "0.9"
|
||||
once_cell = "1.20.3"
|
||||
once_cell = "1.21.3"
|
||||
port_scanner = "0.1.5"
|
||||
delay_timer = "0.11.6"
|
||||
parking_lot = "0.12"
|
||||
percent-encoding = "2.3.1"
|
||||
window-shadows = { version = "0.2.2" }
|
||||
tokio = { version = "1.43", features = ["full"] }
|
||||
tokio = { version = "1.44", features = [
|
||||
"rt-multi-thread",
|
||||
"macros",
|
||||
"time",
|
||||
"sync",
|
||||
] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
reqwest = { version = "0.12", features = ["json", "rustls-tls"] }
|
||||
reqwest = { version = "0.12", features = ["json", "rustls-tls", "cookies"] }
|
||||
regex = "1.11.1"
|
||||
sysproxy = { git = "https://github.com/clash-verge-rev/sysproxy-rs", rev = "3d748b5" }
|
||||
image = "0.25.5"
|
||||
image = "0.25.6"
|
||||
imageproc = "0.25.0"
|
||||
rusttype = "0.9"
|
||||
tauri = { version = "2.3.1", features = [
|
||||
tauri = { version = "2.4.0", features = [
|
||||
"protocol-asset",
|
||||
"devtools",
|
||||
"tray-icon",
|
||||
"image-ico",
|
||||
"image-png",
|
||||
] }
|
||||
network-interface = { version = "2.0.0", features = ["serde"] }
|
||||
network-interface = { version = "2.0.1", features = ["serde"] }
|
||||
tauri-plugin-shell = "2.2.0"
|
||||
tauri-plugin-dialog = "2.2.0"
|
||||
tauri-plugin-fs = "2.2.0"
|
||||
tauri-plugin-notification = "2.2.1"
|
||||
tauri-plugin-process = "2.2.0"
|
||||
tauri-plugin-clipboard-manager = "2.2.1"
|
||||
tauri-plugin-clipboard-manager = "2.2.2"
|
||||
tauri-plugin-deep-link = "2.2.0"
|
||||
tauri-plugin-devtools = "2.0.0-rc"
|
||||
url = "2.5.4"
|
||||
zip = "2.2.3"
|
||||
reqwest_dav = "0.1.14"
|
||||
tauri-plugin-devtools = "2.0.0"
|
||||
zip = "2.5.0"
|
||||
reqwest_dav = "0.1.15"
|
||||
aes-gcm = { version = "0.10.3", features = ["std"] }
|
||||
base64 = "0.22.1"
|
||||
getrandom = "0.3.1"
|
||||
getrandom = "0.3.2"
|
||||
tokio-tungstenite = "0.26.2"
|
||||
futures = "0.3"
|
||||
sys-locale = "0.3.1"
|
||||
async-trait = "0.1.87"
|
||||
mihomo_api = { path = "./src/crate_mihomo_api" }
|
||||
sys-locale = "0.3.2"
|
||||
async-trait = "0.1.88"
|
||||
mihomo_api = { path = "src_crates/crate_mihomo_api" }
|
||||
ab_glyph = "0.2.29"
|
||||
tungstenite = "0.26.2"
|
||||
libc = "0.2"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
runas = "=1.2.0"
|
||||
deelevate = "0.2.0"
|
||||
winreg = "0.55.0"
|
||||
url = "2.5.4"
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
users = "0.11.0"
|
||||
@ -84,9 +86,8 @@ users = "0.11.0"
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
tauri-plugin-autostart = "2.2.0"
|
||||
tauri-plugin-global-shortcut = "2.2.0"
|
||||
tauri-plugin-updater = "2.5.1"
|
||||
tauri-plugin-updater = "2.6.1"
|
||||
tauri-plugin-window-state = "2.2.1"
|
||||
#openssl
|
||||
|
||||
[features]
|
||||
default = ["custom-protocol"]
|
||||
@ -125,11 +126,12 @@ name = "app_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.11.0"
|
||||
mockito = "1.7.0"
|
||||
tempfile = "3.17.1"
|
||||
tempfile = "3.19.1"
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"src/crate_mihomo_api"
|
||||
]
|
||||
members = ["src_crates/crate_mihomo_api"]
|
||||
|
||||
# [patch.crates-io]
|
||||
# bitflags = { git = "https://github.com/bitflags/bitflags", rev = "2.9.0" }
|
||||
# zerocopy = { git = "https://github.com/google/zerocopy", rev = "v0.8.24" }
|
||||
# tungstenite = { git = "https://github.com/snapview/tungstenite-rs", rev = "v0.26.2" }
|
||||
|
@ -68,7 +68,6 @@
|
||||
"shell:allow-spawn",
|
||||
"shell:allow-stdin-write",
|
||||
"dialog:allow-open",
|
||||
"notification:default",
|
||||
"global-shortcut:allow-is-registered",
|
||||
"global-shortcut:allow-register",
|
||||
"global-shortcut:allow-register-all",
|
||||
@ -79,7 +78,6 @@
|
||||
"clipboard-manager:allow-read-text",
|
||||
"clipboard-manager:allow-write-text",
|
||||
"shell:default",
|
||||
"dialog:default",
|
||||
"notification:default"
|
||||
"dialog:default"
|
||||
]
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
use super::CmdResult;
|
||||
use crate::{feat, utils::dirs, wrap_err};
|
||||
use crate::{
|
||||
feat, logging,
|
||||
utils::{dirs, logging::Type},
|
||||
wrap_err,
|
||||
};
|
||||
use tauri::Manager;
|
||||
|
||||
/// 打开应用程序所在目录
|
||||
@ -70,6 +74,13 @@ pub fn get_app_dir() -> CmdResult<String> {
|
||||
Ok(app_home_dir)
|
||||
}
|
||||
|
||||
/// 获取当前自启动状态
|
||||
#[tauri::command]
|
||||
pub fn get_auto_launch_status() -> CmdResult<bool> {
|
||||
use crate::core::sysopt::Sysopt;
|
||||
wrap_err!(Sysopt::global().get_launch_status())
|
||||
}
|
||||
|
||||
/// 下载图标缓存
|
||||
#[tauri::command]
|
||||
pub async fn download_icon_cache(url: String, name: String) -> CmdResult<String> {
|
||||
@ -93,7 +104,8 @@ pub async fn download_icon_cache(url: String, name: String) -> CmdResult<String>
|
||||
let response = wrap_err!(reqwest::get(&url).await)?;
|
||||
|
||||
// 检查内容类型是否为图片
|
||||
let content_type = response.headers()
|
||||
let content_type = response
|
||||
.headers()
|
||||
.get(reqwest::header::CONTENT_TYPE)
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.unwrap_or("");
|
||||
@ -104,10 +116,10 @@ pub async fn download_icon_cache(url: String, name: String) -> CmdResult<String>
|
||||
let content = wrap_err!(response.bytes().await)?;
|
||||
|
||||
// 检查内容是否为HTML (针对CDN错误页面)
|
||||
let is_html = content.len() > 15 &&
|
||||
(content.starts_with(b"<!DOCTYPE html") ||
|
||||
content.starts_with(b"<html") ||
|
||||
content.starts_with(b"<?xml"));
|
||||
let is_html = content.len() > 15
|
||||
&& (content.starts_with(b"<!DOCTYPE html")
|
||||
|| content.starts_with(b"<html")
|
||||
|| content.starts_with(b"<?xml"));
|
||||
|
||||
// 只有当内容确实是图片时才保存
|
||||
if is_image && !is_html {
|
||||
@ -129,7 +141,7 @@ pub async fn download_icon_cache(url: String, name: String) -> CmdResult<String>
|
||||
// 再次检查目标文件是否已存在,避免重命名覆盖其他线程已完成的文件
|
||||
if !icon_path.exists() {
|
||||
match std::fs::rename(&temp_path, &icon_path) {
|
||||
Ok(_) => {},
|
||||
Ok(_) => {}
|
||||
Err(_) => {
|
||||
let _ = std::fs::remove_file(&temp_path);
|
||||
if icon_path.exists() {
|
||||
@ -144,7 +156,7 @@ pub async fn download_icon_cache(url: String, name: String) -> CmdResult<String>
|
||||
Ok(icon_path.to_string_lossy().to_string())
|
||||
} else {
|
||||
let _ = std::fs::remove_file(&temp_path);
|
||||
Err(format!("下载的内容不是有效图片: {}", url).into())
|
||||
Err(format!("下载的内容不是有效图片: {}", url))
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,8 +170,7 @@ pub struct IconInfo {
|
||||
/// 复制图标文件
|
||||
#[tauri::command]
|
||||
pub fn copy_icon_file(path: String, icon_info: IconInfo) -> CmdResult<String> {
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::{fs, path::Path};
|
||||
|
||||
let file_path = Path::new(&path);
|
||||
|
||||
@ -187,7 +198,14 @@ pub fn copy_icon_file(path: String, icon_info: IconInfo) -> CmdResult<String> {
|
||||
)
|
||||
.unwrap_or_default();
|
||||
}
|
||||
|
||||
logging!(
|
||||
info,
|
||||
Type::Cmd,
|
||||
true,
|
||||
"Copying icon file path: {:?} -> file dist: {:?}",
|
||||
path,
|
||||
dest_path
|
||||
);
|
||||
match fs::copy(file_path, &dest_path) {
|
||||
Ok(_) => Ok(dest_path.to_string_lossy().to_string()),
|
||||
Err(err) => Err(err.to_string()),
|
||||
|
@ -24,7 +24,8 @@ pub async fn patch_clash_config(payload: Mapping) -> CmdResult {
|
||||
/// 修改Clash模式
|
||||
#[tauri::command]
|
||||
pub async fn patch_clash_mode(payload: String) -> CmdResult {
|
||||
Ok(feat::change_clash_mode(payload))
|
||||
feat::change_clash_mode(payload);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 切换Clash核心
|
||||
@ -98,9 +99,11 @@ pub async fn save_dns_config(dns_config: Mapping) -> CmdResult {
|
||||
/// 应用或撤销DNS配置
|
||||
#[tauri::command]
|
||||
pub fn apply_dns_config(apply: bool) -> CmdResult {
|
||||
use crate::config::Config;
|
||||
use crate::core::{handle, CoreManager};
|
||||
use crate::utils::dirs;
|
||||
use crate::{
|
||||
config::Config,
|
||||
core::{handle, CoreManager},
|
||||
utils::dirs,
|
||||
};
|
||||
use tauri::async_runtime;
|
||||
|
||||
// 使用spawn来处理异步操作
|
||||
|
9
src-tauri/src/cmd/lightweight.rs
Normal file
9
src-tauri/src/cmd/lightweight.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use crate::module::lightweight;
|
||||
|
||||
use super::CmdResult;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn entry_lightweight_mode() -> CmdResult {
|
||||
lightweight::entry_lightweight_mode();
|
||||
Ok(())
|
||||
}
|
1297
src-tauri/src/cmd/media_unlock_checker.rs
Normal file
1297
src-tauri/src/cmd/media_unlock_checker.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -4,29 +4,35 @@ use anyhow::Result;
|
||||
pub type CmdResult<T = ()> = Result<T, String>;
|
||||
|
||||
// Command modules
|
||||
pub mod profile;
|
||||
pub mod validate;
|
||||
pub mod uwp;
|
||||
pub mod webdav;
|
||||
pub mod app;
|
||||
pub mod network;
|
||||
pub mod clash;
|
||||
pub mod verge;
|
||||
pub mod lightweight;
|
||||
pub mod media_unlock_checker;
|
||||
pub mod network;
|
||||
pub mod profile;
|
||||
pub mod proxy;
|
||||
pub mod runtime;
|
||||
pub mod save_profile;
|
||||
pub mod service;
|
||||
pub mod system;
|
||||
pub mod proxy;
|
||||
pub mod uwp;
|
||||
pub mod validate;
|
||||
pub mod verge;
|
||||
pub mod webdav;
|
||||
|
||||
// Re-export all command functions for backwards compatibility
|
||||
pub use profile::*;
|
||||
pub use validate::*;
|
||||
pub use uwp::*;
|
||||
pub use webdav::*;
|
||||
pub use app::*;
|
||||
pub use network::*;
|
||||
pub use clash::*;
|
||||
pub use verge::*;
|
||||
pub use lightweight::*;
|
||||
pub use media_unlock_checker::*;
|
||||
pub use network::*;
|
||||
pub use profile::*;
|
||||
pub use proxy::*;
|
||||
pub use runtime::*;
|
||||
pub use save_profile::*;
|
||||
pub use service::*;
|
||||
pub use system::*;
|
||||
pub use proxy::*;
|
||||
pub use uwp::*;
|
||||
pub use validate::*;
|
||||
pub use verge::*;
|
||||
pub use webdav::*;
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::wrap_err;
|
||||
use super::CmdResult;
|
||||
use sysproxy::{Autoproxy, Sysproxy};
|
||||
use serde_yaml::Mapping;
|
||||
use crate::wrap_err;
|
||||
use network_interface::NetworkInterface;
|
||||
use serde_yaml::Mapping;
|
||||
use sysproxy::{Autoproxy, Sysproxy};
|
||||
|
||||
/// get the system proxy
|
||||
#[tauri::command]
|
||||
@ -46,8 +46,7 @@ pub fn get_network_interfaces() -> Vec<String> {
|
||||
/// 获取网络接口详细信息
|
||||
#[tauri::command]
|
||||
pub fn get_network_interfaces_info() -> CmdResult<Vec<NetworkInterface>> {
|
||||
use network_interface::NetworkInterface;
|
||||
use network_interface::NetworkInterfaceConfig;
|
||||
use network_interface::{NetworkInterface, NetworkInterfaceConfig};
|
||||
|
||||
let names = get_network_interfaces();
|
||||
let interfaces = wrap_err!(NetworkInterface::show())?;
|
||||
|
@ -1,40 +1,25 @@
|
||||
use crate::{
|
||||
config::*,
|
||||
core::*,
|
||||
feat,
|
||||
utils::{dirs, help},
|
||||
log_err, ret_err, wrap_err,
|
||||
};
|
||||
use super::CmdResult;
|
||||
use crate::{
|
||||
config::{Config, IProfiles, PrfItem, PrfOption},
|
||||
core::{handle, tray::Tray, CoreManager},
|
||||
feat, logging, ret_err,
|
||||
utils::{dirs, help, logging::Type},
|
||||
wrap_err,
|
||||
};
|
||||
|
||||
/// 获取配置文件列表
|
||||
#[tauri::command]
|
||||
pub fn get_profiles() -> CmdResult<IProfiles> {
|
||||
let _ = tray::Tray::global().update_menu();
|
||||
let _ = Tray::global().update_menu();
|
||||
Ok(Config::profiles().data().clone())
|
||||
}
|
||||
|
||||
/// 增强配置文件
|
||||
#[tauri::command]
|
||||
pub async fn enhance_profiles() -> CmdResult {
|
||||
match CoreManager::global().update_config().await {
|
||||
Ok((true, _)) => {
|
||||
println!("[enhance_profiles] 配置更新成功");
|
||||
log_err!(tray::Tray::global().update_tooltip());
|
||||
wrap_err!(feat::enhance_profiles().await)?;
|
||||
handle::Handle::refresh_clash();
|
||||
Ok(())
|
||||
}
|
||||
Ok((false, error_msg)) => {
|
||||
println!("[enhance_profiles] 配置验证失败: {}", error_msg);
|
||||
handle::Handle::notice_message("config_validate::error", &error_msg);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
println!("[enhance_profiles] 更新过程发生错误: {}", e);
|
||||
handle::Handle::notice_message("config_validate::process_terminated", &e.to_string());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 导入配置文件
|
||||
@ -76,36 +61,114 @@ pub async fn delete_profile(index: String) -> CmdResult {
|
||||
|
||||
/// 修改profiles的配置
|
||||
#[tauri::command]
|
||||
pub async fn patch_profiles_config(
|
||||
profiles: IProfiles
|
||||
) -> CmdResult<bool> {
|
||||
println!("[cmd配置patch] 开始修改配置文件");
|
||||
pub async fn patch_profiles_config(profiles: IProfiles) -> CmdResult<bool> {
|
||||
logging!(info, Type::Cmd, true, "开始修改配置文件");
|
||||
|
||||
// 保存当前配置,以便在验证失败时恢复
|
||||
let current_profile = Config::profiles().latest().current.clone();
|
||||
println!("[cmd配置patch] 当前配置: {:?}", current_profile);
|
||||
logging!(info, Type::Cmd, true, "当前配置: {:?}", current_profile);
|
||||
|
||||
// 如果要切换配置,先检查目标配置文件是否有语法错误
|
||||
if let Some(new_profile) = profiles.current.as_ref() {
|
||||
if current_profile.as_ref() != Some(new_profile) {
|
||||
logging!(info, Type::Cmd, true, "正在切换到新配置: {}", new_profile);
|
||||
|
||||
// 获取目标配置文件路径
|
||||
let profiles_config = Config::profiles();
|
||||
let profiles_data = profiles_config.latest();
|
||||
let config_file_result = match profiles_data.get_item(new_profile) {
|
||||
Ok(item) => {
|
||||
if let Some(file) = &item.file {
|
||||
let path = dirs::app_profiles_dir().map(|dir| dir.join(file));
|
||||
path.ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
logging!(error, Type::Cmd, true, "获取目标配置信息失败: {}", e);
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
// 如果获取到文件路径,检查YAML语法
|
||||
if let Some(file_path) = config_file_result {
|
||||
if !file_path.exists() {
|
||||
logging!(
|
||||
error,
|
||||
Type::Cmd,
|
||||
true,
|
||||
"目标配置文件不存在: {}",
|
||||
file_path.display()
|
||||
);
|
||||
handle::Handle::notice_message(
|
||||
"config_validate::file_not_found",
|
||||
format!("{}", file_path.display()),
|
||||
);
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
match std::fs::read_to_string(&file_path) {
|
||||
Ok(content) => match serde_yaml::from_str::<serde_yaml::Value>(&content) {
|
||||
Ok(_) => {
|
||||
logging!(info, Type::Cmd, true, "目标配置文件语法正确");
|
||||
}
|
||||
Err(err) => {
|
||||
let error_msg = format!(" {}", err);
|
||||
logging!(
|
||||
error,
|
||||
Type::Cmd,
|
||||
true,
|
||||
"目标配置文件存在YAML语法错误:{}",
|
||||
error_msg
|
||||
);
|
||||
handle::Handle::notice_message(
|
||||
"config_validate::yaml_syntax_error",
|
||||
&error_msg,
|
||||
);
|
||||
return Ok(false);
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
let error_msg = format!("无法读取目标配置文件: {}", err);
|
||||
logging!(error, Type::Cmd, true, "{}", error_msg);
|
||||
handle::Handle::notice_message(
|
||||
"config_validate::file_read_error",
|
||||
&error_msg,
|
||||
);
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新profiles配置
|
||||
println!("[cmd配置patch] 正在更新配置草稿");
|
||||
wrap_err!({ Config::profiles().draft().patch_config(profiles) })?;
|
||||
logging!(info, Type::Cmd, true, "正在更新配置草稿");
|
||||
let _ = Config::profiles().draft().patch_config(profiles);
|
||||
|
||||
// 更新配置并进行验证
|
||||
match CoreManager::global().update_config().await {
|
||||
Ok((true, _)) => {
|
||||
println!("[cmd配置patch] 配置更新成功");
|
||||
logging!(info, Type::Cmd, true, "配置更新成功");
|
||||
handle::Handle::refresh_clash();
|
||||
let _ = tray::Tray::global().update_tooltip();
|
||||
let _ = Tray::global().update_tooltip();
|
||||
Config::profiles().apply();
|
||||
wrap_err!(Config::profiles().data().save_file())?;
|
||||
Ok(true)
|
||||
}
|
||||
Ok((false, error_msg)) => {
|
||||
println!("[cmd配置patch] 配置验证失败: {}", error_msg);
|
||||
logging!(warn, Type::Cmd, true, "配置验证失败: {}", error_msg);
|
||||
Config::profiles().discard();
|
||||
|
||||
// 如果验证失败,恢复到之前的配置
|
||||
if let Some(prev_profile) = current_profile {
|
||||
println!("[cmd配置patch] 尝试恢复到之前的配置: {}", prev_profile);
|
||||
logging!(
|
||||
info,
|
||||
Type::Cmd,
|
||||
true,
|
||||
"尝试恢复到之前的配置: {}",
|
||||
prev_profile
|
||||
);
|
||||
let restore_profiles = IProfiles {
|
||||
current: Some(prev_profile),
|
||||
items: None,
|
||||
@ -114,7 +177,7 @@ pub async fn patch_profiles_config(
|
||||
wrap_err!({ Config::profiles().draft().patch_config(restore_profiles) })?;
|
||||
Config::profiles().apply();
|
||||
wrap_err!(Config::profiles().data().save_file())?;
|
||||
println!("[cmd配置patch] 成功恢复到之前的配置");
|
||||
logging!(info, Type::Cmd, true, "成功恢复到之前的配置");
|
||||
}
|
||||
|
||||
// 发送验证错误通知
|
||||
@ -122,9 +185,9 @@ pub async fn patch_profiles_config(
|
||||
Ok(false)
|
||||
}
|
||||
Err(e) => {
|
||||
println!("[cmd配置patch] 更新过程发生错误: {}", e);
|
||||
logging!(warn, Type::Cmd, true, "更新过程发生错误: {}", e);
|
||||
Config::profiles().discard();
|
||||
handle::Handle::notice_message("config_validate::boot_error", &e.to_string());
|
||||
handle::Handle::notice_message("config_validate::boot_error", e.to_string());
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
@ -134,9 +197,14 @@ pub async fn patch_profiles_config(
|
||||
#[tauri::command]
|
||||
pub async fn patch_profiles_config_by_profile_index(
|
||||
_app_handle: tauri::AppHandle,
|
||||
profile_index: String
|
||||
profile_index: String,
|
||||
) -> CmdResult<bool> {
|
||||
let profiles = IProfiles{current: Some(profile_index), items: None};
|
||||
logging!(info, Type::Cmd, true, "切换配置到: {}", profile_index);
|
||||
|
||||
let profiles = IProfiles {
|
||||
current: Some(profile_index),
|
||||
items: None,
|
||||
};
|
||||
patch_profiles_config(profiles).await
|
||||
}
|
||||
|
||||
|
@ -4,13 +4,21 @@ use crate::module::mihomo::MihomoManager;
|
||||
#[tauri::command]
|
||||
pub async fn get_proxies() -> CmdResult<serde_json::Value> {
|
||||
let mannager = MihomoManager::global();
|
||||
mannager.refresh_proxies().await.unwrap();
|
||||
Ok(mannager.get_proxies())
|
||||
|
||||
mannager
|
||||
.refresh_proxies()
|
||||
.await
|
||||
.map(|_| mannager.get_proxies())
|
||||
.or_else(|_| Ok(mannager.get_proxies()))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_providers_proxies() -> CmdResult<serde_json::Value> {
|
||||
let mannager = MihomoManager::global();
|
||||
mannager.refresh_providers_proxies().await.unwrap();
|
||||
Ok(mannager.get_providers_proxies())
|
||||
|
||||
mannager
|
||||
.refresh_providers_proxies()
|
||||
.await
|
||||
.map(|_| mannager.get_providers_proxies())
|
||||
.or_else(|_| Ok(mannager.get_providers_proxies()))
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
use crate::{
|
||||
config::*,
|
||||
wrap_err,
|
||||
};
|
||||
use super::CmdResult;
|
||||
use crate::{config::*, wrap_err};
|
||||
use anyhow::Context;
|
||||
use std::collections::HashMap;
|
||||
use serde_yaml::Mapping;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// 获取运行时配置
|
||||
#[tauri::command]
|
||||
|
@ -1,10 +1,5 @@
|
||||
use crate::{
|
||||
config::*,
|
||||
core::*,
|
||||
utils::dirs,
|
||||
wrap_err,
|
||||
};
|
||||
use super::CmdResult;
|
||||
use crate::{config::*, core::*, utils::dirs, wrap_err};
|
||||
use std::fs;
|
||||
|
||||
/// 保存profiles的配置
|
||||
@ -20,7 +15,7 @@ pub async fn save_profile_file(index: String, file_data: Option<String>) -> CmdR
|
||||
let profiles_guard = profiles.latest();
|
||||
let item = wrap_err!(profiles_guard.get_item(&index))?;
|
||||
// 确定是否为merge类型文件
|
||||
let is_merge = item.itype.as_ref().map_or(false, |t| t == "merge");
|
||||
let is_merge = item.itype.as_ref().is_some_and(|t| t == "merge");
|
||||
let content = wrap_err!(item.read_file())?;
|
||||
let path = item.file.clone().ok_or("file field is null")?;
|
||||
let profiles_dir = wrap_err!(dirs::app_profiles_dir())?;
|
||||
@ -31,12 +26,18 @@ pub async fn save_profile_file(index: String, file_data: Option<String>) -> CmdR
|
||||
wrap_err!(fs::write(&file_path, file_data.clone().unwrap()))?;
|
||||
|
||||
let file_path_str = file_path.to_string_lossy().to_string();
|
||||
println!("[cmd配置save] 开始验证配置文件: {}, 是否为merge文件: {}", file_path_str, is_merge_file);
|
||||
println!(
|
||||
"[cmd配置save] 开始验证配置文件: {}, 是否为merge文件: {}",
|
||||
file_path_str, is_merge_file
|
||||
);
|
||||
|
||||
// 对于 merge 文件,只进行语法验证,不进行后续内核验证
|
||||
if is_merge_file {
|
||||
println!("[cmd配置save] 检测到merge文件,只进行语法验证");
|
||||
match CoreManager::global().validate_config_file(&file_path_str, Some(true)).await {
|
||||
match CoreManager::global()
|
||||
.validate_config_file(&file_path_str, Some(true))
|
||||
.await
|
||||
{
|
||||
Ok((true, _)) => {
|
||||
println!("[cmd配置save] merge文件语法验证通过");
|
||||
// 成功后尝试更新整体配置
|
||||
@ -65,7 +66,10 @@ pub async fn save_profile_file(index: String, file_data: Option<String>) -> CmdR
|
||||
}
|
||||
|
||||
// 非merge文件使用完整验证流程
|
||||
match CoreManager::global().validate_config_file(&file_path_str, None).await {
|
||||
match CoreManager::global()
|
||||
.validate_config_file(&file_path_str, None)
|
||||
.await
|
||||
{
|
||||
Ok((true, _)) => {
|
||||
println!("[cmd配置save] 验证成功");
|
||||
Ok(())
|
||||
@ -76,14 +80,15 @@ pub async fn save_profile_file(index: String, file_data: Option<String>) -> CmdR
|
||||
wrap_err!(fs::write(&file_path, original_content))?;
|
||||
|
||||
// 智能判断错误类型
|
||||
let is_script_error = file_path_str.ends_with(".js") ||
|
||||
error_msg.contains("Script syntax error") ||
|
||||
error_msg.contains("Script must contain a main function") ||
|
||||
error_msg.contains("Failed to read script file");
|
||||
let is_script_error = file_path_str.ends_with(".js")
|
||||
|| error_msg.contains("Script syntax error")
|
||||
|| error_msg.contains("Script must contain a main function")
|
||||
|| error_msg.contains("Failed to read script file");
|
||||
|
||||
if error_msg.contains("YAML syntax error") ||
|
||||
error_msg.contains("Failed to read file:") ||
|
||||
(!file_path_str.ends_with(".js") && !is_script_error) {
|
||||
if error_msg.contains("YAML syntax error")
|
||||
|| error_msg.contains("Failed to read file:")
|
||||
|| (!file_path_str.ends_with(".js") && !is_script_error)
|
||||
{
|
||||
// 普通YAML错误使用YAML通知处理
|
||||
println!("[cmd配置save] YAML配置文件验证失败,发送通知");
|
||||
let result = (false, error_msg.clone());
|
||||
|
40
src-tauri/src/cmd/service.rs
Normal file
40
src-tauri/src/cmd/service.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use super::CmdResult;
|
||||
use crate::{
|
||||
core::{service, CoreManager},
|
||||
utils::i18n::t,
|
||||
};
|
||||
|
||||
async fn execute_service_operation(
|
||||
service_op: impl std::future::Future<Output = Result<(), impl ToString + std::fmt::Debug>>,
|
||||
op_type: &str,
|
||||
) -> CmdResult {
|
||||
if service_op.await.is_err() {
|
||||
let emsg = format!("{} {} failed", op_type, "Service");
|
||||
return Err(t(emsg.as_str()));
|
||||
}
|
||||
if CoreManager::global().restart_core().await.is_err() {
|
||||
let emsg = format!("{} {} failed", "Restart", "Core");
|
||||
return Err(t(emsg.as_str()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn install_service() -> CmdResult {
|
||||
execute_service_operation(service::install_service(), "Install").await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn uninstall_service() -> CmdResult {
|
||||
execute_service_operation(service::uninstall_service(), "Uninstall").await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn reinstall_service() -> CmdResult {
|
||||
execute_service_operation(service::reinstall_service(), "Reinstall").await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn repair_service() -> CmdResult {
|
||||
execute_service_operation(service::force_reinstall_service(), "Repair").await
|
||||
}
|
@ -1,35 +1,94 @@
|
||||
use super::CmdResult;
|
||||
use crate::core::handle;
|
||||
use crate::module::sysinfo::PlatformSpecification;
|
||||
use crate::{
|
||||
core::{handle, CoreManager},
|
||||
module::sysinfo::PlatformSpecification,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::{
|
||||
sync::atomic::{AtomicI64, Ordering},
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
use tauri_plugin_clipboard_manager::ClipboardExt;
|
||||
use crate::{core::{self, CoreManager, service}, wrap_err};
|
||||
|
||||
// 存储应用启动时间的全局变量
|
||||
static APP_START_TIME: Lazy<AtomicI64> = Lazy::new(|| {
|
||||
// 获取当前系统时间,转换为毫秒级时间戳
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_millis() as i64;
|
||||
|
||||
AtomicI64::new(now)
|
||||
});
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn export_diagnostic_info() -> CmdResult<()> {
|
||||
let sysinfo = PlatformSpecification::new();
|
||||
let sysinfo = PlatformSpecification::new_async().await;
|
||||
let info = format!("{:?}", sysinfo);
|
||||
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
let cliboard = app_handle.clipboard();
|
||||
|
||||
if let Err(_) = cliboard.write_text(info) {
|
||||
if cliboard.write_text(info).is_err() {
|
||||
log::error!(target: "app", "Failed to write to clipboard");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_system_info() -> CmdResult<String> {
|
||||
let sysinfo = PlatformSpecification::new_async().await;
|
||||
let info = format!("{:?}", sysinfo);
|
||||
Ok(info)
|
||||
}
|
||||
|
||||
/// 获取当前内核运行模式
|
||||
#[tauri::command]
|
||||
pub async fn get_running_mode() -> Result<String, String> {
|
||||
match CoreManager::global().get_running_mode().await {
|
||||
core::RunningMode::Service => Ok("service".to_string()),
|
||||
core::RunningMode::Sidecar => Ok("sidecar".to_string()),
|
||||
core::RunningMode::NotRunning => Ok("not_running".to_string()),
|
||||
}
|
||||
Ok(CoreManager::global().get_running_mode().await.to_string())
|
||||
}
|
||||
|
||||
/// 安装/重装系统服务
|
||||
/// 获取应用的运行时间(毫秒)
|
||||
#[tauri::command]
|
||||
pub async fn install_service() -> CmdResult {
|
||||
wrap_err!(service::reinstall_service().await)
|
||||
pub fn get_app_uptime() -> CmdResult<i64> {
|
||||
let start_time = APP_START_TIME.load(Ordering::Relaxed);
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_millis() as i64;
|
||||
|
||||
Ok(now - start_time)
|
||||
}
|
||||
|
||||
/// 检查应用是否以管理员身份运行
|
||||
#[tauri::command]
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn is_admin() -> CmdResult<bool> {
|
||||
use deelevate::{PrivilegeLevel, Token};
|
||||
|
||||
let result = Token::with_current_process()
|
||||
.and_then(|token| token.privilege_level())
|
||||
.map(|level| level != PrivilegeLevel::NotPrivileged)
|
||||
.unwrap_or(false);
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// 非Windows平台检测是否以管理员身份运行
|
||||
#[tauri::command]
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub fn is_admin() -> CmdResult<bool> {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
Ok(unsafe { libc::geteuid() } == 0)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
Ok(unsafe { libc::geteuid() } == 0)
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
|
||||
{
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ use super::CmdResult;
|
||||
#[cfg(windows)]
|
||||
mod platform {
|
||||
use super::CmdResult;
|
||||
use crate::core::win_uwp;
|
||||
use crate::wrap_err;
|
||||
use crate::{core::win_uwp, wrap_err};
|
||||
|
||||
pub async fn invoke_uwp_tool() -> CmdResult {
|
||||
wrap_err!(win_uwp::invoke_uwptools().await)
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::core::*;
|
||||
use super::CmdResult;
|
||||
use crate::core::*;
|
||||
|
||||
/// 发送脚本验证通知消息
|
||||
#[tauri::command]
|
||||
@ -38,11 +38,14 @@ pub fn handle_script_validation_notice(result: &(bool, String), file_type: &str)
|
||||
pub async fn validate_script_file(file_path: String) -> CmdResult<bool> {
|
||||
log::info!(target: "app", "验证脚本文件: {}", file_path);
|
||||
|
||||
match CoreManager::global().validate_config_file(&file_path, None).await {
|
||||
match CoreManager::global()
|
||||
.validate_config_file(&file_path, None)
|
||||
.await
|
||||
{
|
||||
Ok(result) => {
|
||||
handle_script_validation_notice(&result, "脚本文件");
|
||||
Ok(result.0) // 返回验证结果布尔值
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
let error_msg = e.to_string();
|
||||
log::error!(target: "app", "验证脚本文件过程发生错误: {}", error_msg);
|
||||
|
@ -1,9 +1,5 @@
|
||||
use crate::{
|
||||
config::*,
|
||||
feat,
|
||||
wrap_err,
|
||||
};
|
||||
use super::CmdResult;
|
||||
use crate::{config::*, feat, wrap_err};
|
||||
|
||||
/// 获取Verge配置
|
||||
#[tauri::command]
|
||||
|
@ -1,10 +1,5 @@
|
||||
use crate::{
|
||||
core,
|
||||
config::*,
|
||||
feat,
|
||||
wrap_err,
|
||||
};
|
||||
use super::CmdResult;
|
||||
use crate::{config::*, core, feat, wrap_err};
|
||||
use reqwest_dav::list_cmd::ListFile;
|
||||
|
||||
/// 保存 WebDAV 配置
|
||||
|
@ -33,7 +33,7 @@ impl IClashTemp {
|
||||
let mut map = Mapping::new();
|
||||
let mut tun = Mapping::new();
|
||||
tun.insert("enable".into(), false.into());
|
||||
tun.insert("stack".into(), "mixed".into());
|
||||
tun.insert("stack".into(), "gvisor".into());
|
||||
tun.insert("auto-route".into(), true.into());
|
||||
tun.insert("strict-route".into(), false.into());
|
||||
tun.insert("auto-detect-interface".into(), true.into());
|
||||
|
@ -1,9 +1,9 @@
|
||||
use super::{Draft, IClashTemp, IProfiles, IRuntime, IVerge};
|
||||
use crate::{
|
||||
config::PrfItem,
|
||||
enhance,
|
||||
utils::{dirs, help},
|
||||
core::{handle, CoreManager},
|
||||
enhance, logging,
|
||||
utils::{dirs, help, logging::Type},
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use once_cell::sync::OnceCell;
|
||||
@ -66,32 +66,41 @@ impl Config {
|
||||
let script_item = PrfItem::from_script(Some("Script".to_string()))?;
|
||||
Self::profiles().data().append_item(script_item.clone())?;
|
||||
}
|
||||
|
||||
// 生成运行时配置
|
||||
crate::log_err!(Self::generate().await);
|
||||
if let Err(err) = Self::generate().await {
|
||||
logging!(error, Type::Config, true, "生成运行时配置失败: {}", err);
|
||||
} else {
|
||||
logging!(info, Type::Config, true, "生成运行时配置成功");
|
||||
}
|
||||
|
||||
// 生成运行时配置文件并验证
|
||||
let config_result = Self::generate_file(ConfigType::Run);
|
||||
|
||||
let validation_result = if let Ok(_) = config_result {
|
||||
let validation_result = if config_result.is_ok() {
|
||||
// 验证配置文件
|
||||
println!("[首次启动] 开始验证配置");
|
||||
logging!(info, Type::Config, true, "开始验证配置");
|
||||
|
||||
match CoreManager::global().validate_config().await {
|
||||
Ok((is_valid, error_msg)) => {
|
||||
if !is_valid {
|
||||
println!("[首次启动] 配置验证失败,使用默认最小配置启动: {}", error_msg);
|
||||
logging!(
|
||||
warn,
|
||||
Type::Config,
|
||||
true,
|
||||
"[首次启动] 配置验证失败,使用默认最小配置启动: {}",
|
||||
error_msg
|
||||
);
|
||||
CoreManager::global()
|
||||
.use_default_config("config_validate::boot_error", &error_msg)
|
||||
.await?;
|
||||
Some(("config_validate::boot_error", error_msg))
|
||||
} else {
|
||||
println!("[首次启动] 配置验证成功");
|
||||
logging!(info, Type::Config, true, "配置验证成功");
|
||||
Some(("config_validate::success", String::new()))
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
println!("[首次启动] 验证进程执行失败: {}", err);
|
||||
logging!(warn, Type::Config, true, "验证进程执行失败: {}", err);
|
||||
CoreManager::global()
|
||||
.use_default_config("config_validate::process_terminated", "")
|
||||
.await?;
|
||||
@ -99,12 +108,9 @@ impl Config {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("[首次启动] 生成配置文件失败,使用默认配置");
|
||||
logging!(warn, Type::Config, true, "生成配置文件失败,使用默认配置");
|
||||
CoreManager::global()
|
||||
.use_default_config(
|
||||
"config_validate::error",
|
||||
"",
|
||||
)
|
||||
.use_default_config("config_validate::error", "")
|
||||
.await?;
|
||||
Some(("config_validate::error", String::new()))
|
||||
};
|
||||
|
@ -8,14 +8,9 @@ mod profiles;
|
||||
mod runtime;
|
||||
mod verge;
|
||||
|
||||
pub use self::clash::*;
|
||||
pub use self::config::*;
|
||||
pub use self::draft::*;
|
||||
pub use self::encrypt::*;
|
||||
pub use self::prfitem::*;
|
||||
pub use self::profiles::*;
|
||||
pub use self::runtime::*;
|
||||
pub use self::verge::*;
|
||||
pub use self::{
|
||||
clash::*, config::*, draft::*, encrypt::*, prfitem::*, profiles::*, runtime::*, verge::*,
|
||||
};
|
||||
|
||||
pub const DEFAULT_PAC: &str = r#"function FindProxyForURL(url, host) {
|
||||
return "PROXY 127.0.0.1:%mixed-port%; SOCKS5 127.0.0.1:%mixed-port%; DIRECT;";
|
||||
|
@ -234,10 +234,10 @@ impl PrfItem {
|
||||
option: Option<PrfOption>,
|
||||
) -> Result<PrfItem> {
|
||||
let opt_ref = option.as_ref();
|
||||
let with_proxy = opt_ref.map_or(false, |o| o.with_proxy.unwrap_or(false));
|
||||
let self_proxy = opt_ref.map_or(false, |o| o.self_proxy.unwrap_or(false));
|
||||
let with_proxy = opt_ref.is_some_and(|o| o.with_proxy.unwrap_or(false));
|
||||
let self_proxy = opt_ref.is_some_and(|o| o.self_proxy.unwrap_or(false));
|
||||
let accept_invalid_certs =
|
||||
opt_ref.map_or(false, |o| o.danger_accept_invalid_certs.unwrap_or(false));
|
||||
opt_ref.is_some_and(|o| o.danger_accept_invalid_certs.unwrap_or(false));
|
||||
let user_agent = opt_ref.and_then(|o| o.user_agent.clone());
|
||||
let update_interval = opt_ref.and_then(|o| o.update_interval);
|
||||
let mut merge = opt_ref.and_then(|o| o.merge.clone());
|
||||
|
@ -472,15 +472,17 @@ impl IProfiles {
|
||||
|
||||
/// 获取所有的profiles(uid,名称)
|
||||
pub fn all_profile_uid_and_name(&self) -> Option<Vec<(String, String)>> {
|
||||
match self.items.as_ref() {
|
||||
Some(items) => Some(items.iter().filter_map(|e| {
|
||||
self.items.as_ref().map(|items| {
|
||||
items
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
if let (Some(uid), Some(name)) = (e.uid.clone(), e.name.clone()) {
|
||||
Some((uid, name))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()),
|
||||
None => None,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::config::DEFAULT_PAC;
|
||||
use crate::config::{deserialize_encrypted, serialize_encrypted};
|
||||
use crate::utils::i18n;
|
||||
use crate::utils::{dirs, help};
|
||||
use crate::{
|
||||
config::{deserialize_encrypted, serialize_encrypted, DEFAULT_PAC},
|
||||
utils::{dirs, help, i18n},
|
||||
};
|
||||
use anyhow::Result;
|
||||
use log::LevelFilter;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -105,6 +105,10 @@ pub struct IVerge {
|
||||
/// enable global hotkey
|
||||
pub enable_global_hotkey: Option<bool>,
|
||||
|
||||
/// 首页卡片设置
|
||||
/// 控制首页各个卡片的显示和隐藏
|
||||
pub home_cards: Option<serde_json::Value>,
|
||||
|
||||
/// 切换代理时自动关闭连接
|
||||
pub auto_close_connection: Option<bool>,
|
||||
|
||||
@ -185,8 +189,16 @@ pub struct IVerge {
|
||||
|
||||
pub enable_tray_speed: Option<bool>,
|
||||
|
||||
/// 轻量模式 - 只保留内核运行
|
||||
pub enable_lite_mode: Option<bool>,
|
||||
pub enable_tray_icon: Option<bool>,
|
||||
|
||||
/// 自动进入轻量模式
|
||||
pub enable_auto_light_weight_mode: Option<bool>,
|
||||
|
||||
/// 自动进入轻量模式的延迟(分钟)
|
||||
pub auto_light_weight_minutes: Option<u64>,
|
||||
|
||||
/// 服务状态跟踪
|
||||
pub service_state: Option<crate::core::service::ServiceState>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||
@ -248,7 +260,7 @@ impl IVerge {
|
||||
env_type: Some("bash".into()),
|
||||
#[cfg(target_os = "windows")]
|
||||
env_type: Some("powershell".into()),
|
||||
start_page: Some("/".into()),
|
||||
start_page: Some("/home".into()),
|
||||
traffic_graph: Some(true),
|
||||
enable_memory_usage: Some(true),
|
||||
enable_group_icon: Some(true),
|
||||
@ -288,9 +300,13 @@ impl IVerge {
|
||||
webdav_username: None,
|
||||
webdav_password: None,
|
||||
enable_tray_speed: Some(true),
|
||||
enable_tray_icon: Some(true),
|
||||
enable_global_hotkey: Some(true),
|
||||
enable_lite_mode: Some(false),
|
||||
enable_auto_light_weight_mode: Some(false),
|
||||
auto_light_weight_minutes: Some(10),
|
||||
enable_dns_settings: Some(true),
|
||||
home_cards: None,
|
||||
service_state: None,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
@ -372,8 +388,12 @@ impl IVerge {
|
||||
patch!(webdav_username);
|
||||
patch!(webdav_password);
|
||||
patch!(enable_tray_speed);
|
||||
patch!(enable_lite_mode);
|
||||
patch!(enable_tray_icon);
|
||||
patch!(enable_auto_light_weight_mode);
|
||||
patch!(auto_light_weight_minutes);
|
||||
patch!(enable_dns_settings);
|
||||
patch!(home_cards);
|
||||
patch!(service_state);
|
||||
}
|
||||
|
||||
/// 在初始化前尝试拿到单例端口的值
|
||||
@ -462,8 +482,12 @@ pub struct IVergeResponse {
|
||||
pub webdav_username: Option<String>,
|
||||
pub webdav_password: Option<String>,
|
||||
pub enable_tray_speed: Option<bool>,
|
||||
pub enable_lite_mode: Option<bool>,
|
||||
pub enable_tray_icon: Option<bool>,
|
||||
pub enable_auto_light_weight_mode: Option<bool>,
|
||||
pub auto_light_weight_minutes: Option<u64>,
|
||||
pub enable_dns_settings: Option<bool>,
|
||||
pub home_cards: Option<serde_json::Value>,
|
||||
pub service_state: Option<crate::core::service::ServiceState>,
|
||||
}
|
||||
|
||||
impl From<IVerge> for IVergeResponse {
|
||||
@ -526,8 +550,12 @@ impl From<IVerge> for IVergeResponse {
|
||||
webdav_username: verge.webdav_username,
|
||||
webdav_password: verge.webdav_password,
|
||||
enable_tray_speed: verge.enable_tray_speed,
|
||||
enable_lite_mode: verge.enable_lite_mode,
|
||||
enable_tray_icon: verge.enable_tray_icon,
|
||||
enable_auto_light_weight_mode: verge.enable_auto_light_weight_mode,
|
||||
auto_light_weight_minutes: verge.auto_light_weight_minutes,
|
||||
enable_dns_settings: verge.enable_dns_settings,
|
||||
home_cards: verge.home_cards,
|
||||
service_state: verge.service_state,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
use crate::config::Config;
|
||||
use crate::utils::dirs;
|
||||
use crate::{config::Config, utils::dirs};
|
||||
use anyhow::Error;
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use reqwest_dav::list_cmd::{ListEntity, ListFile};
|
||||
use std::collections::HashMap;
|
||||
use std::env::{consts::OS, temp_dir};
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env::{consts::OS, temp_dir},
|
||||
fs,
|
||||
io::Write,
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::time::timeout;
|
||||
use zip::write::SimpleFileOptions;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,24 @@
|
||||
use crate::log_err;
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use tauri::{AppHandle, Emitter, Manager, WebviewWindow};
|
||||
use tauri_plugin_shell::process::CommandChild;
|
||||
|
||||
use crate::{logging, logging_error, utils::logging::Type};
|
||||
|
||||
/// 存储启动期间的错误消息
|
||||
#[derive(Debug, Clone)]
|
||||
struct ErrorMessage {
|
||||
status: String,
|
||||
message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Handle {
|
||||
pub app_handle: Arc<RwLock<Option<AppHandle>>>,
|
||||
pub is_exiting: Arc<RwLock<bool>>,
|
||||
pub core_process: Arc<RwLock<Option<CommandChild>>>,
|
||||
/// 存储启动过程中产生的错误消息队列
|
||||
startup_errors: Arc<RwLock<Vec<ErrorMessage>>>,
|
||||
startup_completed: Arc<RwLock<bool>>,
|
||||
}
|
||||
|
||||
impl Handle {
|
||||
@ -19,7 +28,8 @@ impl Handle {
|
||||
HANDLE.get_or_init(|| Handle {
|
||||
app_handle: Arc::new(RwLock::new(None)),
|
||||
is_exiting: Arc::new(RwLock::new(false)),
|
||||
core_process: Arc::new(RwLock::new(None)),
|
||||
startup_errors: Arc::new(RwLock::new(Vec::new())),
|
||||
startup_completed: Arc::new(RwLock::new(false)),
|
||||
})
|
||||
}
|
||||
|
||||
@ -43,26 +53,115 @@ impl Handle {
|
||||
|
||||
pub fn refresh_clash() {
|
||||
if let Some(window) = Self::global().get_window() {
|
||||
log_err!(window.emit("verge://refresh-clash-config", "yes"));
|
||||
logging_error!(
|
||||
Type::Frontend,
|
||||
true,
|
||||
window.emit("verge://refresh-clash-config", "yes")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn refresh_verge() {
|
||||
if let Some(window) = Self::global().get_window() {
|
||||
log_err!(window.emit("verge://refresh-verge-config", "yes"));
|
||||
logging_error!(
|
||||
Type::Frontend,
|
||||
true,
|
||||
window.emit("verge://refresh-verge-config", "yes")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn refresh_profiles() {
|
||||
if let Some(window) = Self::global().get_window() {
|
||||
log_err!(window.emit("verge://refresh-profiles-config", "yes"));
|
||||
logging_error!(
|
||||
Type::Frontend,
|
||||
true,
|
||||
window.emit("verge://refresh-profiles-config", "yes")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 通知前端显示消息,如果在启动过程中,则将消息存入启动错误队列
|
||||
pub fn notice_message<S: Into<String>, M: Into<String>>(status: S, msg: M) {
|
||||
if let Some(window) = Self::global().get_window() {
|
||||
log_err!(window.emit("verge://notice-message", (status.into(), msg.into())));
|
||||
let handle = Self::global();
|
||||
let status_str = status.into();
|
||||
let msg_str = msg.into();
|
||||
|
||||
// 检查是否正在启动过程中
|
||||
if !*handle.startup_completed.read() {
|
||||
logging!(
|
||||
info,
|
||||
Type::Frontend,
|
||||
true,
|
||||
"启动过程中发现错误,加入消息队列: {} - {}",
|
||||
status_str,
|
||||
msg_str
|
||||
);
|
||||
|
||||
// 将消息添加到启动错误队列
|
||||
let mut errors = handle.startup_errors.write();
|
||||
errors.push(ErrorMessage {
|
||||
status: status_str,
|
||||
message: msg_str,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 已经完成启动,直接发送消息
|
||||
if let Some(window) = handle.get_window() {
|
||||
logging_error!(
|
||||
Type::Frontend,
|
||||
true,
|
||||
window.emit("verge://notice-message", (status_str, msg_str))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 标记启动已完成,并发送所有启动阶段累积的错误消息
|
||||
pub fn mark_startup_completed(&self) {
|
||||
{
|
||||
let mut completed = self.startup_completed.write();
|
||||
*completed = true;
|
||||
}
|
||||
|
||||
self.send_startup_errors();
|
||||
}
|
||||
|
||||
/// 发送启动时累积的所有错误消息
|
||||
fn send_startup_errors(&self) {
|
||||
let errors = {
|
||||
let mut errors = self.startup_errors.write();
|
||||
std::mem::take(&mut *errors)
|
||||
};
|
||||
|
||||
if errors.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
logging!(
|
||||
info,
|
||||
Type::Frontend,
|
||||
true,
|
||||
"发送{}条启动时累积的错误消息",
|
||||
errors.len()
|
||||
);
|
||||
|
||||
// 等待2秒以确保前端已完全加载,延迟发送错误通知
|
||||
if let Some(window) = self.get_window() {
|
||||
let window_clone = window.clone();
|
||||
let errors_clone = errors.clone();
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||
|
||||
for error in errors_clone {
|
||||
let _ =
|
||||
window_clone.emit("verge://notice-message", (error.status, error.message));
|
||||
// 每条消息之间间隔500ms,避免消息堆积
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,21 +170,6 @@ impl Handle {
|
||||
*is_exiting = true;
|
||||
}
|
||||
|
||||
pub fn set_core_process(&self, process: CommandChild) {
|
||||
let mut core_process = self.core_process.write();
|
||||
*core_process = Some(process);
|
||||
}
|
||||
|
||||
pub fn take_core_process(&self) -> Option<CommandChild> {
|
||||
let mut core_process = self.core_process.write();
|
||||
core_process.take()
|
||||
}
|
||||
|
||||
/// 检查是否有运行中的核心进程
|
||||
pub fn has_core_process(&self) -> bool {
|
||||
self.core_process.read().is_some()
|
||||
}
|
||||
|
||||
pub fn is_exiting(&self) -> bool {
|
||||
*self.is_exiting.read()
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
use crate::core::handle;
|
||||
use crate::{config::Config, feat, log_err};
|
||||
use crate::utils::resolve;
|
||||
use crate::{
|
||||
config::Config,
|
||||
core::handle,
|
||||
feat, logging, logging_error,
|
||||
module::lightweight::entry_lightweight_mode,
|
||||
utils::{logging::Type, resolve},
|
||||
};
|
||||
use anyhow::{bail, Result};
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use tauri::Manager;
|
||||
use tauri::{async_runtime, Manager};
|
||||
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, ShortcutState};
|
||||
use tauri::async_runtime;
|
||||
|
||||
pub struct Hotkey {
|
||||
current: Arc<Mutex<Vec<String>>>, // 保存当前的热键设置
|
||||
@ -26,19 +29,27 @@ impl Hotkey {
|
||||
let verge = Config::verge();
|
||||
let enable_global_hotkey = verge.latest().enable_global_hotkey.unwrap_or(true);
|
||||
|
||||
println!("Initializing hotkeys, global hotkey enabled: {}", enable_global_hotkey);
|
||||
log::info!(target: "app", "Initializing hotkeys, global hotkey enabled: {}", enable_global_hotkey);
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Initializing hotkeys with enable: {}",
|
||||
enable_global_hotkey
|
||||
);
|
||||
|
||||
// 如果全局热键被禁用,则不注册热键
|
||||
if !enable_global_hotkey {
|
||||
println!("Global hotkey is disabled, skipping registration");
|
||||
log::info!(target: "app", "Global hotkey is disabled, skipping registration");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(hotkeys) = verge.latest().hotkeys.as_ref() {
|
||||
println!("Found {} hotkeys to register", hotkeys.len());
|
||||
log::info!(target: "app", "Found {} hotkeys to register", hotkeys.len());
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Has {} hotkeys need to register",
|
||||
hotkeys.len()
|
||||
);
|
||||
|
||||
for hotkey in hotkeys.iter() {
|
||||
let mut iter = hotkey.split(',');
|
||||
@ -47,28 +58,52 @@ impl Hotkey {
|
||||
|
||||
match (key, func) {
|
||||
(Some(key), Some(func)) => {
|
||||
println!("Registering hotkey: {} -> {}", key, func);
|
||||
log::info!(target: "app", "Registering hotkey: {} -> {}", key, func);
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Registering hotkey: {} -> {}",
|
||||
key,
|
||||
func
|
||||
);
|
||||
if let Err(e) = self.register(key, func) {
|
||||
println!("Failed to register hotkey {} -> {}: {:?}", key, func, e);
|
||||
log::error!(target: "app", "Failed to register hotkey {} -> {}: {:?}", key, func, e);
|
||||
logging!(
|
||||
error,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Failed to register hotkey {} -> {}: {:?}",
|
||||
key,
|
||||
func,
|
||||
e
|
||||
);
|
||||
} else {
|
||||
println!("Successfully registered hotkey {} -> {}", key, func);
|
||||
log::info!(target: "app", "Successfully registered hotkey {} -> {}", key, func);
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Successfully registered hotkey {} -> {}",
|
||||
key,
|
||||
func
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let key = key.unwrap_or("None");
|
||||
let func = func.unwrap_or("None");
|
||||
println!("Invalid hotkey configuration: `{key}`:`{func}`");
|
||||
log::error!(target: "app", "Invalid hotkey configuration: `{key}`:`{func}`");
|
||||
logging!(
|
||||
error,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Invalid hotkey configuration: `{}`:`{}`",
|
||||
key,
|
||||
func
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.current.lock().clone_from(hotkeys);
|
||||
} else {
|
||||
println!("No hotkeys configured");
|
||||
log::info!(target: "app", "No hotkeys configured");
|
||||
logging!(debug, Type::Hotkey, true, "No hotkeys configured");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -85,39 +120,60 @@ impl Hotkey {
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
let manager = app_handle.global_shortcut();
|
||||
|
||||
println!("Attempting to register hotkey: {} for function: {}", hotkey, func);
|
||||
log::info!(target: "app", "Attempting to register hotkey: {} for function: {}", hotkey, func);
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Attempting to register hotkey: {} for function: {}",
|
||||
hotkey,
|
||||
func
|
||||
);
|
||||
|
||||
if manager.is_registered(hotkey) {
|
||||
println!("Hotkey {} was already registered, unregistering first", hotkey);
|
||||
log::info!(target: "app", "Hotkey {} was already registered, unregistering first", hotkey);
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Hotkey {} was already registered, unregistering first",
|
||||
hotkey
|
||||
);
|
||||
manager.unregister(hotkey)?;
|
||||
}
|
||||
|
||||
let f = match func.trim() {
|
||||
"open_or_close_dashboard" => {
|
||||
println!("Registering open_or_close_dashboard function");
|
||||
log::info!(target: "app", "Registering open_or_close_dashboard function");
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Registering open_or_close_dashboard function"
|
||||
);
|
||||
|| {
|
||||
println!("=== Hotkey Dashboard Window Operation Start ===");
|
||||
log::info!(target: "app", "=== Hotkey Dashboard Window Operation Start ===");
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"=== Hotkey Dashboard Window Operation Start ==="
|
||||
);
|
||||
|
||||
// 使用 spawn_blocking 来确保在正确的线程上执行
|
||||
async_runtime::spawn_blocking(|| {
|
||||
println!("Toggle dashboard window visibility");
|
||||
log::info!(target: "app", "Toggle dashboard window visibility");
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Toggle dashboard window visibility"
|
||||
);
|
||||
|
||||
// 检查窗口是否存在
|
||||
if let Some(window) = handle::Handle::global().get_window() {
|
||||
// 如果窗口可见,则隐藏它
|
||||
if window.is_visible().unwrap_or(false) {
|
||||
println!("Window is visible, hiding it");
|
||||
log::info!(target: "app", "Window is visible, hiding it");
|
||||
logging!(info, Type::Window, true, "Window is visible, hiding it");
|
||||
let _ = window.hide();
|
||||
} else {
|
||||
// 如果窗口不可见,则显示它
|
||||
println!("Window is hidden, showing it");
|
||||
log::info!(target: "app", "Window is hidden, showing it");
|
||||
logging!(info, Type::Window, true, "Window is hidden, showing it");
|
||||
if window.is_minimized().unwrap_or(false) {
|
||||
let _ = window.unminimize();
|
||||
}
|
||||
@ -126,26 +182,36 @@ impl Hotkey {
|
||||
}
|
||||
} else {
|
||||
// 如果窗口不存在,创建一个新窗口
|
||||
println!("Window does not exist, creating a new one");
|
||||
log::info!(target: "app", "Window does not exist, creating a new one");
|
||||
resolve::create_window();
|
||||
logging!(
|
||||
info,
|
||||
Type::Window,
|
||||
true,
|
||||
"Window does not exist, creating a new one"
|
||||
);
|
||||
resolve::create_window(true);
|
||||
}
|
||||
});
|
||||
|
||||
println!("=== Hotkey Dashboard Window Operation End ===");
|
||||
log::info!(target: "app", "=== Hotkey Dashboard Window Operation End ===");
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"=== Hotkey Dashboard Window Operation End ==="
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
"clash_mode_rule" => || feat::change_clash_mode("rule".into()),
|
||||
"clash_mode_global" => || feat::change_clash_mode("global".into()),
|
||||
"clash_mode_direct" => || feat::change_clash_mode("direct".into()),
|
||||
"toggle_system_proxy" => || feat::toggle_system_proxy(),
|
||||
"toggle_tun_mode" => || feat::toggle_tun_mode(None),
|
||||
"entry_lightweight_mode" => || entry_lightweight_mode(),
|
||||
"quit" => || feat::quit(Some(0)),
|
||||
#[cfg(target_os = "macos")]
|
||||
"hide" => || feat::hide(),
|
||||
|
||||
_ => {
|
||||
println!("Invalid function: {}", func);
|
||||
log::error!(target: "app", "Invalid function: {}", func);
|
||||
logging!(error, Type::Hotkey, true, "Invalid function: {}", func);
|
||||
bail!("invalid function \"{func}\"");
|
||||
}
|
||||
};
|
||||
@ -154,28 +220,26 @@ impl Hotkey {
|
||||
|
||||
let _ = manager.on_shortcut(hotkey, move |app_handle, hotkey, event| {
|
||||
if event.state == ShortcutState::Pressed {
|
||||
println!("Hotkey pressed: {:?}", hotkey);
|
||||
log::info!(target: "app", "Hotkey pressed: {:?}", hotkey);
|
||||
logging!(debug, Type::Hotkey, true, "Hotkey pressed: {:?}", hotkey);
|
||||
|
||||
if hotkey.key == Code::KeyQ && is_quit {
|
||||
if let Some(window) = app_handle.get_webview_window("main") {
|
||||
if window.is_focused().unwrap_or(false) {
|
||||
println!("Executing quit function");
|
||||
log::info!(target: "app", "Executing quit function");
|
||||
logging!(debug, Type::Hotkey, true, "Executing quit function");
|
||||
f();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 直接执行函数,不做任何状态检查
|
||||
println!("Executing function directly");
|
||||
log::info!(target: "app", "Executing function directly");
|
||||
logging!(debug, Type::Hotkey, true, "Executing function directly");
|
||||
|
||||
// 获取轻量模式状态和全局热键状态
|
||||
let is_lite_mode = Config::verge().latest().enable_lite_mode.unwrap_or(false);
|
||||
let is_enable_global_hotkey = Config::verge().latest().enable_global_hotkey.unwrap_or(true);
|
||||
// 获取全局热键状态
|
||||
let is_enable_global_hotkey = Config::verge()
|
||||
.latest()
|
||||
.enable_global_hotkey
|
||||
.unwrap_or(true);
|
||||
|
||||
// 在轻量模式下或配置了全局热键时,始终执行热键功能
|
||||
if is_lite_mode || is_enable_global_hotkey {
|
||||
if is_enable_global_hotkey {
|
||||
f();
|
||||
} else if let Some(window) = app_handle.get_webview_window("main") {
|
||||
// 非轻量模式且未启用全局热键时,只在窗口可见且有焦点的情况下响应热键
|
||||
@ -190,8 +254,14 @@ impl Hotkey {
|
||||
}
|
||||
});
|
||||
|
||||
println!("Successfully registered hotkey {} for {}", hotkey, func);
|
||||
log::info!(target: "app", "Successfully registered hotkey {} for {}", hotkey, func);
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Successfully registered hotkey {} for {}",
|
||||
hotkey,
|
||||
func
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -199,7 +269,7 @@ impl Hotkey {
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
let manager = app_handle.global_shortcut();
|
||||
manager.unregister(hotkey)?;
|
||||
log::debug!(target: "app", "unregister hotkey {hotkey}");
|
||||
logging!(debug, Type::Hotkey, true, "Unregister hotkey {}", hotkey);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -215,7 +285,7 @@ impl Hotkey {
|
||||
});
|
||||
|
||||
add.iter().for_each(|(key, func)| {
|
||||
log_err!(self.register(key, func));
|
||||
logging_error!(Type::Hotkey, true, self.register(key, func));
|
||||
});
|
||||
|
||||
*current = new_hotkeys;
|
||||
@ -272,7 +342,13 @@ impl Drop for Hotkey {
|
||||
fn drop(&mut self) {
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
if let Err(e) = app_handle.global_shortcut().unregister_all() {
|
||||
log::error!(target:"app", "Error unregistering all hotkeys: {:?}", e);
|
||||
logging!(
|
||||
error,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Error unregistering all hotkeys: {:?}",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,95 @@
|
||||
use crate::config::Config;
|
||||
use crate::utils::dirs;
|
||||
use crate::{
|
||||
config::Config,
|
||||
logging,
|
||||
utils::{dirs, logging::Type},
|
||||
};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::{env::current_exe, process::Command as StdCommand};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env::current_exe,
|
||||
path::PathBuf,
|
||||
process::Command as StdCommand,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
use tokio::time::Duration;
|
||||
|
||||
// Windows only
|
||||
|
||||
const SERVICE_URL: &str = "http://127.0.0.1:33211";
|
||||
const REQUIRED_SERVICE_VERSION: &str = "1.0.1"; // 定义所需的服务版本号
|
||||
const REQUIRED_SERVICE_VERSION: &str = "1.0.5"; // 定义所需的服务版本号
|
||||
|
||||
// 限制重装时间和次数的常量
|
||||
const REINSTALL_COOLDOWN_SECS: u64 = 300; // 5分钟冷却期
|
||||
const MAX_REINSTALLS_PER_DAY: u32 = 3; // 每24小时最多重装3次
|
||||
const ONE_DAY_SECS: u64 = 86400; // 24小时的秒数
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
|
||||
pub struct ServiceState {
|
||||
pub last_install_time: u64, // 上次安装时间戳 (Unix 时间戳,秒)
|
||||
pub install_count: u32, // 24小时内安装次数
|
||||
pub last_check_time: u64, // 上次检查时间
|
||||
pub last_error: Option<String>, // 上次错误信息
|
||||
pub prefer_sidecar: bool, // 用户是否偏好sidecar模式,如拒绝安装服务或安装失败
|
||||
}
|
||||
|
||||
impl ServiceState {
|
||||
// 获取当前的服务状态
|
||||
pub fn get() -> Self {
|
||||
if let Some(state) = Config::verge().latest().service_state.clone() {
|
||||
return state;
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
// 保存服务状态
|
||||
pub fn save(&self) -> Result<()> {
|
||||
let config = Config::verge();
|
||||
let mut latest = config.latest().clone();
|
||||
latest.service_state = Some(self.clone());
|
||||
*config.draft() = latest;
|
||||
config.apply();
|
||||
Config::verge().latest().save_file()
|
||||
}
|
||||
|
||||
// 更新安装信息
|
||||
pub fn record_install(&mut self) {
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs();
|
||||
|
||||
// 检查是否需要重置计数器(24小时已过)
|
||||
if now - self.last_install_time > ONE_DAY_SECS {
|
||||
self.install_count = 0;
|
||||
}
|
||||
|
||||
self.last_install_time = now;
|
||||
self.install_count += 1;
|
||||
}
|
||||
|
||||
// 检查是否可以重新安装
|
||||
pub fn can_reinstall(&self) -> bool {
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs();
|
||||
|
||||
// 如果在冷却期内,不允许重装
|
||||
if now - self.last_install_time < REINSTALL_COOLDOWN_SECS {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果24小时内安装次数过多,也不允许
|
||||
if now - self.last_install_time < ONE_DAY_SECS
|
||||
&& self.install_count >= MAX_REINSTALLS_PER_DAY
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct ResponseBody {
|
||||
@ -41,34 +120,56 @@ pub struct VersionJsonResponse {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub async fn reinstall_service() -> Result<()> {
|
||||
log::info!(target:"app", "reinstall service");
|
||||
pub async fn uninstall_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "uninstall service");
|
||||
|
||||
use deelevate::{PrivilegeLevel, Token};
|
||||
use runas::Command as RunasCommand;
|
||||
use std::os::windows::process::CommandExt;
|
||||
|
||||
let binary_path = dirs::service_path()?;
|
||||
let install_path = binary_path.with_file_name("install-service.exe");
|
||||
let uninstall_path = binary_path.with_file_name("uninstall-service.exe");
|
||||
|
||||
if !install_path.exists() {
|
||||
bail!(format!("installer not found: {install_path:?}"));
|
||||
}
|
||||
|
||||
if !uninstall_path.exists() {
|
||||
bail!(format!("uninstaller not found: {uninstall_path:?}"));
|
||||
}
|
||||
|
||||
let token = Token::with_current_process()?;
|
||||
let level = token.privilege_level()?;
|
||||
let _ = match level {
|
||||
let status = match level {
|
||||
PrivilegeLevel::NotPrivileged => RunasCommand::new(uninstall_path).show(false).status()?,
|
||||
_ => StdCommand::new(uninstall_path)
|
||||
.creation_flags(0x08000000)
|
||||
.status()?,
|
||||
};
|
||||
|
||||
if !status.success() {
|
||||
bail!(
|
||||
"failed to uninstall service with status {}",
|
||||
status.code().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub async fn install_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "install service");
|
||||
|
||||
use deelevate::{PrivilegeLevel, Token};
|
||||
use runas::Command as RunasCommand;
|
||||
use std::os::windows::process::CommandExt;
|
||||
|
||||
let binary_path = dirs::service_path()?;
|
||||
let install_path = binary_path.with_file_name("install-service.exe");
|
||||
|
||||
if !install_path.exists() {
|
||||
bail!(format!("installer not found: {install_path:?}"));
|
||||
}
|
||||
|
||||
let token = Token::with_current_process()?;
|
||||
let level = token.privilege_level()?;
|
||||
let status = match level {
|
||||
PrivilegeLevel::NotPrivileged => RunasCommand::new(install_path).show(false).status()?,
|
||||
_ => StdCommand::new(install_path)
|
||||
@ -86,24 +187,64 @@ pub async fn reinstall_service() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "windows")]
|
||||
pub async fn reinstall_service() -> Result<()> {
|
||||
log::info!(target:"app", "reinstall service");
|
||||
logging!(info, Type::Service, true, "reinstall service");
|
||||
|
||||
// 获取当前服务状态
|
||||
let mut service_state = ServiceState::get();
|
||||
|
||||
// 检查是否允许重装
|
||||
if !service_state.can_reinstall() {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
true,
|
||||
"service reinstall rejected: cooldown period or max attempts reached"
|
||||
);
|
||||
bail!("Service reinstallation is rate limited. Please try again later.");
|
||||
}
|
||||
|
||||
// 先卸载服务
|
||||
if let Err(err) = uninstall_service().await {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
true,
|
||||
"failed to uninstall service: {}",
|
||||
err
|
||||
);
|
||||
}
|
||||
|
||||
// 再安装服务
|
||||
match install_service().await {
|
||||
Ok(_) => {
|
||||
// 记录安装信息并保存
|
||||
service_state.record_install();
|
||||
service_state.last_error = None;
|
||||
service_state.save()?;
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
let error = format!("failed to install service: {}", err);
|
||||
service_state.last_error = Some(error.clone());
|
||||
service_state.save()?;
|
||||
bail!(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub async fn uninstall_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "uninstall service");
|
||||
use users::get_effective_uid;
|
||||
|
||||
let install_path = tauri::utils::platform::current_exe()?.with_file_name("install-service");
|
||||
|
||||
let uninstall_path = tauri::utils::platform::current_exe()?.with_file_name("uninstall-service");
|
||||
|
||||
if !install_path.exists() {
|
||||
bail!(format!("installer not found: {install_path:?}"));
|
||||
}
|
||||
|
||||
if !uninstall_path.exists() {
|
||||
bail!(format!("uninstaller not found: {uninstall_path:?}"));
|
||||
}
|
||||
|
||||
let install_shell: String = install_path.to_string_lossy().replace(" ", "\\ ");
|
||||
let uninstall_shell: String = uninstall_path.to_string_lossy().replace(" ", "\\ ");
|
||||
|
||||
let elevator = crate::utils::help::linux_elevator();
|
||||
@ -115,8 +256,38 @@ pub async fn reinstall_service() -> Result<()> {
|
||||
.arg(uninstall_shell)
|
||||
.status()?,
|
||||
};
|
||||
log::info!(target:"app", "status code:{}", status.code().unwrap());
|
||||
logging!(
|
||||
info,
|
||||
Type::Service,
|
||||
true,
|
||||
"uninstall status code:{}",
|
||||
status.code().unwrap()
|
||||
);
|
||||
|
||||
if !status.success() {
|
||||
bail!(
|
||||
"failed to uninstall service with status {}",
|
||||
status.code().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub async fn install_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "install service");
|
||||
use users::get_effective_uid;
|
||||
|
||||
let install_path = tauri::utils::platform::current_exe()?.with_file_name("install-service");
|
||||
|
||||
if !install_path.exists() {
|
||||
bail!(format!("installer not found: {install_path:?}"));
|
||||
}
|
||||
|
||||
let install_shell: String = install_path.to_string_lossy().replace(" ", "\\ ");
|
||||
|
||||
let elevator = crate::utils::help::linux_elevator();
|
||||
let status = match get_effective_uid() {
|
||||
0 => StdCommand::new(install_shell).status()?,
|
||||
_ => StdCommand::new(elevator.clone())
|
||||
@ -125,6 +296,132 @@ pub async fn reinstall_service() -> Result<()> {
|
||||
.arg(install_shell)
|
||||
.status()?,
|
||||
};
|
||||
logging!(
|
||||
info,
|
||||
Type::Service,
|
||||
true,
|
||||
"install status code:{}",
|
||||
status.code().unwrap()
|
||||
);
|
||||
|
||||
if !status.success() {
|
||||
bail!(
|
||||
"failed to install service with status {}",
|
||||
status.code().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub async fn reinstall_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "reinstall service");
|
||||
|
||||
// 获取当前服务状态
|
||||
let mut service_state = ServiceState::get();
|
||||
|
||||
// 检查是否允许重装
|
||||
if !service_state.can_reinstall() {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
true,
|
||||
"service reinstall rejected: cooldown period or max attempts reached"
|
||||
);
|
||||
bail!("Service reinstallation is rate limited. Please try again later.");
|
||||
}
|
||||
|
||||
// 先卸载服务
|
||||
if let Err(err) = uninstall_service().await {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
true,
|
||||
"failed to uninstall service: {}",
|
||||
err
|
||||
);
|
||||
}
|
||||
|
||||
// 再安装服务
|
||||
match install_service().await {
|
||||
Ok(_) => {
|
||||
// 记录安装信息并保存
|
||||
service_state.record_install();
|
||||
service_state.last_error = None;
|
||||
service_state.save()?;
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
let error = format!("failed to install service: {}", err);
|
||||
service_state.last_error = Some(error.clone());
|
||||
service_state.save()?;
|
||||
bail!(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub async fn uninstall_service() -> Result<()> {
|
||||
use crate::utils::i18n::t;
|
||||
|
||||
logging!(info, Type::Service, true, "uninstall service");
|
||||
|
||||
let binary_path = dirs::service_path()?;
|
||||
let uninstall_path = binary_path.with_file_name("uninstall-service");
|
||||
|
||||
if !uninstall_path.exists() {
|
||||
bail!(format!("uninstaller not found: {uninstall_path:?}"));
|
||||
}
|
||||
|
||||
let uninstall_shell: String = uninstall_path.to_string_lossy().into_owned();
|
||||
|
||||
let prompt = t("Service Administrator Prompt");
|
||||
let command = format!(
|
||||
r#"do shell script "sudo '{uninstall_shell}'" with administrator privileges with prompt "{prompt}""#
|
||||
);
|
||||
|
||||
logging!(debug, Type::Service, true, "uninstall command: {}", command);
|
||||
|
||||
let status = StdCommand::new("osascript")
|
||||
.args(vec!["-e", &command])
|
||||
.status()?;
|
||||
|
||||
if !status.success() {
|
||||
bail!(
|
||||
"failed to uninstall service with status {}",
|
||||
status.code().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub async fn install_service() -> Result<()> {
|
||||
use crate::utils::i18n::t;
|
||||
|
||||
logging!(info, Type::Service, true, "install service");
|
||||
|
||||
let binary_path = dirs::service_path()?;
|
||||
let install_path = binary_path.with_file_name("install-service");
|
||||
|
||||
if !install_path.exists() {
|
||||
bail!(format!("installer not found: {install_path:?}"));
|
||||
}
|
||||
|
||||
let install_shell: String = install_path.to_string_lossy().into_owned();
|
||||
|
||||
let prompt = t("Service Administrator Prompt");
|
||||
let command = format!(
|
||||
r#"do shell script "sudo '{install_shell}'" with administrator privileges with prompt "{prompt}""#
|
||||
);
|
||||
|
||||
logging!(debug, Type::Service, true, "install command: {}", command);
|
||||
|
||||
let status = StdCommand::new("osascript")
|
||||
.args(vec!["-e", &command])
|
||||
.status()?;
|
||||
|
||||
if !status.success() {
|
||||
bail!(
|
||||
@ -138,52 +435,49 @@ pub async fn reinstall_service() -> Result<()> {
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub async fn reinstall_service() -> Result<()> {
|
||||
log::info!(target:"app", "reinstall service");
|
||||
logging!(info, Type::Service, true, "reinstall service");
|
||||
|
||||
let binary_path = dirs::service_path()?;
|
||||
let install_path = binary_path.with_file_name("install-service");
|
||||
let uninstall_path = binary_path.with_file_name("uninstall-service");
|
||||
// 获取当前服务状态
|
||||
let mut service_state = ServiceState::get();
|
||||
|
||||
if !install_path.exists() {
|
||||
bail!(format!("installer not found: {install_path:?}"));
|
||||
}
|
||||
|
||||
if !uninstall_path.exists() {
|
||||
bail!(format!("uninstaller not found: {uninstall_path:?}"));
|
||||
}
|
||||
|
||||
let install_shell: String = install_path.to_string_lossy().into_owned();
|
||||
let uninstall_shell: String = uninstall_path.to_string_lossy().into_owned();
|
||||
|
||||
// 获取提示文本,如果 i18n 失败则使用硬编码默认值
|
||||
let prompt = crate::utils::i18n::t("Service Administrator Prompt");
|
||||
let prompt = if prompt == "Service Administrator Prompt" {
|
||||
if Config::verge().latest().language.as_deref() == Some("zh") || Config::verge().latest().language.is_none() {
|
||||
"Clash Verge 需要使用管理员权限来重新安装系统服务"
|
||||
} else {
|
||||
"Clash Verge needs administrator privileges to reinstall the system service"
|
||||
}
|
||||
} else {
|
||||
&prompt
|
||||
};
|
||||
|
||||
let command = format!(
|
||||
r#"do shell script "sudo '{uninstall_shell}' && sudo '{install_shell}'" with administrator privileges with prompt "{prompt}""#
|
||||
// 检查是否允许重装
|
||||
if !service_state.can_reinstall() {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
true,
|
||||
"service reinstall rejected: cooldown period or max attempts reached"
|
||||
);
|
||||
bail!("Service reinstallation is rate limited. Please try again later.");
|
||||
}
|
||||
|
||||
log::debug!(target: "app", "command: {}", command);
|
||||
|
||||
let status = StdCommand::new("osascript")
|
||||
.args(vec!["-e", &command])
|
||||
.status()?;
|
||||
|
||||
if !status.success() {
|
||||
bail!(
|
||||
"failed to install service with status {}",
|
||||
status.code().unwrap()
|
||||
// 先卸载服务
|
||||
if let Err(err) = uninstall_service().await {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
true,
|
||||
"failed to uninstall service: {}",
|
||||
err
|
||||
);
|
||||
}
|
||||
|
||||
// 再安装服务
|
||||
match install_service().await {
|
||||
Ok(_) => {
|
||||
// 记录安装信息并保存
|
||||
service_state.record_install();
|
||||
service_state.last_error = None;
|
||||
service_state.save()?;
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
let error = format!("failed to install service: {}", err);
|
||||
service_state.last_error = Some(error.clone());
|
||||
service_state.save()?;
|
||||
bail!(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// check the windows service status
|
||||
@ -227,19 +521,54 @@ pub async fn check_service_version() -> Result<String> {
|
||||
|
||||
/// check if service needs to be reinstalled
|
||||
pub async fn check_service_needs_reinstall() -> bool {
|
||||
// 获取当前服务状态
|
||||
let service_state = ServiceState::get();
|
||||
|
||||
// 首先检查是否在冷却期或超过重装次数限制
|
||||
if !service_state.can_reinstall() {
|
||||
log::info!(target: "app", "service reinstall check: in cooldown period or max attempts reached");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 然后才检查版本和可用性
|
||||
match check_service_version().await {
|
||||
Ok(version) => version != REQUIRED_SERVICE_VERSION,
|
||||
Err(_) => true, // 如果无法获取版本或服务未运行,也需要重新安装
|
||||
Ok(version) => {
|
||||
// 打印更详细的日志,方便排查问题
|
||||
log::info!(target: "app", "服务版本检测:当前={}, 要求={}", version, REQUIRED_SERVICE_VERSION);
|
||||
|
||||
let needs_reinstall = version != REQUIRED_SERVICE_VERSION;
|
||||
if needs_reinstall {
|
||||
log::warn!(target: "app", "发现服务版本不匹配,需要重装! 当前={}, 要求={}",
|
||||
version, REQUIRED_SERVICE_VERSION);
|
||||
|
||||
// 打印版本字符串的原始字节,确认没有隐藏字符
|
||||
log::debug!(target: "app", "当前版本字节: {:?}", version.as_bytes());
|
||||
log::debug!(target: "app", "要求版本字节: {:?}", REQUIRED_SERVICE_VERSION.as_bytes());
|
||||
} else {
|
||||
log::info!(target: "app", "服务版本匹配,无需重装");
|
||||
}
|
||||
|
||||
needs_reinstall
|
||||
}
|
||||
Err(err) => {
|
||||
// 检查服务是否可用,如果可用但版本检查失败,可能只是版本API有问题
|
||||
match is_service_running().await {
|
||||
Ok(true) => {
|
||||
log::info!(target: "app", "service is running but version check failed: {}", err);
|
||||
false // 服务在运行,不需要重装
|
||||
}
|
||||
_ => {
|
||||
log::info!(target: "app", "service is not running or unavailable");
|
||||
true // 服务不可用,需要重装
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// start the clash by service
|
||||
pub(super) async fn run_core_by_service(config_file: &PathBuf) -> Result<()> {
|
||||
// 检查服务版本,如果不匹配则重新安装
|
||||
if check_service_needs_reinstall().await {
|
||||
log::info!(target: "app", "service version mismatch, reinstalling");
|
||||
reinstall_service().await?;
|
||||
}
|
||||
/// 尝试使用现有服务启动核心,不进行重装
|
||||
pub(super) async fn start_with_existing_service(config_file: &PathBuf) -> Result<()> {
|
||||
log::info!(target:"app", "attempting to start core with existing service");
|
||||
|
||||
let clash_core = { Config::verge().latest().clash_core.clone() };
|
||||
let clash_core = clash_core.unwrap_or("verge-mihomo".into());
|
||||
@ -279,6 +608,106 @@ pub(super) async fn run_core_by_service(config_file: &PathBuf) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// start the clash by service
|
||||
pub(super) async fn run_core_by_service(config_file: &PathBuf) -> Result<()> {
|
||||
log::info!(target: "app", "正在尝试通过服务启动核心");
|
||||
|
||||
// 先检查服务版本,不受冷却期限制
|
||||
let version_check = match check_service_version().await {
|
||||
Ok(version) => {
|
||||
log::info!(target: "app", "检测到服务版本: {}, 要求版本: {}",
|
||||
version, REQUIRED_SERVICE_VERSION);
|
||||
|
||||
// 通过字节比较确保完全匹配
|
||||
if version.as_bytes() != REQUIRED_SERVICE_VERSION.as_bytes() {
|
||||
log::warn!(target: "app", "服务版本不匹配,需要重装");
|
||||
false // 版本不匹配
|
||||
} else {
|
||||
log::info!(target: "app", "服务版本匹配");
|
||||
true // 版本匹配
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!(target: "app", "无法获取服务版本: {}", err);
|
||||
false // 无法获取版本
|
||||
}
|
||||
};
|
||||
|
||||
// 先尝试直接启动服务,如果服务可用且版本匹配
|
||||
if version_check {
|
||||
if let Ok(true) = is_service_running().await {
|
||||
// 服务正在运行且版本匹配,直接使用
|
||||
log::info!(target: "app", "服务已在运行且版本匹配,尝试使用");
|
||||
return start_with_existing_service(config_file).await;
|
||||
}
|
||||
}
|
||||
|
||||
// 强制执行版本检查,如果版本不匹配则重装
|
||||
if !version_check {
|
||||
log::info!(target: "app", "服务版本不匹配,尝试重装");
|
||||
|
||||
// 获取服务状态,检查是否可以重装
|
||||
let service_state = ServiceState::get();
|
||||
if !service_state.can_reinstall() {
|
||||
log::warn!(target: "app", "由于限制无法重装服务");
|
||||
// 尝试直接启动,即使版本不匹配
|
||||
if let Ok(()) = start_with_existing_service(config_file).await {
|
||||
log::info!(target: "app", "尽管版本不匹配,但成功启动了服务");
|
||||
return Ok(());
|
||||
} else {
|
||||
bail!("服务版本不匹配且无法重装,启动失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试重装
|
||||
log::info!(target: "app", "开始重装服务");
|
||||
if let Err(err) = reinstall_service().await {
|
||||
log::warn!(target: "app", "服务重装失败: {}", err);
|
||||
|
||||
// 尝试使用现有服务
|
||||
log::info!(target: "app", "尝试使用现有服务");
|
||||
return start_with_existing_service(config_file).await;
|
||||
}
|
||||
|
||||
// 重装成功,尝试启动
|
||||
log::info!(target: "app", "服务重装成功,尝试启动");
|
||||
return start_with_existing_service(config_file).await;
|
||||
}
|
||||
|
||||
// 检查服务状态
|
||||
match check_service().await {
|
||||
Ok(_) => {
|
||||
// 服务可访问但可能没有运行核心,尝试直接启动
|
||||
log::info!(target: "app", "服务可用但未运行核心,尝试启动");
|
||||
if let Ok(()) = start_with_existing_service(config_file).await {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!(target: "app", "服务检查失败: {}", err);
|
||||
}
|
||||
}
|
||||
|
||||
// 服务不可用或启动失败,检查是否需要重装
|
||||
if check_service_needs_reinstall().await {
|
||||
log::info!(target: "app", "服务需要重装");
|
||||
|
||||
// 尝试重装
|
||||
if let Err(err) = reinstall_service().await {
|
||||
log::warn!(target: "app", "服务重装失败: {}", err);
|
||||
bail!("Failed to reinstall service: {}", err);
|
||||
}
|
||||
|
||||
// 重装后再次尝试启动
|
||||
log::info!(target: "app", "服务重装完成,尝试启动核心");
|
||||
start_with_existing_service(config_file).await
|
||||
} else {
|
||||
// 不需要或不能重装,返回错误
|
||||
log::warn!(target: "app", "服务不可用且无法重装");
|
||||
bail!("Service is not available and cannot be reinstalled at this time")
|
||||
}
|
||||
}
|
||||
|
||||
/// stop the clash by service
|
||||
pub(super) async fn stop_core_by_service() -> Result<()> {
|
||||
let url = format!("{SERVICE_URL}/stop_clash");
|
||||
@ -298,9 +727,42 @@ pub async fn is_service_running() -> Result<bool> {
|
||||
let resp = check_service().await?;
|
||||
|
||||
// 检查服务状态码和消息
|
||||
if resp.code == 200 && resp.msg == "success" && resp.data.is_some() {
|
||||
if resp.code == 0 && resp.msg == "ok" && resp.data.is_some() {
|
||||
logging!(debug, Type::Service, "Service is running");
|
||||
Ok(true)
|
||||
} else {
|
||||
logging!(debug, Type::Service, "Service is not running");
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn is_service_available() -> Result<()> {
|
||||
let resp = check_service().await?;
|
||||
if resp.code == 0 && resp.msg == "ok" && resp.data.is_some() {
|
||||
logging!(debug, Type::Service, "Service is available");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 强制重装服务(用于UI中的修复服务按钮)
|
||||
pub async fn force_reinstall_service() -> Result<()> {
|
||||
log::info!(target: "app", "用户请求强制重装服务");
|
||||
|
||||
// 创建默认服务状态(重置所有限制)
|
||||
let service_state = ServiceState::default();
|
||||
service_state.save()?;
|
||||
|
||||
log::info!(target: "app", "已重置服务状态,开始执行重装");
|
||||
|
||||
// 执行重装
|
||||
match reinstall_service().await {
|
||||
Ok(()) => {
|
||||
log::info!(target: "app", "服务重装成功");
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!(target: "app", "强制重装服务失败: {}", err);
|
||||
bail!("强制重装服务失败: {}", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
use crate::core::handle::Handle;
|
||||
use crate::{
|
||||
config::{Config, IVerge},
|
||||
log_err,
|
||||
core::handle::Handle,
|
||||
logging_error,
|
||||
utils::logging::Type,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use once_cell::sync::OnceCell;
|
||||
@ -126,8 +127,7 @@ impl Sysopt {
|
||||
if !sys_enable {
|
||||
return self.reset_sysproxy().await;
|
||||
}
|
||||
use crate::core::handle::Handle;
|
||||
use crate::utils::dirs;
|
||||
use crate::{core::handle::Handle, utils::dirs};
|
||||
use anyhow::bail;
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
|
||||
@ -185,8 +185,7 @@ impl Sysopt {
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use crate::core::handle::Handle;
|
||||
use crate::utils::dirs;
|
||||
use crate::{core::handle::Handle, utils::dirs};
|
||||
use anyhow::bail;
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
|
||||
@ -222,15 +221,50 @@ impl Sysopt {
|
||||
let enable = enable.unwrap_or(false);
|
||||
let app_handle = Handle::global().app_handle().unwrap();
|
||||
let autostart_manager = app_handle.autolaunch();
|
||||
println!("enable: {}", enable);
|
||||
|
||||
log::info!(target: "app", "Setting auto launch to: {}", enable);
|
||||
|
||||
match enable {
|
||||
true => log_err!(autostart_manager.enable()),
|
||||
false => log_err!(autostart_manager.disable()),
|
||||
true => {
|
||||
let result = autostart_manager.enable();
|
||||
if let Err(ref e) = result {
|
||||
log::error!(target: "app", "Failed to enable auto launch: {}", e);
|
||||
} else {
|
||||
log::info!(target: "app", "Auto launch enabled successfully");
|
||||
}
|
||||
logging_error!(Type::System, true, result);
|
||||
}
|
||||
false => {
|
||||
let result = autostart_manager.disable();
|
||||
if let Err(ref e) = result {
|
||||
log::error!(target: "app", "Failed to disable auto launch: {}", e);
|
||||
} else {
|
||||
log::info!(target: "app", "Auto launch disabled successfully");
|
||||
}
|
||||
logging_error!(Type::System, true, result);
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 获取当前自启动的实际状态
|
||||
pub fn get_launch_status(&self) -> Result<bool> {
|
||||
let app_handle = Handle::global().app_handle().unwrap();
|
||||
let autostart_manager = app_handle.autolaunch();
|
||||
|
||||
match autostart_manager.is_enabled() {
|
||||
Ok(status) => {
|
||||
log::info!(target: "app", "Auto launch status: {}", status);
|
||||
Ok(status)
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!(target: "app", "Failed to get auto launch status: {}", e);
|
||||
Err(anyhow::anyhow!("Failed to get auto launch status: {}", e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn guard_proxy(&self) {
|
||||
let _lock = self.guard_state.lock();
|
||||
|
||||
@ -290,7 +324,7 @@ impl Sysopt {
|
||||
enable: true,
|
||||
url: format!("http://127.0.0.1:{pac_port}/commands/pac"),
|
||||
};
|
||||
log_err!(autoproxy.set_auto_proxy());
|
||||
logging_error!(Type::System, true, autoproxy.set_auto_proxy());
|
||||
} else {
|
||||
let sysproxy = Sysproxy {
|
||||
enable: true,
|
||||
@ -299,14 +333,13 @@ impl Sysopt {
|
||||
bypass: get_bypass(),
|
||||
};
|
||||
|
||||
log_err!(sysproxy.set_system_proxy());
|
||||
logging_error!(Type::System, true, sysproxy.set_system_proxy());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use crate::core::handle::Handle;
|
||||
use crate::utils::dirs;
|
||||
use crate::{core::handle::Handle, utils::dirs};
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
|
||||
let app_handle = Handle::global().app_handle().unwrap();
|
||||
|
@ -1,24 +1,34 @@
|
||||
use crate::config::Config;
|
||||
use crate::feat;
|
||||
use crate::core::CoreManager;
|
||||
use crate::{
|
||||
config::Config, core::CoreManager, feat, logging, logging_error, utils::logging::Type,
|
||||
};
|
||||
use anyhow::{Context, Result};
|
||||
use delay_timer::prelude::{DelayTimer, DelayTimerBuilder, TaskBuilder};
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
type TaskID = u64;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TimerTask {
|
||||
pub task_id: TaskID,
|
||||
pub interval_minutes: u64,
|
||||
#[allow(unused)]
|
||||
pub last_run: i64, // Timestamp of last execution
|
||||
}
|
||||
|
||||
pub struct Timer {
|
||||
/// cron manager
|
||||
delay_timer: Arc<Mutex<DelayTimer>>,
|
||||
pub delay_timer: Arc<RwLock<DelayTimer>>,
|
||||
|
||||
/// save the current state
|
||||
timer_map: Arc<Mutex<HashMap<String, (TaskID, u64)>>>,
|
||||
/// save the current state - using RwLock for better read concurrency
|
||||
pub timer_map: Arc<RwLock<HashMap<String, TimerTask>>>,
|
||||
|
||||
/// increment id
|
||||
timer_count: Arc<Mutex<TaskID>>,
|
||||
/// increment id - kept as mutex since it's just a counter
|
||||
pub timer_count: Arc<Mutex<TaskID>>,
|
||||
|
||||
/// Flag to mark if timer is initialized - atomic for better performance
|
||||
pub initialized: Arc<std::sync::atomic::AtomicBool>,
|
||||
}
|
||||
|
||||
impl Timer {
|
||||
@ -26,68 +36,164 @@ impl Timer {
|
||||
static TIMER: OnceCell<Timer> = OnceCell::new();
|
||||
|
||||
TIMER.get_or_init(|| Timer {
|
||||
delay_timer: Arc::new(Mutex::new(DelayTimerBuilder::default().build())),
|
||||
timer_map: Arc::new(Mutex::new(HashMap::new())),
|
||||
delay_timer: Arc::new(RwLock::new(DelayTimerBuilder::default().build())),
|
||||
timer_map: Arc::new(RwLock::new(HashMap::new())),
|
||||
timer_count: Arc::new(Mutex::new(1)),
|
||||
initialized: Arc::new(std::sync::atomic::AtomicBool::new(false)),
|
||||
})
|
||||
}
|
||||
|
||||
/// restore timer
|
||||
/// Initialize timer with better error handling and atomic operations
|
||||
pub fn init(&self) -> Result<()> {
|
||||
self.refresh()?;
|
||||
// Use compare_exchange for thread-safe initialization check
|
||||
if self
|
||||
.initialized
|
||||
.compare_exchange(
|
||||
false,
|
||||
true,
|
||||
std::sync::atomic::Ordering::SeqCst,
|
||||
std::sync::atomic::Ordering::SeqCst,
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
logging!(debug, Type::Timer, "Timer already initialized, skipping...");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
logging!(info, Type::Timer, true, "Initializing timer...");
|
||||
|
||||
// Initialize timer tasks
|
||||
if let Err(e) = self.refresh() {
|
||||
// Reset initialization flag on error
|
||||
self.initialized
|
||||
.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||
logging_error!(Type::Timer, false, "Failed to initialize timer: {}", e);
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
let cur_timestamp = chrono::Local::now().timestamp();
|
||||
|
||||
let timer_map = self.timer_map.lock();
|
||||
let delay_timer = self.delay_timer.lock();
|
||||
|
||||
if let Some(items) = Config::profiles().latest().get_items() {
|
||||
// Collect profiles that need immediate update
|
||||
let profiles_to_update = if let Some(items) = Config::profiles().latest().get_items() {
|
||||
items
|
||||
.iter()
|
||||
.filter_map(|item| {
|
||||
// mins to seconds
|
||||
let interval = ((item.option.as_ref()?.update_interval?) as i64) * 60;
|
||||
let interval = item.option.as_ref()?.update_interval? as i64;
|
||||
let updated = item.updated? as i64;
|
||||
let uid = item.uid.as_ref()?;
|
||||
|
||||
if interval > 0 && cur_timestamp - updated >= interval {
|
||||
Some(item)
|
||||
if interval > 0 && cur_timestamp - updated >= interval * 60 {
|
||||
Some(uid.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.for_each(|item| {
|
||||
if let Some(uid) = item.uid.as_ref() {
|
||||
if let Some((task_id, _)) = timer_map.get(uid) {
|
||||
crate::log_err!(delay_timer.advance_task(*task_id));
|
||||
.collect::<Vec<String>>()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
// Advance tasks outside of locks to minimize lock contention
|
||||
if !profiles_to_update.is_empty() {
|
||||
let timer_map = self.timer_map.read();
|
||||
let delay_timer = self.delay_timer.write();
|
||||
|
||||
for uid in profiles_to_update {
|
||||
if let Some(task) = timer_map.get(&uid) {
|
||||
logging!(info, Type::Timer, "Advancing task for uid: {}", uid);
|
||||
if let Err(e) = delay_timer.advance_task(task.task_id) {
|
||||
logging!(warn, Type::Timer, "Failed to advance task {}: {}", uid, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
logging!(info, Type::Timer, "Timer initialization completed");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Correctly update all cron tasks
|
||||
/// Refresh timer tasks with better error handling
|
||||
pub fn refresh(&self) -> Result<()> {
|
||||
// Generate diff outside of lock to minimize lock contention
|
||||
let diff_map = self.gen_diff();
|
||||
|
||||
let mut timer_map = self.timer_map.lock();
|
||||
let mut delay_timer = self.delay_timer.lock();
|
||||
if diff_map.is_empty() {
|
||||
logging!(debug, Type::Timer, "No timer changes needed");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
for (uid, diff) in diff_map.into_iter() {
|
||||
logging!(
|
||||
info,
|
||||
Type::Timer,
|
||||
"Refreshing {} timer tasks",
|
||||
diff_map.len()
|
||||
);
|
||||
|
||||
// Apply changes while holding locks
|
||||
let mut timer_map = self.timer_map.write();
|
||||
let mut delay_timer = self.delay_timer.write();
|
||||
|
||||
for (uid, diff) in diff_map {
|
||||
match diff {
|
||||
DiffFlag::Del(tid) => {
|
||||
let _ = timer_map.remove(&uid);
|
||||
crate::log_err!(delay_timer.remove_task(tid));
|
||||
timer_map.remove(&uid);
|
||||
if let Err(e) = delay_timer.remove_task(tid) {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Timer,
|
||||
"Failed to remove task {} for uid {}: {}",
|
||||
tid,
|
||||
uid,
|
||||
e
|
||||
);
|
||||
} else {
|
||||
logging!(debug, Type::Timer, "Removed task {} for uid {}", tid, uid);
|
||||
}
|
||||
DiffFlag::Add(tid, val) => {
|
||||
let _ = timer_map.insert(uid.clone(), (tid, val));
|
||||
crate::log_err!(self.add_task(&mut delay_timer, uid, tid, val));
|
||||
}
|
||||
DiffFlag::Mod(tid, val) => {
|
||||
let _ = timer_map.insert(uid.clone(), (tid, val));
|
||||
crate::log_err!(delay_timer.remove_task(tid));
|
||||
crate::log_err!(self.add_task(&mut delay_timer, uid, tid, val));
|
||||
DiffFlag::Add(tid, interval) => {
|
||||
let task = TimerTask {
|
||||
task_id: tid,
|
||||
interval_minutes: interval,
|
||||
last_run: chrono::Local::now().timestamp(),
|
||||
};
|
||||
|
||||
timer_map.insert(uid.clone(), task);
|
||||
|
||||
if let Err(e) = self.add_task(&mut delay_timer, uid.clone(), tid, interval) {
|
||||
logging_error!(Type::Timer, "Failed to add task for uid {}: {}", uid, e);
|
||||
timer_map.remove(&uid); // Rollback on failure
|
||||
} else {
|
||||
logging!(debug, Type::Timer, "Added task {} for uid {}", tid, uid);
|
||||
}
|
||||
}
|
||||
DiffFlag::Mod(tid, interval) => {
|
||||
// Remove old task first
|
||||
if let Err(e) = delay_timer.remove_task(tid) {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Timer,
|
||||
"Failed to remove old task {} for uid {}: {}",
|
||||
tid,
|
||||
uid,
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
// Then add the new one
|
||||
let task = TimerTask {
|
||||
task_id: tid,
|
||||
interval_minutes: interval,
|
||||
last_run: chrono::Local::now().timestamp(),
|
||||
};
|
||||
|
||||
timer_map.insert(uid.clone(), task);
|
||||
|
||||
if let Err(e) = self.add_task(&mut delay_timer, uid.clone(), tid, interval) {
|
||||
logging_error!(Type::Timer, "Failed to update task for uid {}: {}", uid, e);
|
||||
timer_map.remove(&uid); // Rollback on failure
|
||||
} else {
|
||||
logging!(debug, Type::Timer, "Updated task {} for uid {}", tid, uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,18 +201,17 @@ impl Timer {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// generate a uid -> update_interval map
|
||||
/// Generate map of profile UIDs to update intervals
|
||||
fn gen_map(&self) -> HashMap<String, u64> {
|
||||
let mut new_map = HashMap::new();
|
||||
|
||||
if let Some(items) = Config::profiles().latest().get_items() {
|
||||
for item in items.iter() {
|
||||
if item.option.is_some() {
|
||||
let option = item.option.as_ref().unwrap();
|
||||
let interval = option.update_interval.unwrap_or(0);
|
||||
|
||||
if let Some(option) = item.option.as_ref() {
|
||||
if let (Some(interval), Some(uid)) = (option.update_interval, &item.uid) {
|
||||
if interval > 0 {
|
||||
new_map.insert(item.uid.clone().unwrap(), interval);
|
||||
new_map.insert(uid.clone(), interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,39 +220,50 @@ impl Timer {
|
||||
new_map
|
||||
}
|
||||
|
||||
/// generate the diff map for refresh
|
||||
/// Generate differences between current and new timer configuration
|
||||
fn gen_diff(&self) -> HashMap<String, DiffFlag> {
|
||||
let mut diff_map = HashMap::new();
|
||||
|
||||
let timer_map = self.timer_map.lock();
|
||||
|
||||
let new_map = self.gen_map();
|
||||
let cur_map = &timer_map;
|
||||
|
||||
cur_map.iter().for_each(|(uid, (tid, val))| {
|
||||
let new_val = new_map.get(uid).unwrap_or(&0);
|
||||
// Read lock for comparing current state
|
||||
let timer_map = self.timer_map.read();
|
||||
|
||||
if *new_val == 0 {
|
||||
diff_map.insert(uid.clone(), DiffFlag::Del(*tid));
|
||||
} else if new_val != val {
|
||||
diff_map.insert(uid.clone(), DiffFlag::Mod(*tid, *new_val));
|
||||
// Find tasks to modify or delete
|
||||
for (uid, task) in timer_map.iter() {
|
||||
match new_map.get(uid) {
|
||||
Some(&interval) if interval != task.interval_minutes => {
|
||||
// Task exists but interval changed
|
||||
diff_map.insert(uid.clone(), DiffFlag::Mod(task.task_id, interval));
|
||||
}
|
||||
});
|
||||
|
||||
let mut count = self.timer_count.lock();
|
||||
|
||||
new_map.iter().for_each(|(uid, val)| {
|
||||
if cur_map.get(uid).is_none() {
|
||||
diff_map.insert(uid.clone(), DiffFlag::Add(*count, *val));
|
||||
|
||||
*count += 1;
|
||||
None => {
|
||||
// Task no longer needed
|
||||
diff_map.insert(uid.clone(), DiffFlag::Del(task.task_id));
|
||||
}
|
||||
_ => {
|
||||
// Task exists with same interval, no change needed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find new tasks to add
|
||||
let mut next_id = *self.timer_count.lock();
|
||||
|
||||
for (uid, &interval) in new_map.iter() {
|
||||
if !timer_map.contains_key(uid) {
|
||||
diff_map.insert(uid.clone(), DiffFlag::Add(next_id, interval));
|
||||
next_id += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Update counter only if we added new tasks
|
||||
if next_id > *self.timer_count.lock() {
|
||||
*self.timer_count.lock() = next_id;
|
||||
}
|
||||
});
|
||||
|
||||
diff_map
|
||||
}
|
||||
|
||||
/// add a cron task
|
||||
/// Add a timer task with better error handling
|
||||
fn add_task(
|
||||
&self,
|
||||
delay_timer: &mut DelayTimer,
|
||||
@ -155,12 +271,26 @@ impl Timer {
|
||||
tid: TaskID,
|
||||
minutes: u64,
|
||||
) -> Result<()> {
|
||||
logging!(
|
||||
info,
|
||||
Type::Timer,
|
||||
"Adding task: uid={}, id={}, interval={}min",
|
||||
uid,
|
||||
tid,
|
||||
minutes
|
||||
);
|
||||
|
||||
// Create a task with reasonable retries and backoff
|
||||
let task = TaskBuilder::default()
|
||||
.set_task_id(tid)
|
||||
.set_maximum_parallel_runnable_num(1)
|
||||
.set_frequency_repeated_by_minutes(minutes)
|
||||
// .set_frequency_repeated_by_seconds(minutes) // for test
|
||||
.spawn_async_routine(move || Self::async_task(uid.to_owned()))
|
||||
.spawn_async_routine(move || {
|
||||
let uid = uid.clone();
|
||||
async move {
|
||||
Self::async_task(uid).await;
|
||||
}
|
||||
})
|
||||
.context("failed to create timer task")?;
|
||||
|
||||
delay_timer
|
||||
@ -170,19 +300,41 @@ impl Timer {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// the task runner
|
||||
/// Async task with better error handling and logging
|
||||
async fn async_task(uid: String) {
|
||||
log::info!(target: "app", "running timer task `{uid}`");
|
||||
let task_start = std::time::Instant::now();
|
||||
logging!(info, Type::Timer, "Running timer task for profile: {}", uid);
|
||||
|
||||
// 使用更轻量级的更新方式
|
||||
if let Err(e) = feat::update_profile(uid.clone(), None).await {
|
||||
log::error!(target: "app", "timer task update error: {}", e);
|
||||
return;
|
||||
// Update profile
|
||||
let profile_result = feat::update_profile(uid.clone(), None).await;
|
||||
|
||||
match profile_result {
|
||||
Ok(_) => {
|
||||
// Update configuration
|
||||
match CoreManager::global().update_config().await {
|
||||
Ok(_) => {
|
||||
let duration = task_start.elapsed().as_millis();
|
||||
logging!(
|
||||
info,
|
||||
Type::Timer,
|
||||
"Timer task completed successfully for uid: {} (took {}ms)",
|
||||
uid,
|
||||
duration
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
logging_error!(
|
||||
Type::Timer,
|
||||
"Failed to refresh config after profile update for uid {}: {}",
|
||||
uid,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
logging_error!(Type::Timer, "Failed to update profile uid {}: {}", uid, e);
|
||||
}
|
||||
|
||||
// 只有更新成功后才刷新配置
|
||||
if let Err(e) = CoreManager::global().update_config().await {
|
||||
log::error!(target: "app", "timer task refresh error: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
use once_cell::sync::OnceCell;
|
||||
use tauri::tray::TrayIconBuilder;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub mod speed_rate;
|
||||
use crate::module::mihomo::Rate;
|
||||
use crate::{
|
||||
cmd,
|
||||
config::Config,
|
||||
feat, resolve,
|
||||
utils::resolve::VERSION,
|
||||
utils::{dirs, i18n::t},
|
||||
feat,
|
||||
module::{lightweight::entry_lightweight_mode, mihomo::Rate},
|
||||
resolve,
|
||||
utils::{dirs::find_target_icons, i18n::t, logging::Type, resolve::VERSION},
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
@ -19,29 +20,136 @@ use parking_lot::Mutex;
|
||||
use parking_lot::RwLock;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use speed_rate::{SpeedRate, Traffic};
|
||||
use std::fs;
|
||||
#[cfg(target_os = "macos")]
|
||||
use std::sync::Arc;
|
||||
use tauri::menu::{CheckMenuItem, IsMenuItem};
|
||||
use tauri::AppHandle;
|
||||
use tauri::{
|
||||
menu::{MenuEvent, MenuItem, PredefinedMenuItem, Submenu},
|
||||
tray::{MouseButton, MouseButtonState, TrayIconEvent, TrayIconId},
|
||||
Wry,
|
||||
menu::{CheckMenuItem, IsMenuItem, MenuEvent, MenuItem, PredefinedMenuItem, Submenu},
|
||||
tray::{MouseButton, MouseButtonState, TrayIconEvent},
|
||||
App, AppHandle, Wry,
|
||||
};
|
||||
#[cfg(target_os = "macos")]
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
use super::handle;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct TrayState {}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub struct Tray {
|
||||
pub speed_rate: Arc<Mutex<Option<SpeedRate>>>,
|
||||
shutdown_tx: Arc<RwLock<Option<broadcast::Sender<()>>>>,
|
||||
is_subscribed: Arc<RwLock<bool>>,
|
||||
pub rate_cache: Arc<Mutex<Option<Rate>>>,
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub struct Tray {}
|
||||
|
||||
impl TrayState {
|
||||
pub fn get_common_tray_icon() -> (bool, Vec<u8>) {
|
||||
let verge = Config::verge().latest().clone();
|
||||
let is_common_tray_icon = verge.common_tray_icon.unwrap_or(false);
|
||||
if is_common_tray_icon {
|
||||
if let Some(common_icon_path) = find_target_icons("common").unwrap() {
|
||||
let icon_data = fs::read(common_icon_path).unwrap();
|
||||
return (true, icon_data);
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let tray_icon_colorful = verge.tray_icon.unwrap_or("monochrome".to_string());
|
||||
if tray_icon_colorful == "monochrome" {
|
||||
(
|
||||
false,
|
||||
include_bytes!("../../../icons/tray-icon-mono.ico").to_vec(),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
false,
|
||||
include_bytes!("../../../icons/tray-icon.ico").to_vec(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
(
|
||||
false,
|
||||
include_bytes!("../../../icons/tray-icon.ico").to_vec(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_sysproxy_tray_icon() -> (bool, Vec<u8>) {
|
||||
let verge = Config::verge().latest().clone();
|
||||
let is_sysproxy_tray_icon = verge.sysproxy_tray_icon.unwrap_or(false);
|
||||
if is_sysproxy_tray_icon {
|
||||
if let Some(sysproxy_icon_path) = find_target_icons("sysproxy").unwrap() {
|
||||
let icon_data = fs::read(sysproxy_icon_path).unwrap();
|
||||
return (true, icon_data);
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let tray_icon_colorful = verge.tray_icon.clone().unwrap_or("monochrome".to_string());
|
||||
if tray_icon_colorful == "monochrome" {
|
||||
(
|
||||
false,
|
||||
include_bytes!("../../../icons/tray-icon-sys-mono.ico").to_vec(),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
false,
|
||||
include_bytes!("../../../icons/tray-icon-sys.ico").to_vec(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
(
|
||||
false,
|
||||
include_bytes!("../../../icons/tray-icon-sys.ico").to_vec(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_tun_tray_icon() -> (bool, Vec<u8>) {
|
||||
let verge = Config::verge().latest().clone();
|
||||
let is_tun_tray_icon = verge.tun_tray_icon.unwrap_or(false);
|
||||
if is_tun_tray_icon {
|
||||
if let Some(tun_icon_path) = find_target_icons("tun").unwrap() {
|
||||
let icon_data = fs::read(tun_icon_path).unwrap();
|
||||
return (true, icon_data);
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let tray_icon_colorful = verge.tray_icon.clone().unwrap_or("monochrome".to_string());
|
||||
if tray_icon_colorful == "monochrome" {
|
||||
(
|
||||
false,
|
||||
include_bytes!("../../../icons/tray-icon-tun-mono.ico").to_vec(),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
false,
|
||||
include_bytes!("../../../icons/tray-icon-tun.ico").to_vec(),
|
||||
)
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
(
|
||||
false,
|
||||
include_bytes!("../../../icons/tray-icon-tun.ico").to_vec(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Tray {
|
||||
pub fn global() -> &'static Tray {
|
||||
static TRAY: OnceCell<Tray> = OnceCell::new();
|
||||
@ -51,6 +159,7 @@ impl Tray {
|
||||
speed_rate: Arc::new(Mutex::new(None)),
|
||||
shutdown_tx: Arc::new(RwLock::new(None)),
|
||||
is_subscribed: Arc::new(RwLock::new(false)),
|
||||
rate_cache: Arc::new(Mutex::new(None)),
|
||||
});
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
@ -66,19 +175,27 @@ impl Tray {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn create_systray(&self) -> Result<()> {
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
let tray_incon_id = TrayIconId::new("main");
|
||||
let tray = app_handle.tray_by_id(&tray_incon_id).unwrap();
|
||||
pub fn create_systray(&self, app: &App) -> Result<()> {
|
||||
let mut builder = TrayIconBuilder::with_id("main")
|
||||
.icon(app.default_window_icon().unwrap().clone())
|
||||
.icon_as_template(false);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
tray.set_show_menu_on_left_click(false)?;
|
||||
#[cfg(any(target_os = "macos", target_os = "windows"))]
|
||||
{
|
||||
let tray_event = { Config::verge().latest().tray_event.clone() };
|
||||
let tray_event: String = tray_event.unwrap_or("main_window".into());
|
||||
if tray_event.as_str() != "tray_menu" {
|
||||
builder = builder.show_menu_on_left_click(false);
|
||||
}
|
||||
}
|
||||
|
||||
let tray = builder.build(app)?;
|
||||
|
||||
tray.on_tray_icon_event(|_, event| {
|
||||
let tray_event = { Config::verge().latest().tray_event.clone() };
|
||||
let tray_event: String = tray_event.unwrap_or("main_window".into());
|
||||
log::debug!(target: "app","tray event: {:?}", tray_event);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Down,
|
||||
@ -88,22 +205,7 @@ impl Tray {
|
||||
match tray_event.as_str() {
|
||||
"system_proxy" => feat::toggle_system_proxy(),
|
||||
"tun_mode" => feat::toggle_tun_mode(None),
|
||||
"main_window" => resolve::create_window(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Down,
|
||||
..
|
||||
} = event
|
||||
{
|
||||
match tray_event.as_str() {
|
||||
"system_proxy" => feat::toggle_system_proxy(),
|
||||
"tun_mode" => feat::toggle_tun_mode(None),
|
||||
"main_window" => resolve::create_window(),
|
||||
"main_window" => resolve::create_window(true),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@ -112,6 +214,19 @@ impl Tray {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 更新托盘点击行为
|
||||
pub fn update_click_behavior(&self) -> Result<()> {
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
let tray_event = { Config::verge().latest().tray_event.clone() };
|
||||
let tray_event: String = tray_event.unwrap_or("main_window".into());
|
||||
let tray = app_handle.tray_by_id("main").unwrap();
|
||||
match tray_event.as_str() {
|
||||
"tray_menu" => tray.set_show_menu_on_left_click(true)?,
|
||||
_ => tray.set_show_menu_on_left_click(false)?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 更新托盘菜单
|
||||
pub fn update_menu(&self) -> Result<()> {
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
@ -130,7 +245,7 @@ impl Tray {
|
||||
let profile_uid_and_name = Config::profiles()
|
||||
.data()
|
||||
.all_profile_uid_and_name()
|
||||
.unwrap_or(Vec::new());
|
||||
.unwrap_or_default();
|
||||
|
||||
let tray = app_handle.tray_by_id("main").unwrap();
|
||||
let _ = tray.set_menu(Some(create_tray_menu(
|
||||
@ -144,115 +259,68 @@ impl Tray {
|
||||
}
|
||||
|
||||
/// 更新托盘图标
|
||||
#[allow(unused_variables)]
|
||||
pub fn update_icon(&self, rate: Option<Rate>) -> Result<()> {
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
let verge = Config::verge().latest().clone();
|
||||
let system_proxy = verge.enable_system_proxy.as_ref().unwrap_or(&false);
|
||||
let system_mode = verge.enable_system_proxy.as_ref().unwrap_or(&false);
|
||||
let tun_mode = verge.enable_tun_mode.as_ref().unwrap_or(&false);
|
||||
|
||||
let common_tray_icon = verge.common_tray_icon.as_ref().unwrap_or(&false);
|
||||
let sysproxy_tray_icon = verge.sysproxy_tray_icon.as_ref().unwrap_or(&false);
|
||||
let tun_tray_icon = verge.tun_tray_icon.as_ref().unwrap_or(&false);
|
||||
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
let tray = app_handle.tray_by_id("main").unwrap();
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let tray_icon = verge.tray_icon.clone().unwrap_or("monochrome".to_string());
|
||||
|
||||
let icon_bytes = if *system_proxy && !*tun_mode {
|
||||
#[cfg(target_os = "macos")]
|
||||
let mut icon = match tray_icon.as_str() {
|
||||
"colorful" => include_bytes!("../../../icons/tray-icon-sys.ico").to_vec(),
|
||||
_ => include_bytes!("../../../icons/tray-icon-sys-mono.ico").to_vec(),
|
||||
let (is_custom_icon, icon_bytes) = match (*system_mode, *tun_mode) {
|
||||
(true, true) => TrayState::get_tun_tray_icon(),
|
||||
(true, false) => TrayState::get_sysproxy_tray_icon(),
|
||||
(false, true) => TrayState::get_tun_tray_icon(),
|
||||
(false, false) => TrayState::get_common_tray_icon(),
|
||||
};
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let mut icon = include_bytes!("../../../icons/tray-icon-sys.ico").to_vec();
|
||||
if *sysproxy_tray_icon {
|
||||
let icon_dir_path = dirs::app_home_dir()?.join("icons");
|
||||
let png_path = icon_dir_path.join("sysproxy.png");
|
||||
let ico_path = icon_dir_path.join("sysproxy.ico");
|
||||
if ico_path.exists() {
|
||||
icon = std::fs::read(ico_path).unwrap();
|
||||
} else if png_path.exists() {
|
||||
icon = std::fs::read(png_path).unwrap();
|
||||
}
|
||||
}
|
||||
icon
|
||||
} else if *tun_mode {
|
||||
#[cfg(target_os = "macos")]
|
||||
let mut icon = match tray_icon.as_str() {
|
||||
"colorful" => include_bytes!("../../../icons/tray-icon-tun.ico").to_vec(),
|
||||
_ => include_bytes!("../../../icons/tray-icon-tun-mono.ico").to_vec(),
|
||||
};
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let mut icon = include_bytes!("../../../icons/tray-icon-tun.ico").to_vec();
|
||||
if *tun_tray_icon {
|
||||
let icon_dir_path = dirs::app_home_dir()?.join("icons");
|
||||
let png_path = icon_dir_path.join("tun.png");
|
||||
let ico_path = icon_dir_path.join("tun.ico");
|
||||
if ico_path.exists() {
|
||||
icon = std::fs::read(ico_path).unwrap();
|
||||
} else if png_path.exists() {
|
||||
icon = std::fs::read(png_path).unwrap();
|
||||
}
|
||||
}
|
||||
icon
|
||||
} else {
|
||||
#[cfg(target_os = "macos")]
|
||||
let mut icon = match tray_icon.as_str() {
|
||||
"colorful" => include_bytes!("../../../icons/tray-icon.ico").to_vec(),
|
||||
_ => include_bytes!("../../../icons/tray-icon-mono.ico").to_vec(),
|
||||
};
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let mut icon = include_bytes!("../../../icons/tray-icon.ico").to_vec();
|
||||
if *common_tray_icon {
|
||||
let icon_dir_path = dirs::app_home_dir()?.join("icons");
|
||||
let png_path = icon_dir_path.join("common.png");
|
||||
let ico_path = icon_dir_path.join("common.ico");
|
||||
if ico_path.exists() {
|
||||
icon = std::fs::read(ico_path).unwrap();
|
||||
} else if png_path.exists() {
|
||||
icon = std::fs::read(png_path).unwrap();
|
||||
}
|
||||
}
|
||||
icon
|
||||
};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let enable_tray_speed = Config::verge().latest().enable_tray_speed.unwrap_or(true);
|
||||
let is_colorful = tray_icon == "colorful";
|
||||
let enable_tray_speed = verge.enable_tray_speed.unwrap_or(true);
|
||||
let enable_tray_icon = verge.enable_tray_icon.unwrap_or(true);
|
||||
let colorful = verge.tray_icon.clone().unwrap_or("monochrome".to_string());
|
||||
let is_colorful = colorful == "colorful";
|
||||
|
||||
// 处理图标和速率
|
||||
let final_icon_bytes = if enable_tray_speed {
|
||||
let rate = rate.or_else(|| {
|
||||
self.speed_rate
|
||||
.lock()
|
||||
.as_ref()
|
||||
.and_then(|speed_rate| speed_rate.get_curent_rate())
|
||||
});
|
||||
if !enable_tray_speed {
|
||||
let _ = tray.set_icon(Some(tauri::image::Image::from_bytes(&icon_bytes)?));
|
||||
let _ = tray.set_icon_as_template(!is_colorful);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// 使用新的方法渲染图标和速率
|
||||
SpeedRate::add_speed_text(icon_bytes, rate)?
|
||||
let rate = if let Some(rate) = rate {
|
||||
Some(rate)
|
||||
} else {
|
||||
icon_bytes
|
||||
let guard = self.speed_rate.lock();
|
||||
if let Some(rate) = guard.as_ref().unwrap().get_curent_rate() {
|
||||
Some(rate)
|
||||
} else {
|
||||
Some(Rate::default())
|
||||
}
|
||||
};
|
||||
|
||||
// 设置系统托盘图标
|
||||
let _ = tray.set_icon(Some(tauri::image::Image::from_bytes(&final_icon_bytes)?));
|
||||
// 只对单色图标使用 template 模式
|
||||
let _ = tray.set_icon_as_template(!is_colorful);
|
||||
let mut rate_guard = self.rate_cache.lock();
|
||||
if *rate_guard != rate {
|
||||
*rate_guard = rate;
|
||||
|
||||
let bytes = if enable_tray_icon {
|
||||
Some(icon_bytes)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let rate = rate_guard.as_ref();
|
||||
let rate_bytes = SpeedRate::add_speed_text(is_custom_icon, bytes, rate).unwrap();
|
||||
let _ = tray.set_icon(Some(tauri::image::Image::from_bytes(&rate_bytes)?));
|
||||
let _ = tray.set_icon_as_template(!is_custom_icon && !is_colorful);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
let _ = tray.set_icon(Some(tauri::image::Image::from_bytes(&icon_bytes)?));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新托盘提示
|
||||
pub fn update_tooltip(&self) -> Result<()> {
|
||||
@ -399,17 +467,20 @@ fn create_tray_menu(
|
||||
let profile_menu_items: Vec<CheckMenuItem<Wry>> = profile_uid_and_name
|
||||
.iter()
|
||||
.map(|(profile_uid, profile_name)| {
|
||||
let is_current_profile = Config::profiles().data().is_current_profile_index(profile_uid.to_string());
|
||||
let is_current_profile = Config::profiles()
|
||||
.data()
|
||||
.is_current_profile_index(profile_uid.to_string());
|
||||
CheckMenuItem::with_id(
|
||||
app_handle,
|
||||
&format!("profiles_{}", profile_uid),
|
||||
t(&profile_name),
|
||||
format!("profiles_{}", profile_uid),
|
||||
t(profile_name),
|
||||
true,
|
||||
is_current_profile,
|
||||
None::<&str>,
|
||||
)
|
||||
.unwrap()
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
let profile_menu_items: Vec<&dyn IsMenuItem<Wry>> = profile_menu_items
|
||||
.iter()
|
||||
.map(|item| item as &dyn IsMenuItem<Wry>)
|
||||
@ -460,7 +531,8 @@ fn create_tray_menu(
|
||||
t("Profiles"),
|
||||
true,
|
||||
&profile_menu_items,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let system_proxy = &CheckMenuItem::with_id(
|
||||
app_handle,
|
||||
@ -482,6 +554,15 @@ fn create_tray_menu(
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let lighteweight_mode = &MenuItem::with_id(
|
||||
app_handle,
|
||||
"entry_lightweight_mode",
|
||||
t("LightWeight Mode"),
|
||||
true,
|
||||
hotkeys.get("entry_lightweight_mode").map(|s| s.as_str()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let copy_env =
|
||||
&MenuItem::with_id(app_handle, "copy_env", t("Copy Env"), true, None::<&str>).unwrap();
|
||||
|
||||
@ -574,6 +655,8 @@ fn create_tray_menu(
|
||||
separator,
|
||||
system_proxy,
|
||||
tun_mode,
|
||||
separator,
|
||||
lighteweight_mode,
|
||||
copy_env,
|
||||
open_dir,
|
||||
more,
|
||||
@ -592,19 +675,19 @@ fn on_menu_event(_: &AppHandle, event: MenuEvent) {
|
||||
println!("change mode to: {}", mode);
|
||||
feat::change_clash_mode(mode.into());
|
||||
}
|
||||
"open_window" => resolve::create_window(),
|
||||
"open_window" => resolve::create_window(true),
|
||||
"system_proxy" => feat::toggle_system_proxy(),
|
||||
"tun_mode" => feat::toggle_tun_mode(None),
|
||||
"copy_env" => feat::copy_clash_env(),
|
||||
"open_app_dir" => crate::log_err!(cmd::open_app_dir()),
|
||||
"open_core_dir" => crate::log_err!(cmd::open_core_dir()),
|
||||
"open_logs_dir" => crate::log_err!(cmd::open_logs_dir()),
|
||||
"open_app_dir" => crate::logging_error!(Type::Cmd, true, cmd::open_app_dir()),
|
||||
"open_core_dir" => crate::logging_error!(Type::Cmd, true, cmd::open_core_dir()),
|
||||
"open_logs_dir" => crate::logging_error!(Type::Cmd, true, cmd::open_logs_dir()),
|
||||
"restart_clash" => feat::restart_clash_core(),
|
||||
"restart_app" => feat::restart_app(),
|
||||
"entry_lightweight_mode" => entry_lightweight_mode(),
|
||||
"quit" => {
|
||||
println!("quit");
|
||||
feat::quit(Some(0));
|
||||
},
|
||||
}
|
||||
id if id.starts_with("profiles_") => {
|
||||
let profile_index = &id["profiles_".len()..];
|
||||
feat::toggle_proxy_profile(profile_index.into());
|
||||
|
@ -1,22 +1,20 @@
|
||||
use crate::module::mihomo::Rate;
|
||||
use crate::module::mihomo::MihomoManager;
|
||||
use crate::utils::help::format_bytes_speed;
|
||||
use crate::{
|
||||
module::mihomo::{MihomoManager, Rate},
|
||||
utils::help::format_bytes_speed,
|
||||
};
|
||||
use ab_glyph::FontArc;
|
||||
use anyhow::Result;
|
||||
use futures::Stream;
|
||||
use image::{GenericImageView, Rgba, RgbaImage};
|
||||
use imageproc::drawing::draw_text_mut;
|
||||
use parking_lot::Mutex;
|
||||
use std::io::Cursor;
|
||||
use std::sync::Arc;
|
||||
use tokio_tungstenite::tungstenite::http;
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
use std::{io::Cursor, sync::Arc};
|
||||
use tokio_tungstenite::tungstenite::{http, Message};
|
||||
use tungstenite::client::IntoClientRequest;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SpeedRate {
|
||||
rate: Arc<Mutex<(Rate, Rate)>>,
|
||||
last_update: Arc<Mutex<std::time::Instant>>,
|
||||
// 移除 base_image,不再缓存原始图像
|
||||
}
|
||||
|
||||
impl SpeedRate {
|
||||
@ -39,12 +37,20 @@ impl SpeedRate {
|
||||
|
||||
let (current, previous) = &mut *rates;
|
||||
|
||||
// 如果速率变化不大(小于10%),则不更新
|
||||
let should_update = {
|
||||
let up_change = (current.up as f64 - up as f64).abs() / (current.up as f64 + 1.0);
|
||||
let down_change =
|
||||
(current.down as f64 - down as f64).abs() / (current.down as f64 + 1.0);
|
||||
up_change > 0.1 || down_change > 0.1
|
||||
// Avoid unnecessary float conversions for small value checks
|
||||
let should_update = if current.up < 1000 && down < 1000 {
|
||||
// For small values, always update to ensure accuracy
|
||||
current.up != up || current.down != down
|
||||
} else {
|
||||
// For larger values, use integer math to check for >5% change
|
||||
// Multiply by 20 instead of dividing by 0.05 to avoid floating point
|
||||
let up_threshold = current.up / 20;
|
||||
let down_threshold = current.down / 20;
|
||||
|
||||
(up > current.up && up - current.up > up_threshold)
|
||||
|| (up < current.up && current.up - up > up_threshold)
|
||||
|| (down > current.down && down - current.down > down_threshold)
|
||||
|| (down < current.down && current.down - down > down_threshold)
|
||||
};
|
||||
|
||||
if !should_update {
|
||||
@ -70,44 +76,71 @@ impl SpeedRate {
|
||||
}
|
||||
|
||||
// 分离图标加载和速率渲染
|
||||
pub fn add_speed_text(icon_bytes: Vec<u8>, rate: Option<Rate>) -> Result<Vec<u8>> {
|
||||
let rate = rate.unwrap_or(Rate { up: 0, down: 0 });
|
||||
pub fn add_speed_text(
|
||||
is_custom_icon: bool,
|
||||
icon_bytes: Option<Vec<u8>>,
|
||||
rate: Option<&Rate>,
|
||||
) -> Result<Vec<u8>> {
|
||||
let rate = rate.unwrap_or(&Rate { up: 0, down: 0 });
|
||||
|
||||
// 加载原始图标
|
||||
let icon_image = image::load_from_memory(&icon_bytes)?;
|
||||
let (icon_width, icon_height) = (icon_image.width(), icon_image.height());
|
||||
let (mut icon_width, mut icon_height) = (0, 256);
|
||||
let icon_image = if let Some(bytes) = icon_bytes.clone() {
|
||||
let icon_image = image::load_from_memory(&bytes)?;
|
||||
icon_width = icon_image.width();
|
||||
icon_height = icon_image.height();
|
||||
icon_image
|
||||
} else {
|
||||
// 返回一个空的 RGBA 图像
|
||||
image::DynamicImage::new_rgba8(0, 0)
|
||||
};
|
||||
|
||||
// 判断是否为彩色图标
|
||||
let is_colorful =
|
||||
!crate::utils::help::is_monochrome_image_from_bytes(&icon_bytes).unwrap_or(false);
|
||||
let total_width = match (is_custom_icon, icon_bytes.is_some()) {
|
||||
(true, true) => 510,
|
||||
(true, false) => 740,
|
||||
(false, false) => 740,
|
||||
(false, true) => icon_width + 740,
|
||||
};
|
||||
|
||||
// 增加文本宽度和间距
|
||||
let text_width = 580; // 文本区域宽度
|
||||
let total_width = icon_width + text_width;
|
||||
// println!(
|
||||
// "icon_height: {}, icon_wight: {}, total_width: {}",
|
||||
// icon_height, icon_width, total_width
|
||||
// );
|
||||
|
||||
// 创建新的透明画布
|
||||
let mut combined_image = RgbaImage::new(total_width, icon_height);
|
||||
|
||||
// 将原始图标绘制到新画布的左侧
|
||||
if icon_bytes.is_some() {
|
||||
for y in 0..icon_height {
|
||||
for x in 0..icon_width {
|
||||
let pixel = icon_image.get_pixel(x, y);
|
||||
combined_image.put_pixel(x, y, pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let is_colorful = if let Some(bytes) = icon_bytes.clone() {
|
||||
!crate::utils::help::is_monochrome_image_from_bytes(&bytes).unwrap_or(false)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
// 选择文本颜色
|
||||
let (text_color, shadow_color) = if is_colorful {
|
||||
// 彩色图标使用黑色文本和轻微白色阴影
|
||||
(
|
||||
Rgba([255u8, 255u8, 255u8, 255u8]),
|
||||
Rgba([0u8, 0u8, 0u8, 160u8]),
|
||||
Rgba([144u8, 144u8, 144u8, 255u8]),
|
||||
// Rgba([255u8, 255u8, 255u8, 128u8]),
|
||||
Rgba([0u8, 0u8, 0u8, 128u8]),
|
||||
)
|
||||
// (
|
||||
// Rgba([160u8, 160u8, 160u8, 255u8]),
|
||||
// // Rgba([255u8, 255u8, 255u8, 128u8]),
|
||||
// Rgba([0u8, 0u8, 0u8, 255u8]),
|
||||
// )
|
||||
} else {
|
||||
// 单色图标使用白色文本和轻微黑色阴影
|
||||
(
|
||||
Rgba([255u8, 255u8, 255u8, 255u8]),
|
||||
Rgba([0u8, 0u8, 0u8, 120u8]),
|
||||
Rgba([0u8, 0u8, 0u8, 128u8]),
|
||||
)
|
||||
};
|
||||
// 减小字体大小以适应文本区域
|
||||
@ -117,17 +150,30 @@ impl SpeedRate {
|
||||
let scale = ab_glyph::PxScale::from(font_size);
|
||||
|
||||
// 使用更简洁的速率格式
|
||||
let up_text = format_bytes_speed(rate.up);
|
||||
let down_text = format_bytes_speed(rate.down);
|
||||
let up_text = format!("↑ {}", format_bytes_speed(rate.up));
|
||||
let down_text = format!("↓ {}", format_bytes_speed(rate.down));
|
||||
|
||||
// For test rate display
|
||||
// let down_text = format!("↓ {}", format_bytes_speed(102 * 1020 * 1024));
|
||||
|
||||
// 计算文本位置,确保垂直间距合适
|
||||
// 修改文本位置为居右显示
|
||||
let up_text_width = imageproc::drawing::text_size(scale, &font, &up_text).0 as u32;
|
||||
let down_text_width = imageproc::drawing::text_size(scale, &font, &down_text).0 as u32;
|
||||
|
||||
// 计算右对齐的文本位置
|
||||
let up_text_x = total_width - up_text_width;
|
||||
let down_text_x = total_width - down_text_width;
|
||||
// let up_text_width = imageproc::drawing::text_size(scale, &font, &up_text).0 as u32;
|
||||
// let down_text_width = imageproc::drawing::text_size(scale, &font, &down_text).0 as u32;
|
||||
// let up_text_x = total_width - up_text_width;
|
||||
// let down_text_x = total_width - down_text_width;
|
||||
|
||||
// 计算左对齐的文本位置
|
||||
let (up_text_x, down_text_x) = {
|
||||
if is_custom_icon || icon_bytes.is_some() {
|
||||
let text_left_offset = 30;
|
||||
let left_begin = icon_width + text_left_offset;
|
||||
(left_begin, left_begin)
|
||||
} else {
|
||||
(icon_width, icon_width)
|
||||
}
|
||||
};
|
||||
|
||||
// 优化垂直位置,使速率显示的高度和上下间距正好等于图标大小
|
||||
let text_height = font_size as i32;
|
||||
|
@ -1,14 +0,0 @@
|
||||
[package]
|
||||
name = "mihomo_api"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
debug = []
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.12.12", features = ["json"] }
|
||||
serde = { version = "1.0.218", features = ["derive"] }
|
||||
serde_json = "1.0.140"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.43.0", features = ["rt", "macros"] }
|
@ -5,17 +5,10 @@ mod script;
|
||||
pub mod seq;
|
||||
mod tun;
|
||||
|
||||
use self::chain::*;
|
||||
use self::field::*;
|
||||
use self::merge::*;
|
||||
use self::script::*;
|
||||
use self::seq::*;
|
||||
use self::tun::*;
|
||||
use crate::config::Config;
|
||||
use crate::utils::tmpl;
|
||||
use self::{chain::*, field::*, merge::*, script::*, seq::*, tun::*};
|
||||
use crate::{config::Config, utils::tmpl};
|
||||
use serde_yaml::Mapping;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
type ResultLog = Vec<(String, String)>;
|
||||
|
||||
|
@ -121,16 +121,32 @@ proxy-groups:
|
||||
let proxies = config.get("proxies").unwrap().as_sequence().unwrap();
|
||||
assert_eq!(proxies.len(), 1);
|
||||
assert_eq!(
|
||||
proxies[0].as_mapping().unwrap().get("name").unwrap().as_str().unwrap(),
|
||||
proxies[0]
|
||||
.as_mapping()
|
||||
.unwrap()
|
||||
.get("name")
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.unwrap(),
|
||||
"proxy2"
|
||||
);
|
||||
|
||||
// Check if proxy1 is removed from all groups
|
||||
let groups = config.get("proxy-groups").unwrap().as_sequence().unwrap();
|
||||
let group1_proxies = groups[0].as_mapping().unwrap()
|
||||
.get("proxies").unwrap().as_sequence().unwrap();
|
||||
let group2_proxies = groups[1].as_mapping().unwrap()
|
||||
.get("proxies").unwrap().as_sequence().unwrap();
|
||||
let group1_proxies = groups[0]
|
||||
.as_mapping()
|
||||
.unwrap()
|
||||
.get("proxies")
|
||||
.unwrap()
|
||||
.as_sequence()
|
||||
.unwrap();
|
||||
let group2_proxies = groups[1]
|
||||
.as_mapping()
|
||||
.unwrap()
|
||||
.get("proxies")
|
||||
.unwrap()
|
||||
.as_sequence()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(group1_proxies.len(), 1);
|
||||
assert_eq!(group1_proxies[0].as_str().unwrap(), "proxy2");
|
||||
|
@ -40,20 +40,20 @@ pub async fn use_tun(mut config: Mapping, enable: bool) -> Mapping {
|
||||
|
||||
// 检查现有的 enhanced-mode 设置
|
||||
let current_mode = dns_val
|
||||
.get(&Value::from("enhanced-mode"))
|
||||
.get(Value::from("enhanced-mode"))
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("fake-ip");
|
||||
|
||||
// 只有当 enhanced-mode 是 fake-ip 或未设置时才修改 DNS 配置
|
||||
if current_mode == "fake-ip" || !dns_val.contains_key(&Value::from("enhanced-mode")) {
|
||||
if current_mode == "fake-ip" || !dns_val.contains_key(Value::from("enhanced-mode")) {
|
||||
revise!(dns_val, "enable", true);
|
||||
revise!(dns_val, "ipv6", ipv6_val);
|
||||
|
||||
if !dns_val.contains_key(&Value::from("enhanced-mode")) {
|
||||
if !dns_val.contains_key(Value::from("enhanced-mode")) {
|
||||
revise!(dns_val, "enhanced-mode", "fake-ip");
|
||||
}
|
||||
|
||||
if !dns_val.contains_key(&Value::from("fake-ip-range")) {
|
||||
if !dns_val.contains_key(Value::from("fake-ip-range")) {
|
||||
revise!(dns_val, "fake-ip-range", "198.18.0.1/16");
|
||||
}
|
||||
|
||||
|
1
src-tauri/src/error/mod.rs
Normal file
1
src-tauri/src/error/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod service;
|
1
src-tauri/src/error/service.rs
Normal file
1
src-tauri/src/error/service.rs
Normal file
@ -0,0 +1 @@
|
||||
|
@ -1,7 +1,9 @@
|
||||
use crate::config::{Config, IVerge};
|
||||
use crate::core::backup;
|
||||
use crate::log_err;
|
||||
use crate::utils::dirs::app_home_dir;
|
||||
use crate::{
|
||||
config::{Config, IVerge},
|
||||
core::backup,
|
||||
logging_error,
|
||||
utils::{dirs::app_home_dir, logging::Type},
|
||||
};
|
||||
use anyhow::Result;
|
||||
use reqwest_dav::list_cmd::ListFile;
|
||||
use std::fs;
|
||||
@ -67,8 +69,9 @@ pub async fn restore_webdav_backup(filename: String) -> Result<()> {
|
||||
// extract zip file
|
||||
let mut zip = zip::ZipArchive::new(fs::File::open(backup_storage_path.clone())?)?;
|
||||
zip.extract(app_home_dir()?)?;
|
||||
|
||||
log_err!(
|
||||
logging_error!(
|
||||
Type::Backup,
|
||||
true,
|
||||
super::patch_verge(
|
||||
IVerge {
|
||||
webdav_url,
|
||||
|
@ -1,8 +1,10 @@
|
||||
use crate::config::Config;
|
||||
use crate::core::{handle, tray, CoreManager};
|
||||
use crate::log_err;
|
||||
use crate::module::mihomo::MihomoManager;
|
||||
use crate::utils::resolve;
|
||||
use crate::{
|
||||
config::Config,
|
||||
core::{handle, tray, CoreManager},
|
||||
logging_error,
|
||||
module::mihomo::MihomoManager,
|
||||
utils::{logging::Type, resolve},
|
||||
};
|
||||
use serde_yaml::{Mapping, Value};
|
||||
use tauri::Manager;
|
||||
|
||||
@ -26,13 +28,32 @@ pub fn restart_clash_core() {
|
||||
pub fn restart_app() {
|
||||
tauri::async_runtime::spawn_blocking(|| {
|
||||
tauri::async_runtime::block_on(async {
|
||||
log_err!(CoreManager::global().stop_core().await);
|
||||
});
|
||||
resolve::resolve_reset();
|
||||
logging_error!(Type::Core, true, CoreManager::global().stop_core().await);
|
||||
resolve::resolve_reset_async().await;
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||
tauri::process::restart(&app_handle.env());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn after_change_clash_mode() {
|
||||
tauri::async_runtime::spawn(async {
|
||||
match MihomoManager::global().get_connections().await {
|
||||
Ok(connections) => {
|
||||
if let Some(connections_array) = connections["connections"].as_array() {
|
||||
for connection in connections_array {
|
||||
if let Some(id) = connection["id"].as_str() {
|
||||
let _ = MihomoManager::global().delete_connection(id).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!(target: "app", "Failed to get connections: {}", err);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Change Clash mode (rule/global/direct/script)
|
||||
@ -45,7 +66,6 @@ pub fn change_clash_mode(mode: String) {
|
||||
});
|
||||
tauri::async_runtime::spawn(async move {
|
||||
log::debug!(target: "app", "change clash mode to {mode}");
|
||||
|
||||
match MihomoManager::global().patch_configs(json_value).await {
|
||||
Ok(_) => {
|
||||
// 更新订阅
|
||||
@ -53,11 +73,19 @@ pub fn change_clash_mode(mode: String) {
|
||||
|
||||
if Config::clash().data().save_config().is_ok() {
|
||||
handle::Handle::refresh_clash();
|
||||
log_err!(tray::Tray::global().update_menu());
|
||||
log_err!(tray::Tray::global().update_icon(None));
|
||||
logging_error!(Type::Tray, true, tray::Tray::global().update_menu());
|
||||
logging_error!(Type::Tray, true, tray::Tray::global().update_icon(None));
|
||||
}
|
||||
|
||||
let is_auto_close_connection = Config::verge()
|
||||
.data()
|
||||
.auto_close_connection
|
||||
.unwrap_or(false);
|
||||
if is_auto_close_connection {
|
||||
after_change_clash_mode();
|
||||
}
|
||||
}
|
||||
Err(err) => log::error!(target: "app", "{err}"),
|
||||
Err(err) => println!("{err}"),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
use crate::config::{Config, IVerge};
|
||||
use crate::core::{handle, hotkey, sysopt, tray, CoreManager};
|
||||
use crate::log_err;
|
||||
use crate::utils::resolve;
|
||||
use crate::{
|
||||
config::{Config, IVerge},
|
||||
core::{handle, hotkey, sysopt, tray, CoreManager},
|
||||
logging_error,
|
||||
module::lightweight,
|
||||
utils::logging::Type,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use serde_yaml::Mapping;
|
||||
use tauri::Manager;
|
||||
|
||||
/// Patch Clash configuration
|
||||
pub async fn patch_clash(patch: Mapping) -> Result<()> {
|
||||
@ -17,8 +19,8 @@ pub async fn patch_clash(patch: Mapping) -> Result<()> {
|
||||
CoreManager::global().restart_core().await?;
|
||||
} else {
|
||||
if patch.get("mode").is_some() {
|
||||
log_err!(tray::Tray::global().update_menu());
|
||||
log_err!(tray::Tray::global().update_icon(None));
|
||||
logging_error!(Type::Tray, true, tray::Tray::global().update_menu());
|
||||
logging_error!(Type::Tray, true, tray::Tray::global().update_icon(None));
|
||||
}
|
||||
Config::runtime().latest().patch_config(patch);
|
||||
CoreManager::global().update_config().await?;
|
||||
@ -39,6 +41,23 @@ pub async fn patch_clash(patch: Mapping) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
// Define update flags as bitflags for better performance
|
||||
#[derive(Clone, Copy)]
|
||||
enum UpdateFlags {
|
||||
None = 0,
|
||||
RestartCore = 1 << 0,
|
||||
ClashConfig = 1 << 1,
|
||||
VergeConfig = 1 << 2,
|
||||
Launch = 1 << 3,
|
||||
SysProxy = 1 << 4,
|
||||
SystrayIcon = 1 << 5,
|
||||
Hotkey = 1 << 6,
|
||||
SystrayMenu = 1 << 7,
|
||||
SystrayTooltip = 1 << 8,
|
||||
SystrayClickBehavior = 1 << 9,
|
||||
LighteWeight = 1 << 10,
|
||||
}
|
||||
|
||||
/// Patch Verge configuration
|
||||
pub async fn patch_verge(patch: IVerge, not_save_file: bool) -> Result<()> {
|
||||
Config::verge().draft().patch_config(patch.clone());
|
||||
@ -51,7 +70,6 @@ pub async fn patch_verge(patch: IVerge, not_save_file: bool) -> Result<()> {
|
||||
let proxy_bypass = patch.system_proxy_bypass;
|
||||
let language = patch.language;
|
||||
let mixed_port = patch.verge_mixed_port;
|
||||
let lite_mode = patch.enable_lite_mode;
|
||||
#[cfg(target_os = "macos")]
|
||||
let tray_icon = patch.tray_icon;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
@ -72,35 +90,31 @@ pub async fn patch_verge(patch: IVerge, not_save_file: bool) -> Result<()> {
|
||||
let http_enabled = patch.verge_http_enabled;
|
||||
let http_port = patch.verge_port;
|
||||
let enable_tray_speed = patch.enable_tray_speed;
|
||||
let enable_tray_icon = patch.enable_tray_icon;
|
||||
let enable_global_hotkey = patch.enable_global_hotkey;
|
||||
|
||||
let tray_event = patch.tray_event;
|
||||
let home_cards = patch.home_cards.clone();
|
||||
let enable_auto_light_weight = patch.enable_auto_light_weight_mode;
|
||||
let res: std::result::Result<(), anyhow::Error> = {
|
||||
let mut should_restart_core = false;
|
||||
let mut should_update_clash_config = false;
|
||||
let mut should_update_verge_config = false;
|
||||
let mut should_update_launch = false;
|
||||
let mut should_update_sysproxy = false;
|
||||
let mut should_update_systray_icon = false;
|
||||
let mut should_update_hotkey = false;
|
||||
let mut should_update_systray_menu = false;
|
||||
let mut should_update_systray_tooltip = false;
|
||||
// Initialize with no flags set
|
||||
let mut update_flags: i32 = UpdateFlags::None as i32;
|
||||
|
||||
if tun_mode.is_some() {
|
||||
should_update_clash_config = true;
|
||||
should_update_systray_menu = true;
|
||||
should_update_systray_tooltip = true;
|
||||
should_update_systray_icon = true;
|
||||
update_flags |= UpdateFlags::ClashConfig as i32;
|
||||
update_flags |= UpdateFlags::SystrayMenu as i32;
|
||||
update_flags |= UpdateFlags::SystrayTooltip as i32;
|
||||
update_flags |= UpdateFlags::SystrayIcon as i32;
|
||||
}
|
||||
if enable_global_hotkey.is_some() {
|
||||
should_update_verge_config = true;
|
||||
if enable_global_hotkey.is_some() || home_cards.is_some() {
|
||||
update_flags |= UpdateFlags::VergeConfig as i32;
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
if redir_enabled.is_some() || redir_port.is_some() {
|
||||
should_restart_core = true;
|
||||
update_flags |= UpdateFlags::RestartCore as i32;
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
if tproxy_enabled.is_some() || tproxy_port.is_some() {
|
||||
should_restart_core = true;
|
||||
update_flags |= UpdateFlags::RestartCore as i32;
|
||||
}
|
||||
if socks_enabled.is_some()
|
||||
|| http_enabled.is_some()
|
||||
@ -108,91 +122,88 @@ pub async fn patch_verge(patch: IVerge, not_save_file: bool) -> Result<()> {
|
||||
|| http_port.is_some()
|
||||
|| mixed_port.is_some()
|
||||
{
|
||||
should_restart_core = true;
|
||||
update_flags |= UpdateFlags::RestartCore as i32;
|
||||
}
|
||||
if auto_launch.is_some() {
|
||||
should_update_launch = true;
|
||||
update_flags |= UpdateFlags::Launch as i32;
|
||||
}
|
||||
|
||||
if system_proxy.is_some() {
|
||||
should_update_sysproxy = true;
|
||||
should_update_systray_menu = true;
|
||||
should_update_systray_tooltip = true;
|
||||
should_update_systray_icon = true;
|
||||
update_flags |= UpdateFlags::SysProxy as i32;
|
||||
update_flags |= UpdateFlags::SystrayMenu as i32;
|
||||
update_flags |= UpdateFlags::SystrayTooltip as i32;
|
||||
update_flags |= UpdateFlags::SystrayIcon as i32;
|
||||
}
|
||||
|
||||
if proxy_bypass.is_some() || pac_content.is_some() || pac.is_some() {
|
||||
should_update_sysproxy = true;
|
||||
update_flags |= UpdateFlags::SysProxy as i32;
|
||||
}
|
||||
|
||||
if language.is_some() {
|
||||
should_update_systray_menu = true;
|
||||
update_flags |= UpdateFlags::SystrayMenu as i32;
|
||||
}
|
||||
if common_tray_icon.is_some()
|
||||
|| sysproxy_tray_icon.is_some()
|
||||
|| tun_tray_icon.is_some()
|
||||
|| tray_icon.is_some()
|
||||
|| enable_tray_speed.is_some()
|
||||
|| enable_tray_icon.is_some()
|
||||
{
|
||||
should_update_systray_icon = true;
|
||||
update_flags |= UpdateFlags::SystrayIcon as i32;
|
||||
}
|
||||
|
||||
if patch.hotkeys.is_some() {
|
||||
should_update_hotkey = true;
|
||||
should_update_systray_menu = true;
|
||||
update_flags |= UpdateFlags::Hotkey as i32;
|
||||
update_flags |= UpdateFlags::SystrayMenu as i32;
|
||||
}
|
||||
|
||||
if enable_tray_speed.is_some() {
|
||||
should_update_systray_icon = true;
|
||||
if tray_event.is_some() {
|
||||
update_flags |= UpdateFlags::SystrayClickBehavior as i32;
|
||||
}
|
||||
|
||||
if should_restart_core {
|
||||
if enable_auto_light_weight.is_some() {
|
||||
update_flags |= UpdateFlags::LighteWeight as i32;
|
||||
}
|
||||
|
||||
// Process updates based on flags
|
||||
if (update_flags & (UpdateFlags::RestartCore as i32)) != 0 {
|
||||
Config::generate().await?;
|
||||
CoreManager::global().restart_core().await?;
|
||||
}
|
||||
if should_update_clash_config {
|
||||
if (update_flags & (UpdateFlags::ClashConfig as i32)) != 0 {
|
||||
CoreManager::global().update_config().await?;
|
||||
handle::Handle::refresh_clash();
|
||||
}
|
||||
if should_update_verge_config {
|
||||
if (update_flags & (UpdateFlags::VergeConfig as i32)) != 0 {
|
||||
Config::verge().draft().enable_global_hotkey = enable_global_hotkey;
|
||||
handle::Handle::refresh_verge();
|
||||
}
|
||||
if should_update_launch {
|
||||
if (update_flags & (UpdateFlags::Launch as i32)) != 0 {
|
||||
sysopt::Sysopt::global().update_launch()?;
|
||||
}
|
||||
|
||||
if should_update_sysproxy {
|
||||
if (update_flags & (UpdateFlags::SysProxy as i32)) != 0 {
|
||||
sysopt::Sysopt::global().update_sysproxy().await?;
|
||||
}
|
||||
|
||||
if should_update_hotkey {
|
||||
if (update_flags & (UpdateFlags::Hotkey as i32)) != 0 {
|
||||
hotkey::Hotkey::global().update(patch.hotkeys.unwrap())?;
|
||||
}
|
||||
|
||||
if should_update_systray_menu {
|
||||
if (update_flags & (UpdateFlags::SystrayMenu as i32)) != 0 {
|
||||
tray::Tray::global().update_menu()?;
|
||||
}
|
||||
|
||||
if should_update_systray_icon {
|
||||
if (update_flags & (UpdateFlags::SystrayIcon as i32)) != 0 {
|
||||
tray::Tray::global().update_icon(None)?;
|
||||
}
|
||||
|
||||
if should_update_systray_tooltip {
|
||||
if (update_flags & (UpdateFlags::SystrayTooltip as i32)) != 0 {
|
||||
tray::Tray::global().update_tooltip()?;
|
||||
}
|
||||
|
||||
// 处理轻量模式切换
|
||||
if lite_mode.is_some() {
|
||||
if let Some(window) = handle::Handle::global().get_window() {
|
||||
if lite_mode.unwrap() {
|
||||
// 完全退出 webview 进程
|
||||
window.close()?; // 先关闭窗口
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
if let Some(webview) = app_handle.get_webview_window("main") {
|
||||
webview.destroy()?; // 销毁 webview 进程
|
||||
if (update_flags & (UpdateFlags::SystrayClickBehavior as i32)) != 0 {
|
||||
tray::Tray::global().update_click_behavior()?;
|
||||
}
|
||||
if (update_flags & (UpdateFlags::LighteWeight as i32)) != 0 {
|
||||
if enable_auto_light_weight.unwrap() {
|
||||
lightweight::enable_auto_light_weight_mode();
|
||||
} else {
|
||||
resolve::create_window(); // 重新创建窗口
|
||||
}
|
||||
lightweight::disable_auto_light_weight_mode();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::cmd;
|
||||
use crate::config::{Config, PrfItem, PrfOption};
|
||||
use crate::core::handle;
|
||||
use crate::core::CoreManager;
|
||||
use crate::core::*;
|
||||
use crate::{
|
||||
cmd,
|
||||
config::{Config, PrfItem, PrfOption},
|
||||
core::{handle, CoreManager, *},
|
||||
};
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
/// Toggle proxy profile
|
||||
@ -29,7 +29,7 @@ pub async fn update_profile(uid: String, option: Option<PrfOption>) -> Result<()
|
||||
let profiles = Config::profiles();
|
||||
let profiles = profiles.latest();
|
||||
let item = profiles.get_item(&uid)?;
|
||||
let is_remote = item.itype.as_ref().map_or(false, |s| s == "remote");
|
||||
let is_remote = item.itype.as_ref().is_some_and(|s| s == "remote");
|
||||
|
||||
if !is_remote {
|
||||
println!("[订阅更新] {} 不是远程订阅,跳过更新", uid);
|
||||
@ -82,3 +82,11 @@ pub async fn update_profile(uid: String, option: Option<PrfOption>) -> Result<()
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 增强配置
|
||||
pub async fn enhance_profiles() -> Result<()> {
|
||||
crate::core::CoreManager::global()
|
||||
.update_config()
|
||||
.await
|
||||
.map(|_| ())
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::config::Config;
|
||||
use crate::config::IVerge;
|
||||
use crate::core::handle;
|
||||
use crate::{
|
||||
config::{Config, IVerge},
|
||||
core::handle,
|
||||
};
|
||||
use std::env;
|
||||
use tauri_plugin_clipboard_manager::ClipboardExt;
|
||||
|
||||
@ -27,6 +28,19 @@ pub fn toggle_system_proxy() {
|
||||
|
||||
/// Toggle TUN mode on/off
|
||||
pub fn toggle_tun_mode(not_save_file: Option<bool>) {
|
||||
// tauri::async_runtime::spawn(async move {
|
||||
// logging!(
|
||||
// info,
|
||||
// Type::Service,
|
||||
// true,
|
||||
// "Toggle TUN mode need install service"
|
||||
// );
|
||||
// if is_service_available().await.is_err() {
|
||||
// logging_error!(Type::Service, true, install_service().await);
|
||||
// }
|
||||
// logging_error!(Type::Core, true, CoreManager::global().restart_core().await);
|
||||
// });
|
||||
|
||||
let enable = Config::verge().data().enable_tun_mode;
|
||||
let enable = enable.unwrap_or(false);
|
||||
|
||||
@ -72,10 +86,16 @@ pub fn copy_clash_env() {
|
||||
};
|
||||
|
||||
let export_text = match env_type.as_str() {
|
||||
"bash" => format!("export https_proxy={http_proxy} http_proxy={http_proxy} all_proxy={socks5_proxy}"),
|
||||
"bash" => format!(
|
||||
"export https_proxy={http_proxy} http_proxy={http_proxy} all_proxy={socks5_proxy}"
|
||||
),
|
||||
"cmd" => format!("set http_proxy={http_proxy}\r\nset https_proxy={http_proxy}"),
|
||||
"powershell" => format!("$env:HTTP_PROXY=\"{http_proxy}\"; $env:HTTPS_PROXY=\"{http_proxy}\""),
|
||||
"nushell" => format!("load-env {{ http_proxy: \"{http_proxy}\", https_proxy: \"{http_proxy}\" }}"),
|
||||
"powershell" => {
|
||||
format!("$env:HTTP_PROXY=\"{http_proxy}\"; $env:HTTPS_PROXY=\"{http_proxy}\"")
|
||||
}
|
||||
"nushell" => {
|
||||
format!("load-env {{ http_proxy: \"{http_proxy}\", https_proxy: \"{http_proxy}\" }}")
|
||||
}
|
||||
"fish" => format!("set -x http_proxy {http_proxy}; set -x https_proxy {http_proxy}"),
|
||||
_ => {
|
||||
log::error!(target: "app", "copy_clash_env: Invalid env type! {env_type}");
|
||||
@ -83,7 +103,7 @@ pub fn copy_clash_env() {
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(_) = cliboard.write_text(export_text) {
|
||||
if cliboard.write_text(export_text).is_err() {
|
||||
log::error!(target: "app", "Failed to write to clipboard");
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
use crate::config::Config;
|
||||
use crate::core::handle;
|
||||
use crate::core::{sysopt, CoreManager};
|
||||
use crate::module::mihomo::MihomoManager;
|
||||
use crate::utils::resolve;
|
||||
use futures;
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
||||
#[cfg(target_os = "macos")]
|
||||
use crate::AppHandleManager;
|
||||
use crate::{
|
||||
config::Config,
|
||||
core::{handle, sysopt, CoreManager},
|
||||
module::mihomo::MihomoManager,
|
||||
utils::resolve,
|
||||
};
|
||||
|
||||
/// Open or close the dashboard window
|
||||
#[allow(dead_code)]
|
||||
@ -45,40 +45,10 @@ pub fn open_or_close_dashboard() {
|
||||
} else {
|
||||
println!("No existing window found, creating new window");
|
||||
log::info!(target: "app", "No existing window found, creating new window");
|
||||
resolve::create_window();
|
||||
resolve::create_window(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Setup window state monitor to save window position and size in real-time
|
||||
pub fn setup_window_state_monitor(app_handle: &tauri::AppHandle) {
|
||||
let window = app_handle.get_webview_window("main").unwrap();
|
||||
let app_handle_clone = app_handle.clone();
|
||||
|
||||
// 监听窗口移动事件
|
||||
let app_handle_move = app_handle_clone.clone();
|
||||
window.on_window_event(move |event| {
|
||||
match event {
|
||||
// 窗口移动时保存状态
|
||||
tauri::WindowEvent::Moved(_) => {
|
||||
let _ = app_handle_move.save_window_state(StateFlags::all());
|
||||
}
|
||||
// 窗口调整大小时保存状态
|
||||
tauri::WindowEvent::Resized(_) => {
|
||||
let _ = app_handle_move.save_window_state(StateFlags::all());
|
||||
}
|
||||
// 其他可能改变窗口状态的事件
|
||||
tauri::WindowEvent::ScaleFactorChanged { .. } => {
|
||||
let _ = app_handle_move.save_window_state(StateFlags::all());
|
||||
}
|
||||
// 窗口关闭时保存
|
||||
tauri::WindowEvent::CloseRequested { .. } => {
|
||||
let _ = app_handle_move.save_window_state(StateFlags::all());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// 优化的应用退出函数
|
||||
pub fn quit(code: Option<i32>) {
|
||||
log::debug!(target: "app", "启动退出流程");
|
||||
@ -137,3 +107,13 @@ pub fn quit(code: Option<i32>) {
|
||||
app_handle.exit(code.unwrap_or(0));
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn hide() {
|
||||
if let Some(window) = handle::Handle::global().get_window() {
|
||||
if window.is_visible().unwrap_or(false) {
|
||||
AppHandleManager::global().set_activation_policy_accessory();
|
||||
let _ = window.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,22 @@ mod cmd;
|
||||
mod config;
|
||||
mod core;
|
||||
mod enhance;
|
||||
mod error;
|
||||
mod feat;
|
||||
mod utils;
|
||||
mod module;
|
||||
use crate::core::hotkey;
|
||||
use crate::utils::{resolve, resolve::resolve_scheme, server};
|
||||
mod utils;
|
||||
use crate::{
|
||||
core::hotkey,
|
||||
utils::{resolve, resolve::resolve_scheme, server},
|
||||
};
|
||||
use config::Config;
|
||||
use tauri_plugin_autostart::MacosLauncher;
|
||||
use tauri_plugin_deep_link::DeepLinkExt;
|
||||
use std::sync::{Mutex, Once};
|
||||
use tauri::AppHandle;
|
||||
#[cfg(target_os = "macos")]
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_autostart::MacosLauncher;
|
||||
use tauri_plugin_deep_link::DeepLinkExt;
|
||||
use utils::logging::Type;
|
||||
|
||||
/// A global singleton handle to the application.
|
||||
pub struct AppHandleManager {
|
||||
@ -77,6 +81,7 @@ impl AppHandleManager {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::panic)]
|
||||
pub fn run() {
|
||||
// 单例检测
|
||||
let app_exists: bool = tauri::async_runtime::block_on(async move {
|
||||
@ -96,7 +101,6 @@ pub fn run() {
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
let devtools = tauri_plugin_devtools::init();
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut builder = tauri::Builder::default()
|
||||
.plugin(tauri_plugin_autostart::init(
|
||||
@ -108,7 +112,6 @@ pub fn run() {
|
||||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
||||
.plugin(tauri_plugin_notification::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
@ -118,13 +121,13 @@ pub fn run() {
|
||||
#[cfg(any(target_os = "linux", all(debug_assertions, windows)))]
|
||||
{
|
||||
use tauri_plugin_deep_link::DeepLinkExt;
|
||||
log_err!(app.deep_link().register_all());
|
||||
logging_error!(Type::System, true, app.deep_link().register_all());
|
||||
}
|
||||
|
||||
app.deep_link().on_open_url(|event| {
|
||||
tauri::async_runtime::spawn(async move {
|
||||
if let Some(url) = event.urls().first() {
|
||||
log_err!(resolve_scheme(url.to_string()).await);
|
||||
logging_error!(Type::Setup, true, resolve_scheme(url.to_string()).await);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -149,7 +152,14 @@ pub fn run() {
|
||||
cmd::restart_app,
|
||||
// 添加新的命令
|
||||
cmd::get_running_mode,
|
||||
cmd::get_app_uptime,
|
||||
cmd::get_auto_launch_status,
|
||||
cmd::is_admin,
|
||||
// service 管理
|
||||
cmd::install_service,
|
||||
cmd::uninstall_service,
|
||||
cmd::reinstall_service,
|
||||
cmd::repair_service,
|
||||
// clash
|
||||
cmd::get_clash_info,
|
||||
cmd::patch_clash_config,
|
||||
@ -203,6 +213,13 @@ pub fn run() {
|
||||
cmd::restore_webdav_backup,
|
||||
// export diagnostic info for issue reporting
|
||||
cmd::export_diagnostic_info,
|
||||
// get system info for display
|
||||
cmd::get_system_info,
|
||||
// media unlock checker
|
||||
cmd::get_unlock_items,
|
||||
cmd::check_media_unlock,
|
||||
// light-weight model
|
||||
cmd::entry_lightweight_mode,
|
||||
]);
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
@ -210,6 +227,12 @@ pub fn run() {
|
||||
builder = builder.plugin(devtools);
|
||||
}
|
||||
|
||||
// Macos Application Menu
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
// Temporary Achived due to cannot CMD+C/V/A
|
||||
}
|
||||
|
||||
let app = builder
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
@ -219,12 +242,19 @@ pub fn run() {
|
||||
AppHandleManager::global().init(app_handle.clone());
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let main_window = AppHandleManager::global().get_handle().get_webview_window("main").unwrap();
|
||||
let _ = main_window.set_title("Clash Verge");
|
||||
if let Some(window) = AppHandleManager::global()
|
||||
.get_handle()
|
||||
.get_webview_window("main")
|
||||
{
|
||||
let _ = window.set_title("Clash Verge");
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
tauri::RunEvent::Reopen { has_visible_windows, .. } => {
|
||||
tauri::RunEvent::Reopen {
|
||||
has_visible_windows,
|
||||
..
|
||||
} => {
|
||||
if !has_visible_windows {
|
||||
AppHandleManager::global().set_activation_policy_regular();
|
||||
}
|
||||
@ -252,45 +282,90 @@ pub fn run() {
|
||||
tauri::WindowEvent::Focused(true) => {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
log_err!(hotkey::Hotkey::global().register("CMD+Q", "quit"));
|
||||
logging_error!(
|
||||
Type::Hotkey,
|
||||
true,
|
||||
hotkey::Hotkey::global().register("CMD+Q", "quit")
|
||||
);
|
||||
logging_error!(
|
||||
Type::Hotkey,
|
||||
true,
|
||||
hotkey::Hotkey::global().register("CMD+W", "hide")
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
log_err!(hotkey::Hotkey::global().register("Control+Q", "quit"));
|
||||
logging_error!(
|
||||
Type::Hotkey,
|
||||
true,
|
||||
hotkey::Hotkey::global().register("Control+Q", "quit")
|
||||
);
|
||||
};
|
||||
{
|
||||
let is_enable_global_hotkey = Config::verge().latest().enable_global_hotkey.unwrap_or(true);
|
||||
let is_enable_global_hotkey = Config::verge()
|
||||
.latest()
|
||||
.enable_global_hotkey
|
||||
.unwrap_or(true);
|
||||
if !is_enable_global_hotkey {
|
||||
log_err!(hotkey::Hotkey::global().init())
|
||||
logging_error!(Type::Hotkey, true, hotkey::Hotkey::global().init())
|
||||
}
|
||||
}
|
||||
}
|
||||
tauri::WindowEvent::Focused(false) => {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
log_err!(hotkey::Hotkey::global().unregister("CMD+Q"));
|
||||
logging_error!(
|
||||
Type::Hotkey,
|
||||
true,
|
||||
hotkey::Hotkey::global().unregister("CMD+Q")
|
||||
);
|
||||
logging_error!(
|
||||
Type::Hotkey,
|
||||
true,
|
||||
hotkey::Hotkey::global().unregister("CMD+W")
|
||||
);
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
log_err!(hotkey::Hotkey::global().unregister("Control+Q"));
|
||||
logging_error!(
|
||||
Type::Hotkey,
|
||||
true,
|
||||
hotkey::Hotkey::global().unregister("Control+Q")
|
||||
);
|
||||
};
|
||||
{
|
||||
let is_enable_global_hotkey = Config::verge().latest().enable_global_hotkey.unwrap_or(true);
|
||||
let is_enable_global_hotkey = Config::verge()
|
||||
.latest()
|
||||
.enable_global_hotkey
|
||||
.unwrap_or(true);
|
||||
if !is_enable_global_hotkey {
|
||||
log_err!(hotkey::Hotkey::global().reset())
|
||||
logging_error!(Type::Hotkey, true, hotkey::Hotkey::global().reset())
|
||||
}
|
||||
}
|
||||
}
|
||||
tauri::WindowEvent::Destroyed => {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
log_err!(hotkey::Hotkey::global().unregister("CMD+Q"));
|
||||
logging_error!(
|
||||
Type::Hotkey,
|
||||
true,
|
||||
hotkey::Hotkey::global().unregister("CMD+Q")
|
||||
);
|
||||
logging_error!(
|
||||
Type::Hotkey,
|
||||
true,
|
||||
hotkey::Hotkey::global().unregister("CMD+W")
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
log_err!(hotkey::Hotkey::global().unregister("Control+Q"));
|
||||
logging_error!(
|
||||
Type::Hotkey,
|
||||
true,
|
||||
hotkey::Hotkey::global().unregister("Control+Q")
|
||||
);
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
|
142
src-tauri/src/module/lightweight.rs
Normal file
142
src-tauri/src/module/lightweight.rs
Normal file
@ -0,0 +1,142 @@
|
||||
use anyhow::{Context, Result};
|
||||
use delay_timer::prelude::TaskBuilder;
|
||||
use tauri::{Listener, Manager};
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
core::{handle, timer::Timer},
|
||||
log_err, logging,
|
||||
utils::logging::Type,
|
||||
AppHandleManager,
|
||||
};
|
||||
|
||||
const LIGHT_WEIGHT_TASK_UID: &str = "light_weight_task";
|
||||
|
||||
pub fn enable_auto_light_weight_mode() {
|
||||
Timer::global().init().unwrap();
|
||||
logging!(info, Type::Lightweight, true, "开启自动轻量模式");
|
||||
setup_window_close_listener();
|
||||
setup_webview_focus_listener();
|
||||
}
|
||||
|
||||
pub fn disable_auto_light_weight_mode() {
|
||||
logging!(info, Type::Lightweight, true, "关闭自动轻量模式");
|
||||
let _ = cancel_light_weight_timer();
|
||||
cancel_window_close_listener();
|
||||
}
|
||||
|
||||
pub fn entry_lightweight_mode() {
|
||||
if let Some(window) = handle::Handle::global().get_window() {
|
||||
if window.is_visible().unwrap_or(false) {
|
||||
let _ = window.hide();
|
||||
}
|
||||
if let Some(webview) = window.get_webview_window("main") {
|
||||
let _ = webview.destroy();
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
AppHandleManager::global().set_activation_policy_accessory();
|
||||
logging!(info, Type::Lightweight, true, "轻量模式已开启");
|
||||
}
|
||||
let _ = cancel_light_weight_timer();
|
||||
}
|
||||
|
||||
fn setup_window_close_listener() -> u32 {
|
||||
if let Some(window) = handle::Handle::global().get_window() {
|
||||
let handler = window.listen("tauri://close-requested", move |_event| {
|
||||
let _ = setup_light_weight_timer();
|
||||
logging!(
|
||||
info,
|
||||
Type::Lightweight,
|
||||
true,
|
||||
"监听到关闭请求,开始轻量模式计时"
|
||||
);
|
||||
});
|
||||
return handler;
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
fn setup_webview_focus_listener() -> u32 {
|
||||
if let Some(window) = handle::Handle::global().get_window() {
|
||||
let handler = window.listen("tauri://focus", move |_event| {
|
||||
log_err!(cancel_light_weight_timer());
|
||||
logging!(
|
||||
info,
|
||||
Type::Lightweight,
|
||||
true,
|
||||
"监听到窗口获得焦点,取消轻量模式计时"
|
||||
);
|
||||
});
|
||||
return handler;
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
fn cancel_window_close_listener() {
|
||||
if let Some(window) = handle::Handle::global().get_window() {
|
||||
window.unlisten(setup_window_close_listener());
|
||||
logging!(info, Type::Lightweight, true, "取消了窗口关闭监听");
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_light_weight_timer() -> Result<()> {
|
||||
Timer::global().init()?;
|
||||
|
||||
let mut timer_map = Timer::global().timer_map.write();
|
||||
let delay_timer = Timer::global().delay_timer.write();
|
||||
let mut timer_count = Timer::global().timer_count.lock();
|
||||
|
||||
let task_id = *timer_count;
|
||||
*timer_count += 1;
|
||||
|
||||
let once_by_minutes = Config::verge()
|
||||
.latest()
|
||||
.auto_light_weight_minutes
|
||||
.unwrap_or(10);
|
||||
|
||||
let task = TaskBuilder::default()
|
||||
.set_task_id(task_id)
|
||||
.set_maximum_parallel_runnable_num(1)
|
||||
.set_frequency_once_by_minutes(once_by_minutes)
|
||||
.spawn_async_routine(move || async move {
|
||||
logging!(info, Type::Timer, true, "计时器到期,开始进入轻量模式");
|
||||
entry_lightweight_mode();
|
||||
})
|
||||
.context("failed to create timer task")?;
|
||||
|
||||
delay_timer
|
||||
.add_task(task)
|
||||
.context("failed to add timer task")?;
|
||||
|
||||
let timer_task = crate::core::timer::TimerTask {
|
||||
task_id,
|
||||
interval_minutes: once_by_minutes,
|
||||
last_run: chrono::Local::now().timestamp(),
|
||||
};
|
||||
|
||||
timer_map.insert(LIGHT_WEIGHT_TASK_UID.to_string(), timer_task);
|
||||
|
||||
logging!(
|
||||
info,
|
||||
Type::Timer,
|
||||
true,
|
||||
"计时器已设置,{} 分钟后将自动进入轻量模式",
|
||||
once_by_minutes
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cancel_light_weight_timer() -> Result<()> {
|
||||
let mut timer_map = Timer::global().timer_map.write();
|
||||
let delay_timer = Timer::global().delay_timer.write();
|
||||
|
||||
if let Some(task) = timer_map.remove(LIGHT_WEIGHT_TASK_UID) {
|
||||
delay_timer
|
||||
.remove_task(task.task_id)
|
||||
.context("failed to remove timer task")?;
|
||||
logging!(info, Type::Timer, true, "计时器已取消");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
@ -65,6 +65,6 @@ impl MihomoManager {
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let token = http::header::HeaderValue::from_str(&auth).unwrap();
|
||||
return (ws_url, token);
|
||||
(ws_url, token)
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
pub mod sysinfo;
|
||||
pub mod lightweight;
|
||||
pub mod mihomo;
|
||||
pub mod sysinfo;
|
||||
|
@ -1,4 +1,7 @@
|
||||
use crate::core::{handle, CoreManager};
|
||||
use crate::{
|
||||
cmd::system,
|
||||
core::{handle, CoreManager},
|
||||
};
|
||||
use std::fmt::{self, Debug, Formatter};
|
||||
use sysinfo::System;
|
||||
|
||||
@ -9,14 +12,15 @@ pub struct PlatformSpecification {
|
||||
system_arch: String,
|
||||
verge_version: String,
|
||||
running_mode: String,
|
||||
is_admin: bool,
|
||||
}
|
||||
|
||||
impl Debug for PlatformSpecification {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"System Name: {}\nSystem Version: {}\nSystem kernel Version: {}\nSystem Arch: {}\nVerge Version: {}\nRunning Mode: {}",
|
||||
self.system_name, self.system_version, self.system_kernel_version, self.system_arch, self.verge_version, self.running_mode
|
||||
"System Name: {}\nSystem Version: {}\nSystem kernel Version: {}\nSystem Arch: {}\nVerge Version: {}\nRunning Mode: {}\nIs Admin: {}",
|
||||
self.system_name, self.system_version, self.system_kernel_version, self.system_arch, self.verge_version, self.running_mode, self.is_admin
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -26,23 +30,16 @@ impl PlatformSpecification {
|
||||
let system_name = System::name().unwrap_or("Null".into());
|
||||
let system_version = System::long_os_version().unwrap_or("Null".into());
|
||||
let system_kernel_version = System::kernel_version().unwrap_or("Null".into());
|
||||
let system_arch = std::env::consts::ARCH.to_string();
|
||||
let system_arch = System::cpu_arch();
|
||||
|
||||
let handler = handle::Handle::global().app_handle().unwrap();
|
||||
let config = handler.config();
|
||||
let verge_version = config.version.clone().unwrap_or("Null".into());
|
||||
|
||||
// Get running mode asynchronously
|
||||
let running_mode = tokio::task::block_in_place(|| {
|
||||
tokio::runtime::Handle::current().block_on(async {
|
||||
match CoreManager::global().get_running_mode().await {
|
||||
crate::core::RunningMode::Service => "Service".to_string(),
|
||||
crate::core::RunningMode::Sidecar => "Sidecar".to_string(),
|
||||
crate::core::RunningMode::NotRunning => "Not Running".to_string(),
|
||||
}
|
||||
})
|
||||
});
|
||||
// 使用默认值避免在同步上下文中执行异步操作
|
||||
let running_mode = "NotRunning".to_string();
|
||||
|
||||
let is_admin = system::is_admin().unwrap_or_default();
|
||||
|
||||
Self {
|
||||
system_name,
|
||||
@ -51,6 +48,17 @@ impl PlatformSpecification {
|
||||
system_arch,
|
||||
verge_version,
|
||||
running_mode,
|
||||
is_admin,
|
||||
}
|
||||
}
|
||||
|
||||
// 异步方法来获取完整的系统信息
|
||||
pub async fn new_async() -> Self {
|
||||
let mut info = Self::new();
|
||||
|
||||
let running_mode = CoreManager::global().get_running_mode().await;
|
||||
info.running_mode = running_mode.to_string();
|
||||
|
||||
info
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::core::handle;
|
||||
use anyhow::Result;
|
||||
use once_cell::sync::OnceCell;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::{fs, path::PathBuf};
|
||||
use tauri::Manager;
|
||||
|
||||
#[cfg(not(feature = "verge-dev"))]
|
||||
@ -78,6 +77,36 @@ pub fn app_profiles_dir() -> Result<PathBuf> {
|
||||
Ok(app_home_dir()?.join("profiles"))
|
||||
}
|
||||
|
||||
/// icons dir
|
||||
pub fn app_icons_dir() -> Result<PathBuf> {
|
||||
Ok(app_home_dir()?.join("icons"))
|
||||
}
|
||||
|
||||
pub fn find_target_icons(target: &str) -> Result<Option<String>> {
|
||||
let icons_dir = app_icons_dir()?;
|
||||
let mut matching_files = Vec::new();
|
||||
|
||||
for entry in fs::read_dir(icons_dir)? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
||||
if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) {
|
||||
if file_name.starts_with(target)
|
||||
&& (file_name.ends_with(".ico") || file_name.ends_with(".png"))
|
||||
{
|
||||
matching_files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if matching_files.is_empty() {
|
||||
Ok(None)
|
||||
} else {
|
||||
let first = path_to_str(matching_files.first().unwrap())?;
|
||||
Ok(Some(first.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
/// logs dir
|
||||
pub fn app_logs_dir() -> Result<PathBuf> {
|
||||
Ok(app_home_dir()?.join("logs"))
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::enhance::seq::SeqMap;
|
||||
use crate::{enhance::seq::SeqMap, logging, utils::logging::Type};
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use nanoid::nanoid;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use serde_yaml::{Mapping, Value};
|
||||
use serde_yaml::Mapping;
|
||||
use std::{fs, path::PathBuf, str::FromStr};
|
||||
|
||||
/// read data from yaml as struct T
|
||||
@ -22,9 +22,18 @@ pub fn read_yaml<T: DeserializeOwned>(path: &PathBuf) -> Result<T> {
|
||||
})
|
||||
}
|
||||
|
||||
/// read mapping from yaml fix #165
|
||||
/// read mapping from yaml
|
||||
pub fn read_mapping(path: &PathBuf) -> Result<Mapping> {
|
||||
let mut val: Value = read_yaml(path)?;
|
||||
if !path.exists() {
|
||||
bail!("file not found \"{}\"", path.display());
|
||||
}
|
||||
|
||||
let yaml_str = fs::read_to_string(path)
|
||||
.with_context(|| format!("failed to read the file \"{}\"", path.display()))?;
|
||||
|
||||
// YAML语法检查
|
||||
match serde_yaml::from_str::<serde_yaml::Value>(&yaml_str) {
|
||||
Ok(mut val) => {
|
||||
val.apply_merge()
|
||||
.with_context(|| format!("failed to apply merge \"{}\"", path.display()))?;
|
||||
|
||||
@ -35,6 +44,19 @@ pub fn read_mapping(path: &PathBuf) -> Result<Mapping> {
|
||||
path.display()
|
||||
))?
|
||||
.to_owned())
|
||||
}
|
||||
Err(err) => {
|
||||
let error_msg = format!("YAML syntax error in {}: {}", path.display(), err);
|
||||
logging!(error, Type::Config, true, "{}", error_msg);
|
||||
|
||||
crate::core::handle::Handle::notice_message(
|
||||
"config_validate::yaml_syntax_error",
|
||||
&error_msg,
|
||||
);
|
||||
|
||||
bail!("YAML syntax error: {}", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// read mapping from yaml fix #165
|
||||
@ -136,52 +158,6 @@ pub fn linux_elevator() -> String {
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! error {
|
||||
($result: expr) => {
|
||||
log::error!(target: "app", "{}", $result);
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! log_err {
|
||||
($result: expr) => {
|
||||
if let Err(err) = $result {
|
||||
log::error!(target: "app", "{err}");
|
||||
}
|
||||
};
|
||||
|
||||
($result: expr, $err_str: expr) => {
|
||||
if let Err(_) = $result {
|
||||
log::error!(target: "app", "{}", $err_str);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! trace_err {
|
||||
($result: expr, $err_str: expr) => {
|
||||
if let Err(err) = $result {
|
||||
log::trace!(target: "app", "{}, err {}", $err_str, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// wrap the anyhow error
|
||||
/// transform the error to String
|
||||
#[macro_export]
|
||||
macro_rules! wrap_err {
|
||||
($stat: expr) => {
|
||||
match $stat {
|
||||
Ok(a) => Ok(a),
|
||||
Err(err) => {
|
||||
log::error!(target: "app", "{}", err.to_string());
|
||||
Err(format!("{}", err.to_string()))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// return the string literal error
|
||||
#[macro_export]
|
||||
macro_rules! ret_err {
|
||||
@ -213,15 +189,16 @@ macro_rules! t {
|
||||
/// ```
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn format_bytes_speed(speed: u64) -> String {
|
||||
if speed < 1024 {
|
||||
format!("{}B/s", speed)
|
||||
} else if speed < 1024 * 1024 {
|
||||
format!("{:.1}KB/s", speed as f64 / 1024.0)
|
||||
} else if speed < 1024 * 1024 * 1024 {
|
||||
format!("{:.1}MB/s", speed as f64 / 1024.0 / 1024.0)
|
||||
} else {
|
||||
format!("{:.1}GB/s", speed as f64 / 1024.0 / 1024.0 / 1024.0)
|
||||
const UNITS: [&str; 4] = ["B", "KB", "MB", "GB"];
|
||||
let mut size = speed as f64;
|
||||
let mut unit_index = 0;
|
||||
|
||||
while size >= 1000.0 && unit_index < UNITS.len() - 1 {
|
||||
size /= 1024.0;
|
||||
unit_index += 1;
|
||||
}
|
||||
|
||||
format!("{:.1}{}/s", size, UNITS[unit_index])
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::config::Config;
|
||||
use crate::utils::dirs;
|
||||
use crate::{config::Config, utils::dirs};
|
||||
use once_cell::sync::Lazy;
|
||||
use serde_json::Value;
|
||||
use std::{collections::HashMap, fs, path::PathBuf};
|
||||
|
@ -1,16 +1,21 @@
|
||||
use crate::config::*;
|
||||
use crate::core::handle;
|
||||
use crate::utils::{dirs, help};
|
||||
use crate::{
|
||||
config::*,
|
||||
core::handle,
|
||||
utils::{dirs, help},
|
||||
};
|
||||
use anyhow::Result;
|
||||
use chrono::{Local, TimeZone};
|
||||
use log::LevelFilter;
|
||||
use log4rs::append::console::ConsoleAppender;
|
||||
use log4rs::append::file::FileAppender;
|
||||
use log4rs::config::{Appender, Logger, Root};
|
||||
use log4rs::encode::pattern::PatternEncoder;
|
||||
use std::fs::{self, DirEntry};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use log4rs::{
|
||||
append::{console::ConsoleAppender, file::FileAppender},
|
||||
config::{Appender, Logger, Root},
|
||||
encode::pattern::PatternEncoder,
|
||||
};
|
||||
use std::{
|
||||
fs::{self, DirEntry},
|
||||
path::PathBuf,
|
||||
str::FromStr,
|
||||
};
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
|
||||
/// initialize this instance's log file
|
||||
@ -142,13 +147,21 @@ fn init_dns_config() -> Result<()> {
|
||||
("enable".into(), Value::Bool(true)),
|
||||
("listen".into(), Value::String(":53".into())),
|
||||
("enhanced-mode".into(), Value::String("fake-ip".into())),
|
||||
("fake-ip-range".into(), Value::String("198.18.0.1/16".into())),
|
||||
("fake-ip-filter-mode".into(), Value::String("blacklist".into())),
|
||||
(
|
||||
"fake-ip-range".into(),
|
||||
Value::String("198.18.0.1/16".into()),
|
||||
),
|
||||
(
|
||||
"fake-ip-filter-mode".into(),
|
||||
Value::String("blacklist".into()),
|
||||
),
|
||||
("prefer-h3".into(), Value::Bool(false)),
|
||||
("respect-rules".into(), Value::Bool(false)),
|
||||
("use-hosts".into(), Value::Bool(false)),
|
||||
("use-system-hosts".into(), Value::Bool(false)),
|
||||
("fake-ip-filter".into(), Value::Sequence(vec![
|
||||
(
|
||||
"fake-ip-filter".into(),
|
||||
Value::Sequence(vec![
|
||||
Value::String("*.lan".into()),
|
||||
Value::String("*.local".into()),
|
||||
Value::String("*.arpa".into()),
|
||||
@ -159,41 +172,61 @@ fn init_dns_config() -> Result<()> {
|
||||
Value::String("localhost.ptlogin2.qq.com".into()),
|
||||
Value::String("*.msftncsi.com".into()),
|
||||
Value::String("www.msftconnecttest.com".into()),
|
||||
])),
|
||||
("default-nameserver".into(), Value::Sequence(vec![
|
||||
]),
|
||||
),
|
||||
(
|
||||
"default-nameserver".into(),
|
||||
Value::Sequence(vec![
|
||||
Value::String("system".into()),
|
||||
Value::String("223.6.6.6".into()),
|
||||
Value::String("8.8.8.8".into()),
|
||||
])),
|
||||
("nameserver".into(), Value::Sequence(vec![
|
||||
]),
|
||||
),
|
||||
(
|
||||
"nameserver".into(),
|
||||
Value::Sequence(vec![
|
||||
Value::String("8.8.8.8".into()),
|
||||
Value::String("https://doh.pub/dns-query".into()),
|
||||
Value::String("https://dns.alidns.com/dns-query".into()),
|
||||
])),
|
||||
("fallback".into(), Value::Sequence(vec![
|
||||
Value::String("https://dns.alidns.com/dns-query".into()),
|
||||
Value::String("https://dns.google/dns-query".into()),
|
||||
Value::String("https://cloudflare-dns.com/dns-query".into()),
|
||||
])),
|
||||
("nameserver-policy".into(), Value::Mapping(serde_yaml::Mapping::new())),
|
||||
("proxy-server-nameserver".into(), Value::Sequence(vec![
|
||||
]),
|
||||
),
|
||||
("fallback".into(), Value::Sequence(vec![])),
|
||||
(
|
||||
"nameserver-policy".into(),
|
||||
Value::Mapping(serde_yaml::Mapping::new()),
|
||||
),
|
||||
(
|
||||
"proxy-server-nameserver".into(),
|
||||
Value::Sequence(vec![
|
||||
Value::String("https://doh.pub/dns-query".into()),
|
||||
Value::String("https://dns.alidns.com/dns-query".into()),
|
||||
])),
|
||||
Value::String("tls://223.5.5.5".into()),
|
||||
]),
|
||||
),
|
||||
("direct-nameserver".into(), Value::Sequence(vec![])),
|
||||
("direct-nameserver-follow-policy".into(), Value::Bool(false)),
|
||||
("fallback-filter".into(), Value::Mapping(serde_yaml::Mapping::from_iter([
|
||||
(
|
||||
"fallback-filter".into(),
|
||||
Value::Mapping(serde_yaml::Mapping::from_iter([
|
||||
("geoip".into(), Value::Bool(true)),
|
||||
("geoip-code".into(), Value::String("CN".into())),
|
||||
("ipcidr".into(), Value::Sequence(vec![
|
||||
(
|
||||
"ipcidr".into(),
|
||||
Value::Sequence(vec![
|
||||
Value::String("240.0.0.0/4".into()),
|
||||
Value::String("0.0.0.0/32".into()),
|
||||
])),
|
||||
("domain".into(), Value::Sequence(vec![
|
||||
]),
|
||||
),
|
||||
(
|
||||
"domain".into(),
|
||||
Value::Sequence(vec![
|
||||
Value::String("+.google.com".into()),
|
||||
Value::String("+.facebook.com".into()),
|
||||
Value::String("+.youtube.com".into()),
|
||||
]),
|
||||
),
|
||||
])),
|
||||
]))),
|
||||
),
|
||||
]);
|
||||
|
||||
// 检查DNS配置文件是否存在
|
||||
@ -202,7 +235,11 @@ fn init_dns_config() -> Result<()> {
|
||||
|
||||
if !dns_path.exists() {
|
||||
log::info!(target: "app", "Creating default DNS config file");
|
||||
help::save_yaml(&dns_path, &default_dns_config, Some("# Clash Verge DNS Config"))?;
|
||||
help::save_yaml(
|
||||
&dns_path,
|
||||
&default_dns_config,
|
||||
Some("# Clash Verge DNS Config"),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -258,15 +295,11 @@ pub fn init_config() -> Result<()> {
|
||||
/// after tauri setup
|
||||
pub fn init_resources() -> Result<()> {
|
||||
let app_dir = dirs::app_home_dir()?;
|
||||
let test_dir = app_dir.join("test");
|
||||
let res_dir = dirs::app_resources_dir()?;
|
||||
|
||||
if !app_dir.exists() {
|
||||
let _ = fs::create_dir_all(&app_dir);
|
||||
}
|
||||
if !test_dir.exists() {
|
||||
let _ = fs::create_dir_all(&test_dir);
|
||||
}
|
||||
if !res_dir.exists() {
|
||||
let _ = fs::create_dir_all(&res_dir);
|
||||
}
|
||||
@ -278,7 +311,6 @@ pub fn init_resources() -> Result<()> {
|
||||
for file in file_list.iter() {
|
||||
let src_path = res_dir.join(file);
|
||||
let dest_path = app_dir.join(file);
|
||||
let test_dest_path = test_dir.join(file);
|
||||
log::debug!(target: "app", "src_path: {src_path:?}, dest_path: {dest_path:?}");
|
||||
|
||||
let handle_copy = |dest: &PathBuf| {
|
||||
@ -290,9 +322,6 @@ pub fn init_resources() -> Result<()> {
|
||||
};
|
||||
};
|
||||
|
||||
if src_path.exists() && !test_dest_path.exists() {
|
||||
handle_copy(&test_dest_path);
|
||||
}
|
||||
if src_path.exists() && !dest_path.exists() {
|
||||
handle_copy(&dest_path);
|
||||
continue;
|
||||
@ -323,8 +352,7 @@ pub fn init_resources() -> Result<()> {
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn init_scheme() -> Result<()> {
|
||||
use tauri::utils::platform::current_exe;
|
||||
use winreg::enums::*;
|
||||
use winreg::RegKey;
|
||||
use winreg::{enums::*, RegKey};
|
||||
|
||||
let app_exe = current_exe()?;
|
||||
let app_exe = dunce::canonicalize(app_exe)?;
|
||||
|
139
src-tauri/src/utils/logging.rs
Normal file
139
src-tauri/src/utils/logging.rs
Normal file
@ -0,0 +1,139 @@
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Type {
|
||||
Cmd,
|
||||
Core,
|
||||
Config,
|
||||
Setup,
|
||||
System,
|
||||
Service,
|
||||
Hotkey,
|
||||
Window,
|
||||
Tray,
|
||||
Timer,
|
||||
Frontend,
|
||||
Backup,
|
||||
Lightweight,
|
||||
}
|
||||
|
||||
impl fmt::Display for Type {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Type::Cmd => write!(f, "[Cmd]"),
|
||||
Type::Core => write!(f, "[Core]"),
|
||||
Type::Config => write!(f, "[Config]"),
|
||||
Type::Setup => write!(f, "[Setup]"),
|
||||
Type::System => write!(f, "[System]"),
|
||||
Type::Service => write!(f, "[Service]"),
|
||||
Type::Hotkey => write!(f, "[Hotkey]"),
|
||||
Type::Window => write!(f, "[Window]"),
|
||||
Type::Tray => write!(f, "[Tray]"),
|
||||
Type::Timer => write!(f, "[Timer]"),
|
||||
Type::Frontend => write!(f, "[Frontend]"),
|
||||
Type::Backup => write!(f, "[Backup]"),
|
||||
Type::Lightweight => write!(f, "[Lightweight]"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! error {
|
||||
($result: expr) => {
|
||||
log::error!(target: "app", "{}", $result);
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! log_err {
|
||||
($result: expr) => {
|
||||
if let Err(err) = $result {
|
||||
log::error!(target: "app", "{err}");
|
||||
}
|
||||
};
|
||||
|
||||
($result: expr, $err_str: expr) => {
|
||||
if let Err(_) = $result {
|
||||
log::error!(target: "app", "{}", $err_str);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! trace_err {
|
||||
($result: expr, $err_str: expr) => {
|
||||
if let Err(err) = $result {
|
||||
log::trace!(target: "app", "{}, err {}", $err_str, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// wrap the anyhow error
|
||||
/// transform the error to String
|
||||
#[macro_export]
|
||||
macro_rules! wrap_err {
|
||||
($stat: expr) => {
|
||||
match $stat {
|
||||
Ok(a) => Ok(a),
|
||||
Err(err) => {
|
||||
log::error!(target: "app", "{}", err.to_string());
|
||||
Err(format!("{}", err.to_string()))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! logging {
|
||||
// 带 println 的版本(支持格式化参数)
|
||||
($level:ident, $type:expr, true, $($arg:tt)*) => {
|
||||
println!("{} {}", $type, format_args!($($arg)*));
|
||||
log::$level!(target: "app", "{} {}", $type, format_args!($($arg)*));
|
||||
};
|
||||
|
||||
// 带 println 的版本(使用 false 明确不打印)
|
||||
($level:ident, $type:expr, false, $($arg:tt)*) => {
|
||||
log::$level!(target: "app", "{} {}", $type, format_args!($($arg)*));
|
||||
};
|
||||
|
||||
// 不带 print 参数的版本(默认不打印)
|
||||
($level:ident, $type:expr, $($arg:tt)*) => {
|
||||
log::$level!(target: "app", "{} {}", $type, format_args!($($arg)*));
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! logging_error {
|
||||
// 1. 处理 Result<T, E>,带打印控制
|
||||
($type:expr, $print:expr, $expr:expr) => {
|
||||
match $expr {
|
||||
Ok(_) => {},
|
||||
Err(err) => {
|
||||
if $print {
|
||||
println!("[{}] Error: {}", $type, err);
|
||||
}
|
||||
log::error!(target: "app", "[{}] {}", $type, err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 2. 处理 Result<T, E>,默认不打印
|
||||
($type:expr, $expr:expr) => {
|
||||
if let Err(err) = $expr {
|
||||
log::error!(target: "app", "[{}] {}", $type, err);
|
||||
}
|
||||
};
|
||||
|
||||
// 3. 处理格式化字符串,带打印控制
|
||||
($type:expr, $print:expr, $fmt:literal $(, $arg:expr)*) => {
|
||||
if $print {
|
||||
println!("[{}] {}", $type, format_args!($fmt $(, $arg)*));
|
||||
}
|
||||
log::error!(target: "app", "[{}] {}", $type, format_args!($fmt $(, $arg)*));
|
||||
};
|
||||
|
||||
// 4. 处理格式化字符串,不带 bool 时,默认 `false`
|
||||
($type:expr, $fmt:literal $(, $arg:expr)*) => {
|
||||
logging_error!($type, false, $fmt $(, $arg)*);
|
||||
};
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
pub mod dirs;
|
||||
pub mod error;
|
||||
pub mod help;
|
||||
pub mod i18n;
|
||||
pub mod init;
|
||||
pub mod logging;
|
||||
pub mod resolve;
|
||||
pub mod server;
|
||||
pub mod tmpl;
|
||||
pub mod i18n;
|
||||
|
@ -1,9 +1,13 @@
|
||||
use crate::config::IVerge;
|
||||
use crate::utils::error;
|
||||
use crate::{config::Config, config::PrfItem, core::*, utils::init, utils::server};
|
||||
use crate::{log_err, wrap_err};
|
||||
#[cfg(target_os = "macos")]
|
||||
use crate::AppHandleManager;
|
||||
use crate::{
|
||||
config::{Config, IVerge, PrfItem},
|
||||
core::*,
|
||||
logging, logging_error,
|
||||
module::lightweight,
|
||||
utils::{error, init, logging::Type, server},
|
||||
wrap_err,
|
||||
};
|
||||
use anyhow::{bail, Result};
|
||||
use once_cell::sync::OnceCell;
|
||||
use percent_encoding::percent_decode_str;
|
||||
@ -11,10 +15,9 @@ use serde_yaml::Mapping;
|
||||
use std::net::TcpListener;
|
||||
use tauri::{App, Manager};
|
||||
|
||||
use url::Url;
|
||||
use tauri::Url;
|
||||
//#[cfg(not(target_os = "linux"))]
|
||||
// use window_shadows::set_shadow;
|
||||
use tauri_plugin_notification::NotificationExt;
|
||||
|
||||
pub static VERSION: OnceCell<String> = OnceCell::new();
|
||||
|
||||
@ -48,101 +51,98 @@ pub async fn resolve_setup(app: &mut App) {
|
||||
handle::Handle::global().init(app.app_handle());
|
||||
VERSION.get_or_init(|| version.clone());
|
||||
|
||||
log_err!(init::init_config());
|
||||
log_err!(init::init_resources());
|
||||
log_err!(init::init_scheme());
|
||||
log_err!(init::startup_script().await);
|
||||
logging_error!(Type::Config, true, init::init_config());
|
||||
logging_error!(Type::Setup, true, init::init_resources());
|
||||
logging_error!(Type::Setup, true, init::init_scheme());
|
||||
logging_error!(Type::Setup, true, init::startup_script().await);
|
||||
// 处理随机端口
|
||||
log_err!(resolve_random_port_config());
|
||||
logging_error!(Type::System, true, resolve_random_port_config());
|
||||
// 启动核心
|
||||
log::trace!(target:"app", "init config");
|
||||
log_err!(Config::init_config().await);
|
||||
logging!(trace, Type::Config, true, "Initial config");
|
||||
logging_error!(Type::Config, true, Config::init_config().await);
|
||||
|
||||
if service::check_service().await.is_err() {
|
||||
match service::reinstall_service().await {
|
||||
Ok(_) => {
|
||||
log::info!(target:"app", "install service susccess.");
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
std::thread::sleep(std::time::Duration::from_millis(1000));
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let mut service_runing = false;
|
||||
for _ in 0..40 {
|
||||
if service::check_service().await.is_ok() {
|
||||
service_runing = true;
|
||||
break;
|
||||
} else {
|
||||
log::warn!(target: "app", "service not runing, sleep 500ms and check again.");
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
}
|
||||
}
|
||||
if !service_runing {
|
||||
log::warn!(target: "app", "service not running, will fallback to user mode");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!(target: "app", "failed to install service: {e:?}, will fallback to user mode");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log::trace!(target: "app", "launch core");
|
||||
log_err!(CoreManager::global().init().await);
|
||||
logging!(trace, Type::Core, "Starting CoreManager");
|
||||
logging_error!(Type::Core, true, CoreManager::global().init().await);
|
||||
|
||||
// setup a simple http server for singleton
|
||||
log::trace!(target: "app", "launch embed server");
|
||||
server::embed_server();
|
||||
|
||||
log::trace!(target: "app", "init system tray");
|
||||
log_err!(tray::Tray::global().init());
|
||||
log_err!(tray::Tray::global().create_systray());
|
||||
log::trace!(target: "app", "Initial system tray");
|
||||
logging_error!(Type::Tray, true, tray::Tray::global().init());
|
||||
logging_error!(Type::Tray, true, tray::Tray::global().create_systray(app));
|
||||
|
||||
log_err!(sysopt::Sysopt::global().update_sysproxy().await);
|
||||
log_err!(sysopt::Sysopt::global().init_guard_sysproxy());
|
||||
logging_error!(
|
||||
Type::System,
|
||||
true,
|
||||
sysopt::Sysopt::global().update_sysproxy().await
|
||||
);
|
||||
logging_error!(
|
||||
Type::System,
|
||||
true,
|
||||
sysopt::Sysopt::global().init_guard_sysproxy()
|
||||
);
|
||||
|
||||
// 初始化热键
|
||||
log::trace!(target: "app", "init hotkeys");
|
||||
log_err!(hotkey::Hotkey::global().init());
|
||||
let is_silent_start = { Config::verge().data().enable_silent_start }.unwrap_or(false);
|
||||
create_window(!is_silent_start);
|
||||
|
||||
let silent_start = { Config::verge().data().enable_silent_start };
|
||||
if !silent_start.unwrap_or(false) {
|
||||
create_window();
|
||||
logging_error!(Type::System, true, timer::Timer::global().init());
|
||||
|
||||
let enable_auto_light_weight_mode = { Config::verge().data().enable_auto_light_weight_mode };
|
||||
if enable_auto_light_weight_mode.unwrap_or(false) {
|
||||
lightweight::enable_auto_light_weight_mode();
|
||||
}
|
||||
|
||||
log_err!(tray::Tray::global().update_part());
|
||||
log_err!(timer::Timer::global().init());
|
||||
logging_error!(Type::Tray, true, tray::Tray::global().update_part());
|
||||
|
||||
// 初始化热键
|
||||
logging!(trace, Type::System, true, "Initial hotkeys");
|
||||
logging_error!(Type::System, true, hotkey::Hotkey::global().init());
|
||||
}
|
||||
|
||||
/// reset system proxy
|
||||
pub fn resolve_reset() {
|
||||
tauri::async_runtime::block_on(async move {
|
||||
/// reset system proxy (异步版)
|
||||
pub async fn resolve_reset_async() {
|
||||
#[cfg(target_os = "macos")]
|
||||
logging!(info, Type::Tray, true, "Unsubscribing from traffic updates");
|
||||
#[cfg(target_os = "macos")]
|
||||
tray::Tray::global().unsubscribe_traffic();
|
||||
|
||||
log_err!(sysopt::Sysopt::global().reset_sysproxy().await);
|
||||
log_err!(CoreManager::global().stop_core().await);
|
||||
logging_error!(
|
||||
Type::System,
|
||||
true,
|
||||
sysopt::Sysopt::global().reset_sysproxy().await
|
||||
);
|
||||
logging_error!(Type::Core, true, CoreManager::global().stop_core().await);
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
logging!(info, Type::System, true, "Restoring system DNS settings");
|
||||
restore_public_dns().await;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// create main window
|
||||
pub fn create_window() {
|
||||
println!("Starting to create window");
|
||||
log::info!(target: "app", "Starting to create window");
|
||||
pub fn create_window(is_showup: bool) {
|
||||
logging!(info, Type::Window, true, "Creating window");
|
||||
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
#[cfg(target_os = "macos")]
|
||||
AppHandleManager::global().set_activation_policy_regular();
|
||||
|
||||
if let Some(window) = handle::Handle::global().get_window() {
|
||||
println!("Found existing window, trying to show it");
|
||||
log::info!(target: "app", "Found existing window, trying to show it");
|
||||
logging!(
|
||||
info,
|
||||
Type::Window,
|
||||
true,
|
||||
"Found existing window, attempting to restore visibility"
|
||||
);
|
||||
|
||||
if window.is_minimized().unwrap_or(false) {
|
||||
println!("Window is minimized, unminimizing");
|
||||
log::info!(target: "app", "Window is minimized, unminimizing");
|
||||
logging!(
|
||||
info,
|
||||
Type::Window,
|
||||
true,
|
||||
"Window is minimized, restoring window state"
|
||||
);
|
||||
let _ = window.unminimize();
|
||||
}
|
||||
let _ = window.show();
|
||||
@ -150,8 +150,7 @@ pub fn create_window() {
|
||||
return;
|
||||
}
|
||||
|
||||
println!("Creating new window");
|
||||
log::info!(target: "app", "Creating new window");
|
||||
logging!(info, Type::Window, true, "Creating new application window");
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let window = tauri::WebviewWindowBuilder::new(
|
||||
@ -197,17 +196,46 @@ pub fn create_window() {
|
||||
|
||||
match window {
|
||||
Ok(window) => {
|
||||
println!("Window created successfully, attempting to show");
|
||||
log::info!(target: "app", "Window created successfully, attempting to show");
|
||||
logging!(info, Type::Window, true, "Window created successfully");
|
||||
if is_showup {
|
||||
println!("is showup");
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
} else {
|
||||
let _ = window.hide();
|
||||
#[cfg(target_os = "macos")]
|
||||
AppHandleManager::global().set_activation_policy_accessory();
|
||||
}
|
||||
|
||||
// 设置窗口状态监控,实时保存窗口位置和大小
|
||||
crate::feat::setup_window_state_monitor(&app_handle);
|
||||
// crate::feat::setup_window_state_monitor(&app_handle);
|
||||
|
||||
// 标记前端UI已准备就绪,向前端发送启动完成事件
|
||||
let app_handle_clone = app_handle.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
use tauri::Emitter;
|
||||
|
||||
logging!(
|
||||
info,
|
||||
Type::Window,
|
||||
true,
|
||||
"标记前端UI已准备就绪,开始处理启动错误队列"
|
||||
);
|
||||
handle::Handle::global().mark_startup_completed();
|
||||
|
||||
if let Some(window) = app_handle_clone.get_webview_window("main") {
|
||||
let _ = window.emit("verge://startup-completed", ());
|
||||
}
|
||||
});
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Failed to create window: {:?}", e);
|
||||
log::error!(target: "app", "Failed to create window: {:?}", e);
|
||||
logging!(
|
||||
error,
|
||||
Type::Window,
|
||||
true,
|
||||
"Failed to create window: {:?}",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -215,8 +243,6 @@ pub fn create_window() {
|
||||
pub async fn resolve_scheme(param: String) -> Result<()> {
|
||||
log::info!(target:"app", "received deep link: {}", param);
|
||||
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
|
||||
let param_str = if param.starts_with("[") && param.len() > 4 {
|
||||
param
|
||||
.get(2..param.len() - 2)
|
||||
@ -239,41 +265,32 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
|
||||
.find(|(key, _)| key == "name")
|
||||
.map(|(_, value)| value.into_owned());
|
||||
|
||||
let encode_url = link_parsed
|
||||
.query_pairs()
|
||||
.find(|(key, _)| key == "url")
|
||||
.map(|(_, value)| value.into_owned());
|
||||
// 通过直接获取查询部分并解析特定参数来避免 URL 转义问题
|
||||
let url_param = if let Some(query) = link_parsed.query() {
|
||||
let prefix = "url=";
|
||||
if let Some(pos) = query.find(prefix) {
|
||||
let raw_url = &query[pos + prefix.len()..];
|
||||
Some(percent_decode_str(raw_url).decode_utf8_lossy().to_string())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
match encode_url {
|
||||
match url_param {
|
||||
Some(url) => {
|
||||
let url = percent_decode_str(url.as_ref())
|
||||
.decode_utf8_lossy()
|
||||
.to_string();
|
||||
log::info!(target:"app", "decoded subscription url: {}", url);
|
||||
|
||||
create_window();
|
||||
create_window(false);
|
||||
match PrfItem::from_url(url.as_ref(), name, None, None).await {
|
||||
Ok(item) => {
|
||||
let uid = item.uid.clone().unwrap();
|
||||
let _ = wrap_err!(Config::profiles().data().append_item(item));
|
||||
handle::Handle::notice_message("import_sub_url::ok", uid);
|
||||
|
||||
app_handle
|
||||
.notification()
|
||||
.builder()
|
||||
.title("Clash Verge")
|
||||
.body("Import profile success")
|
||||
.show()
|
||||
.unwrap();
|
||||
}
|
||||
Err(e) => {
|
||||
handle::Handle::notice_message("import_sub_url::error", e.to_string());
|
||||
app_handle
|
||||
.notification()
|
||||
.builder()
|
||||
.title("Clash Verge")
|
||||
.body(format!("Import profile failed: {e}"))
|
||||
.show()
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -315,8 +332,7 @@ fn resolve_random_port_config() -> Result<()> {
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub async fn set_public_dns(dns_server: String) {
|
||||
use crate::core::handle;
|
||||
use crate::utils::dirs;
|
||||
use crate::{core::handle, utils::dirs};
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
|
||||
@ -352,8 +368,7 @@ pub async fn set_public_dns(dns_server: String) {
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub async fn restore_public_dns() {
|
||||
use crate::core::handle;
|
||||
use crate::utils::dirs;
|
||||
use crate::{core::handle, utils::dirs};
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
log::info!(target: "app", "try to unset system dns");
|
||||
|
@ -1,8 +1,11 @@
|
||||
extern crate warp;
|
||||
|
||||
use super::resolve;
|
||||
use crate::config::{Config, IVerge, DEFAULT_PAC};
|
||||
use crate::log_err;
|
||||
use crate::{
|
||||
config::{Config, IVerge, DEFAULT_PAC},
|
||||
logging_error,
|
||||
utils::logging::Type,
|
||||
};
|
||||
use anyhow::{bail, Result};
|
||||
use port_scanner::local_port_available;
|
||||
use std::convert::Infallible;
|
||||
@ -46,7 +49,7 @@ pub fn embed_server() {
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let visible = warp::path!("commands" / "visible").map(move || {
|
||||
resolve::create_window();
|
||||
resolve::create_window(false);
|
||||
"ok"
|
||||
});
|
||||
|
||||
@ -67,7 +70,11 @@ pub fn embed_server() {
|
||||
.unwrap_or_default()
|
||||
});
|
||||
async fn scheme_handler(query: QueryParam) -> Result<impl warp::Reply, Infallible> {
|
||||
log_err!(resolve::resolve_scheme(query.param).await);
|
||||
logging_error!(
|
||||
Type::Setup,
|
||||
true,
|
||||
resolve::resolve_scheme(query.param).await
|
||||
);
|
||||
Ok("ok")
|
||||
}
|
||||
|
||||
|
14
src-tauri/src_crates/crate_mihomo_api/Cargo.toml
Normal file
14
src-tauri/src_crates/crate_mihomo_api/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "mihomo_api"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
debug = []
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.12.15", features = ["json"] }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_json = "1.0.140"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.44.1", features = ["rt", "macros"] }
|
@ -1,4 +1,4 @@
|
||||
use reqwest::header::HeaderMap;
|
||||
use reqwest::{Method, header::HeaderMap};
|
||||
use serde_json::json;
|
||||
use std::{
|
||||
sync::{Arc, Mutex},
|
||||
@ -15,7 +15,7 @@ impl MihomoManager {
|
||||
proxies: serde_json::Value::Null,
|
||||
providers_proxies: serde_json::Value::Null,
|
||||
})),
|
||||
headers: headers,
|
||||
headers,
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,68 +45,77 @@ impl MihomoManager {
|
||||
|
||||
async fn send_request(
|
||||
&self,
|
||||
method: &str,
|
||||
method: Method,
|
||||
url: String,
|
||||
data: Option<serde_json::Value>,
|
||||
) -> Result<serde_json::Value, String> {
|
||||
let client_response = reqwest::ClientBuilder::new()
|
||||
.default_headers(self.headers.clone())
|
||||
.no_proxy()
|
||||
.timeout(Duration::from_secs(2))
|
||||
.timeout(Duration::from_secs(60))
|
||||
.build()
|
||||
.map_err(|e| e.to_string())?
|
||||
.request(
|
||||
match method {
|
||||
"GET" => reqwest::Method::GET,
|
||||
"PUT" => reqwest::Method::PUT,
|
||||
"POST" => reqwest::Method::POST,
|
||||
"PATCH" => reqwest::Method::PATCH,
|
||||
_ => reqwest::Method::GET,
|
||||
},
|
||||
&url,
|
||||
)
|
||||
.request(method.clone(), &url)
|
||||
.json(&data.unwrap_or(json!({})))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let response = if method != "PUT" {
|
||||
client_response.json::<serde_json::Value>().await
|
||||
let response = match method {
|
||||
Method::PATCH => {
|
||||
let status = client_response.status();
|
||||
if status.as_u16() == 204 {
|
||||
json!({"code": 204})
|
||||
} else {
|
||||
client_response.text().await.map(|text| json!(text))
|
||||
client_response
|
||||
.json::<serde_json::Value>()
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
}
|
||||
.map_err(|e| e.to_string())?;
|
||||
return Ok(response);
|
||||
}
|
||||
Method::PUT => json!(client_response.text().await.map_err(|e| e.to_string())?),
|
||||
_ => client_response
|
||||
.json::<serde_json::Value>()
|
||||
.await
|
||||
.map_err(|e| e.to_string())?,
|
||||
};
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub async fn refresh_proxies(&self) -> Result<&Self, String> {
|
||||
let url = format!("{}/proxies", self.mihomo_server);
|
||||
let proxies = self.send_request("GET", url, None).await?;
|
||||
let proxies = self.send_request(Method::GET, url, None).await?;
|
||||
self.update_proxies(proxies);
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub async fn refresh_providers_proxies(&self) -> Result<&Self, String> {
|
||||
let url = format!("{}/providers/proxies", self.mihomo_server);
|
||||
let providers_proxies = self.send_request("GET", url, None).await?;
|
||||
let providers_proxies = self.send_request(Method::GET, url, None).await?;
|
||||
self.update_providers_proxies(providers_proxies);
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl MihomoManager {
|
||||
pub async fn is_mihomo_running(&self) -> Result<(), String> {
|
||||
let url = format!("{}/version", self.mihomo_server);
|
||||
let _response = self.send_request(Method::GET, url, None).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn put_configs_force(&self, clash_config_path: &str) -> Result<(), String> {
|
||||
let url = format!("{}/configs?force=true", self.mihomo_server);
|
||||
let payload = serde_json::json!({
|
||||
"path": clash_config_path,
|
||||
});
|
||||
let _response = self.send_request("PUT", url, Some(payload)).await?;
|
||||
let _response = self.send_request(Method::PUT, url, Some(payload)).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn patch_configs(&self, config: serde_json::Value) -> Result<(), String> {
|
||||
let url = format!("{}/configs", self.mihomo_server);
|
||||
let response = self.send_request("PATCH", url, Some(config)).await?;
|
||||
let response = self.send_request(Method::PATCH, url, Some(config)).await?;
|
||||
if response["code"] == 204 {
|
||||
Ok(())
|
||||
} else {
|
||||
@ -128,7 +137,26 @@ impl MihomoManager {
|
||||
"{}/proxies/{}/delay?url={}&timeout={}",
|
||||
self.mihomo_server, name, test_url, timeout
|
||||
);
|
||||
let response = self.send_request("GET", url, None).await?;
|
||||
return Ok(response);
|
||||
let response = self.send_request(Method::GET, url, None).await?;
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub async fn get_connections(&self) -> Result<serde_json::Value, String> {
|
||||
let url = format!("{}/connections", self.mihomo_server);
|
||||
let response = self.send_request(Method::GET, url, None).await?;
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub async fn delete_connection(&self, id: &str) -> Result<(), String> {
|
||||
let url = format!("{}/connections/{}", self.mihomo_server, id);
|
||||
let response = self.send_request(Method::DELETE, url, None).await?;
|
||||
if response["code"] == 204 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(response["message"]
|
||||
.as_str()
|
||||
.unwrap_or("unknown error")
|
||||
.to_string())
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "2.1.3-alpha",
|
||||
"version": "2.2.3",
|
||||
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
||||
"bundle": {
|
||||
"active": true,
|
||||
@ -11,9 +11,15 @@
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"resources": ["resources", "resources/locales/*"],
|
||||
"resources": [
|
||||
"resources",
|
||||
"resources/locales/*"
|
||||
],
|
||||
"publisher": "Clash Verge Rev",
|
||||
"externalBin": ["sidecar/verge-mihomo", "sidecar/verge-mihomo-alpha"],
|
||||
"externalBin": [
|
||||
"sidecar/verge-mihomo",
|
||||
"sidecar/verge-mihomo-alpha"
|
||||
],
|
||||
"copyright": "GNU General Public License v3.0",
|
||||
"category": "DeveloperTool",
|
||||
"shortDescription": "Clash Verge Rev",
|
||||
@ -32,7 +38,11 @@
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEQyOEMyRjBCQkVGOUJEREYKUldUZnZmbStDeStNMHU5Mmo1N24xQXZwSVRYbXA2NUpzZE5oVzlqeS9Bc0t6RVV4MmtwVjBZaHgK",
|
||||
"endpoints": [
|
||||
"https://download.clashverge.dev/https://github.com/clash-verge-rev/clash-verge-rev/releases/download/updater/update-proxy.json",
|
||||
"https://github.com/clash-verge-rev/clash-verge-rev/releases/download/updater/update.json"
|
||||
"https://gh-proxy.com/https://github.com/clash-verge-rev/clash-verge-rev/releases/download/updater/update-proxy.json",
|
||||
"https://github.com/clash-verge-rev/clash-verge-rev/releases/download/updater/update.json",
|
||||
"https://download.clashverge.dev/https://github.com/clash-verge-rev/clash-verge-rev/releases/download/updater-alpha/update-alpha-proxy.json",
|
||||
"https://gh-proxy.com/https://github.com/clash-verge-rev/clash-verge-rev/releases/download/updater-alpha/update-alpha-proxy.json",
|
||||
"https://github.com/clash-verge-rev/clash-verge-rev/releases/download/updater-alpha/update-alpha.json"
|
||||
],
|
||||
"windows": {
|
||||
"installMode": "basicUi"
|
||||
@ -40,15 +50,25 @@
|
||||
},
|
||||
"deep-link": {
|
||||
"desktop": {
|
||||
"schemes": ["clash", "clash-verge"]
|
||||
"schemes": [
|
||||
"clash",
|
||||
"clash-verge"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
"security": {
|
||||
"capabilities": ["desktop-capability", "migrated"],
|
||||
"capabilities": [
|
||||
"desktop-capability",
|
||||
"migrated"
|
||||
],
|
||||
"assetProtocol": {
|
||||
"scope": ["$APPDATA/**", "$RESOURCE/../**", "**"],
|
||||
"scope": [
|
||||
"$APPDATA/**",
|
||||
"$RESOURCE/../**",
|
||||
"**"
|
||||
],
|
||||
"enable": true
|
||||
},
|
||||
"csp": null
|
||||
|
@ -30,10 +30,5 @@
|
||||
"./sidecar/verge-mihomo",
|
||||
"./sidecar/verge-mihomo-alpha"
|
||||
]
|
||||
},
|
||||
"app": {
|
||||
"trayIcon": {
|
||||
"iconPath": "icons/tray-icon.ico"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,5 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
"trayIcon": {
|
||||
"iconPath": "icons/tray-icon-mono.ico",
|
||||
"iconAsTemplate": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,6 @@
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
"trayIcon": {
|
||||
"iconPath": "icons/tray-icon.ico",
|
||||
"iconAsTemplate": true,
|
||||
"showMenuOnLeftClick": false
|
||||
},
|
||||
"windows": []
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,5 @@
|
||||
],
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEQyOEMyRjBCQkVGOUJEREYKUldUZnZmbStDeStNMHU5Mmo1N24xQXZwSVRYbXA2NUpzZE5oVzlqeS9Bc0t6RVV4MmtwVjBZaHgK"
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
"trayIcon": {
|
||||
"iconPath": "icons/tray-icon.ico",
|
||||
"iconAsTemplate": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,5 @@
|
||||
],
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEQyOEMyRjBCQkVGOUJEREYKUldUZnZmbStDeStNMHU5Mmo1N24xQXZwSVRYbXA2NUpzZE5oVzlqeS9Bc0t6RVV4MmtwVjBZaHgK"
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
"trayIcon": {
|
||||
"iconPath": "icons/tray-icon.ico",
|
||||
"iconAsTemplate": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,5 @@
|
||||
],
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEQyOEMyRjBCQkVGOUJEREYKUldUZnZmbStDeStNMHU5Mmo1N24xQXZwSVRYbXA2NUpzZE5oVzlqeS9Bc0t6RVV4MmtwVjBZaHgK"
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
"trayIcon": {
|
||||
"iconPath": "icons/tray-icon.ico",
|
||||
"iconAsTemplate": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
src/App.tsx
Normal file
13
src/App.tsx
Normal file
@ -0,0 +1,13 @@
|
||||
import { AppDataProvider } from "./providers/app-data-provider";
|
||||
import React from "react";
|
||||
import Layout from "./pages/_layout";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<AppDataProvider>
|
||||
<Layout />
|
||||
</AppDataProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
11
src/assets/image/itemicon/home.svg
Normal file
11
src/assets/image/itemicon/home.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 48 KiB |
10
src/assets/image/itemicon/unlock.svg
Normal file
10
src/assets/image/itemicon/unlock.svg
Normal file
@ -0,0 +1,10 @@
|
||||
<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="36" height="36" rx="18" fill="url(#paint0_linear_3004_316)"/>
|
||||
<path d="M23 14.6666H22.1667V13C22.1667 10.7 20.3 8.83331 18 8.83331C15.7 8.83331 13.8334 10.7 13.8334 13H15.5C15.5 11.6166 16.6167 10.5 18 10.5C19.3834 10.5 20.5 11.6166 20.5 13V14.6666H13C12.0834 14.6666 11.3334 15.4166 11.3334 16.3333V24.6666C11.3334 25.5833 12.0834 26.3333 13 26.3333H23C23.9167 26.3333 24.6667 25.5833 24.6667 24.6666V16.3333C24.6667 15.4166 23.9167 14.6666 23 14.6666ZM23 24.6666H13V16.3333H23V24.6666ZM18 22.1666C18.9167 22.1666 19.6667 21.4166 19.6667 20.5C19.6667 19.5833 18.9167 18.8333 18 18.8333C17.0834 18.8333 16.3334 19.5833 16.3334 20.5C16.3334 21.4166 17.0834 22.1666 18 22.1666Z" fill="white"/>
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_3004_316" x1="31" y1="27.5" x2="6.5" y2="7" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#FFA800"/>
|
||||
<stop offset="1" stop-color="#FFAC4B"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
After Width: | Height: | Size: 1020 B |
21
src/components/center.tsx
Normal file
21
src/components/center.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
import { Box, BoxProps } from "@mui/material";
|
||||
import React from "react";
|
||||
|
||||
interface CenterProps extends BoxProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export const Center: React.FC<CenterProps> = ({ children, ...props }) => {
|
||||
return (
|
||||
<Box
|
||||
display="flex"
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
width="100%"
|
||||
height="100%"
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Box>
|
||||
);
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
import dayjs from "dayjs";
|
||||
import { forwardRef, useImperativeHandle, useState } from "react";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { Box, Button, Snackbar } from "@mui/material";
|
||||
import { Box, Button, Snackbar, useTheme } from "@mui/material";
|
||||
import { deleteConnection } from "@/services/api";
|
||||
import parseTraffic from "@/utils/parse-traffic";
|
||||
import { t } from "i18next";
|
||||
@ -14,6 +14,7 @@ export const ConnectionDetail = forwardRef<ConnectionDetailRef>(
|
||||
(props, ref) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [detail, setDetail] = useState<IConnectionsItem>(null!);
|
||||
const theme = useTheme();
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
open: (detail: IConnectionsItem) => {
|
||||
@ -35,6 +36,8 @@ export const ConnectionDetail = forwardRef<ConnectionDetailRef>(
|
||||
maxWidth: "520px",
|
||||
maxHeight: "480px",
|
||||
overflowY: "auto",
|
||||
backgroundColor: theme.palette.background.paper,
|
||||
color: theme.palette.text.primary,
|
||||
},
|
||||
}}
|
||||
message={
|
||||
@ -54,6 +57,7 @@ interface InnerProps {
|
||||
|
||||
const InnerConnectionDetail = ({ data, onClose }: InnerProps) => {
|
||||
const { metadata, rulePayload } = data;
|
||||
const theme = useTheme();
|
||||
const chains = [...data.chains].reverse().join(" / ");
|
||||
const rule = rulePayload ? `${data.rule}(${rulePayload})` : data.rule;
|
||||
const host = metadata.host
|
||||
@ -99,11 +103,11 @@ const InnerConnectionDetail = ({ data, onClose }: InnerProps) => {
|
||||
const onDelete = useLockFn(async () => deleteConnection(data.id));
|
||||
|
||||
return (
|
||||
<Box sx={{ userSelect: "text" }}>
|
||||
<Box sx={{ userSelect: "text", color: theme.palette.text.secondary }}>
|
||||
{information.map((each) => (
|
||||
<div key={each.label}>
|
||||
<b>{each.label}</b>
|
||||
<span style={{ wordBreak: "break-all" }}>: {each.value}</span>
|
||||
<span style={{ wordBreak: "break-all", color: theme.palette.text.primary }}>: {each.value}</span>
|
||||
</div>
|
||||
))}
|
||||
|
||||
|
89
src/components/home/clash-info-card.tsx
Normal file
89
src/components/home/clash-info-card.tsx
Normal file
@ -0,0 +1,89 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Typography, Stack, Divider } from "@mui/material";
|
||||
import { DeveloperBoardOutlined } from "@mui/icons-material";
|
||||
import { useClash } from "@/hooks/use-clash";
|
||||
import { EnhancedCard } from "./enhanced-card";
|
||||
import { useMemo } from "react";
|
||||
import { useAppData } from "@/providers/app-data-provider";
|
||||
|
||||
// 将毫秒转换为时:分:秒格式的函数
|
||||
const formatUptime = (uptimeMs: number) => {
|
||||
const hours = Math.floor(uptimeMs / 3600000);
|
||||
const minutes = Math.floor((uptimeMs % 3600000) / 60000);
|
||||
const seconds = Math.floor((uptimeMs % 60000) / 1000);
|
||||
return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
||||
};
|
||||
|
||||
export const ClashInfoCard = () => {
|
||||
const { t } = useTranslation();
|
||||
const { version: clashVersion } = useClash();
|
||||
const { clashConfig, sysproxy, rules, uptime } = useAppData();
|
||||
|
||||
// 使用useMemo缓存格式化后的uptime,避免频繁计算
|
||||
const formattedUptime = useMemo(() => formatUptime(uptime), [uptime]);
|
||||
|
||||
// 使用备忘录组件内容,减少重新渲染
|
||||
const cardContent = useMemo(() => {
|
||||
if (!clashConfig) return null;
|
||||
|
||||
return (
|
||||
<Stack spacing={1.5}>
|
||||
<Stack direction="row" justifyContent="space-between">
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t("Core Version")}
|
||||
</Typography>
|
||||
<Typography variant="body2" fontWeight="medium">
|
||||
{clashVersion || "-"}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Divider />
|
||||
<Stack direction="row" justifyContent="space-between">
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t("System Proxy Address")}
|
||||
</Typography>
|
||||
<Typography variant="body2" fontWeight="medium">
|
||||
{sysproxy?.server || "-"}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Divider />
|
||||
<Stack direction="row" justifyContent="space-between">
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t("Mixed Port")}
|
||||
</Typography>
|
||||
<Typography variant="body2" fontWeight="medium">
|
||||
{clashConfig["mixed-port"] || "-"}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Divider />
|
||||
<Stack direction="row" justifyContent="space-between">
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t("Uptime")}
|
||||
</Typography>
|
||||
<Typography variant="body2" fontWeight="medium">
|
||||
{formattedUptime}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Divider />
|
||||
<Stack direction="row" justifyContent="space-between">
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t("Rules Count")}
|
||||
</Typography>
|
||||
<Typography variant="body2" fontWeight="medium">
|
||||
{rules.length}
|
||||
</Typography>
|
||||
</Stack>
|
||||
</Stack>
|
||||
);
|
||||
}, [clashConfig, clashVersion, t, formattedUptime, rules.length, sysproxy]);
|
||||
|
||||
return (
|
||||
<EnhancedCard
|
||||
title={t("Clash Info")}
|
||||
icon={<DeveloperBoardOutlined />}
|
||||
iconColor="warning"
|
||||
action={null}
|
||||
>
|
||||
{cardContent}
|
||||
</EnhancedCard>
|
||||
);
|
||||
};
|
156
src/components/home/clash-mode-card.tsx
Normal file
156
src/components/home/clash-mode-card.tsx
Normal file
@ -0,0 +1,156 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Box, Typography, Paper, Stack, Fade } from "@mui/material";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { closeAllConnections } from "@/services/api";
|
||||
import { patchClashMode } from "@/services/cmds";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import {
|
||||
LanguageRounded,
|
||||
MultipleStopRounded,
|
||||
DirectionsRounded,
|
||||
} from "@mui/icons-material";
|
||||
import { useMemo } from "react";
|
||||
import { useAppData } from "@/providers/app-data-provider";
|
||||
|
||||
export const ClashModeCard = () => {
|
||||
const { t } = useTranslation();
|
||||
const { verge } = useVerge();
|
||||
const { clashConfig, refreshProxy } = useAppData();
|
||||
|
||||
// 支持的模式列表
|
||||
const modeList = useMemo(() => ["rule", "global", "direct"] as const, []);
|
||||
|
||||
// 直接使用API返回的模式,不维护本地状态
|
||||
const currentMode = clashConfig?.mode?.toLowerCase();
|
||||
|
||||
// 模式图标映射
|
||||
const modeIcons = useMemo(() => ({
|
||||
rule: <MultipleStopRounded fontSize="small" />,
|
||||
global: <LanguageRounded fontSize="small" />,
|
||||
direct: <DirectionsRounded fontSize="small" />
|
||||
}), []);
|
||||
|
||||
// 切换模式的处理函数
|
||||
const onChangeMode = useLockFn(async (mode: string) => {
|
||||
if (mode === currentMode) return;
|
||||
if (verge?.auto_close_connection) {
|
||||
closeAllConnections();
|
||||
}
|
||||
|
||||
try {
|
||||
await patchClashMode(mode);
|
||||
// 使用共享的刷新方法
|
||||
refreshProxy();
|
||||
} catch (error) {
|
||||
console.error("Failed to change mode:", error);
|
||||
}
|
||||
});
|
||||
|
||||
// 按钮样式
|
||||
const buttonStyles = (mode: string) => ({
|
||||
cursor: "pointer",
|
||||
px: 2,
|
||||
py: 1.2,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
gap: 1,
|
||||
bgcolor: mode === currentMode ? "primary.main" : "background.paper",
|
||||
color: mode === currentMode ? "primary.contrastText" : "text.primary",
|
||||
borderRadius: 1.5,
|
||||
transition: "all 0.2s ease-in-out",
|
||||
position: "relative",
|
||||
overflow: "visible",
|
||||
"&:hover": {
|
||||
transform: "translateY(-1px)",
|
||||
boxShadow: 1,
|
||||
},
|
||||
"&:active": {
|
||||
transform: "translateY(1px)",
|
||||
},
|
||||
"&::after": mode === currentMode
|
||||
? {
|
||||
content: '""',
|
||||
position: "absolute",
|
||||
bottom: -16,
|
||||
left: "50%",
|
||||
width: 2,
|
||||
height: 16,
|
||||
bgcolor: "primary.main",
|
||||
transform: "translateX(-50%)",
|
||||
}
|
||||
: {},
|
||||
});
|
||||
|
||||
// 描述样式
|
||||
const descriptionStyles = {
|
||||
width: "95%",
|
||||
textAlign: "center",
|
||||
color: "text.secondary",
|
||||
p: 0.8,
|
||||
borderRadius: 1,
|
||||
borderColor: "primary.main",
|
||||
borderWidth: 1,
|
||||
borderStyle: "solid",
|
||||
backgroundColor: "background.paper",
|
||||
wordBreak: "break-word",
|
||||
hyphens: "auto",
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ display: "flex", flexDirection: "column", width: "100%" }}>
|
||||
{/* 模式选择按钮组 */}
|
||||
<Stack
|
||||
direction="row"
|
||||
spacing={1}
|
||||
sx={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
py: 1,
|
||||
position: "relative",
|
||||
zIndex: 2,
|
||||
}}
|
||||
>
|
||||
{modeList.map((mode) => (
|
||||
<Paper
|
||||
key={mode}
|
||||
elevation={mode === currentMode ? 2 : 0}
|
||||
onClick={() => onChangeMode(mode)}
|
||||
sx={buttonStyles(mode)}
|
||||
>
|
||||
{modeIcons[mode]}
|
||||
<Typography
|
||||
variant="body2"
|
||||
sx={{
|
||||
textTransform: "capitalize",
|
||||
fontWeight: mode === currentMode ? 600 : 400,
|
||||
}}
|
||||
>
|
||||
{t(mode)}
|
||||
</Typography>
|
||||
</Paper>
|
||||
))}
|
||||
</Stack>
|
||||
|
||||
{/* 说明文本区域 */}
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
my: 1,
|
||||
position: "relative",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
overflow: "visible",
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
variant="caption"
|
||||
component="div"
|
||||
sx={descriptionStyles}
|
||||
>
|
||||
{t(`${currentMode} Mode Description`)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
615
src/components/home/current-proxy-card.tsx
Normal file
615
src/components/home/current-proxy-card.tsx
Normal file
@ -0,0 +1,615 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Box,
|
||||
Typography,
|
||||
Chip,
|
||||
Button,
|
||||
alpha,
|
||||
useTheme,
|
||||
Select,
|
||||
MenuItem,
|
||||
FormControl,
|
||||
InputLabel,
|
||||
SelectChangeEvent,
|
||||
Tooltip,
|
||||
} from "@mui/material";
|
||||
import { useEffect, useState, useMemo, useCallback } from "react";
|
||||
import {
|
||||
SignalWifi4Bar as SignalStrong,
|
||||
SignalWifi3Bar as SignalGood,
|
||||
SignalWifi2Bar as SignalMedium,
|
||||
SignalWifi1Bar as SignalWeak,
|
||||
SignalWifi0Bar as SignalNone,
|
||||
WifiOff as SignalError,
|
||||
ChevronRight,
|
||||
} from "@mui/icons-material";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { EnhancedCard } from "@/components/home/enhanced-card";
|
||||
import { updateProxy, deleteConnection } from "@/services/api";
|
||||
import delayManager from "@/services/delay";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import { useAppData } from "@/providers/app-data-provider";
|
||||
|
||||
// 本地存储的键名
|
||||
const STORAGE_KEY_GROUP = "clash-verge-selected-proxy-group";
|
||||
const STORAGE_KEY_PROXY = "clash-verge-selected-proxy";
|
||||
|
||||
// 代理节点信息接口
|
||||
interface ProxyOption {
|
||||
name: string;
|
||||
}
|
||||
|
||||
// 将delayManager返回的颜色格式转换为MUI Chip组件需要的格式
|
||||
function convertDelayColor(delayValue: number) {
|
||||
const colorStr = delayManager.formatDelayColor(delayValue);
|
||||
if (!colorStr) return "default";
|
||||
|
||||
// 从"error.main"这样的格式转为"error"
|
||||
const mainColor = colorStr.split(".")[0];
|
||||
|
||||
switch (mainColor) {
|
||||
case "success":
|
||||
return "success";
|
||||
case "warning":
|
||||
return "warning";
|
||||
case "error":
|
||||
return "error";
|
||||
case "primary":
|
||||
return "primary";
|
||||
default:
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
|
||||
// 根据延迟值获取合适的WiFi信号图标
|
||||
function getSignalIcon(delay: number) {
|
||||
if (delay < 0)
|
||||
return { icon: <SignalNone />, text: "未测试", color: "text.secondary" };
|
||||
if (delay >= 10000)
|
||||
return { icon: <SignalError />, text: "超时", color: "error.main" };
|
||||
if (delay >= 500)
|
||||
return { icon: <SignalWeak />, text: "延迟较高", color: "error.main" };
|
||||
if (delay >= 300)
|
||||
return { icon: <SignalMedium />, text: "延迟中等", color: "warning.main" };
|
||||
if (delay >= 200)
|
||||
return { icon: <SignalGood />, text: "延迟良好", color: "info.main" };
|
||||
return { icon: <SignalStrong />, text: "延迟极佳", color: "success.main" };
|
||||
}
|
||||
|
||||
// 简单的防抖函数
|
||||
function debounce(fn: Function, ms = 100) {
|
||||
let timeoutId: ReturnType<typeof setTimeout>;
|
||||
return function (this: any, ...args: any[]) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), ms);
|
||||
};
|
||||
}
|
||||
|
||||
export const CurrentProxyCard = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const theme = useTheme();
|
||||
const { verge } = useVerge();
|
||||
const { proxies, connections, clashConfig, refreshProxy } = useAppData();
|
||||
|
||||
// 判断模式
|
||||
const mode = clashConfig?.mode?.toLowerCase() || "rule";
|
||||
const isGlobalMode = mode === "global";
|
||||
const isDirectMode = mode === "direct";
|
||||
|
||||
// 定义状态类型
|
||||
type ProxyState = {
|
||||
proxyData: {
|
||||
groups: { name: string; now: string; all: string[] }[];
|
||||
records: Record<string, any>;
|
||||
globalProxy: string;
|
||||
directProxy: any;
|
||||
};
|
||||
selection: {
|
||||
group: string;
|
||||
proxy: string;
|
||||
};
|
||||
displayProxy: any;
|
||||
};
|
||||
|
||||
// 合并状态,减少状态更新次数
|
||||
const [state, setState] = useState<ProxyState>({
|
||||
proxyData: {
|
||||
groups: [],
|
||||
records: {},
|
||||
globalProxy: "",
|
||||
directProxy: null,
|
||||
},
|
||||
selection: {
|
||||
group: "",
|
||||
proxy: "",
|
||||
},
|
||||
displayProxy: null,
|
||||
});
|
||||
|
||||
// 初始化选择的组
|
||||
useEffect(() => {
|
||||
if (!proxies) return;
|
||||
|
||||
// 提取primaryGroupName
|
||||
const getPrimaryGroupName = () => {
|
||||
if (!proxies?.groups?.length) return "";
|
||||
|
||||
// 查找主要的代理组(优先级:包含关键词 > 第一个非GLOBAL组)
|
||||
const primaryKeywords = [
|
||||
"auto",
|
||||
"select",
|
||||
"proxy",
|
||||
"节点选择",
|
||||
"自动选择",
|
||||
];
|
||||
const primaryGroup =
|
||||
proxies.groups.find((group: { name: string }) =>
|
||||
primaryKeywords.some((keyword) =>
|
||||
group.name.toLowerCase().includes(keyword.toLowerCase()),
|
||||
),
|
||||
) || proxies.groups.filter((g: { name: string }) => g.name !== "GLOBAL")[0];
|
||||
|
||||
return primaryGroup?.name || "";
|
||||
};
|
||||
|
||||
const primaryGroupName = getPrimaryGroupName();
|
||||
|
||||
// 根据模式确定初始组
|
||||
if (isGlobalMode) {
|
||||
setState((prev) => ({
|
||||
...prev,
|
||||
selection: {
|
||||
...prev.selection,
|
||||
group: "GLOBAL",
|
||||
},
|
||||
}));
|
||||
} else if (isDirectMode) {
|
||||
setState((prev) => ({
|
||||
...prev,
|
||||
selection: {
|
||||
...prev.selection,
|
||||
group: "DIRECT",
|
||||
},
|
||||
}));
|
||||
} else {
|
||||
const savedGroup = localStorage.getItem(STORAGE_KEY_GROUP);
|
||||
setState((prev) => ({
|
||||
...prev,
|
||||
selection: {
|
||||
...prev.selection,
|
||||
group: savedGroup || primaryGroupName || "",
|
||||
},
|
||||
}));
|
||||
}
|
||||
}, [isGlobalMode, isDirectMode, proxies]);
|
||||
|
||||
// 监听代理数据变化,更新状态
|
||||
useEffect(() => {
|
||||
if (!proxies) return;
|
||||
|
||||
// 使用函数式更新确保状态更新的原子性
|
||||
setState((prev) => {
|
||||
// 过滤和格式化组
|
||||
const filteredGroups = proxies.groups
|
||||
.filter((g: { name: string }) => g.name !== "DIRECT" && g.name !== "REJECT")
|
||||
.map((g: { name: string; now: string; all: Array<{ name: string }> }) => ({
|
||||
name: g.name,
|
||||
now: g.now || "",
|
||||
all: g.all.map((p: { name: string }) => p.name),
|
||||
}));
|
||||
|
||||
let newProxy = "";
|
||||
let newDisplayProxy = null;
|
||||
let newGroup = prev.selection.group;
|
||||
|
||||
// 根据模式确定新代理
|
||||
if (isDirectMode) {
|
||||
newGroup = "DIRECT";
|
||||
newProxy = "DIRECT";
|
||||
newDisplayProxy = proxies.records?.DIRECT || null;
|
||||
} else if (isGlobalMode && proxies.global) {
|
||||
newGroup = "GLOBAL";
|
||||
newProxy = proxies.global.now || "";
|
||||
newDisplayProxy = proxies.records?.[newProxy] || null;
|
||||
} else {
|
||||
// 普通模式 - 检查当前选择的组是否存在
|
||||
const currentGroup = filteredGroups.find(
|
||||
(g: { name: string }) => g.name === prev.selection.group,
|
||||
);
|
||||
|
||||
// 如果当前组不存在或为空,自动选择第一个组
|
||||
if (!currentGroup && filteredGroups.length > 0) {
|
||||
newGroup = filteredGroups[0].name;
|
||||
const firstGroup = filteredGroups[0];
|
||||
newProxy = firstGroup.now;
|
||||
newDisplayProxy = proxies.records?.[newProxy] || null;
|
||||
|
||||
// 保存到本地存储
|
||||
if (!isGlobalMode && !isDirectMode) {
|
||||
localStorage.setItem(STORAGE_KEY_GROUP, newGroup);
|
||||
if (newProxy) {
|
||||
localStorage.setItem(STORAGE_KEY_PROXY, newProxy);
|
||||
}
|
||||
}
|
||||
} else if (currentGroup) {
|
||||
// 使用当前组的代理
|
||||
newProxy = currentGroup.now;
|
||||
newDisplayProxy = proxies.records?.[newProxy] || null;
|
||||
}
|
||||
}
|
||||
|
||||
// 返回新状态
|
||||
return {
|
||||
proxyData: {
|
||||
groups: filteredGroups,
|
||||
records: proxies.records || {},
|
||||
globalProxy: proxies.global?.now || "",
|
||||
directProxy: proxies.records?.DIRECT || null,
|
||||
},
|
||||
selection: {
|
||||
group: newGroup,
|
||||
proxy: newProxy,
|
||||
},
|
||||
displayProxy: newDisplayProxy,
|
||||
};
|
||||
});
|
||||
}, [proxies, isGlobalMode, isDirectMode]);
|
||||
|
||||
// 使用防抖包装状态更新,避免快速连续更新,增加防抖时间
|
||||
const debouncedSetState = useCallback(
|
||||
debounce((updateFn: (prev: ProxyState) => ProxyState) => {
|
||||
setState(updateFn);
|
||||
}, 300),
|
||||
[],
|
||||
);
|
||||
|
||||
// 处理代理组变更
|
||||
const handleGroupChange = useCallback(
|
||||
(event: SelectChangeEvent) => {
|
||||
if (isGlobalMode || isDirectMode) return;
|
||||
|
||||
const newGroup = event.target.value;
|
||||
|
||||
// 保存到本地存储
|
||||
localStorage.setItem(STORAGE_KEY_GROUP, newGroup);
|
||||
|
||||
// 获取该组当前选中的代理
|
||||
setState((prev) => {
|
||||
const group = prev.proxyData.groups.find((g: { name: string }) => g.name === newGroup);
|
||||
if (group) {
|
||||
return {
|
||||
...prev,
|
||||
selection: {
|
||||
group: newGroup,
|
||||
proxy: group.now,
|
||||
},
|
||||
displayProxy: prev.proxyData.records[group.now] || null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
...prev,
|
||||
selection: {
|
||||
...prev.selection,
|
||||
group: newGroup,
|
||||
},
|
||||
};
|
||||
});
|
||||
},
|
||||
[isGlobalMode, isDirectMode],
|
||||
);
|
||||
|
||||
// 处理代理节点变更
|
||||
const handleProxyChange = useCallback(
|
||||
async (event: SelectChangeEvent) => {
|
||||
if (isDirectMode) return;
|
||||
|
||||
const newProxy = event.target.value;
|
||||
const currentGroup = state.selection.group;
|
||||
const previousProxy = state.selection.proxy;
|
||||
|
||||
// 立即更新UI,优化体验
|
||||
debouncedSetState((prev: ProxyState) => ({
|
||||
...prev,
|
||||
selection: {
|
||||
...prev.selection,
|
||||
proxy: newProxy,
|
||||
},
|
||||
displayProxy: prev.proxyData.records[newProxy] || null,
|
||||
}));
|
||||
|
||||
// 非特殊模式下保存到本地存储
|
||||
if (!isGlobalMode && !isDirectMode) {
|
||||
localStorage.setItem(STORAGE_KEY_PROXY, newProxy);
|
||||
}
|
||||
|
||||
try {
|
||||
// 更新代理设置
|
||||
await updateProxy(currentGroup, newProxy);
|
||||
|
||||
// 自动关闭连接设置
|
||||
if (verge?.auto_close_connection && previousProxy) {
|
||||
connections.data.forEach((conn: any) => {
|
||||
if (conn.chains.includes(previousProxy)) {
|
||||
deleteConnection(conn.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 延长刷新延迟时间
|
||||
setTimeout(() => {
|
||||
refreshProxy();
|
||||
}, 500);
|
||||
} catch (error) {
|
||||
console.error("更新代理失败", error);
|
||||
}
|
||||
},
|
||||
[
|
||||
isDirectMode,
|
||||
isGlobalMode,
|
||||
state.proxyData.records,
|
||||
state.selection,
|
||||
verge?.auto_close_connection,
|
||||
refreshProxy,
|
||||
debouncedSetState,
|
||||
connections.data,
|
||||
],
|
||||
);
|
||||
|
||||
// 导航到代理页面
|
||||
const goToProxies = useCallback(() => {
|
||||
navigate("/");
|
||||
}, [navigate]);
|
||||
|
||||
// 获取要显示的代理节点
|
||||
const currentProxy = useMemo(() => {
|
||||
// 从state中获取当前代理信息
|
||||
return state.displayProxy;
|
||||
}, [state.displayProxy]);
|
||||
|
||||
// 获取当前节点的延迟
|
||||
const currentDelay = currentProxy
|
||||
? delayManager.getDelayFix(currentProxy, state.selection.group)
|
||||
: -1;
|
||||
|
||||
// 获取信号图标
|
||||
const signalInfo = getSignalIcon(currentDelay);
|
||||
|
||||
// 自定义渲染选择框中的值
|
||||
const renderProxyValue = useCallback(
|
||||
(selected: string) => {
|
||||
if (!selected || !state.proxyData.records[selected]) return selected;
|
||||
|
||||
const delayValue = delayManager.getDelayFix(
|
||||
state.proxyData.records[selected],
|
||||
state.selection.group,
|
||||
);
|
||||
|
||||
return (
|
||||
<Box sx={{ display: "flex", justifyContent: "space-between" }}>
|
||||
<Typography noWrap>{selected}</Typography>
|
||||
<Chip
|
||||
size="small"
|
||||
label={delayManager.formatDelay(delayValue)}
|
||||
color={convertDelayColor(delayValue)}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
},
|
||||
[state.proxyData.records, state.selection.group],
|
||||
);
|
||||
|
||||
// 计算要显示的代理选项 - 使用 useMemo 优化
|
||||
const proxyOptions = useMemo(() => {
|
||||
if (isDirectMode) {
|
||||
return [{ name: "DIRECT" }];
|
||||
}
|
||||
if (isGlobalMode && state.proxyData.records) {
|
||||
// 全局模式下的选项
|
||||
return Object.keys(state.proxyData.records)
|
||||
.filter((name) => name !== "DIRECT" && name !== "REJECT")
|
||||
.map((name) => ({ name }));
|
||||
}
|
||||
|
||||
// 普通模式
|
||||
const group = state.proxyData.groups.find(
|
||||
(g: { name: string }) => g.name === state.selection.group,
|
||||
);
|
||||
if (group) {
|
||||
return group.all.map((name) => ({ name }));
|
||||
}
|
||||
return [];
|
||||
}, [isDirectMode, isGlobalMode, state.proxyData, state.selection.group]);
|
||||
|
||||
return (
|
||||
<EnhancedCard
|
||||
title={t("Current Node")}
|
||||
icon={
|
||||
<Tooltip
|
||||
title={
|
||||
currentProxy
|
||||
? `${signalInfo.text}: ${delayManager.formatDelay(currentDelay)}`
|
||||
: "无代理节点"
|
||||
}
|
||||
>
|
||||
<Box sx={{ color: signalInfo.color }}>
|
||||
{currentProxy ? signalInfo.icon : <SignalNone color="disabled" />}
|
||||
</Box>
|
||||
</Tooltip>
|
||||
}
|
||||
iconColor={currentProxy ? "primary" : undefined}
|
||||
action={
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="small"
|
||||
onClick={goToProxies}
|
||||
sx={{ borderRadius: 1.5 }}
|
||||
endIcon={<ChevronRight fontSize="small" />}
|
||||
>
|
||||
{t("Label-Proxies")}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{currentProxy ? (
|
||||
<Box>
|
||||
{/* 代理节点信息显示 */}
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
p: 1,
|
||||
mb: 2,
|
||||
borderRadius: 1,
|
||||
bgcolor: alpha(theme.palette.primary.main, 0.05),
|
||||
border: `1px solid ${alpha(theme.palette.primary.main, 0.1)}`,
|
||||
}}
|
||||
>
|
||||
<Box>
|
||||
<Typography variant="body1" fontWeight="medium">
|
||||
{currentProxy.name}
|
||||
</Typography>
|
||||
|
||||
<Box
|
||||
sx={{ display: "flex", alignItems: "center", flexWrap: "wrap" }}
|
||||
>
|
||||
<Typography
|
||||
variant="caption"
|
||||
color="text.secondary"
|
||||
sx={{ mr: 1 }}
|
||||
>
|
||||
{currentProxy.type}
|
||||
</Typography>
|
||||
{isGlobalMode && (
|
||||
<Chip
|
||||
size="small"
|
||||
label={t("Global Mode")}
|
||||
color="primary"
|
||||
sx={{ mr: 0.5 }}
|
||||
/>
|
||||
)}
|
||||
{isDirectMode && (
|
||||
<Chip
|
||||
size="small"
|
||||
label={t("Direct Mode")}
|
||||
color="success"
|
||||
sx={{ mr: 0.5 }}
|
||||
/>
|
||||
)}
|
||||
{/* 节点特性 */}
|
||||
{currentProxy.udp && (
|
||||
<Chip size="small" label="UDP" variant="outlined" />
|
||||
)}
|
||||
{currentProxy.tfo && (
|
||||
<Chip size="small" label="TFO" variant="outlined" />
|
||||
)}
|
||||
{currentProxy.xudp && (
|
||||
<Chip size="small" label="XUDP" variant="outlined" />
|
||||
)}
|
||||
{currentProxy.mptcp && (
|
||||
<Chip size="small" label="MPTCP" variant="outlined" />
|
||||
)}
|
||||
{currentProxy.smux && (
|
||||
<Chip size="small" label="SMUX" variant="outlined" />
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
{/* 显示延迟 */}
|
||||
{currentProxy && !isDirectMode && (
|
||||
<Chip
|
||||
size="small"
|
||||
label={delayManager.formatDelay(currentDelay)}
|
||||
color={convertDelayColor(currentDelay)}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
{/* 代理组选择器 */}
|
||||
<FormControl
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
size="small"
|
||||
sx={{ mb: 1.5 }}
|
||||
>
|
||||
<InputLabel id="proxy-group-select-label">{t("Group")}</InputLabel>
|
||||
<Select
|
||||
labelId="proxy-group-select-label"
|
||||
value={state.selection.group}
|
||||
onChange={handleGroupChange}
|
||||
label={t("Group")}
|
||||
disabled={isGlobalMode || isDirectMode}
|
||||
>
|
||||
{state.proxyData.groups.map((group) => (
|
||||
<MenuItem key={group.name} value={group.name}>
|
||||
{group.name}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
|
||||
{/* 代理节点选择器 */}
|
||||
<FormControl fullWidth variant="outlined" size="small" sx={{ mb: 0 }}>
|
||||
<InputLabel id="proxy-select-label">{t("Proxy")}</InputLabel>
|
||||
<Select
|
||||
labelId="proxy-select-label"
|
||||
value={state.selection.proxy}
|
||||
onChange={handleProxyChange}
|
||||
label={t("Proxy")}
|
||||
disabled={isDirectMode}
|
||||
renderValue={renderProxyValue}
|
||||
MenuProps={{
|
||||
PaperProps: {
|
||||
style: {
|
||||
maxHeight: 500,
|
||||
},
|
||||
},
|
||||
}}
|
||||
>
|
||||
{isDirectMode
|
||||
? null
|
||||
: proxyOptions.map((proxy, index) => {
|
||||
const delayValue = delayManager.getDelayFix(
|
||||
state.proxyData.records[proxy.name],
|
||||
state.selection.group,
|
||||
);
|
||||
return (
|
||||
<MenuItem
|
||||
key={`${proxy.name}-${index}`}
|
||||
value={proxy.name}
|
||||
sx={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
width: "100%",
|
||||
pr: 1,
|
||||
}}
|
||||
>
|
||||
<Typography noWrap sx={{ flex: 1, mr: 1 }}>
|
||||
{proxy.name}
|
||||
</Typography>
|
||||
<Chip
|
||||
size="small"
|
||||
label={delayManager.formatDelay(delayValue)}
|
||||
color={convertDelayColor(delayValue)}
|
||||
sx={{
|
||||
minWidth: "60px",
|
||||
height: "22px",
|
||||
flexShrink: 0,
|
||||
}}
|
||||
/>
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Box>
|
||||
) : (
|
||||
<Box sx={{ textAlign: "center", py: 4 }}>
|
||||
<Typography variant="body1" color="text.secondary">
|
||||
{t("No active proxy node")}
|
||||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
</EnhancedCard>
|
||||
);
|
||||
};
|
121
src/components/home/enhanced-card.tsx
Normal file
121
src/components/home/enhanced-card.tsx
Normal file
@ -0,0 +1,121 @@
|
||||
import { Box, Typography, alpha, useTheme } from "@mui/material";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
// 自定义卡片组件接口
|
||||
export interface EnhancedCardProps {
|
||||
title: ReactNode;
|
||||
icon: ReactNode;
|
||||
action?: ReactNode;
|
||||
children: ReactNode;
|
||||
iconColor?:
|
||||
| "primary"
|
||||
| "secondary"
|
||||
| "error"
|
||||
| "warning"
|
||||
| "info"
|
||||
| "success";
|
||||
minHeight?: number | string;
|
||||
noContentPadding?: boolean;
|
||||
}
|
||||
|
||||
// 自定义卡片组件
|
||||
export const EnhancedCard = ({
|
||||
title,
|
||||
icon,
|
||||
action,
|
||||
children,
|
||||
iconColor = "primary",
|
||||
minHeight,
|
||||
noContentPadding = false,
|
||||
}: EnhancedCardProps) => {
|
||||
const theme = useTheme();
|
||||
const isDark = theme.palette.mode === "dark";
|
||||
|
||||
// 统一的标题截断样式
|
||||
const titleTruncateStyle = {
|
||||
minWidth: 0,
|
||||
maxWidth: "100%",
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
display: "block"
|
||||
};
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
height: "100%",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
borderRadius: 2,
|
||||
backgroundColor: isDark ? "#282a36" : "#ffffff",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
px: 2,
|
||||
py: 1,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
borderBottom: 1,
|
||||
borderColor: "divider",
|
||||
}}
|
||||
>
|
||||
<Box sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
minWidth: 0,
|
||||
flex: 1,
|
||||
overflow: "hidden"
|
||||
}}>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
borderRadius: 1.5,
|
||||
width: 38,
|
||||
height: 38,
|
||||
mr: 1.5,
|
||||
flexShrink: 0,
|
||||
backgroundColor: alpha(theme.palette[iconColor].main, 0.12),
|
||||
color: theme.palette[iconColor].main,
|
||||
}}
|
||||
>
|
||||
{icon}
|
||||
</Box>
|
||||
<Box sx={{ minWidth: 0, flex: 1 }}>
|
||||
{typeof title === "string" ? (
|
||||
<Typography
|
||||
variant="h6"
|
||||
fontWeight="medium"
|
||||
fontSize={18}
|
||||
sx={titleTruncateStyle}
|
||||
title={title}
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
) : (
|
||||
<Box sx={titleTruncateStyle}>
|
||||
{title}
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
{action && <Box sx={{ ml: 2, flexShrink: 0 }}>{action}</Box>}
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
flex: 1,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
p: noContentPadding ? 0 : 2,
|
||||
...(minHeight && { minHeight }),
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
370
src/components/home/enhanced-traffic-graph.tsx
Normal file
370
src/components/home/enhanced-traffic-graph.tsx
Normal file
@ -0,0 +1,370 @@
|
||||
import {
|
||||
forwardRef,
|
||||
useImperativeHandle,
|
||||
useState,
|
||||
useEffect,
|
||||
useCallback,
|
||||
useMemo,
|
||||
useRef,
|
||||
memo,
|
||||
} from "react";
|
||||
import { Box, useTheme } from "@mui/material";
|
||||
import parseTraffic from "@/utils/parse-traffic";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
LineChart,
|
||||
Line,
|
||||
XAxis,
|
||||
YAxis,
|
||||
CartesianGrid,
|
||||
Tooltip,
|
||||
ResponsiveContainer,
|
||||
AreaChart,
|
||||
Area,
|
||||
} from "recharts";
|
||||
|
||||
// 流量数据项接口
|
||||
export interface ITrafficItem {
|
||||
up: number;
|
||||
down: number;
|
||||
timestamp?: number;
|
||||
}
|
||||
|
||||
// 组件对外暴露的方法
|
||||
export interface EnhancedTrafficGraphRef {
|
||||
appendData: (data: ITrafficItem) => void;
|
||||
toggleStyle: () => void;
|
||||
}
|
||||
|
||||
// 时间范围类型
|
||||
type TimeRange = 1 | 5 | 10; // 分钟
|
||||
|
||||
// 数据点类型
|
||||
type DataPoint = ITrafficItem & { name: string; timestamp: number };
|
||||
|
||||
/**
|
||||
* 增强型流量图表组件
|
||||
*/
|
||||
export const EnhancedTrafficGraph = memo(forwardRef<EnhancedTrafficGraphRef>(
|
||||
(props, ref) => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
|
||||
// 基础状态
|
||||
const [timeRange, setTimeRange] = useState<TimeRange>(10);
|
||||
const [chartStyle, setChartStyle] = useState<"line" | "area">("area");
|
||||
const [displayData, setDisplayData] = useState<DataPoint[]>([]);
|
||||
|
||||
// 数据缓冲区
|
||||
const dataBufferRef = useRef<DataPoint[]>([]);
|
||||
|
||||
// 根据时间范围计算保留的数据点数量
|
||||
const getMaxPointsByTimeRange = useCallback(
|
||||
(minutes: TimeRange): number => minutes * 60,
|
||||
[]
|
||||
);
|
||||
|
||||
// 最大数据点数量
|
||||
const MAX_BUFFER_SIZE = useMemo(
|
||||
() => getMaxPointsByTimeRange(10),
|
||||
[getMaxPointsByTimeRange]
|
||||
);
|
||||
|
||||
// 颜色配置
|
||||
const colors = useMemo(
|
||||
() => ({
|
||||
up: theme.palette.secondary.main,
|
||||
down: theme.palette.primary.main,
|
||||
grid: theme.palette.divider,
|
||||
tooltip: theme.palette.background.paper,
|
||||
text: theme.palette.text.primary,
|
||||
}),
|
||||
[theme]
|
||||
);
|
||||
|
||||
// 切换时间范围
|
||||
const handleTimeRangeClick = useCallback(() => {
|
||||
setTimeRange((prevRange) => {
|
||||
// 在1、5、10分钟之间循环切换
|
||||
return prevRange === 1 ? 5 : prevRange === 5 ? 10 : 1;
|
||||
});
|
||||
}, []);
|
||||
|
||||
// 初始化数据缓冲区
|
||||
useEffect(() => {
|
||||
// 创建初始空数据
|
||||
const now = Date.now();
|
||||
const tenMinutesAgo = now - 10 * 60 * 1000;
|
||||
|
||||
const initialBuffer = Array.from(
|
||||
{ length: MAX_BUFFER_SIZE },
|
||||
(_, index) => {
|
||||
const pointTime =
|
||||
tenMinutesAgo + index * ((10 * 60 * 1000) / MAX_BUFFER_SIZE);
|
||||
const date = new Date(pointTime);
|
||||
|
||||
return {
|
||||
up: 0,
|
||||
down: 0,
|
||||
timestamp: pointTime,
|
||||
name: date.toLocaleTimeString("en-US", {
|
||||
hour12: false,
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
}),
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
dataBufferRef.current = initialBuffer;
|
||||
|
||||
// 更新显示数据
|
||||
const pointsToShow = getMaxPointsByTimeRange(timeRange);
|
||||
setDisplayData(initialBuffer.slice(-pointsToShow));
|
||||
}, [MAX_BUFFER_SIZE, getMaxPointsByTimeRange]);
|
||||
|
||||
// 添加数据点方法
|
||||
const appendData = useCallback((data: ITrafficItem) => {
|
||||
// 安全处理数据
|
||||
const safeData = {
|
||||
up: typeof data.up === "number" && !isNaN(data.up) ? data.up : 0,
|
||||
down: typeof data.down === "number" && !isNaN(data.down) ? data.down : 0,
|
||||
};
|
||||
|
||||
// 使用提供的时间戳或当前时间
|
||||
const timestamp = data.timestamp || Date.now();
|
||||
const date = new Date(timestamp);
|
||||
|
||||
// 带时间标签的新数据点
|
||||
const newPoint: DataPoint = {
|
||||
...safeData,
|
||||
name: date.toLocaleTimeString("en-US", {
|
||||
hour12: false,
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
}),
|
||||
timestamp: timestamp,
|
||||
};
|
||||
|
||||
// 更新缓冲区,保持原数组大小
|
||||
const newBuffer = [...dataBufferRef.current.slice(1), newPoint];
|
||||
dataBufferRef.current = newBuffer;
|
||||
|
||||
// 更新显示数据
|
||||
const pointsToShow = getMaxPointsByTimeRange(timeRange);
|
||||
setDisplayData(newBuffer.slice(-pointsToShow));
|
||||
}, [timeRange, getMaxPointsByTimeRange]);
|
||||
|
||||
// 监听时间范围变化,更新显示数据
|
||||
useEffect(() => {
|
||||
const pointsToShow = getMaxPointsByTimeRange(timeRange);
|
||||
setDisplayData(dataBufferRef.current.slice(-pointsToShow));
|
||||
}, [timeRange, getMaxPointsByTimeRange]);
|
||||
|
||||
// 切换图表样式
|
||||
const toggleStyle = useCallback(() => {
|
||||
setChartStyle((prev) => prev === "line" ? "area" : "line");
|
||||
}, []);
|
||||
|
||||
// 暴露方法给父组件
|
||||
useImperativeHandle(
|
||||
ref,
|
||||
() => ({
|
||||
appendData,
|
||||
toggleStyle,
|
||||
}),
|
||||
[appendData, toggleStyle]
|
||||
);
|
||||
|
||||
// 格式化工具提示内容
|
||||
const formatTooltip = useCallback((value: number, name: string, props: any) => {
|
||||
const [num, unit] = parseTraffic(value);
|
||||
return [`${num} ${unit}/s`, props?.dataKey === "up" ? t("Upload") : t("Download")];
|
||||
}, [t]);
|
||||
|
||||
// Y轴刻度格式化
|
||||
const formatYAxis = useCallback((value: number) => {
|
||||
const [num, unit] = parseTraffic(value);
|
||||
return `${num}${unit}`;
|
||||
}, []);
|
||||
|
||||
// 格式化X轴标签
|
||||
const formatXLabel = useCallback((value: string) => {
|
||||
if (!value) return "";
|
||||
const parts = value.split(":");
|
||||
return `${parts[0]}:${parts[1]}`;
|
||||
}, []);
|
||||
|
||||
// 获取当前时间范围文本
|
||||
const getTimeRangeText = useCallback(() => {
|
||||
return t("{{time}} Minutes", { time: timeRange });
|
||||
}, [timeRange, t]);
|
||||
|
||||
// 共享图表配置
|
||||
const chartConfig = useMemo(() => ({
|
||||
data: displayData,
|
||||
margin: { top: 20, right: 10, left: 0, bottom: -10 },
|
||||
}), [displayData]);
|
||||
|
||||
// 共享的线条/区域配置
|
||||
const commonLineProps = useMemo(() => ({
|
||||
dot: false,
|
||||
strokeWidth: 2,
|
||||
connectNulls: false,
|
||||
activeDot: { r: 4, strokeWidth: 1 },
|
||||
isAnimationActive: false, // 禁用动画以减少CPU使用
|
||||
}), []);
|
||||
|
||||
// 曲线类型
|
||||
const curveType = "monotone";
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
position: "relative",
|
||||
bgcolor: "action.hover",
|
||||
borderRadius: 1,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
onClick={toggleStyle}
|
||||
>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
{/* 根据chartStyle动态选择图表类型 */}
|
||||
{(() => {
|
||||
// 创建共享的图表组件
|
||||
const commonChartComponents = (
|
||||
<>
|
||||
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke={colors.grid} opacity={0.3} />
|
||||
<XAxis
|
||||
dataKey="name"
|
||||
tick={{ fontSize: 10, fill: colors.text }}
|
||||
tickLine={{ stroke: colors.grid }}
|
||||
axisLine={{ stroke: colors.grid }}
|
||||
interval="preserveStart"
|
||||
tickFormatter={formatXLabel}
|
||||
minTickGap={30}
|
||||
/>
|
||||
<YAxis
|
||||
tickFormatter={formatYAxis}
|
||||
tick={{ fontSize: 10, fill: colors.text }}
|
||||
tickLine={{ stroke: colors.grid }}
|
||||
axisLine={{ stroke: colors.grid }}
|
||||
width={44}
|
||||
domain={[0, "auto"]}
|
||||
padding={{ top: 8, bottom: 0 }}
|
||||
/>
|
||||
<Tooltip
|
||||
formatter={formatTooltip}
|
||||
labelFormatter={(label) => `${t("Time")}: ${label}`}
|
||||
contentStyle={{
|
||||
backgroundColor: colors.tooltip,
|
||||
borderColor: colors.grid,
|
||||
borderRadius: 4,
|
||||
}}
|
||||
itemStyle={{ color: colors.text }}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
|
||||
{/* 可点击的时间范围标签 */}
|
||||
<text
|
||||
x="1%"
|
||||
y="11%"
|
||||
textAnchor="start"
|
||||
fill={theme.palette.text.secondary}
|
||||
fontSize={11}
|
||||
fontWeight="bold"
|
||||
onClick={handleTimeRangeClick}
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
{getTimeRangeText()}
|
||||
</text>
|
||||
|
||||
{/* 上传标签 - 右上角 */}
|
||||
<text
|
||||
x="99%"
|
||||
y="11%"
|
||||
textAnchor="end"
|
||||
fill={colors.up}
|
||||
fontSize={12}
|
||||
fontWeight="bold"
|
||||
onClick={toggleStyle}
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
{t("Upload")}
|
||||
</text>
|
||||
|
||||
{/* 下载标签 - 右上角下方 */}
|
||||
<text
|
||||
x="99%"
|
||||
y="19%"
|
||||
textAnchor="end"
|
||||
fill={colors.down}
|
||||
fontSize={12}
|
||||
fontWeight="bold"
|
||||
onClick={toggleStyle}
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
{t("Download")}
|
||||
</text>
|
||||
</>
|
||||
);
|
||||
|
||||
// 根据chartStyle返回相应的图表类型
|
||||
if (chartStyle === "line") {
|
||||
return (
|
||||
<LineChart {...chartConfig}>
|
||||
{commonChartComponents}
|
||||
<Line
|
||||
type={curveType}
|
||||
{...commonLineProps}
|
||||
dataKey="up"
|
||||
name={t("Upload")}
|
||||
stroke={colors.up}
|
||||
/>
|
||||
<Line
|
||||
type={curveType}
|
||||
{...commonLineProps}
|
||||
dataKey="down"
|
||||
name={t("Download")}
|
||||
stroke={colors.down}
|
||||
/>
|
||||
</LineChart>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<AreaChart {...chartConfig}>
|
||||
{commonChartComponents}
|
||||
<Area
|
||||
type={curveType}
|
||||
{...commonLineProps}
|
||||
dataKey="up"
|
||||
name={t("Upload")}
|
||||
stroke={colors.up}
|
||||
fill={colors.up}
|
||||
fillOpacity={0.2}
|
||||
/>
|
||||
<Area
|
||||
type={curveType}
|
||||
{...commonLineProps}
|
||||
dataKey="down"
|
||||
name={t("Download")}
|
||||
stroke={colors.down}
|
||||
fill={colors.down}
|
||||
fillOpacity={0.3}
|
||||
/>
|
||||
</AreaChart>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
</ResponsiveContainer>
|
||||
</Box>
|
||||
);
|
||||
},
|
||||
));
|
||||
|
||||
// 添加显示名称以便调试
|
||||
EnhancedTrafficGraph.displayName = "EnhancedTrafficGraph";
|
418
src/components/home/enhanced-traffic-stats.tsx
Normal file
418
src/components/home/enhanced-traffic-stats.tsx
Normal file
@ -0,0 +1,418 @@
|
||||
import { useState, useEffect, useRef, useCallback, memo, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Typography,
|
||||
Paper,
|
||||
alpha,
|
||||
useTheme,
|
||||
PaletteColor,
|
||||
} from "@mui/material";
|
||||
import Grid from "@mui/material/Grid2";
|
||||
import {
|
||||
ArrowUpwardRounded,
|
||||
ArrowDownwardRounded,
|
||||
MemoryRounded,
|
||||
LinkRounded,
|
||||
CloudUploadRounded,
|
||||
CloudDownloadRounded,
|
||||
} from "@mui/icons-material";
|
||||
import {
|
||||
EnhancedTrafficGraph,
|
||||
EnhancedTrafficGraphRef,
|
||||
ITrafficItem,
|
||||
} from "./enhanced-traffic-graph";
|
||||
import { useVisibility } from "@/hooks/use-visibility";
|
||||
import { useClashInfo } from "@/hooks/use-clash";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import { createAuthSockette } from "@/utils/websocket";
|
||||
import parseTraffic from "@/utils/parse-traffic";
|
||||
import { getConnections, isDebugEnabled, gc } from "@/services/api";
|
||||
import { ReactNode } from "react";
|
||||
import { useAppData } from "@/providers/app-data-provider";
|
||||
|
||||
interface MemoryUsage {
|
||||
inuse: number;
|
||||
oslimit?: number;
|
||||
}
|
||||
|
||||
interface TrafficStatData {
|
||||
uploadTotal: number;
|
||||
downloadTotal: number;
|
||||
activeConnections: number;
|
||||
}
|
||||
|
||||
interface StatCardProps {
|
||||
icon: ReactNode;
|
||||
title: string;
|
||||
value: string | number;
|
||||
unit: string;
|
||||
color: "primary" | "secondary" | "error" | "warning" | "info" | "success";
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
// 全局变量类型定义
|
||||
declare global {
|
||||
interface Window {
|
||||
animationFrameId?: number;
|
||||
lastTrafficData?: {
|
||||
up: number;
|
||||
down: number;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 控制更新频率
|
||||
const CONNECTIONS_UPDATE_INTERVAL = 5000; // 5秒更新一次连接数据
|
||||
const THROTTLE_TRAFFIC_UPDATE = 500; // 500ms节流流量数据更新
|
||||
|
||||
// 统计卡片组件 - 使用memo优化
|
||||
const CompactStatCard = memo(({
|
||||
icon,
|
||||
title,
|
||||
value,
|
||||
unit,
|
||||
color,
|
||||
onClick,
|
||||
}: StatCardProps) => {
|
||||
const theme = useTheme();
|
||||
|
||||
// 获取调色板颜色 - 使用useMemo避免重复计算
|
||||
const colorValue = useMemo(() => {
|
||||
const palette = theme.palette;
|
||||
if (
|
||||
color in palette &&
|
||||
palette[color as keyof typeof palette] &&
|
||||
"main" in (palette[color as keyof typeof palette] as PaletteColor)
|
||||
) {
|
||||
return (palette[color as keyof typeof palette] as PaletteColor).main;
|
||||
}
|
||||
return palette.primary.main;
|
||||
}, [theme.palette, color]);
|
||||
|
||||
return (
|
||||
<Paper
|
||||
elevation={0}
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
borderRadius: 2,
|
||||
bgcolor: alpha(colorValue, 0.05),
|
||||
border: `1px solid ${alpha(colorValue, 0.15)}`,
|
||||
padding: "8px",
|
||||
transition: "all 0.2s ease-in-out",
|
||||
cursor: onClick ? "pointer" : "default",
|
||||
"&:hover": onClick ? {
|
||||
bgcolor: alpha(colorValue, 0.1),
|
||||
border: `1px solid ${alpha(colorValue, 0.3)}`,
|
||||
boxShadow: `0 4px 8px rgba(0,0,0,0.05)`,
|
||||
} : {},
|
||||
}}
|
||||
onClick={onClick}
|
||||
>
|
||||
{/* 图标容器 */}
|
||||
<Grid
|
||||
component="div"
|
||||
sx={{
|
||||
mr: 1,
|
||||
ml: "2px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
width: 32,
|
||||
height: 32,
|
||||
borderRadius: "50%",
|
||||
bgcolor: alpha(colorValue, 0.1),
|
||||
color: colorValue,
|
||||
}}
|
||||
>
|
||||
{icon}
|
||||
</Grid>
|
||||
|
||||
{/* 文本内容 */}
|
||||
<Grid component="div" sx={{ flexGrow: 1, minWidth: 0 }}>
|
||||
<Typography variant="caption" color="text.secondary" noWrap>
|
||||
{title}
|
||||
</Typography>
|
||||
<Grid component="div" sx={{ display: "flex", alignItems: "baseline" }}>
|
||||
<Typography variant="body1" fontWeight="bold" noWrap sx={{ mr: 0.5 }}>
|
||||
{value}
|
||||
</Typography>
|
||||
<Typography variant="caption" color="text.secondary">
|
||||
{unit}
|
||||
</Typography>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Paper>
|
||||
);
|
||||
});
|
||||
|
||||
// 添加显示名称
|
||||
CompactStatCard.displayName = "CompactStatCard";
|
||||
|
||||
export const EnhancedTrafficStats = () => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const { clashInfo } = useClashInfo();
|
||||
const { verge } = useVerge();
|
||||
const trafficRef = useRef<EnhancedTrafficGraphRef>(null);
|
||||
const pageVisible = useVisibility();
|
||||
const [isDebug, setIsDebug] = useState(false);
|
||||
|
||||
// 使用AppDataProvider
|
||||
const { connections, uptime } = useAppData();
|
||||
|
||||
// 使用单一状态对象减少状态更新次数
|
||||
const [stats, setStats] = useState({
|
||||
traffic: { up: 0, down: 0 },
|
||||
memory: { inuse: 0, oslimit: undefined as number | undefined },
|
||||
});
|
||||
|
||||
// 创建一个标记来追踪最后更新时间,用于节流
|
||||
const lastUpdateRef = useRef({ traffic: 0 });
|
||||
|
||||
// 是否显示流量图表
|
||||
const trafficGraph = verge?.traffic_graph ?? true;
|
||||
|
||||
// WebSocket引用
|
||||
const socketRefs = useRef({
|
||||
traffic: null as ReturnType<typeof createAuthSockette> | null,
|
||||
memory: null as ReturnType<typeof createAuthSockette> | null,
|
||||
});
|
||||
|
||||
// 检查是否支持调试
|
||||
useEffect(() => {
|
||||
isDebugEnabled().then((flag) => setIsDebug(flag));
|
||||
}, []);
|
||||
|
||||
// 处理流量数据更新 - 使用节流控制更新频率
|
||||
const handleTrafficUpdate = useCallback((event: MessageEvent) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data) as ITrafficItem;
|
||||
if (
|
||||
data &&
|
||||
typeof data.up === "number" &&
|
||||
typeof data.down === "number"
|
||||
) {
|
||||
// 使用节流控制更新频率
|
||||
const now = Date.now();
|
||||
if (now - lastUpdateRef.current.traffic < THROTTLE_TRAFFIC_UPDATE) {
|
||||
// 如果距离上次更新时间小于阈值,只更新图表不更新状态
|
||||
if (trafficRef.current) {
|
||||
trafficRef.current.appendData({
|
||||
up: data.up,
|
||||
down: data.down,
|
||||
timestamp: now,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新最后更新时间
|
||||
lastUpdateRef.current.traffic = now;
|
||||
|
||||
// 验证数据有效性,防止NaN
|
||||
const safeUp = isNaN(data.up) ? 0 : data.up;
|
||||
const safeDown = isNaN(data.down) ? 0 : data.down;
|
||||
|
||||
// 批量更新状态
|
||||
setStats(prev => ({
|
||||
...prev,
|
||||
traffic: { up: safeUp, down: safeDown }
|
||||
}));
|
||||
|
||||
// 更新图表数据
|
||||
if (trafficRef.current) {
|
||||
trafficRef.current.appendData({
|
||||
up: safeUp,
|
||||
down: safeDown,
|
||||
timestamp: now,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[Traffic] 解析数据错误:", err);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 处理内存数据更新
|
||||
const handleMemoryUpdate = useCallback((event: MessageEvent) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data) as MemoryUsage;
|
||||
if (data && typeof data.inuse === "number") {
|
||||
setStats(prev => ({
|
||||
...prev,
|
||||
memory: {
|
||||
inuse: isNaN(data.inuse) ? 0 : data.inuse,
|
||||
oslimit: data.oslimit,
|
||||
}
|
||||
}));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[Memory] 解析数据错误:", err);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 使用 WebSocket 连接获取数据 - 合并流量和内存连接逻辑
|
||||
useEffect(() => {
|
||||
if (!clashInfo || !pageVisible) return;
|
||||
|
||||
const { server, secret = "" } = clashInfo;
|
||||
if (!server) return;
|
||||
|
||||
// 清理现有连接的函数
|
||||
const cleanupSockets = () => {
|
||||
Object.values(socketRefs.current).forEach(socket => {
|
||||
if (socket) {
|
||||
socket.close();
|
||||
}
|
||||
});
|
||||
socketRefs.current = { traffic: null, memory: null };
|
||||
};
|
||||
|
||||
// 关闭现有连接
|
||||
cleanupSockets();
|
||||
|
||||
// 创建新连接
|
||||
socketRefs.current.traffic = createAuthSockette(`${server}/traffic`, secret, {
|
||||
onmessage: handleTrafficUpdate,
|
||||
});
|
||||
|
||||
socketRefs.current.memory = createAuthSockette(`${server}/memory`, secret, {
|
||||
onmessage: handleMemoryUpdate,
|
||||
});
|
||||
|
||||
return cleanupSockets;
|
||||
}, [clashInfo, pageVisible, handleTrafficUpdate, handleMemoryUpdate]);
|
||||
|
||||
// 执行垃圾回收
|
||||
const handleGarbageCollection = useCallback(async () => {
|
||||
if (isDebug) {
|
||||
try {
|
||||
await gc();
|
||||
console.log("[Debug] 垃圾回收已执行");
|
||||
} catch (err) {
|
||||
console.error("[Debug] 垃圾回收失败:", err);
|
||||
}
|
||||
}
|
||||
}, [isDebug]);
|
||||
|
||||
// 使用useMemo计算解析后的流量数据
|
||||
const parsedData = useMemo(() => {
|
||||
const [up, upUnit] = parseTraffic(stats.traffic.up);
|
||||
const [down, downUnit] = parseTraffic(stats.traffic.down);
|
||||
const [inuse, inuseUnit] = parseTraffic(stats.memory.inuse);
|
||||
const [uploadTotal, uploadTotalUnit] = parseTraffic(connections.uploadTotal);
|
||||
const [downloadTotal, downloadTotalUnit] = parseTraffic(connections.downloadTotal);
|
||||
|
||||
return {
|
||||
up, upUnit, down, downUnit, inuse, inuseUnit,
|
||||
uploadTotal, uploadTotalUnit, downloadTotal, downloadTotalUnit
|
||||
};
|
||||
}, [stats, connections.uploadTotal, connections.downloadTotal]);
|
||||
|
||||
// 渲染流量图表 - 使用useMemo缓存渲染结果
|
||||
const trafficGraphComponent = useMemo(() => {
|
||||
if (!trafficGraph || !pageVisible) return null;
|
||||
|
||||
return (
|
||||
<Paper
|
||||
elevation={0}
|
||||
sx={{
|
||||
height: 130,
|
||||
cursor: "pointer",
|
||||
border: `1px solid ${alpha(theme.palette.divider, 0.2)}`,
|
||||
borderRadius: 2,
|
||||
overflow: "hidden",
|
||||
}}
|
||||
onClick={() => trafficRef.current?.toggleStyle()}
|
||||
>
|
||||
<div style={{ height: "100%", position: "relative" }}>
|
||||
<EnhancedTrafficGraph ref={trafficRef} />
|
||||
{isDebug && (
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "2px",
|
||||
left: "2px",
|
||||
zIndex: 10,
|
||||
backgroundColor: "rgba(0,0,0,0.5)",
|
||||
color: "white",
|
||||
fontSize: "8px",
|
||||
padding: "2px 4px",
|
||||
borderRadius: "4px",
|
||||
}}
|
||||
>
|
||||
DEBUG: {!!trafficRef.current ? "图表已初始化" : "图表未初始化"}
|
||||
<br />
|
||||
{new Date().toISOString().slice(11, 19)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Paper>
|
||||
);
|
||||
}, [trafficGraph, pageVisible, theme.palette.divider, isDebug]);
|
||||
|
||||
// 使用useMemo计算统计卡片配置
|
||||
const statCards = useMemo(() => [
|
||||
{
|
||||
icon: <ArrowUpwardRounded fontSize="small" />,
|
||||
title: t("Upload Speed"),
|
||||
value: parsedData.up,
|
||||
unit: `${parsedData.upUnit}/s`,
|
||||
color: "secondary" as const,
|
||||
},
|
||||
{
|
||||
icon: <ArrowDownwardRounded fontSize="small" />,
|
||||
title: t("Download Speed"),
|
||||
value: parsedData.down,
|
||||
unit: `${parsedData.downUnit}/s`,
|
||||
color: "primary" as const,
|
||||
},
|
||||
{
|
||||
icon: <LinkRounded fontSize="small" />,
|
||||
title: t("Active Connections"),
|
||||
value: connections.count,
|
||||
unit: "",
|
||||
color: "success" as const,
|
||||
},
|
||||
{
|
||||
icon: <CloudUploadRounded fontSize="small" />,
|
||||
title: t("Uploaded"),
|
||||
value: parsedData.uploadTotal,
|
||||
unit: parsedData.uploadTotalUnit,
|
||||
color: "secondary" as const,
|
||||
},
|
||||
{
|
||||
icon: <CloudDownloadRounded fontSize="small" />,
|
||||
title: t("Downloaded"),
|
||||
value: parsedData.downloadTotal,
|
||||
unit: parsedData.downloadTotalUnit,
|
||||
color: "primary" as const,
|
||||
},
|
||||
{
|
||||
icon: <MemoryRounded fontSize="small" />,
|
||||
title: t("Memory Usage"),
|
||||
value: parsedData.inuse,
|
||||
unit: parsedData.inuseUnit,
|
||||
color: "error" as const,
|
||||
onClick: isDebug ? handleGarbageCollection : undefined,
|
||||
},
|
||||
], [t, parsedData, connections.count, isDebug, handleGarbageCollection]);
|
||||
|
||||
return (
|
||||
<Grid container spacing={1} columns={{ xs: 8, sm: 8, md: 12 }}>
|
||||
{trafficGraph && (
|
||||
<Grid size={12}>
|
||||
{/* 流量图表区域 */}
|
||||
{trafficGraphComponent}
|
||||
</Grid>
|
||||
)}
|
||||
{/* 统计卡片区域 */}
|
||||
{statCards.map((card, index) => (
|
||||
<Grid key={index} size={4}>
|
||||
<CompactStatCard {...card} />
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
);
|
||||
};
|
380
src/components/home/home-profile-card.tsx
Normal file
380
src/components/home/home-profile-card.tsx
Normal file
@ -0,0 +1,380 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Box,
|
||||
Typography,
|
||||
Button,
|
||||
Stack,
|
||||
LinearProgress,
|
||||
alpha,
|
||||
useTheme,
|
||||
Link,
|
||||
keyframes,
|
||||
} from "@mui/material";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import {
|
||||
CloudUploadOutlined,
|
||||
StorageOutlined,
|
||||
UpdateOutlined,
|
||||
DnsOutlined,
|
||||
SpeedOutlined,
|
||||
EventOutlined,
|
||||
LaunchOutlined,
|
||||
} from "@mui/icons-material";
|
||||
import dayjs from "dayjs";
|
||||
import parseTraffic from "@/utils/parse-traffic";
|
||||
import { useMemo, useCallback, useState } from "react";
|
||||
import { openWebUrl, updateProfile } from "@/services/cmds";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { Notice } from "@/components/base";
|
||||
import { EnhancedCard } from "./enhanced-card";
|
||||
import { useAppData } from "@/providers/app-data-provider";
|
||||
|
||||
// 定义旋转动画
|
||||
const round = keyframes`
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
`;
|
||||
|
||||
// 辅助函数解析URL和过期时间
|
||||
const parseUrl = (url?: string) => {
|
||||
if (!url) return "-";
|
||||
if (url.startsWith("http")) return new URL(url).host;
|
||||
return "local";
|
||||
};
|
||||
|
||||
const parseExpire = (expire?: number) => {
|
||||
if (!expire) return "-";
|
||||
return dayjs(expire * 1000).format("YYYY-MM-DD");
|
||||
};
|
||||
|
||||
// 使用类型定义,而不是导入
|
||||
interface ProfileExtra {
|
||||
upload: number;
|
||||
download: number;
|
||||
total: number;
|
||||
expire: number;
|
||||
}
|
||||
|
||||
export interface ProfileItem {
|
||||
uid: string;
|
||||
type?: "local" | "remote" | "merge" | "script";
|
||||
name?: string;
|
||||
desc?: string;
|
||||
file?: string;
|
||||
url?: string;
|
||||
updated?: number;
|
||||
extra?: ProfileExtra;
|
||||
home?: string;
|
||||
option?: any;
|
||||
}
|
||||
|
||||
export interface HomeProfileCardProps {
|
||||
current: ProfileItem | null | undefined;
|
||||
onProfileUpdated?: () => void;
|
||||
}
|
||||
|
||||
// 添加一个通用的截断样式
|
||||
const truncateStyle = {
|
||||
maxWidth: "calc(100% - 28px)",
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap"
|
||||
};
|
||||
|
||||
// 提取独立组件减少主组件复杂度
|
||||
const ProfileDetails = ({ current, onUpdateProfile, updating }: {
|
||||
current: ProfileItem;
|
||||
onUpdateProfile: () => void;
|
||||
updating: boolean;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
|
||||
const usedTraffic = useMemo(() => {
|
||||
if (!current.extra) return 0;
|
||||
return current.extra.upload + current.extra.download;
|
||||
}, [current.extra]);
|
||||
|
||||
const trafficPercentage = useMemo(() => {
|
||||
if (!current.extra || !current.extra.total) return 1;
|
||||
return Math.min(
|
||||
Math.round((usedTraffic * 100) / (current.extra.total + 0.01)) + 1,
|
||||
100
|
||||
);
|
||||
}, [current.extra, usedTraffic]);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Stack spacing={2}>
|
||||
{current.url && (
|
||||
<Stack direction="row" alignItems="center" spacing={1}>
|
||||
<DnsOutlined fontSize="small" color="action" />
|
||||
<Typography variant="body2" color="text.secondary" noWrap sx={{ display: "flex", alignItems: "center" }}>
|
||||
<span style={{ flexShrink: 0 }}>{t("From")}: </span>
|
||||
{current.home ? (
|
||||
<Link
|
||||
component="button"
|
||||
fontWeight="medium"
|
||||
onClick={() => current.home && openWebUrl(current.home)}
|
||||
sx={{
|
||||
display: "inline-flex",
|
||||
alignItems: "center",
|
||||
minWidth: 0,
|
||||
maxWidth: "calc(100% - 40px)",
|
||||
ml: 0.5
|
||||
}}
|
||||
title={parseUrl(current.url)}
|
||||
>
|
||||
<Typography
|
||||
component="span"
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
minWidth: 0,
|
||||
flex: 1
|
||||
}}
|
||||
>
|
||||
{parseUrl(current.url)}
|
||||
</Typography>
|
||||
<LaunchOutlined
|
||||
fontSize="inherit"
|
||||
sx={{ ml: 0.5, fontSize: "0.8rem", opacity: 0.7, flexShrink: 0 }}
|
||||
/>
|
||||
</Link>
|
||||
) : (
|
||||
<Typography
|
||||
component="span"
|
||||
fontWeight="medium"
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
minWidth: 0,
|
||||
flex: 1,
|
||||
ml: 0.5
|
||||
}}
|
||||
title={parseUrl(current.url)}
|
||||
>
|
||||
{parseUrl(current.url)}
|
||||
</Typography>
|
||||
)}
|
||||
</Typography>
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
{current.updated && (
|
||||
<Stack direction="row" alignItems="center" spacing={1}>
|
||||
<UpdateOutlined
|
||||
fontSize="small"
|
||||
color="action"
|
||||
sx={{
|
||||
cursor: "pointer",
|
||||
animation: updating ? `${round} 1.5s linear infinite` : "none",
|
||||
}}
|
||||
onClick={onUpdateProfile}
|
||||
/>
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
sx={{ cursor: "pointer" }}
|
||||
onClick={onUpdateProfile}
|
||||
>
|
||||
{t("Update Time")}:{" "}
|
||||
<Box component="span" fontWeight="medium">
|
||||
{dayjs(current.updated * 1000).format("YYYY-MM-DD HH:mm")}
|
||||
</Box>
|
||||
</Typography>
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
{current.extra && (
|
||||
<>
|
||||
<Stack direction="row" alignItems="center" spacing={1}>
|
||||
<SpeedOutlined fontSize="small" color="action" />
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t("Used / Total")}:{" "}
|
||||
<Box component="span" fontWeight="medium">
|
||||
{parseTraffic(usedTraffic)} / {parseTraffic(current.extra.total)}
|
||||
</Box>
|
||||
</Typography>
|
||||
</Stack>
|
||||
|
||||
{current.extra.expire > 0 && (
|
||||
<Stack direction="row" alignItems="center" spacing={1}>
|
||||
<EventOutlined fontSize="small" color="action" />
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t("Expire Time")}:{" "}
|
||||
<Box component="span" fontWeight="medium">
|
||||
{parseExpire(current.extra.expire)}
|
||||
</Box>
|
||||
</Typography>
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
<Box sx={{ mt: 1 }}>
|
||||
<Typography
|
||||
variant="caption"
|
||||
color="text.secondary"
|
||||
sx={{ mb: 0.5, display: "block" }}
|
||||
>
|
||||
{trafficPercentage}%
|
||||
</Typography>
|
||||
<LinearProgress
|
||||
variant="determinate"
|
||||
value={trafficPercentage}
|
||||
sx={{
|
||||
height: 8,
|
||||
borderRadius: 4,
|
||||
backgroundColor: alpha(theme.palette.primary.main, 0.12),
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
// 提取空配置组件
|
||||
const EmptyProfile = ({ onClick }: { onClick: () => void }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
py: 2.4,
|
||||
cursor: "pointer",
|
||||
"&:hover": { bgcolor: "action.hover" },
|
||||
borderRadius: 2,
|
||||
}}
|
||||
onClick={onClick}
|
||||
>
|
||||
<CloudUploadOutlined
|
||||
sx={{ fontSize: 60, color: "primary.main", mb: 2 }}
|
||||
/>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
{t("Import")} {t("Profiles")}
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t("Click to import subscription")}
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export const HomeProfileCard = ({ current, onProfileUpdated }: HomeProfileCardProps) => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const { refreshAll } = useAppData();
|
||||
|
||||
// 更新当前订阅
|
||||
const [updating, setUpdating] = useState(false);
|
||||
|
||||
const onUpdateProfile = useLockFn(async () => {
|
||||
if (!current?.uid) return;
|
||||
|
||||
setUpdating(true);
|
||||
try {
|
||||
await updateProfile(current.uid);
|
||||
Notice.success(t("Update subscription successfully"));
|
||||
onProfileUpdated?.();
|
||||
|
||||
// 刷新首页数据
|
||||
refreshAll();
|
||||
} catch (err: any) {
|
||||
Notice.error(err?.message || err.toString());
|
||||
} finally {
|
||||
setUpdating(false);
|
||||
}
|
||||
});
|
||||
|
||||
// 导航到订阅页面
|
||||
const goToProfiles = useCallback(() => {
|
||||
navigate("/profile");
|
||||
}, [navigate]);
|
||||
|
||||
// 卡片标题
|
||||
const cardTitle = useMemo(() => {
|
||||
if (!current) return t("Profiles");
|
||||
|
||||
if (!current.home) return current.name;
|
||||
|
||||
return (
|
||||
<Link
|
||||
component="button"
|
||||
variant="h6"
|
||||
fontWeight="medium"
|
||||
fontSize={18}
|
||||
onClick={() => current.home && openWebUrl(current.home)}
|
||||
sx={{
|
||||
color: "inherit",
|
||||
textDecoration: "none",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
minWidth: 0,
|
||||
maxWidth: "100%",
|
||||
"& > span": {
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
flex: 1
|
||||
}
|
||||
}}
|
||||
title={current.name}
|
||||
>
|
||||
<span>{current.name}</span>
|
||||
<LaunchOutlined
|
||||
fontSize="inherit"
|
||||
sx={{
|
||||
ml: 0.5,
|
||||
fontSize: "0.8rem",
|
||||
opacity: 0.7,
|
||||
flexShrink: 0
|
||||
}}
|
||||
/>
|
||||
</Link>
|
||||
);
|
||||
}, [current, t]);
|
||||
|
||||
// 卡片操作按钮
|
||||
const cardAction = useMemo(() => {
|
||||
if (!current) return null;
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="small"
|
||||
onClick={goToProfiles}
|
||||
endIcon={<StorageOutlined fontSize="small" />}
|
||||
sx={{ borderRadius: 1.5 }}
|
||||
>
|
||||
{t("Label-Profiles")}
|
||||
</Button>
|
||||
);
|
||||
}, [current, goToProfiles, t]);
|
||||
|
||||
return (
|
||||
<EnhancedCard
|
||||
title={cardTitle}
|
||||
icon={<CloudUploadOutlined />}
|
||||
iconColor="info"
|
||||
action={cardAction}
|
||||
>
|
||||
{current ? (
|
||||
<ProfileDetails
|
||||
current={current}
|
||||
onUpdateProfile={onUpdateProfile}
|
||||
updating={updating}
|
||||
/>
|
||||
) : (
|
||||
<EmptyProfile onClick={goToProfiles} />
|
||||
)}
|
||||
</EnhancedCard>
|
||||
);
|
||||
};
|
324
src/components/home/ip-info-card.tsx
Normal file
324
src/components/home/ip-info-card.tsx
Normal file
@ -0,0 +1,324 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Box,
|
||||
Typography,
|
||||
Button,
|
||||
Skeleton,
|
||||
IconButton,
|
||||
useTheme,
|
||||
} from "@mui/material";
|
||||
import {
|
||||
LocationOnOutlined,
|
||||
RefreshOutlined,
|
||||
VisibilityOutlined,
|
||||
VisibilityOffOutlined,
|
||||
} from "@mui/icons-material";
|
||||
import { EnhancedCard } from "./enhanced-card";
|
||||
import { getIpInfo } from "@/services/api";
|
||||
import { useState, useEffect, useCallback, memo } from "react";
|
||||
|
||||
// 定义刷新时间(秒)
|
||||
const IP_REFRESH_SECONDS = 300;
|
||||
|
||||
// 提取InfoItem子组件并使用memo优化
|
||||
const InfoItem = memo(({ label, value }: { label: string; value: string }) => (
|
||||
<Box sx={{ mb: 0.7, display: "flex", alignItems: "flex-start" }}>
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
sx={{ minwidth: 60, mr: 0.5, flexShrink: 0, textAlign: "right" }}
|
||||
>
|
||||
{label}:
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="body2"
|
||||
sx={{
|
||||
ml: 0.5,
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
wordBreak: "break-word",
|
||||
whiteSpace: "normal",
|
||||
flexGrow: 1,
|
||||
}}
|
||||
>
|
||||
{value || "Unknown"}
|
||||
</Typography>
|
||||
</Box>
|
||||
));
|
||||
|
||||
// 获取国旗表情
|
||||
const getCountryFlag = (countryCode: string) => {
|
||||
if (!countryCode) return "";
|
||||
const codePoints = countryCode
|
||||
.toUpperCase()
|
||||
.split("")
|
||||
.map((char) => 127397 + char.charCodeAt(0));
|
||||
return String.fromCodePoint(...codePoints);
|
||||
};
|
||||
|
||||
// IP信息卡片组件
|
||||
export const IpInfoCard = () => {
|
||||
const { t } = useTranslation();
|
||||
const [ipInfo, setIpInfo] = useState<any>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState("");
|
||||
const [showIp, setShowIp] = useState(false);
|
||||
const [countdown, setCountdown] = useState(IP_REFRESH_SECONDS);
|
||||
|
||||
// 获取IP信息
|
||||
const fetchIpInfo = useCallback(async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
const data = await getIpInfo();
|
||||
setIpInfo(data);
|
||||
setCountdown(IP_REFRESH_SECONDS);
|
||||
} catch (err: any) {
|
||||
setError(err.message || t("Failed to get IP info"));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [t]);
|
||||
|
||||
// 组件加载时获取IP信息
|
||||
useEffect(() => {
|
||||
fetchIpInfo();
|
||||
|
||||
// 倒计时实现优化,减少不必要的重渲染
|
||||
let timer: number | null = null;
|
||||
let currentCount = IP_REFRESH_SECONDS;
|
||||
|
||||
// 只在必要时更新状态,减少重渲染次数
|
||||
const startCountdown = () => {
|
||||
timer = window.setInterval(() => {
|
||||
currentCount -= 1;
|
||||
|
||||
if (currentCount <= 0) {
|
||||
fetchIpInfo();
|
||||
currentCount = IP_REFRESH_SECONDS;
|
||||
}
|
||||
|
||||
// 每5秒或倒计时结束时才更新UI
|
||||
if (currentCount % 5 === 0 || currentCount <= 0) {
|
||||
setCountdown(currentCount);
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
startCountdown();
|
||||
return () => {
|
||||
if (timer) clearInterval(timer);
|
||||
};
|
||||
}, [fetchIpInfo]);
|
||||
|
||||
const toggleShowIp = useCallback(() => {
|
||||
setShowIp(prev => !prev);
|
||||
}, []);
|
||||
|
||||
// 渲染加载状态
|
||||
if (loading) {
|
||||
return (
|
||||
<EnhancedCard
|
||||
title={t("IP Information")}
|
||||
icon={<LocationOnOutlined />}
|
||||
iconColor="info"
|
||||
action={
|
||||
<IconButton size="small" onClick={fetchIpInfo} disabled={true}>
|
||||
<RefreshOutlined />
|
||||
</IconButton>
|
||||
}
|
||||
>
|
||||
<Box sx={{ display: "flex", flexDirection: "column", gap: 1 }}>
|
||||
<Skeleton variant="text" width="60%" height={30} />
|
||||
<Skeleton variant="text" width="80%" height={24} />
|
||||
<Skeleton variant="text" width="70%" height={24} />
|
||||
<Skeleton variant="text" width="50%" height={24} />
|
||||
</Box>
|
||||
</EnhancedCard>
|
||||
);
|
||||
}
|
||||
|
||||
// 渲染错误状态
|
||||
if (error) {
|
||||
return (
|
||||
<EnhancedCard
|
||||
title={t("IP Information")}
|
||||
icon={<LocationOnOutlined />}
|
||||
iconColor="info"
|
||||
action={
|
||||
<IconButton size="small" onClick={fetchIpInfo}>
|
||||
<RefreshOutlined />
|
||||
</IconButton>
|
||||
}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
height: "100%",
|
||||
color: "error.main",
|
||||
}}
|
||||
>
|
||||
<Typography variant="body1" color="error">
|
||||
{error}
|
||||
</Typography>
|
||||
<Button onClick={fetchIpInfo} sx={{ mt: 2 }}>
|
||||
{t("Retry")}
|
||||
</Button>
|
||||
</Box>
|
||||
</EnhancedCard>
|
||||
);
|
||||
}
|
||||
|
||||
// 渲染正常数据
|
||||
return (
|
||||
<EnhancedCard
|
||||
title={t("IP Information")}
|
||||
icon={<LocationOnOutlined />}
|
||||
iconColor="info"
|
||||
action={
|
||||
<IconButton size="small" onClick={fetchIpInfo}>
|
||||
<RefreshOutlined />
|
||||
</IconButton>
|
||||
}
|
||||
>
|
||||
<Box sx={{ height: "100%", display: "flex", flexDirection: "column" }}>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
flex: 1,
|
||||
overflow: "hidden",
|
||||
}}
|
||||
>
|
||||
{/* 左侧:国家和IP地址 */}
|
||||
<Box sx={{ width: "40%", overflow: "hidden" }}>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
mb: 1,
|
||||
overflow: "hidden",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
component="span"
|
||||
sx={{
|
||||
fontSize: "1.5rem",
|
||||
mr: 1,
|
||||
display: "inline-block",
|
||||
width: 28,
|
||||
textAlign: "center",
|
||||
flexShrink: 0,
|
||||
fontFamily: '"twemoji mozilla", sans-serif',
|
||||
}}
|
||||
>
|
||||
{getCountryFlag(ipInfo?.country_code)}
|
||||
</Box>
|
||||
<Typography
|
||||
variant="subtitle1"
|
||||
sx={{
|
||||
fontWeight: "medium",
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
maxWidth: "100%",
|
||||
}}
|
||||
>
|
||||
{ipInfo?.country || t("Unknown")}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: "flex", alignItems: "center", mb: 1 }}>
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
sx={{ flexShrink: 0 }}
|
||||
>
|
||||
{t("IP")}:
|
||||
</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
ml: 1,
|
||||
overflow: "hidden",
|
||||
maxWidth: "calc(100% - 30px)",
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
variant="body2"
|
||||
sx={{
|
||||
fontFamily: "monospace",
|
||||
fontSize: "0.75rem",
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
wordBreak: "break-all",
|
||||
}}
|
||||
>
|
||||
{showIp ? ipInfo?.ip : "••••••••••"}
|
||||
</Typography>
|
||||
<IconButton size="small" onClick={toggleShowIp}>
|
||||
{showIp ? (
|
||||
<VisibilityOffOutlined fontSize="small" />
|
||||
) : (
|
||||
<VisibilityOutlined fontSize="small" />
|
||||
)}
|
||||
</IconButton>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<InfoItem
|
||||
label={t("ASN")}
|
||||
value={ipInfo?.asn ? `AS${ipInfo.asn}` : "N/A"}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
{/* 右侧:组织、ISP和位置信息 */}
|
||||
<Box sx={{ width: "60%", overflow: "auto" }}>
|
||||
<InfoItem label={t("ISP")} value={ipInfo?.isp} />
|
||||
<InfoItem label={t("ORG")} value={ipInfo?.asn_organization} />
|
||||
<InfoItem
|
||||
label={t("Location")}
|
||||
value={[ipInfo?.city, ipInfo?.region]
|
||||
.filter(Boolean)
|
||||
.join(", ")}
|
||||
/>
|
||||
<InfoItem label={t("Timezone")} value={ipInfo?.timezone} />
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Box
|
||||
sx={{
|
||||
mt: "auto",
|
||||
pt: 0.5,
|
||||
borderTop: 1,
|
||||
borderColor: "divider",
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
opacity: 0.7,
|
||||
fontSize: "0.7rem",
|
||||
}}
|
||||
>
|
||||
<Typography variant="caption">
|
||||
{t("Auto refresh")}: {countdown}s
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
sx={{
|
||||
textOverflow: "ellipsis",
|
||||
overflow: "hidden",
|
||||
whiteSpace: "nowrap",
|
||||
}}
|
||||
>
|
||||
{ipInfo?.country_code}, {ipInfo?.longitude?.toFixed(2)},{" "}
|
||||
{ipInfo?.latitude?.toFixed(2)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
</EnhancedCard>
|
||||
);
|
||||
};
|
246
src/components/home/proxy-tun-card.tsx
Normal file
246
src/components/home/proxy-tun-card.tsx
Normal file
@ -0,0 +1,246 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Box,
|
||||
Typography,
|
||||
Stack,
|
||||
Paper,
|
||||
Tooltip,
|
||||
alpha,
|
||||
useTheme,
|
||||
Fade,
|
||||
} from "@mui/material";
|
||||
import { useState, useMemo, memo, FC } from "react";
|
||||
import ProxyControlSwitches from "@/components/shared/ProxyControlSwitches";
|
||||
import { Notice } from "@/components/base";
|
||||
import {
|
||||
ComputerRounded,
|
||||
TroubleshootRounded,
|
||||
HelpOutlineRounded,
|
||||
SvgIconComponent,
|
||||
} from "@mui/icons-material";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import { useSystemState } from "@/hooks/use-system-state";
|
||||
|
||||
const LOCAL_STORAGE_TAB_KEY = "clash-verge-proxy-active-tab";
|
||||
|
||||
interface TabButtonProps {
|
||||
isActive: boolean;
|
||||
onClick: () => void;
|
||||
icon: SvgIconComponent;
|
||||
label: string;
|
||||
hasIndicator?: boolean;
|
||||
}
|
||||
|
||||
// 抽取Tab组件以减少重复代码
|
||||
const TabButton: FC<TabButtonProps> = memo(
|
||||
({ isActive, onClick, icon: Icon, label, hasIndicator = false }) => (
|
||||
<Paper
|
||||
elevation={isActive ? 2 : 0}
|
||||
onClick={onClick}
|
||||
sx={{
|
||||
cursor: "pointer",
|
||||
px: 2,
|
||||
py: 1,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
gap: 1,
|
||||
bgcolor: isActive ? "primary.main" : "background.paper",
|
||||
color: isActive ? "primary.contrastText" : "text.primary",
|
||||
borderRadius: 1.5,
|
||||
flex: 1,
|
||||
maxWidth: 160,
|
||||
transition: "all 0.2s ease-in-out",
|
||||
position: "relative",
|
||||
"&:hover": {
|
||||
transform: "translateY(-1px)",
|
||||
boxShadow: 1,
|
||||
},
|
||||
"&:after": isActive
|
||||
? {
|
||||
content: '""',
|
||||
position: "absolute",
|
||||
bottom: -9,
|
||||
left: "50%",
|
||||
width: 2,
|
||||
height: 9,
|
||||
bgcolor: "primary.main",
|
||||
transform: "translateX(-50%)",
|
||||
}
|
||||
: {},
|
||||
}}
|
||||
>
|
||||
<Icon fontSize="small" />
|
||||
<Typography variant="body2" sx={{ fontWeight: isActive ? 600 : 400 }}>
|
||||
{label}
|
||||
</Typography>
|
||||
{hasIndicator && (
|
||||
<Box
|
||||
sx={{
|
||||
width: 8,
|
||||
height: 8,
|
||||
borderRadius: "50%",
|
||||
bgcolor: isActive ? "#fff" : "success.main",
|
||||
position: "absolute",
|
||||
top: 8,
|
||||
right: 8,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Paper>
|
||||
),
|
||||
);
|
||||
|
||||
interface TabDescriptionProps {
|
||||
description: string;
|
||||
tooltipTitle: string;
|
||||
}
|
||||
|
||||
// 抽取描述文本组件
|
||||
const TabDescription: FC<TabDescriptionProps> = memo(
|
||||
({ description, tooltipTitle }) => (
|
||||
<Fade in={true} timeout={200}>
|
||||
<Typography
|
||||
variant="caption"
|
||||
component="div"
|
||||
sx={{
|
||||
width: "95%",
|
||||
textAlign: "center",
|
||||
color: "text.secondary",
|
||||
p: 0.8,
|
||||
borderRadius: 1,
|
||||
borderColor: "primary.main",
|
||||
borderWidth: 1,
|
||||
borderStyle: "solid",
|
||||
backgroundColor: "background.paper",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
gap: 0.5,
|
||||
wordBreak: "break-word",
|
||||
hyphens: "auto",
|
||||
}}
|
||||
>
|
||||
{description}
|
||||
<Tooltip title={tooltipTitle}>
|
||||
<HelpOutlineRounded
|
||||
sx={{ fontSize: 14, opacity: 0.7, flexShrink: 0 }}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Typography>
|
||||
</Fade>
|
||||
),
|
||||
);
|
||||
|
||||
export const ProxyTunCard: FC = () => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const [activeTab, setActiveTab] = useState<string>(
|
||||
() => localStorage.getItem(LOCAL_STORAGE_TAB_KEY) || "system",
|
||||
);
|
||||
|
||||
// 获取代理状态信息
|
||||
const { verge } = useVerge();
|
||||
const { isSidecarMode, isAdminMode } = useSystemState();
|
||||
|
||||
// 从verge配置中获取开关状态
|
||||
const { enable_system_proxy, enable_tun_mode } = verge ?? {};
|
||||
|
||||
// 判断Tun模式是否可用 - 当处于服务模式或管理员模式时可用
|
||||
const isTunAvailable = !isSidecarMode || isAdminMode;
|
||||
|
||||
// 处理错误
|
||||
const handleError = (err: Error) => {
|
||||
Notice.error(err.message || err.toString(), 3000);
|
||||
};
|
||||
|
||||
// 处理标签切换并保存到localStorage
|
||||
const handleTabChange = (tab: string) => {
|
||||
setActiveTab(tab);
|
||||
localStorage.setItem(LOCAL_STORAGE_TAB_KEY, tab);
|
||||
};
|
||||
|
||||
// 用户提示文本 - 使用useMemo避免重复计算
|
||||
const tabDescription = useMemo(() => {
|
||||
if (activeTab === "system") {
|
||||
return {
|
||||
text: enable_system_proxy
|
||||
? t("System Proxy Enabled")
|
||||
: t("System Proxy Disabled"),
|
||||
tooltip: t("System Proxy Info"),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
text: !isTunAvailable
|
||||
? t("TUN Mode Service Required")
|
||||
: enable_tun_mode
|
||||
? t("TUN Mode Enabled")
|
||||
: t("TUN Mode Disabled"),
|
||||
tooltip: t("TUN Mode Intercept Info"),
|
||||
};
|
||||
}
|
||||
}, [activeTab, enable_system_proxy, enable_tun_mode, isTunAvailable, t]);
|
||||
|
||||
return (
|
||||
<Box sx={{ display: "flex", flexDirection: "column", width: "100%" }}>
|
||||
{/* 选项卡 */}
|
||||
<Stack
|
||||
direction="row"
|
||||
spacing={1}
|
||||
sx={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
position: "relative",
|
||||
zIndex: 2,
|
||||
}}
|
||||
>
|
||||
<TabButton
|
||||
isActive={activeTab === "system"}
|
||||
onClick={() => handleTabChange("system")}
|
||||
icon={ComputerRounded}
|
||||
label={t("System Proxy")}
|
||||
hasIndicator={enable_system_proxy}
|
||||
/>
|
||||
<TabButton
|
||||
isActive={activeTab === "tun"}
|
||||
onClick={() => handleTabChange("tun")}
|
||||
icon={TroubleshootRounded}
|
||||
label={t("Tun Mode")}
|
||||
hasIndicator={enable_tun_mode && isTunAvailable}
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
{/* 说明文本区域 */}
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
my: 1,
|
||||
position: "relative",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
overflow: "visible",
|
||||
}}
|
||||
>
|
||||
<TabDescription
|
||||
description={tabDescription.text}
|
||||
tooltipTitle={tabDescription.tooltip}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
{/* 控制开关部分 */}
|
||||
<Box
|
||||
sx={{
|
||||
mt: 0,
|
||||
p: 1,
|
||||
bgcolor: alpha(theme.palette.primary.main, 0.04),
|
||||
borderRadius: 2,
|
||||
}}
|
||||
>
|
||||
<ProxyControlSwitches
|
||||
onError={handleError}
|
||||
label={activeTab === "system" ? t("System Proxy") : t("Tun Mode")}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user