mirror of
https://github.com/EasyTier/EasytierGame.git
synced 2025-05-19 10:27:56 +00:00
新增+修复+优化
+ 新增子网代理页面 表格查看代理情况 + 修复子网代理启动联机被覆盖的bug + 优化部分代码逻辑
This commit is contained in:
@@ -9,26 +9,26 @@
|
||||
import { warn, debug, trace, info, error } from "@tauri-apps/plugin-log";
|
||||
function forwardConsole(fnName: "log" | "debug" | "info" | "warn" | "error", logger: (message: string) => Promise<void>) {
|
||||
const original = console[fnName];
|
||||
console[fnName] = (message) => {
|
||||
console[fnName] = message => {
|
||||
original(message);
|
||||
if (import.meta.env.PROD) {
|
||||
try {
|
||||
if (typeof message === "string") {
|
||||
logger(message);
|
||||
} else {
|
||||
logger(JSON.stringify(message));
|
||||
}
|
||||
} catch (e) {
|
||||
logger(`${message}`);
|
||||
try {
|
||||
if (typeof message === "string") {
|
||||
logger(message);
|
||||
} else {
|
||||
logger(JSON.stringify(message));
|
||||
}
|
||||
} catch (e) {
|
||||
logger(`${message}`);
|
||||
}
|
||||
};
|
||||
}
|
||||
forwardConsole("log", info);
|
||||
forwardConsole("debug", debug);
|
||||
forwardConsole("info", info);
|
||||
forwardConsole("warn", warn);
|
||||
forwardConsole("error", error);
|
||||
if (import.meta.env.PROD) {
|
||||
forwardConsole("log", info);
|
||||
forwardConsole("debug", debug);
|
||||
forwardConsole("info", info);
|
||||
forwardConsole("warn", warn);
|
||||
forwardConsole("error", error);
|
||||
}
|
||||
|
||||
const mainStore = useMainStore();
|
||||
// console.log(mainStore.theme)
|
||||
|
||||
+97
-3
@@ -1,6 +1,9 @@
|
||||
<template>
|
||||
<div class="h-full flex flex-col gap-[10px]">
|
||||
<ElRadioGroup v-model="mainStore.cidrEnable">
|
||||
<div class="flex h-full flex-col gap-[10px]">
|
||||
<ElRadioGroup
|
||||
:disabled="!data.isSwitchEnable"
|
||||
v-model="mainStore.cidrEnable"
|
||||
>
|
||||
<ElRadioButton :value="true">开启</ElRadioButton>
|
||||
<ElRadioButton :value="false">关闭</ElRadioButton>
|
||||
</ElRadioGroup>
|
||||
@@ -9,16 +12,107 @@
|
||||
placeholder="例如: 192.168.1.0/24 一行一个"
|
||||
v-model="mainStore.config.proxyNetworks"
|
||||
type="textarea"
|
||||
:rows="30"
|
||||
:rows="5"
|
||||
resize="none"
|
||||
></ElInput>
|
||||
<ElTable
|
||||
stripe
|
||||
border
|
||||
empty-text="暂无数据"
|
||||
:data="data.route"
|
||||
class="mt-[5px]"
|
||||
>
|
||||
<ElTableColumn
|
||||
sortable
|
||||
width="140"
|
||||
label="主机名"
|
||||
prop="hostname"
|
||||
></ElTableColumn>
|
||||
<ElTableColumn
|
||||
width="120"
|
||||
sortable
|
||||
label="虚拟网IP"
|
||||
prop="ipv4"
|
||||
></ElTableColumn>
|
||||
<ElTableColumn
|
||||
sortable
|
||||
label="被代理的子网"
|
||||
prop="proxy_cidrs"
|
||||
></ElTableColumn>
|
||||
</ElTable>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import useMainStore from "@/stores/index";
|
||||
import { dataSubscribe } from "@/composables/windows";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { reactive, onMounted, onBeforeUnmount } from "vue";
|
||||
import { ATJ, parseCliInfo } from "@/utils";
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
const mainStore = useMainStore();
|
||||
|
||||
const data = reactive<{ [key: string]: any }>({
|
||||
route: [],
|
||||
isStart: false,
|
||||
isSwitchEnable: false,
|
||||
isRunning: false
|
||||
});
|
||||
|
||||
const listenOutput = async () => {
|
||||
data.isRunning = true;
|
||||
const [error, member] = await ATJ(invoke<string>("get_route_by_cli"));
|
||||
data.isRunning = false;
|
||||
// if(!member) return;
|
||||
if (error) {
|
||||
data.route = [];
|
||||
return "";
|
||||
}
|
||||
if (member === "_EasytierGameCliFailedToConnect_") {
|
||||
data.route = [];
|
||||
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;
|
||||
};
|
||||
|
||||
const listenStart = async () => {
|
||||
const unListen = await listen<boolean>("route", async event => {
|
||||
data.isStart = event.payload;
|
||||
if (data.isStart) {
|
||||
data.isSwitchEnable = false;
|
||||
if (mainStore.cidrEnable && !data.isRunning) {
|
||||
await listenOutput();
|
||||
} else {
|
||||
data.route = [];
|
||||
}
|
||||
} else {
|
||||
data.isSwitchEnable = true;
|
||||
data.route = [];
|
||||
}
|
||||
});
|
||||
return unListen;
|
||||
};
|
||||
|
||||
let unlistenStart: UnlistenFn | null = null;
|
||||
|
||||
onMounted(async () => {
|
||||
unlistenStart = await listenStart();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
unlistenStart && unlistenStart();
|
||||
});
|
||||
|
||||
dataSubscribe(async (...a) => {
|
||||
return { cidrEnable: mainStore.cidrEnable, config: { ...mainStore.config } };
|
||||
});
|
||||
|
||||
+37
-17
@@ -518,11 +518,11 @@
|
||||
import { initStartWinIpBroadcast } from "~/composables/netcard";
|
||||
import useMainStore from "@/stores/index";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { getAllWebviewWindows } from "@tauri-apps/api/webviewWindow";
|
||||
import { getCurrentWindow, type Window } from "@tauri-apps/api/window";
|
||||
import { getAllWebviewWindows, WebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import etWindows from "@/composables/windows";
|
||||
import { resourceDir as getResourceDir, join } from "@tauri-apps/api/path";
|
||||
import { readDir, exists, mkdir, BaseDirectory, readTextFile } from "@tauri-apps/plugin-fs";
|
||||
import { readDir, exists, mkdir, BaseDirectory, readTextFile, readFile } from "@tauri-apps/plugin-fs";
|
||||
import { updateConfigJson } from "~/composables/configJson";
|
||||
import { writeText, readText } from "@tauri-apps/plugin-clipboard-manager";
|
||||
import { sortedUniq, uniq } from "lodash-es";
|
||||
@@ -648,6 +648,18 @@
|
||||
mainStore.basePeers = uniq([mainStore.config.serverUrl, ...mainStore.basePeers]);
|
||||
};
|
||||
|
||||
// 手动触发持久化数据
|
||||
const persist = async (appWindow: Window) => {
|
||||
try {
|
||||
appWindow.emitTo({ kind: "Any" }, "global-main-store", { store: { ...mainStore.$state } });
|
||||
mainStore.$persist();
|
||||
}catch(err) {
|
||||
console.error(err);
|
||||
ElMessage.error("手动持久数据失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const listenObj: { [key: string]: any } = {
|
||||
unListenOutPut: null,
|
||||
unListenThreadId: null,
|
||||
@@ -742,7 +754,6 @@
|
||||
const appWindow = getCurrentWindow();
|
||||
const unListen = await listen("config", event => {
|
||||
const ipv4 = config.ipv4;
|
||||
console.log(event.payload)
|
||||
mainStore.$patch(event.payload as any);
|
||||
config.ipv4 = ipv4;
|
||||
if(mainStore.config.enablePreventSleep) {
|
||||
@@ -750,10 +761,10 @@
|
||||
}else {
|
||||
stopPreventSleep();
|
||||
}
|
||||
appWindow.emitTo({ kind: "Any" }, "global-main-store", { store: { ...mainStore.$state } });
|
||||
persist(appWindow);
|
||||
});
|
||||
const unListen2 = mainStore.$subscribe(() => {
|
||||
appWindow.emitTo({ kind: "Any" }, "global-main-store", { store: { ...mainStore.$state } });
|
||||
persist(appWindow);
|
||||
})
|
||||
this.unListenConfigStart = [unListen, unListen2];
|
||||
},
|
||||
@@ -894,9 +905,11 @@
|
||||
const path = import.meta.env.VITE_CONFIG_FILE_NAME;
|
||||
const isExists = await exists(path, { baseDir: BaseDirectory.Resource });
|
||||
if (isExists) {
|
||||
const guiJsonStr = await readTextFile(path, { baseDir: BaseDirectory.Resource });
|
||||
if (guiJsonStr) {
|
||||
const guiJsonStrUint8 = await readFile(path, { baseDir: BaseDirectory.Resource });
|
||||
if (guiJsonStrUint8) {
|
||||
try {
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
const guiJsonStr = decoder.decode(guiJsonStrUint8);
|
||||
const regex = /^(\s*\/\/.*)/gm;
|
||||
const regex2 = /(,?)\s*\/\/.*(?=\n|$|\r\n)/gm;
|
||||
const resultStr = guiJsonStr.replace(regex, "").replace(regex2, "$1");
|
||||
@@ -926,7 +939,7 @@
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
ElMessage.error(`config.json格式错误`);
|
||||
ElMessage.error(`config.json格式或编码错误`);
|
||||
} finally {
|
||||
mainStore.$patch({
|
||||
createConfigInEasytier: true // 发现本地存在config.json 默认启用该功能
|
||||
@@ -975,6 +988,7 @@
|
||||
|
||||
let logsTimer: NodeJS.Timeout | null = null;
|
||||
let serverLogsTimer: NodeJS.Timeout | null = null;
|
||||
let cidrTimer : NodeJS.Timeout | null = null;
|
||||
|
||||
onMounted(async () => {
|
||||
await initGuiJson();
|
||||
@@ -1003,6 +1017,7 @@
|
||||
listenObj.unListenStartStopServer && listenObj.unListenStartStopServer();
|
||||
logsTimer && clearInterval(logsTimer);
|
||||
serverLogsTimer && clearInterval(serverLogsTimer);
|
||||
cidrTimer && clearInterval(cidrTimer);
|
||||
stopPreventSleep();
|
||||
});
|
||||
|
||||
@@ -1084,13 +1099,13 @@
|
||||
args.push("-l", config.port);
|
||||
}
|
||||
if (mainStore.cidrEnable && config.proxyNetworks) {
|
||||
// console.error(config.proxyNetworks);
|
||||
const reg = /\d+\.\d+\.\d+\.\d+\/\d+/g;
|
||||
const formatProxyNetworks = config.proxyNetworks
|
||||
.split("\n")
|
||||
.map(item => item.trim())
|
||||
.filter(item => item && reg.test(item));
|
||||
args.push("--proxy-networks", ...formatProxyNetworks);
|
||||
let formatProxyNetworks = config.proxyNetworks.split("\n");
|
||||
const newformatProxyNetworks = formatProxyNetworks
|
||||
.map(el => el.trim())
|
||||
.filter(cidr => {
|
||||
return /^\d+\.\d+\.\d+\.\d+\/\d+$/g.test(cidr);
|
||||
});
|
||||
args.push("--proxy-networks", ...newformatProxyNetworks);
|
||||
config.proxyNetworks = formatProxyNetworks.join("\n");
|
||||
}
|
||||
if (config.disableEncryption) {
|
||||
@@ -1168,10 +1183,10 @@
|
||||
data.startLoading = true;
|
||||
await unListenAll();
|
||||
await listenObj.listenOutput();
|
||||
|
||||
await invoke("run_command", {
|
||||
args
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1335,8 +1350,13 @@
|
||||
},
|
||||
(_, appWindow) => {
|
||||
data.cidrVisible = true;
|
||||
cidrTimer && clearInterval(cidrTimer);
|
||||
cidrTimer = setInterval(() => {
|
||||
appWindow.emitTo({ kind: "WebviewWindow", label: "cidr" }, "route", data.isStart);
|
||||
}, 1000);
|
||||
},
|
||||
() => {
|
||||
cidrTimer && clearInterval(cidrTimer);
|
||||
data.cidrVisible = false;
|
||||
}
|
||||
);
|
||||
|
||||
+2
-2
@@ -16,8 +16,8 @@
|
||||
});
|
||||
|
||||
const listenStart = async () => {
|
||||
const unListen = await listen("logs", event => {
|
||||
data.log = (event.payload as string) || "";
|
||||
const unListen = await listen<string>("logs", event => {
|
||||
data.log = event.payload || "";
|
||||
});
|
||||
return unListen;
|
||||
};
|
||||
|
||||
+20
-11
@@ -1,7 +1,12 @@
|
||||
<template>
|
||||
<div class="overflow-auto h-full">
|
||||
<div class="h-full overflow-auto">
|
||||
<div class="w-[1200px]">
|
||||
<ElText size="small" v-if="!data.member || data.member.length <= 0">{{ "等待成员信息中..." }}</ElText>
|
||||
<ElText
|
||||
size="small"
|
||||
v-if="!data.member || data.member.length <= 0"
|
||||
>
|
||||
{{ "等待成员信息中..." }}
|
||||
</ElText>
|
||||
<ElTable
|
||||
stripe
|
||||
border
|
||||
@@ -14,8 +19,12 @@
|
||||
label="主机名"
|
||||
prop="hostname"
|
||||
>
|
||||
<template #default="{row}">
|
||||
{{ (row.hostname || "").toLowerCase().includes('publicserver') ? (row.hostname || "").replace("PublicServer", "服务器") : (row.hostname || "-") }}
|
||||
<template #default="{ row }">
|
||||
{{
|
||||
(row.hostname || "").toLowerCase().includes("publicserver")
|
||||
? (row.hostname || "").replace("PublicServer", "服务器")
|
||||
: row.hostname || "-"
|
||||
}}
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn
|
||||
@@ -96,9 +105,9 @@
|
||||
<script setup lang="ts">
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { reactive, onMounted, onBeforeUnmount } from "vue";
|
||||
import { ATJ, parsePeerInfo } from "@/utils";
|
||||
import { ATJ, parseCliInfo } from "@/utils";
|
||||
import { ElConfirmDanger } from "~/utils/element";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
// enum NatType {
|
||||
// // has NAT; but own a single public IP, port is not changed
|
||||
// Unknown = 0;
|
||||
@@ -126,7 +135,7 @@ import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
};
|
||||
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: { hostname: string; cost: string; ipv4: string; lat_msg: string; loss_rate: string; nat_type: string }[] }>({
|
||||
member: []
|
||||
});
|
||||
|
||||
@@ -139,8 +148,8 @@ import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
["nat_type", "NAT类型"],
|
||||
["version", "版本"],
|
||||
["tunnel_proto", "隧道协议"],
|
||||
['rx_bytes', '接收'],
|
||||
['tx_bytes', '传输']
|
||||
["rx_bytes", "接收"],
|
||||
["tx_bytes", "传输"]
|
||||
];
|
||||
|
||||
let timer: NodeJS.Timeout | null = null;
|
||||
@@ -167,7 +176,7 @@ import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
}
|
||||
return;
|
||||
}
|
||||
const peerInfo = parsePeerInfo(member);
|
||||
const peerInfo = parseCliInfo(member);
|
||||
peerInfo.forEach(value => {
|
||||
if (value.cost === "Local") {
|
||||
value.cost = "本机";
|
||||
@@ -191,7 +200,7 @@ import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
const stopTimer = () => {
|
||||
timer && clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await listenOutput();
|
||||
|
||||
@@ -221,6 +221,32 @@ async fn get_members_by_cli() -> 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("route")
|
||||
.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 "_EasytierGameCliFailedToConnect_".to_string();
|
||||
}
|
||||
}
|
||||
Err(_e) => {
|
||||
log::error!("get route list error");
|
||||
return "".to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command(rename_all = "snake_case")]
|
||||
async fn download_easytier_zip(download_url: String, file_name: String) {
|
||||
let cache_dir_path = get_tool_exe_path("\\easytier\\cache");
|
||||
@@ -685,6 +711,7 @@ pub fn run() {
|
||||
fetch_game_releases,
|
||||
download_easytier_zip,
|
||||
get_members_by_cli,
|
||||
get_route_by_cli,
|
||||
search_pid_by_pname,
|
||||
get_exe_directory,
|
||||
spawn_autostart,
|
||||
|
||||
+5
-3
@@ -1,5 +1,5 @@
|
||||
import { defineStore } from "pinia";
|
||||
export default defineStore("main", {
|
||||
import { acceptHMRUpdate, defineStore } from "pinia";
|
||||
const store = defineStore("main", {
|
||||
state() {
|
||||
return {
|
||||
config: {
|
||||
@@ -35,7 +35,7 @@ export default defineStore("main", {
|
||||
customProtocol: "tcp", //自定义默认协议
|
||||
enableNetCardMetric: false, //启用网卡自定义跃点
|
||||
netCardMetricValue: 1, //自定义网卡跃点值
|
||||
enablePreventSleep: false, //组织系统休眠
|
||||
enablePreventSleep: false //组织系统休眠
|
||||
},
|
||||
serverConfig: {
|
||||
enableWhiteList: true, // 是否启用白名单
|
||||
@@ -115,3 +115,5 @@ export default defineStore("main", {
|
||||
// omit: ["winipBcPid", "winipBcStart"]
|
||||
}
|
||||
});
|
||||
if (import.meta.hot) import.meta.hot.accept(acceptHMRUpdate(store, import.meta.hot));
|
||||
export default store;
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ export const stopPreventSleep = () => {
|
||||
_prevent_timer = null;
|
||||
}
|
||||
|
||||
export const parsePeerInfo = (content: string) => {
|
||||
export const parseCliInfo = (content: string) => {
|
||||
if(!content) return [];
|
||||
// 将表格字符串分割成行
|
||||
const lines = content.split("\n");
|
||||
|
||||
Reference in New Issue
Block a user