mirror of
https://github.com/EasyTier/EasytierGame.git
synced 2026-09-20 03:21:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0da1ab85cd | ||
|
|
b1d1144e78 | ||
|
|
d71b93c1a8 | ||
|
|
9e83ca7d91 | ||
|
|
c10a3ae22f | ||
|
|
6f5e0a85f8 | ||
|
|
ae42baa73a |
+7
-7
@@ -22,7 +22,7 @@ async function toggleVisibility() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function useTray(init: boolean = false, beforExit: Function, handleConnection: Function, handleReconnect: Function) {
|
||||
export async function useTray(init: boolean = false, beforExit: Function, handleConnection: Function, handleReconnect: Function, handleNodesList: Function) {
|
||||
let tray;
|
||||
try {
|
||||
tray = await TrayIcon.getById(DEFAULT_TRAY_NAME);
|
||||
@@ -31,7 +31,7 @@ export async function useTray(init: boolean = false, beforExit: Function, handle
|
||||
tooltip: `EasyTierGame\n${pkg.version}`,
|
||||
title: `EasyTierGame\n${pkg.version}`,
|
||||
id: DEFAULT_TRAY_NAME,
|
||||
menu: await Menu.new({ id: "main", items: await generateMenuItem(beforExit, handleConnection, handleReconnect) }),
|
||||
menu: await Menu.new({ id: "main", items: await generateMenuItem(beforExit, handleConnection, handleReconnect, handleNodesList) }),
|
||||
action: async e => {
|
||||
toggleVisibility();
|
||||
}
|
||||
@@ -45,20 +45,20 @@ export async function useTray(init: boolean = false, beforExit: Function, handle
|
||||
if (init) {
|
||||
tray.setTooltip(`EasyTierGame\n${pkg.version}`);
|
||||
tray.setShowMenuOnLeftClick(false);
|
||||
tray.setMenu(await Menu.new({ id: "main", items: await generateMenuItem(beforExit, handleConnection, handleReconnect) }));
|
||||
tray.setMenu(await Menu.new({ id: "main", items: await generateMenuItem(beforExit, handleConnection, handleReconnect, handleNodesList) }));
|
||||
}
|
||||
|
||||
return tray;
|
||||
}
|
||||
|
||||
export async function generateMenuItem(beforExit: Function, handleConnection: Function, handleReconnect: Function) {
|
||||
export async function generateMenuItem(beforExit: Function, handleConnection: Function, handleReconnect: Function, handleNodesList: Function) {
|
||||
return [
|
||||
await MenuItemShow("显示 / 隐藏"),
|
||||
await MenuItemExchangeConnection("联机 / 断开", handleConnection),
|
||||
await MenuItemReconnect("重新联机", handleReconnect),
|
||||
await MenuItemTheme(),
|
||||
await PredefinedMenuItem.new({ item: "Separator" }),
|
||||
await MenuItemPublicPeers(),
|
||||
await MenuItemPublicPeers(handleNodesList),
|
||||
await PredefinedMenuItem.new({ item: "Separator" }),
|
||||
await MenuItemExit("退出", beforExit)
|
||||
];
|
||||
@@ -87,12 +87,12 @@ export async function MenuItemExit(text: string, beforExit: Function) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function MenuItemPublicPeers() {
|
||||
export async function MenuItemPublicPeers(handleNodesList: Function) {
|
||||
return await MenuItem.new({
|
||||
id: "publicPeers",
|
||||
text: "公共节点",
|
||||
action: async () => {
|
||||
await open(import.meta.env.VITE_PUBLIC_PEERS_URL);
|
||||
await handleNodesList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+12
-12
@@ -3,7 +3,7 @@
|
||||
"private": true,
|
||||
"author": "leizi97",
|
||||
"description": "A simple network initiator based on Easytier",
|
||||
"version": "1.4.9",
|
||||
"version": "1.5.1",
|
||||
"scripts": {
|
||||
"dev": "nuxt dev --dotenv env/.env.dev --host 0.0.0.0",
|
||||
"build": "nuxt generate --dotenv env/.env.prod",
|
||||
@@ -11,29 +11,29 @@
|
||||
"release-win7": "node zip.js win7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"@element-plus/nuxt": "1.1.4",
|
||||
"@nuxtjs/tailwindcss": "6.13.2",
|
||||
"@pinia/nuxt": "0.11.1",
|
||||
"@tauri-apps/api": "2.7.0",
|
||||
"@tauri-apps/cli": "2.7.1",
|
||||
"@pinia/nuxt": "0.11.2",
|
||||
"@tauri-apps/api": "2.9.0",
|
||||
"@tauri-apps/cli": "2.9.1",
|
||||
"@tauri-apps/plugin-cli": "2.4.0",
|
||||
"@tauri-apps/plugin-clipboard-manager": "2.3.0",
|
||||
"@tauri-apps/plugin-dialog": "2.3.1",
|
||||
"@tauri-apps/plugin-fs": "2.4.1",
|
||||
"@tauri-apps/plugin-log": "2.6.0",
|
||||
"@tauri-apps/plugin-shell": "2.3.0",
|
||||
"@tauri-apps/plugin-dialog": "2.4.0",
|
||||
"@tauri-apps/plugin-fs": "2.4.2",
|
||||
"@tauri-apps/plugin-log": "2.7.0",
|
||||
"@tauri-apps/plugin-shell": "2.3.1",
|
||||
"@tauri-apps/plugin-window-state": "2.4.0",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@vitejs/plugin-vue-jsx": "5.0.1",
|
||||
"@vitejs/plugin-vue-jsx": "5.1.1",
|
||||
"@vueuse/core": "12.7.0",
|
||||
"archiver": "^7.0.1",
|
||||
"element-plus": "2.10.7",
|
||||
"element-plus": "2.11.5",
|
||||
"less": "4.2.1",
|
||||
"lodash-es": "^4.17.21",
|
||||
"nuxt": "3.19.2",
|
||||
"pinia": "3.0.3",
|
||||
"pinia-plugin-persistedstate": "4.4.1",
|
||||
"pinia-plugin-persistedstate": "4.5.0",
|
||||
"postcss": "^8.4.38",
|
||||
"prettier": "3.6.2",
|
||||
"prettier-plugin-tailwindcss": "0.6.14"
|
||||
|
||||
+2
-11
@@ -69,7 +69,7 @@
|
||||
data.isRunning = true;
|
||||
const [error, member] = await ATJ(invoke<string>("get_route_by_cli"));
|
||||
data.isRunning = false;
|
||||
// if(!member) return;
|
||||
if(!member) return;
|
||||
if (error) {
|
||||
data.route = [];
|
||||
return "";
|
||||
@@ -79,16 +79,7 @@
|
||||
await listenOutput();
|
||||
return;
|
||||
}
|
||||
const routeInfo = parseCliInfo(member);
|
||||
routeInfo.forEach(value => {
|
||||
if (value.cost === "Local") {
|
||||
value.cost = "本机";
|
||||
}
|
||||
if (value.ipv4 && value.ipv4.includes("/")) {
|
||||
value.ipv4 = value.ipv4.split("/")[0];
|
||||
}
|
||||
});
|
||||
data.route = routeInfo;
|
||||
data.route = JSON.parse(member);
|
||||
};
|
||||
|
||||
const listenStart = async () => {
|
||||
|
||||
+129
-4
@@ -67,6 +67,7 @@
|
||||
</template>
|
||||
<ElSelect
|
||||
allow-create
|
||||
:reserve-keyword="false"
|
||||
filterable
|
||||
multiple
|
||||
collapse-tags
|
||||
@@ -101,7 +102,7 @@
|
||||
type="primary"
|
||||
size="small"
|
||||
underline="never"
|
||||
@click.stop="open(publicPeersLink)"
|
||||
@click.stop="handleShowPublicServersDialog"
|
||||
>
|
||||
其他公共服务器
|
||||
</ElLink>
|
||||
@@ -804,6 +805,9 @@
|
||||
},
|
||||
async () => {
|
||||
await handleReconnect();
|
||||
},
|
||||
async () => {
|
||||
await handleShowPublicServersDialog();
|
||||
}
|
||||
);
|
||||
|
||||
@@ -817,6 +821,7 @@
|
||||
advanceVisible: false,
|
||||
toolVisible: false,
|
||||
gameListVisible: false,
|
||||
nodesListVisible: false,
|
||||
serverVisible: false,
|
||||
winipBcPid: 0, //WinIPBroadcast进程id
|
||||
winipBcStart: false,
|
||||
@@ -958,7 +963,7 @@
|
||||
// console.log(mainStore.config.serverUrl);
|
||||
for (const p of protocols) {
|
||||
for (const url of mainStore.config.serverUrl) {
|
||||
if (url.toLowerCase().startsWith(`${p}://`)) {
|
||||
if (url.replace(/\\/g, "/").toLowerCase().startsWith(`${p}://`)) {
|
||||
inputProtocols.push(p);
|
||||
}
|
||||
}
|
||||
@@ -967,8 +972,8 @@
|
||||
mainStore.config.protocol = uniq([...mainStore.config.protocol, ...inputProtocols]);
|
||||
mainStore.config.serverUrl = (mainStore.config.serverUrl || []).map(url => {
|
||||
for (const p of protocols) {
|
||||
if (url.toLowerCase().startsWith(`${p}://`)) {
|
||||
return url.slice(inputProtocols.length + 3);
|
||||
if (url.replace(/\\/g, "/").toLowerCase().startsWith(`${p}://`)) {
|
||||
return url.slice(p.length + 3);
|
||||
}
|
||||
}
|
||||
return url;
|
||||
@@ -1146,6 +1151,28 @@
|
||||
// await getReleaseList();
|
||||
};
|
||||
|
||||
const handleShowPublicServersDialog = async () => {
|
||||
await etWindows(
|
||||
"nodesList",
|
||||
{
|
||||
title: "公共服务器节点",
|
||||
width: 1000,
|
||||
height: 600,
|
||||
minWidth: 800,
|
||||
minHeight: 500,
|
||||
resizable: true,
|
||||
url: "#/nodesList"
|
||||
},
|
||||
(_, appWindow) => {
|
||||
data.nodesListVisible = true;
|
||||
},
|
||||
() => {
|
||||
data.nodesListVisible = false;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
let unlistenDownload: UnlistenFn | null = null;
|
||||
let unlistenDownloadError: UnlistenFn | null = null;
|
||||
let progress = ref<number>(0);
|
||||
@@ -1359,6 +1386,101 @@
|
||||
});
|
||||
};
|
||||
|
||||
// 过滤可用节点的函数
|
||||
const filterAvailableNodes = (nodes: NodeItem[]): NodeItem[] => {
|
||||
return nodes.filter(node => {
|
||||
// 基本条件:节点必须激活且被批准
|
||||
if (!node.is_active || !node.is_approved) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 健康状态检查
|
||||
if (node.current_health_status !== "healthy") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 使用率检查:使用率不能超过95%
|
||||
if (node.usage_percentage > 95) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 24小时健康率检查:必须大于90%
|
||||
if (node.health_percentage_24h < 90) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 响应时间检查:响应时间不能超过60秒
|
||||
if (node.last_response_time > 60000) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 连接数检查:当前连接数不能超过最大连接数的90%
|
||||
if (node.current_connections > node.max_connections * 0.9) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 必须有有效的地址
|
||||
if (!node.address || !node.host || !node.port) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
// 按优先级排序节点的函数
|
||||
const sortNodesByPriority = (nodes: NodeItem[]): NodeItem[] => {
|
||||
return nodes.sort((a, b) => {
|
||||
// 优先级排序规则:
|
||||
// 1. 响应时间越短越好
|
||||
// 2. 使用率越低越好
|
||||
// 3. 24小时健康率越高越好
|
||||
// 4. 当前连接数越少越好
|
||||
|
||||
// 响应时间权重最高
|
||||
const responseTimeDiff = a.last_response_time - b.last_response_time;
|
||||
if (Math.abs(responseTimeDiff) > 1000) {
|
||||
// 如果响应时间差异超过1秒
|
||||
return responseTimeDiff;
|
||||
}
|
||||
|
||||
// 使用率权重次之
|
||||
const usageDiff = a.usage_percentage - b.usage_percentage;
|
||||
if (Math.abs(usageDiff) > 5) {
|
||||
// 如果使用率差异超过5%
|
||||
return usageDiff;
|
||||
}
|
||||
|
||||
// 24小时健康率
|
||||
const healthDiff = b.health_percentage_24h - a.health_percentage_24h;
|
||||
if (Math.abs(healthDiff) > 1) {
|
||||
// 如果健康率差异超过1%
|
||||
return healthDiff;
|
||||
}
|
||||
|
||||
// 当前连接数
|
||||
return a.current_connections - b.current_connections;
|
||||
});
|
||||
};
|
||||
|
||||
// 将节点添加到服务器列表的函数
|
||||
const addNodesToServerList = (nodes: NodeItem[]) => {
|
||||
// 提取服务器地址
|
||||
const serverAddresses = nodes.map(node => node.address.replace(`${node.protocol}://`, ""));
|
||||
|
||||
// 去重并添加到基础服务器列表
|
||||
const uniqueAddresses = uniq([...serverAddresses, ...mainStore.basePeers]);
|
||||
mainStore.basePeers = uniqueAddresses;
|
||||
|
||||
// 如果当前没有选择服务器,自动选择第一个最佳节点
|
||||
if (mainStore.config.serverUrl.length === 0 && serverAddresses.length > 0) {
|
||||
mainStore.config.serverUrl = [serverAddresses[0]];
|
||||
console.log(`自动选择最佳服务器: ${serverAddresses[0]}`);
|
||||
}
|
||||
|
||||
console.log(`已添加 ${serverAddresses.length} 个可用服务器到列表`);
|
||||
};
|
||||
|
||||
let logsTimer: number | null = null;
|
||||
let serverLogsTimer: number | null = null;
|
||||
let cidrTimer: number | null = null;
|
||||
@@ -1384,6 +1506,7 @@
|
||||
checkNewVersion();
|
||||
}
|
||||
await storageDialog();
|
||||
|
||||
});
|
||||
|
||||
// storageEventEmitter.addEventListener("localStorageChange", () => {
|
||||
@@ -1396,6 +1519,7 @@
|
||||
return data.configJsonSeverUrl;
|
||||
});
|
||||
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
unListenAll();
|
||||
listenObj.unListenReleaseList && listenObj.unListenReleaseList();
|
||||
@@ -1405,6 +1529,7 @@
|
||||
cidrTimer && clearInterval(cidrTimer);
|
||||
stopPreventSleep();
|
||||
// unListenStorage && unListenStorage();
|
||||
|
||||
});
|
||||
|
||||
const getArgs = async () => {
|
||||
|
||||
+104
-49
@@ -15,16 +15,31 @@
|
||||
>
|
||||
<ElTableColumn
|
||||
sortable
|
||||
width="140"
|
||||
label="成员名"
|
||||
prop="hostname"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
{{
|
||||
(row.hostname || "").toLowerCase().includes("publicserver")
|
||||
? (row.hostname || "").replace("PublicServer", "服务器")
|
||||
: row.hostname || "-"
|
||||
}}
|
||||
<div class="whitespace-pre-wrap">
|
||||
<div>
|
||||
{{
|
||||
(row.hostname || "").toLowerCase().includes("publicserver")
|
||||
? (row.hostname || "").replace("PublicServer", "服务器")
|
||||
: row.hostname || "-"
|
||||
}}
|
||||
</div>
|
||||
<div
|
||||
class="space-y-1"
|
||||
v-if="row?.connections_addrs?.length > 0"
|
||||
>
|
||||
<ElTag
|
||||
:key="url"
|
||||
v-for="url in row.connections_addrs"
|
||||
class="!flex !h-auto !whitespace-pre-wrap !break-all !py-[5px]"
|
||||
>
|
||||
{{ url }}
|
||||
</ElTag>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn
|
||||
@@ -70,7 +85,13 @@
|
||||
label="丢包率"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
{{ row.loss_rate && row.loss_rate != "-" ? Number(row.loss_rate * 100).toFixed(2) + "%" : row.loss_rate }}
|
||||
{{
|
||||
row.loss_rate && row.loss_rate != "-"
|
||||
? row.loss_rate.endsWith("%")
|
||||
? row.loss_rate
|
||||
: Number(row.loss_rate * 100).toFixed(2) + "%"
|
||||
: row.loss_rate
|
||||
}}
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn
|
||||
@@ -107,7 +128,7 @@
|
||||
sortable
|
||||
prop="tx_bytes"
|
||||
label="传输"
|
||||
:sort-method="(a, b) => sortBytes(a, b, 'tx_bytes')"
|
||||
:sort-method="(a: any, b: any) => sortBytes(a, b, 'tx_bytes')"
|
||||
:sort-orders="['ascending', 'descending', null]"
|
||||
></ElTableColumn>
|
||||
</ElTable>
|
||||
@@ -120,20 +141,62 @@
|
||||
import { ATJ, parseCliInfo } from "@/utils";
|
||||
import { ElConfirmDanger } from "~/utils/element";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { isNaN } from "lodash-es";
|
||||
// enum NatType {
|
||||
// // has NAT; but own a single public IP, port is not changed
|
||||
// Unknown = 0;
|
||||
// OpenInternet = 1;
|
||||
// NoPAT = 2;
|
||||
// FullCone = 3;
|
||||
// Restricted = 4;
|
||||
// PortRestricted = 5;
|
||||
// Symmetric = 6;
|
||||
// SymUdpFirewall = 7;
|
||||
// SymmetricEasyInc = 8;
|
||||
// SymmetricEasyDec = 9;
|
||||
// }
|
||||
import { endsWith, isNaN } from "lodash-es";
|
||||
|
||||
type Member = {
|
||||
cidr: string;
|
||||
ipv4: string;
|
||||
hostname: string;
|
||||
cost: string;
|
||||
lat_ms: string;
|
||||
loss_rate: string;
|
||||
rx_bytes: string;
|
||||
tx_bytes: string;
|
||||
tunnel_proto: string;
|
||||
nat_type: string;
|
||||
id: string;
|
||||
version: string;
|
||||
connections_addrs: string[];
|
||||
};
|
||||
|
||||
type ConnectionsType = {
|
||||
route: {
|
||||
peer_id: number;
|
||||
ipv4_addr: string | null;
|
||||
next_hop_peer_id: number;
|
||||
cost: number;
|
||||
path_latency: number;
|
||||
proxy_cidrs: string[];
|
||||
hostname: string;
|
||||
stun_info: {
|
||||
udp_nat_type: number;
|
||||
tcp_nat_type: number;
|
||||
last_update_time: number;
|
||||
public_ip: string[];
|
||||
min_port: number;
|
||||
max_port: number;
|
||||
};
|
||||
};
|
||||
peer: {
|
||||
peer_id: number;
|
||||
conns: {
|
||||
conn_id: string;
|
||||
my_peer_id: number;
|
||||
peer_id: number;
|
||||
features: string[];
|
||||
tunnel: {
|
||||
tunnel_type: string;
|
||||
local_addr: {
|
||||
url: string;
|
||||
};
|
||||
remote_addr: {
|
||||
url: string;
|
||||
};
|
||||
};
|
||||
}[];
|
||||
};
|
||||
};
|
||||
|
||||
const natMaps = {
|
||||
unknown: "未知",
|
||||
OpenInternet: "nat0-openinternet",
|
||||
@@ -148,13 +211,13 @@
|
||||
};
|
||||
type natKyes = keyof typeof natMaps;
|
||||
|
||||
const data = reactive<{ member: { hostname: string; cost: string; ipv4: string; lat_msg: string; loss_rate: string; nat_type: string }[] }>({
|
||||
const data = reactive<{ member: Member[] }>({
|
||||
member: []
|
||||
});
|
||||
|
||||
// 延迟排序函数
|
||||
const sortLatMs = (a: any, b: any): number => {
|
||||
const getLatencyValue = (row: any): number => {
|
||||
const sortLatMs = (a: Member, b: Member): number => {
|
||||
const getLatencyValue = (row: Member): number => {
|
||||
const latMs = row.lat_ms;
|
||||
|
||||
if (latMs === null || latMs === undefined || latMs === "") {
|
||||
@@ -292,19 +355,6 @@
|
||||
return num.toFixed(0);
|
||||
};
|
||||
|
||||
const _showTableHeader = [
|
||||
["hostname", "主机名"],
|
||||
["cost", "路由"],
|
||||
["ipv4", "虚拟网IP"],
|
||||
["lat_ms", "延迟/ms"],
|
||||
["loss_rate", "丢包率"],
|
||||
["nat_type", "NAT类型"],
|
||||
["version", "版本"],
|
||||
["tunnel_proto", "隧道协议"],
|
||||
["rx_bytes", "接收"],
|
||||
["tx_bytes", "传输"]
|
||||
];
|
||||
|
||||
let timer: number | null = null;
|
||||
|
||||
const listenOutput = async () => {
|
||||
@@ -328,18 +378,23 @@
|
||||
}
|
||||
return;
|
||||
}
|
||||
// const peerInfo = parseCliInfo(member);
|
||||
// peerInfo.forEach(value => {
|
||||
// if (value.cost === "Local") {
|
||||
// value.cost = "本机";
|
||||
// }
|
||||
// if (value.ipv4 && value.ipv4.includes("/")) {
|
||||
// value.ipv4 = value.ipv4.split("/")[0];
|
||||
// }
|
||||
// });
|
||||
// data.member = peerInfo;
|
||||
const [errorConnections, connections] = await ATJ(invoke<string>("get_members_connections_cli"));
|
||||
const memberConnections: ConnectionsType[] = JSON.parse(connections) as ConnectionsType[];
|
||||
|
||||
data.member = JSON.parse(member);
|
||||
if (errorConnections != "_EasytierGameCliFailedToGetConnections_") {
|
||||
data.member = (JSON.parse(member) as Member[]).map(member => {
|
||||
const connection = memberConnections.find(conn => String(conn.route.peer_id) === member.id);
|
||||
if (connection) {
|
||||
member.connections_addrs = connection?.peer?.conns?.map(conn => conn?.tunnel?.remote_addr?.url || "") || [];
|
||||
} else {
|
||||
member.connections_addrs = [];
|
||||
}
|
||||
return member;
|
||||
});
|
||||
} else {
|
||||
data.member = JSON.parse(member) as Member[];
|
||||
}
|
||||
// console.log(data.member);
|
||||
startTimer();
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,364 @@
|
||||
<template>
|
||||
<div class="relative flex h-full flex-col flex-wrap gap-[0] overflow-hidden">
|
||||
<div class="flex h-[40px] w-full flex-nowrap items-center gap-[0_5px]">
|
||||
<div class="ml-[5px] mr-auto flex flex-1">
|
||||
<ElText class="text-lg font-semibold">公共服务器节点列表</ElText>
|
||||
</div>
|
||||
<div>
|
||||
<ElButton
|
||||
:loading="loading"
|
||||
size="small"
|
||||
type="primary"
|
||||
class="mr-[5px]"
|
||||
@click="refreshNodes"
|
||||
>
|
||||
刷新
|
||||
</ElButton>
|
||||
<ElButton
|
||||
:disabled="selectedNodes.length === 0"
|
||||
size="small"
|
||||
type="success"
|
||||
class="mr-[5px]"
|
||||
@click="addSelectedToServerList"
|
||||
>
|
||||
添加选中 ({{ selectedNodes.length }})
|
||||
</ElButton>
|
||||
<ElTag
|
||||
v-if="lastUpdateTime"
|
||||
size="small"
|
||||
type="info"
|
||||
>
|
||||
最后更新: {{ lastUpdateTime }}
|
||||
</ElTag>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex w-full flex-1 flex-wrap gap-[0] overflow-auto">
|
||||
<ElTable
|
||||
:data="nodes"
|
||||
stripe
|
||||
height="100%"
|
||||
ref="tableRef"
|
||||
:empty-text="loading ? '加载中...' : '暂无可用服务器'"
|
||||
:default-sort="{ prop: 'last_response_time', order: 'ascending' }"
|
||||
@selection-change="handleSelectionChange"
|
||||
@row-click="handleRowClick"
|
||||
>
|
||||
<ElTableColumn
|
||||
type="selection"
|
||||
width="55"
|
||||
/>
|
||||
<ElTableColumn
|
||||
prop="name"
|
||||
label="服务器名称"
|
||||
width="200"
|
||||
show-overflow-tooltip
|
||||
sortable
|
||||
/>
|
||||
<ElTableColumn
|
||||
prop="protocol"
|
||||
label="协议"
|
||||
width="80"
|
||||
sortable
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<ElTag
|
||||
:type="row.protocol === 'tcp' ? 'success' : 'warning'"
|
||||
size="small"
|
||||
>
|
||||
{{ row.protocol.toUpperCase() }}
|
||||
</ElTag>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn
|
||||
prop="address"
|
||||
label="地址"
|
||||
width="200"
|
||||
show-overflow-tooltip
|
||||
sortable
|
||||
/>
|
||||
<ElTableColumn
|
||||
prop="last_response_time"
|
||||
label="响应时间"
|
||||
width="100"
|
||||
sortable
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<ElTag
|
||||
:type="getResponseTimeType(row.last_response_time)"
|
||||
size="small"
|
||||
>
|
||||
{{ Number(row.last_response_time / 1000).toFixed(2) }}ms
|
||||
</ElTag>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn
|
||||
prop="current_health_status"
|
||||
label="状态/健康率"
|
||||
width="120"
|
||||
sortable
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<div class="flex flex-col gap-1">
|
||||
<ElTag
|
||||
:type="row.current_health_status === 'healthy' ? 'success' : 'danger'"
|
||||
size="small"
|
||||
>
|
||||
{{ row.current_health_status === "healthy" ? "健康" : "异常" }}
|
||||
</ElTag>
|
||||
<ElTag
|
||||
:type="getHealthType(row.health_percentage_24h)"
|
||||
size="small"
|
||||
>
|
||||
{{ Number(row.health_percentage_24h).toFixed(1) }}%
|
||||
</ElTag>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn
|
||||
prop="usage_percentage"
|
||||
label="使用率"
|
||||
width="100"
|
||||
sortable
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<div class="flex items-center">
|
||||
<ElProgress
|
||||
:percentage="row.usage_percentage"
|
||||
:stroke-width="6"
|
||||
:show-text="false"
|
||||
:color="getUsageColor(row.usage_percentage)"
|
||||
class="mr-2 flex-1"
|
||||
/>
|
||||
<span class="text-xs">{{ row.usage_percentage.toFixed(1) }}%</span>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn
|
||||
prop="description"
|
||||
label="描述"
|
||||
width="300"
|
||||
sortable
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<div class="whitespace-pre-wrap">{{ row.description }}</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import useMainStore from "@/stores/index";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { reactive, onMounted, onBeforeUnmount, ref, useTemplateRef } from "vue";
|
||||
import { ElMessage, type TableInstance } from "element-plus";
|
||||
import { dataSubscribe } from "~/composables/windows";
|
||||
import { uniq } from "lodash-es";
|
||||
|
||||
const mainStore = useMainStore();
|
||||
// 节点数据
|
||||
const nodes = reactive<NodeItem[]>([]);
|
||||
const loading = ref(false);
|
||||
const lastUpdateTime = ref("");
|
||||
const selectedNodes = ref<NodeItem[]>([]);
|
||||
const tableRef = useTemplateRef<TableInstance>("tableRef");
|
||||
|
||||
// 定时器
|
||||
let refreshTimer: number | null = null;
|
||||
|
||||
// 获取使用率颜色
|
||||
const getUsageColor = (percentage: number) => {
|
||||
if (percentage < 50) return "#67c23a";
|
||||
if (percentage < 80) return "#e6a23c";
|
||||
return "#f56c6c";
|
||||
};
|
||||
|
||||
// 获取响应时间类型
|
||||
const getResponseTimeType = (responseTime: number) => {
|
||||
if (responseTime < 60 * 1000) return "success";
|
||||
if (responseTime < 100 * 1000) return "warning";
|
||||
return "danger";
|
||||
};
|
||||
|
||||
// 获取健康率类型
|
||||
const getHealthType = (health: number) => {
|
||||
if (health >= 95) return "success";
|
||||
if (health >= 90) return "warning";
|
||||
return "danger";
|
||||
};
|
||||
|
||||
// 刷新节点数据
|
||||
const refreshNodes = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
let nodesList = await invoke<string>("fetch_nodes_list", { page: 1, limit: 1000 });
|
||||
if (nodesList === "_EasytierGameFetchNodesError_") {
|
||||
nodesList = "";
|
||||
}
|
||||
if (nodesList) {
|
||||
const nodesListData: NodesResponse = JSON.parse(nodesList);
|
||||
console.log(nodesListData);
|
||||
if (nodesListData.success && nodesListData.data.items) {
|
||||
// 过滤可用节点
|
||||
const availableNodes = filterAvailableNodes(nodesListData.data.items);
|
||||
// 按优先级排序
|
||||
const sortedNodes = sortNodesByPriority(availableNodes);
|
||||
|
||||
// 更新节点数据
|
||||
nodes.splice(0, nodes.length, ...sortedNodes);
|
||||
|
||||
// 更新最后更新时间
|
||||
lastUpdateTime.value = new Date().toLocaleTimeString();
|
||||
|
||||
// console.log(`已更新 ${sortedNodes.length} 个可用节点`);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("获取节点数据失败:", err);
|
||||
ElMessage.error("获取节点数据失败");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 过滤可用节点的函数
|
||||
const filterAvailableNodes = (nodes: NodeItem[]): NodeItem[] => {
|
||||
return nodes.filter(node => {
|
||||
// 基本条件:节点必须激活且被批准
|
||||
if (!node.is_active || !node.is_approved) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 健康状态检查
|
||||
if (node.current_health_status !== "healthy") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 使用率检查:使用率不能超过95%
|
||||
if (node.usage_percentage > 95) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 24小时健康率检查:必须大于90%
|
||||
if (node.health_percentage_24h < 90) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 响应时间检查:响应时间不能超过60秒
|
||||
if (node.last_response_time > 60000) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 连接数检查:当前连接数不能超过最大连接数的90%
|
||||
if (node.current_connections > node.max_connections * 0.9) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 必须有有效的地址
|
||||
if (!node.address || !node.host || !node.port) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
// 按优先级排序节点的函数
|
||||
const sortNodesByPriority = (nodes: NodeItem[]): NodeItem[] => {
|
||||
return nodes.sort((a, b) => {
|
||||
// 优先级排序规则:
|
||||
// 1. 响应时间越短越好
|
||||
// 2. 使用率越低越好
|
||||
// 3. 24小时健康率越高越好
|
||||
// 4. 当前连接数越少越好
|
||||
|
||||
// 响应时间权重最高
|
||||
const responseTimeDiff = a.last_response_time - b.last_response_time;
|
||||
if (Math.abs(responseTimeDiff) > 1000) {
|
||||
// 如果响应时间差异超过1秒
|
||||
return responseTimeDiff;
|
||||
}
|
||||
|
||||
// 使用率权重次之
|
||||
const usageDiff = a.usage_percentage - b.usage_percentage;
|
||||
if (Math.abs(usageDiff) > 5) {
|
||||
// 如果使用率差异超过5%
|
||||
return usageDiff;
|
||||
}
|
||||
|
||||
// 24小时健康率
|
||||
const healthDiff = b.health_percentage_24h - a.health_percentage_24h;
|
||||
if (Math.abs(healthDiff) > 1) {
|
||||
// 如果健康率差异超过1%
|
||||
return healthDiff;
|
||||
}
|
||||
|
||||
// 当前连接数
|
||||
return a.current_connections - b.current_connections;
|
||||
});
|
||||
};
|
||||
|
||||
// 启动定时器
|
||||
const startRefreshTimer = () => {
|
||||
refreshTimer = setInterval(() => {
|
||||
refreshNodes();
|
||||
}, 10000); // 10秒刷新一次
|
||||
};
|
||||
|
||||
// 停止定时器
|
||||
const stopRefreshTimer = () => {
|
||||
if (refreshTimer) {
|
||||
clearInterval(refreshTimer);
|
||||
refreshTimer = null;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理选择变化
|
||||
const handleSelectionChange = (selection: NodeItem[]) => {
|
||||
selectedNodes.value = selection;
|
||||
};
|
||||
|
||||
const handleRowClick = (row: NodeItem) => {
|
||||
tableRef.value?.toggleRowSelection(row);
|
||||
};
|
||||
|
||||
// 添加选中的服务器到主页面服务器列表
|
||||
const addSelectedToServerList = async () => {
|
||||
if (selectedNodes.value.length === 0) {
|
||||
ElMessage.warning("请先选择要添加的服务器");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 提取服务器地址(去掉协议前缀)
|
||||
const protocols = selectedNodes.value.map(node => node.protocol.toLowerCase());
|
||||
const serverAddresses = selectedNodes.value.map(node => node.address.replace(`${node.protocol}://`, ""));
|
||||
mainStore.basePeers = uniq([...mainStore.basePeers, ...serverAddresses]);
|
||||
mainStore.config.serverUrl = uniq([...serverAddresses, ...mainStore.config.serverUrl]);
|
||||
mainStore.config.protocol = uniq([...protocols, ...mainStore.config.protocol]);
|
||||
ElMessage.success(`${selectedNodes.value.length} 个服务器,添加成功`);
|
||||
|
||||
// 清空选择
|
||||
tableRef.value?.clearSelection();
|
||||
selectedNodes.value = [];
|
||||
} catch (err) {
|
||||
console.error("处理选中服务器失败:", err);
|
||||
ElMessage.error("处理选中服务器失败");
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
// 初始加载数据
|
||||
await refreshNodes();
|
||||
// 启动定时器
|
||||
startRefreshTimer();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// 清理定时器
|
||||
stopRefreshTimer();
|
||||
});
|
||||
|
||||
dataSubscribe();
|
||||
</script>
|
||||
Generated
+612
-788
File diff suppressed because it is too large
Load Diff
Generated
+513
-555
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "easytier-game"
|
||||
version = "1.4.9"
|
||||
version = "1.5.1"
|
||||
homepage = "https://github.com/EasyTier/EasyTier"
|
||||
repository = "https://github.com/EasyTier/EasytierGame"
|
||||
description = "A simple network initiator based on Easytier"
|
||||
@@ -18,7 +18,7 @@ name = "app_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2.3.1", features = [] }
|
||||
tauri-build = { version = "2.5.1", features = [] }
|
||||
# prost-build = "0.13.2"
|
||||
|
||||
[target.x86_64-pc-windows-msvc.build-dependencies]
|
||||
@@ -28,24 +28,24 @@ thunk-rs = { git = "https://github.com/easytier/thunk.git", default-features = f
|
||||
serde_json = "1.0.137"
|
||||
serde = { version = "1.0.217", features = ["derive"] }
|
||||
log = "0.4.26"
|
||||
tauri = { version = "2.7.0", features = [ "protocol-asset",
|
||||
tauri = { version = "2.9.1", features = [ "protocol-asset",
|
||||
"tray-icon",
|
||||
"image-png",
|
||||
"image-ico"
|
||||
] }
|
||||
|
||||
tauri-plugin-log = "2.6.0"
|
||||
tauri-plugin-shell = "2.3.0"
|
||||
tauri-plugin-log = "2.7.0"
|
||||
tauri-plugin-shell = "2.3.1"
|
||||
reqwest = { version = "0.12.12", features = ["json"] }
|
||||
zip = "2.2.3"
|
||||
sysinfo = '0.33.1'
|
||||
# planif = { git = "https://github.com/mattrobineau/planif", tag = "1.0.1" }
|
||||
whoami = "1.5.2"
|
||||
tauri-plugin-fs = "2.4.1"
|
||||
tauri-plugin-fs = "2.4.2"
|
||||
tauri-plugin-clipboard-manager = "2.3.0"
|
||||
rand = "0.9.0"
|
||||
tokio = { version = "1.45.1", features = ["process"] }
|
||||
tauri-plugin-dialog = "2.3.1"
|
||||
tauri-plugin-dialog = "2.4.0"
|
||||
# prost = "0.13"
|
||||
# prost-types = "0.13"
|
||||
hashbrown = "0.15.2"
|
||||
@@ -57,5 +57,5 @@ features = ["Win32_System_TaskScheduler", "Win32_System_Com", "Win32_System_Powe
|
||||
|
||||
[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
|
||||
tauri-plugin-cli = "2.4.0"
|
||||
tauri-plugin-single-instance = "2.3.2"
|
||||
tauri-plugin-single-instance = "2.3.4"
|
||||
tauri-plugin-window-state = "2.4.0"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+70
-4
@@ -269,6 +269,7 @@ struct MyResponse {
|
||||
response: PeerRoute,
|
||||
}
|
||||
|
||||
|
||||
#[tauri::command(rename_all = "snake_case")]
|
||||
async fn get_members_by_cli() -> String {
|
||||
let cli_path = get_tool_exe_path("\\easytier\\easytier-cli.exe");
|
||||
@@ -298,10 +299,41 @@ async fn get_members_by_cli() -> String {
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command(rename_all = "snake_case")]
|
||||
async fn get_members_connections_cli() -> String {
|
||||
let cli_path = get_tool_exe_path("\\easytier\\easytier-cli.exe");
|
||||
match tokioCommand::new(&cli_path)
|
||||
.arg("-v")
|
||||
.arg("-o")
|
||||
.arg("json")
|
||||
.arg("peer")
|
||||
.creation_flags(0x08000000)
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
Ok(output) => {
|
||||
if output.status.success() {
|
||||
let output_str = String::from_utf8_lossy(&output.stdout);
|
||||
return output_str.trim().to_string();
|
||||
} else {
|
||||
let output_str = String::from_utf8_lossy(&output.stderr);
|
||||
log::error!("{}", output_str.trim().to_string());
|
||||
return "_EasytierGameCliFailedToGetConnections_".to_string();
|
||||
}
|
||||
}
|
||||
Err(_e) => {
|
||||
log::error!("get member list error");
|
||||
return "".to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command(rename_all = "snake_case")]
|
||||
async fn get_route_by_cli() -> String {
|
||||
let cli_path = get_tool_exe_path("\\easytier\\easytier-cli.exe");
|
||||
match tokioCommand::new(&cli_path)
|
||||
.arg("-o")
|
||||
.arg("json")
|
||||
.arg("route")
|
||||
.creation_flags(0x08000000)
|
||||
.output()
|
||||
@@ -324,6 +356,39 @@ async fn get_route_by_cli() -> String {
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command(rename_all = "snake_case")]
|
||||
async fn fetch_nodes_list(page: u64, limit: u64) -> String {
|
||||
let client = Client::new();
|
||||
let url = format!("https://uptime.easytier.cn/api/nodes?page={}&per_page={}", page, limit);
|
||||
let user_agent = generate_random_user_agent();
|
||||
|
||||
match client
|
||||
.get(url)
|
||||
.header("User-Agent", user_agent)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(response) => {
|
||||
if response.status().is_success() {
|
||||
match response.text().await {
|
||||
Ok(text) => text,
|
||||
Err(e) => {
|
||||
log::error!("Failed to get response text: {}", e);
|
||||
format!("_EasytierGameFetchNodesError_: {}", e)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log::error!("HTTP request failed with status: {}", response.status());
|
||||
format!("_EasytierGameFetchNodesError_: HTTP request failed with status: {}", response.status())
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to fetch nodes list: {}", e);
|
||||
format!("_EasytierGameFetchNodesError_: {}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command(rename_all = "snake_case")]
|
||||
async fn download_easytier_zip(
|
||||
app_handle: tauri::AppHandle,
|
||||
@@ -660,11 +725,11 @@ fn autostart_enabled() -> Result<bool, Box<dyn std::error::Error>> {
|
||||
fn autostart_is_enabled() -> bool {
|
||||
match autostart_enabled() {
|
||||
Ok(enabled) => {
|
||||
println!("autostart enabled: {}", enabled);
|
||||
// println!("autostart enabled: {}", enabled);
|
||||
return enabled;
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("autostart enabled: false -> {}", e);
|
||||
Err(_e) => {
|
||||
// log::error!("autostart enabled: false -> {}", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -782,7 +847,6 @@ fn autostart(enabled: bool) -> std::result::Result<(), Box<dyn std::error::Error
|
||||
exec_action.SetPath(&BSTR::from(exe_path))?;
|
||||
exec_action.SetArguments(&BSTR::from("--task-auto-start"))?;
|
||||
|
||||
// 使用当前用户运行
|
||||
let principal = task_definition.Principal()?;
|
||||
principal.SetUserId(&BSTR::from(whoami::username().as_str()))?;
|
||||
principal.SetLogonType(TASK_LOGON_INTERACTIVE_TOKEN)?;
|
||||
@@ -895,7 +959,9 @@ pub fn run() {
|
||||
fetch_game_releases,
|
||||
download_easytier_zip,
|
||||
get_members_by_cli,
|
||||
get_members_connections_cli,
|
||||
get_route_by_cli,
|
||||
fetch_nodes_list,
|
||||
search_pid_by_pname,
|
||||
get_exe_directory,
|
||||
spawn_autostart,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
||||
"productName": "easytier-game",
|
||||
"version": "1.4.9",
|
||||
"version": "1.5.1",
|
||||
"identifier": "com.tauri.easytier-game",
|
||||
|
||||
"build": {
|
||||
@@ -12,7 +12,7 @@
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"title": "easytier-game 1.4.9",
|
||||
"title": "easytier-game 1.5.1",
|
||||
"label": "main",
|
||||
"minWidth": 340,
|
||||
"width": 340,
|
||||
@@ -49,7 +49,7 @@
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": false,
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"resources": [
|
||||
"easytier/config/",
|
||||
|
||||
Vendored
+47
@@ -10,3 +10,50 @@ interface ImportMetaEnv {
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
|
||||
// 节点数据类型定义
|
||||
interface NodeItem {
|
||||
id: number;
|
||||
name: string;
|
||||
host: string;
|
||||
port: number;
|
||||
protocol: string;
|
||||
version: string;
|
||||
description: string;
|
||||
max_connections: number;
|
||||
current_connections: number;
|
||||
is_active: boolean;
|
||||
is_approved: boolean;
|
||||
allow_relay: boolean;
|
||||
network_name: string | null;
|
||||
network_secret: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
address: string;
|
||||
usage_percentage: number;
|
||||
current_health_status: string;
|
||||
last_check_time: string;
|
||||
last_response_time: number;
|
||||
health_percentage_24h: number;
|
||||
health_record_total_counter_ring: number[];
|
||||
health_record_healthy_counter_ring: number[];
|
||||
ring_granularity: number;
|
||||
qq_number: string | null;
|
||||
wechat: string | null;
|
||||
mail: string | null;
|
||||
}
|
||||
|
||||
interface NodesData {
|
||||
items: NodeItem[];
|
||||
total: number;
|
||||
page: number;
|
||||
per_page: number;
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
interface NodesResponse {
|
||||
success: boolean;
|
||||
data: NodesData;
|
||||
error: string | null;
|
||||
message: string | null;
|
||||
}
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ export const ATJ = (promise: Promise<any>, errorExt: string | undefined = undefi
|
||||
});
|
||||
};
|
||||
|
||||
const _supportProtocols = ["tcp", "udp", "ws", "wss"];
|
||||
const _supportProtocols = ["tcp", "udp", "ws", "wss", 'srv', 'schema'];
|
||||
|
||||
export const supportProtocols = () => {
|
||||
return _supportProtocols.slice();
|
||||
|
||||
Reference in New Issue
Block a user