Compare commits

..
5 Commits
19 changed files with 3727 additions and 1211 deletions
+18 -1
View File
@@ -2,7 +2,21 @@ import { BaseDirectory, writeTextFile } from "@tauri-apps/plugin-fs";
import useMainStore from "@/stores/index";
import { ElMessage } from "element-plus";
import { uniq, intersection, isNil } from "lodash-es";
export const updateConfigJson = async (configJsonSeverUrl: Array<string> | string | null | undefined) => {
import { bounce } from "~/utils";
const b = bounce(600);
export type ConfigServerUrlType = Array<string> | string | null | undefined | null;
export const updateConfigJsonBounce = (configJsonSeverUrl?: ConfigServerUrlType) => {
b(async () => {
const mainStore = useMainStore();
if (mainStore.createConfigInEasytier) {
await updateConfigJson(configJsonSeverUrl);
}
});
};
export const updateConfigJson = async (configJsonSeverUrl?: ConfigServerUrlType) => {
const mainStore = useMainStore();
const path = import.meta.env.VITE_CONFIG_FILE_NAME;
if (isNil(configJsonSeverUrl)) {
@@ -20,6 +34,9 @@ export const updateConfigJson = async (configJsonSeverUrl: Array<string> | strin
enableCustomListener,
customListenerData,
bindDeviceEnable,
acceptDNS,
enablePortForward,
portForwardData,
...otherConfig
} = mainStore.config;
let writeServerUrl: Array<string> | string = serverUrl;
+17 -15
View File
@@ -4,14 +4,11 @@ import { WebviewWindow } from "@tauri-apps/api/webviewWindow";
import type { WebviewLabel, WebviewOptions } from "@tauri-apps/api/webview";
import useMainStore from "@/stores/index";
import { onBeforeUnmount } from "vue";
import { updateConfigJsonBounce, type ConfigServerUrlType } from "./configJson";
const _listenersMaps: { [key: string]: [UnlistenFn | null] } = {};
const dealCloseListener = async (
dialog: WebviewWindow,
label: string,
beforeCloseFunc?: () => void | null
) => {
const dealCloseListener = async (dialog: WebviewWindow, label: string, beforeCloseFunc?: () => void | null) => {
const unlistenFnList: [UnlistenFn | null] = _listenersMaps[label] || [null];
let [unListenlogClose] = unlistenFnList;
@@ -20,7 +17,7 @@ const dealCloseListener = async (
unListenlogClose = await dialog.onCloseRequested(async () => {
beforeCloseFunc && (await beforeCloseFunc());
unListenlogClose && (await unListenlogClose());
console.log("close")
console.log("close");
});
};
export default async (
@@ -44,20 +41,21 @@ export default async (
};
const appWindow = getCurrentWindow();
if (appWindow) {
const appSize = await appWindow.outerSize();
const factor = await appWindow.scaleFactor();
const appPosition = await appWindow.outerPosition();
const logicalPosition = new PhysicalPosition(appPosition.x + appSize.width, appPosition.y).toLogical(factor);
defaultOpts.parent = appWindow;
// console.error(logicalPosition);
defaultOpts.x = logicalPosition.x;
defaultOpts.y = logicalPosition.y;
if (defaultOpts.x == 0 && defaultOpts.y == 0) {
const appSize = await appWindow.outerSize();
const factor = await appWindow.scaleFactor();
const appPosition = await appWindow.outerPosition();
const logicalPosition = new PhysicalPosition(appPosition.x + appSize.width, appPosition.y).toLogical(factor);
defaultOpts.x = logicalPosition.x;
defaultOpts.y = logicalPosition.y;
}
}
dialog = new WebviewWindow(label, { ...defaultOpts, ...options });
await dealCloseListener(dialog, label, beforeCloseFunc);
afterCreatedFunc && (await afterCreatedFunc(dialog, appWindow));
await dialog.show();
} else {
const visible = await dialog.isVisible();
if (visible) {
@@ -71,14 +69,17 @@ export default async (
}
};
export const dataSubscribe = async (cb?: (...args: any) => any) => {
if (!cb) return;
export const dataSubscribe = async (cb?: any, getconfigServerUrl?: () => ConfigServerUrlType) => {
const mainStore = useMainStore();
const abort = new AbortController();
window.addEventListener(
"storage",
async () => {
// console.log("触发", {dhcp:mainStore.config.dhcp, c: mainStore.createConfigInEasytier})
mainStore.$hydrate();
const configServerUrl = getconfigServerUrl && getconfigServerUrl instanceof Function ? getconfigServerUrl() : null;
updateConfigJsonBounce(configServerUrl);
if (cb && cb instanceof Function) {
await cb();
}
@@ -88,6 +89,7 @@ export const dataSubscribe = async (cb?: (...args: any) => any) => {
}
);
onBeforeUnmount(() => {
console.log("取消监听");
abort?.abort();
});
};
+8 -8
View File
@@ -3,7 +3,7 @@
"private": true,
"author": "leizi97",
"description": "A simple network initiator based on Easytier",
"version": "1.4.4",
"version": "1.4.5",
"scripts": {
"dev": "nuxt dev --dotenv env/.env.dev --host 0.0.0.0",
"build": "nuxt generate --dotenv env/.env.prod",
@@ -12,28 +12,28 @@
},
"devDependencies": {
"@element-plus/icons-vue": "^2.3.1",
"@element-plus/nuxt": "^1.1.1",
"@element-plus/nuxt": "1.1.2",
"@nuxtjs/tailwindcss": "6.13.2",
"@pinia/nuxt": "0.11.0",
"@tauri-apps/api": "2.5.0",
"@tauri-apps/cli": "2.5.0",
"@tauri-apps/plugin-cli": "^2.2.0",
"@tauri-apps/plugin-clipboard-manager": "2.2.2",
"@tauri-apps/plugin-dialog": "2.2.1",
"@tauri-apps/plugin-fs": "2.2.1",
"@tauri-apps/plugin-log": "2.3.1",
"@tauri-apps/plugin-dialog": "2.2.2",
"@tauri-apps/plugin-fs": "2.3.0",
"@tauri-apps/plugin-log": "2.4.0",
"@tauri-apps/plugin-shell": "2.2.1",
"@tauri-apps/plugin-window-state": "2.2.2",
"@types/lodash-es": "^4.17.12",
"@vitejs/plugin-vue-jsx": "4.1.2",
"@vueuse/core": "12.7.0",
"archiver": "^7.0.1",
"element-plus": "2.9.7",
"element-plus": "2.9.11",
"less": "4.2.1",
"lodash-es": "^4.17.21",
"nuxt": "3.16.2",
"nuxt": "3.17.4",
"pinia": "3.0.2",
"pinia-plugin-persistedstate": "^4.2.0",
"pinia-plugin-persistedstate": "4.3.0",
"postcss": "^8.4.38",
"prettier": "3.5.2",
"prettier-plugin-tailwindcss": "0.6.11"
+73 -47
View File
@@ -59,6 +59,13 @@
</div>
<div><ElCheckbox v-model="mainStore.config.disableUdpHolePunching">禁用UDP打洞功能</ElCheckbox></div>
<div><ElCheckbox v-model="mainStore.config.disableIpv6">不使用IPv6</ElCheckbox></div>
<div class="flex flex-nowrap items-center gap-[5px]">
<ElCheckbox v-model="mainStore.config.acceptDNS">魔法DNS</ElCheckbox>
<ElTooltip content="您可以使用域名访问其他节点,例如:<hostname>.et.net。魔法DNS将修改您的系统DNS设置,请谨慎启用">
<ElIcon><QuestionFilled /></ElIcon>
</ElTooltip>
<CoreVersionWarning version="2.3.0" />
</div>
<ElDivider />
<div class="flex items-center gap-[10px]">
<ElCheckbox v-model="mainStore.config.disbleListenner">不监听任何端口只连接到对等节点</ElCheckbox>
@@ -103,6 +110,7 @@
class="!mb-0"
v-model="listenerDialogData.visible"
:close-on-press-escape="false"
:close-on-click-modal="false"
title="自定义监听地址"
>
<ElInput
@@ -124,28 +132,63 @@
</template>
</ElDialog>
</div>
<!-- <div class="flex items-center gap-[10px]">
<ElCheckbox
:disabled="mainStore.config.disbleListenner"
:model-value="mainStore.config.enableCustomListenerV6"
@change="handleCustomListenerV6Change"
<div class="flex items-center gap-[10px]">
<ElCheckbox v-model="mainStore.config.enablePortForward">端口转发</ElCheckbox>
<ElTooltip
:disabled="mainStore.config.enablePortForward"
content="请先开启端口转发功能"
>
自定义IPV6监听地址
</ElCheckbox>
<div class="w-[200px]">
<ElInput
:disabled="mainStore.config.disbleListenner || mainStore.config.enableCustomListenerV6"
<ElButton
size="small"
:maxlength="100"
v-model="mainStore.config.customListenerV6Data"
placeholder="请输入自定义IPV6监听地址"
/>
</div>
<ElTooltip content="例如:tcp://[::]:11010,如果未设置,将在随机UDP端口上监听(内核版本2.2.3之后,ipv6监听被移除并合并到'自定义监听')">
:disabled="!mainStore.config.enablePortForward"
@click="handlePortForwardDialog"
>
配置
</ElButton>
</ElTooltip>
<ElTooltip content="将本地端口转发到虚拟网络中的远程端口.如:udp://0.0.0.0:12345/10.126.126.1:23456,表示将本地UDP端口12345转发到虚拟网络中的10.126.126.1:23456.可以指定多个">
<ElIcon><QuestionFilled /></ElIcon>
</ElTooltip>
<CoreVersionWarning version="2.1.0" />
</div> -->
<CoreVersionWarning version="2.3.0" />
<ElDialog
width="95%"
top="5px"
append-to-body
:z-index="10"
class="!mb-0"
v-model="portForwardDialogData.visible"
:close-on-press-escape="false"
:close-on-click-modal="false"
title="端口转发配置"
>
<div class="mb-4">
<ElText
size="small"
type="info"
>
<div> 每行一个转发规则</div>
<div> 格式协议://本地地址:本地端口/目标地址:目标端口</div>
<div class="flex items-center">
<span class="mr-auto"> 例如udp://0.0.0.0:12345/10.126.126.1:23456</span>
<ElButton
size="default"
type="primary"
@click.stop="handleFinishInputPortForward"
>
填写完毕
</ElButton>
</div>
</ElText>
</div>
<ElInput
type="textarea"
:rows="10"
placeholder="请输入端口转发规则,每行一个&#10;例如:&#10;udp://0.0.0.0:12345/10.126.126.1:23456&#10;tcp://0.0.0.0:8080/192.168.1.100:80"
v-model="mainStore.config.portForwardData"
></ElInput>
<!-- -->
</ElDialog>
</div>
<ElDivider />
<div class="flex items-center gap-[10px]">
<ElCheckbox v-model="mainStore.config.devName">自定义虚拟网卡名称</ElCheckbox>
@@ -193,25 +236,9 @@
<div class="flex items-center gap-[5px]">
<div><ElCheckbox v-model="mainStore.config.bindDeviceEnable">绑定物理网卡</ElCheckbox></div>
<!-- <div class="flex items-center gap-[5px]"> -->
<!-- <ElSelect
placeholder="选择设备"
v-model="mainStore.config.bindDevice"
filterable
no-data-text="暂无网卡设备数据请刷新"
>
<ElOption
v-for="guid in guids"
:key="guid[0]"
:label="guid[1]"
:value="guid[0]"
></ElOption>
</ElSelect> -->
<!-- <ElButton @click="getGuids">刷新</ElButton> -->
<ElTooltip content="将连接器的套接字绑定到物理设备以避免路由问题。比如子网代理网段与某节点的网段冲突,绑定物理设备后可以与该节点正常通信">
<ElIcon><QuestionFilled /></ElIcon>
</ElTooltip>
<!-- </div> -->
<CoreVersionWarning version="2.2.3" />
</div>
@@ -304,6 +331,15 @@
loading: false
});
const portForwardDialogData = reactive<{ [key: string]: any }>({
visible: false,
loading: false
});
const handlePortForwardDialog = () => {
portForwardDialogData.visible = true;
};
const handleListenerDialog = () => {
listenerDialogData.visible = true;
};
@@ -312,19 +348,9 @@
listenerDialogData.visible = false;
};
// const handleCustomListenerV6Change = async (value: boolean) => {
// if (value) {
// const [error, _] = await ElConfirmDanger("内核版本2.2.3之后,ipv6监听被移除并合并到'自定义监听',请谨慎使用", "警告", {
// confirmButtonText: "继续使用",
// cancelButtonText: "取消"
// });
// if (!error) {
// mainStore.config.enableCustomListenerV6 = value;
// }
// } else {
// mainStore.config.enableCustomListenerV6 = value;
// }
// };
const handleFinishInputPortForward = async () => {
portForwardDialogData.visible = false;
};
const mainStore = useMainStore();
const data = ["trace", "debug", "info", "warn", "error", "off"];
+2 -1
View File
@@ -113,9 +113,10 @@
onMounted(async () => {
unlistenStart = await listenStart();
dataSubscribe();
});
dataSubscribe();
onBeforeUnmount(() => {
unlistenStart && unlistenStart();
});
+128 -97
View File
@@ -2,7 +2,7 @@
<ElForm
size="small"
label-position="top"
:model="config"
:model="mainStore.config"
>
<ElFormItem
label="服务器"
@@ -70,18 +70,18 @@
filterable
placeholder="请选择服务器地址"
default-first-option
v-model="config.serverUrl"
v-model="mainStore.config.serverUrl"
no-data-text="无服务器地址"
@change="handleServerUrlChange"
>
<template #prefix>
<div :class="config.protocol && config.protocol.length > 1 ? 'w-[120px]' : 'w-[80px]'">
<div :class="mainStore.config.protocol && mainStore.config.protocol.length > 1 ? 'w-[120px]' : 'w-[80px]'">
<ElSelect
placeholder="协议"
multiple
collapse-tags
@click.stop
v-model="config.protocol"
v-model="mainStore.config.protocol"
@change="handleServerUrlChange"
>
<ElOption
@@ -98,7 +98,7 @@
<ElLink
type="primary"
size="small"
:underline="false"
underline="never"
@click.stop="open(publicPeersLink)"
>
其他公共服务器
@@ -161,7 +161,7 @@
<ElInput
maxlength="100"
placeholder="请输入房间名"
v-model="config.networkName"
v-model="mainStore.config.networkName"
></ElInput>
</ElFormItem>
</div>
@@ -179,7 +179,7 @@
show-password
maxlength="100"
placeholder="请输入房间密码"
v-model="config.networkPassword"
v-model="mainStore.config.networkPassword"
type="password"
></ElInput>
</ElFormItem>
@@ -198,7 +198,7 @@
<ElInput
maxlength="100"
placeholder="例如: Player1"
v-model="config.hostname"
v-model="mainStore.config.hostname"
></ElInput>
</ElFormItem>
<ElFormItem
@@ -217,7 +217,7 @@
:icon="CopyDocument"
></ElButton>
<ElSwitch
v-model="config.dhcp"
v-model="mainStore.config.dhcp"
inline-prompt
inactive-text="固定IP"
active-text="动态获取"
@@ -230,21 +230,21 @@
</template>
<ElInput
maxlength="100"
:readonly="config.dhcp"
:placeholder="data.isStart && config.dhcp ? '等待动态分配IP...' : '例如: 10.126.126.1'"
v-model="config.ipv4"
:readonly="mainStore.config.dhcp"
:placeholder="data.isStart && mainStore.config.dhcp ? '等待动态分配IP...' : '例如: 10.126.126.1'"
v-model="mainStore.config.ipv4"
>
<template #prefix>
<ElTooltip
class="!text-[10px]"
placement="top-end"
:content="config.dhcp ? '动态获取无法手动填写' : '固定IP可以手动填写'"
:content="mainStore.config.dhcp ? '动态获取无法手动填写' : '固定IP可以手动填写'"
>
<ElTag
size="small"
:type="config.dhcp ? 'info' : 'success'"
:type="mainStore.config.dhcp ? 'info' : 'success'"
>
{{ config.dhcp ? "只读" : "可填" }}
{{ mainStore.config.dhcp ? "只读" : "可填" }}
</ElTag>
</ElTooltip>
</template>
@@ -363,7 +363,7 @@
</div>
<div class="ml-auto">
<ElCheckbox
v-model="config.disbleP2p"
v-model="mainStore.config.disbleP2p"
size="small"
>
强制中转
@@ -374,7 +374,7 @@
>
<ElCheckbox
@change="handleAutoStartByTask"
:model-value="config.autoStart"
:model-value="mainStore.config.autoStart"
size="small"
>
开机自启
@@ -419,7 +419,7 @@
<ElLink
class="ml-[8px] truncate pb-[2px] !text-[9px]"
type="info"
:underline="false"
underline="never"
@click="open('https://github.com/EasyTier/EasytierGame')"
>
EasytierGame主页
@@ -724,11 +724,11 @@
import { getAllWebviewWindows, WebviewWindow } from "@tauri-apps/api/webviewWindow";
import etWindows, { dataSubscribe } from "@/composables/windows";
import { resourceDir as getResourceDir, join } from "@tauri-apps/api/path";
import { readDir, exists, mkdir, BaseDirectory, readTextFile, readFile, writeFile, remove as removeFile } from "@tauri-apps/plugin-fs";
import { updateConfigJson } from "~/composables/configJson";
import { readDir, exists, mkdir, BaseDirectory, readTextFile, readFile, writeFile, remove as removeFile, stat } from "@tauri-apps/plugin-fs";
import { updateConfigJson, updateConfigJsonBounce } from "~/composables/configJson";
import { writeText, readText } from "@tauri-apps/plugin-clipboard-manager";
import { sortedUniq, uniq } from "lodash-es";
import { bounce, addQQGroup, supportProtocols, preventSleep, stopPreventSleep, ATJ, copyText, isValidWindowsFileName } from "~/utils";
import { addQQGroup, supportProtocols, preventSleep, stopPreventSleep, ATJ, copyText, isValidWindowsFileName } from "~/utils";
import { ElConfirmDanger, ElConfirmPrimary } from "~/utils/element";
import { getServerArgs } from "@/composables/server";
@@ -750,8 +750,7 @@
);
const mainStore = useMainStore();
const config = mainStore.config;
// console.error(config);
const protocols = supportProtocols();
const data = reactive({
//easytierGame有没有新版
@@ -816,8 +815,8 @@
};
const handleCopyIp = async () => {
if (!config.ipv4?.trim()) return;
if (data.isStart || !config.dhcp) {
if (!mainStore.config.ipv4?.trim()) return;
if (data.isStart || !mainStore.config.dhcp) {
await copyText(mainStore.config.ipv4);
} else {
await copyText(mainStore.config.ipv4, "复制成功,联机后IP可能会变化");
@@ -842,8 +841,8 @@
const newBasePeers = [...mainStore.basePeers];
const idx = newBasePeers.indexOf(url);
if (idx >= 0) {
if (config.serverUrl === url) {
config.serverUrl = "";
if (mainStore.config.serverUrl === url) {
mainStore.config.serverUrl = "";
}
newBasePeers.splice(idx, 1);
}
@@ -856,7 +855,7 @@
const handleServerUrlChange = () => {
let inputProtocols: string | null = null;
for (const p of protocols) {
if (config.serverUrl.toLowerCase().startsWith(`${p}://`)) {
if (mainStore.config.serverUrl.toLowerCase().startsWith(`${p}://`)) {
inputProtocols = p;
break;
}
@@ -1096,9 +1095,9 @@
const handleAutoStartByTask = async () => {
if (import.meta.env.DEV) return ElMessage.warning("开发环境不支持开机自启");
await invoke("spawn_autostart", { enabled: !config.autoStart });
await invoke("spawn_autostart", { enabled: !mainStore.config.autoStart });
const is_enable_by_task = (await invoke("autostart_is_enabled")) as boolean;
config.autoStart = is_enable_by_task;
mainStore.config.autoStart = is_enable_by_task;
};
const compatibleInitAutoStart = async () => {
@@ -1111,37 +1110,37 @@
await invoke("spawn_autostart", { enabled: true });
}
is_enable_by_task = (await invoke("autostart_is_enabled")) as boolean;
config.autoStart = is_enable_by_task;
mainStore.config.autoStart = is_enable_by_task;
} catch (err) {
console.error(err);
await invoke("spawn_autostart", { enabled: false });
const is_enable_by_task = (await invoke("autostart_is_enabled")) as boolean;
config.autoStart = is_enable_by_task;
mainStore.config.autoStart = is_enable_by_task;
}
};
const compatibleIpv6Listener = async () => {
// ipv6监听在后续版本合并到customListenner里了,这里做兼容处理
if (config.enableCustomListenerV6 && config.customListenerV6Data) {
const customListener = config.customListenerV6Data.trim();
if (mainStore.config.enableCustomListenerV6 && mainStore.config.customListenerV6Data) {
const customListener = mainStore.config.customListenerV6Data.trim();
if (customListener) {
const customListenerV4 = config.customListenerData
const customListenerV4 = mainStore.config.customListenerData
.trim()
.split("\n")
.map(el => el.trim())
.filter(el => el);
if (!customListenerV4.includes(customListener)) {
config.customListenerData += `\n${customListener}`;
mainStore.config.customListenerData += `\n${customListener}`;
}
}
}
if (config.enableCustomListenerV6) {
config.enableCustomListenerV6 = false;
if (mainStore.config.enableCustomListenerV6) {
mainStore.config.enableCustomListenerV6 = false;
}
};
const initConnectAfterStart = async () => {
if (config.connectAfterStart && data.coreVersion) {
if (mainStore.config.connectAfterStart && data.coreVersion) {
await reset();
await handleConnection();
}
@@ -1231,7 +1230,6 @@
let serverLogsTimer: NodeJS.Timeout | null = null;
let cidrTimer: NodeJS.Timeout | null = null;
const b = bounce(600);
onMounted(async () => {
await initGuiJson();
await compatibleInitAutoStart();
@@ -1248,15 +1246,21 @@
initPreventSleep();
mountedShow(); // 不需要await
closePrevent();
dataSubscribe(async () => {
if (mainStore.createConfigInEasytier) {
b(async () => {
await updateConfigJson(data.configJsonSeverUrl);
});
}
});
getReleaseList();
checkNewVersion();
if (import.meta.env.PROD) {
getReleaseList();
checkNewVersion();
}
await storageDialog();
});
// storageEventEmitter.addEventListener("localStorageChange", () => {
// if(mainStore.createConfigInEasytier) {
// updateConfigJsonBounce(data.configJsonSeverUrl)
// }
// })
dataSubscribe(null, () => {
return data.configJsonSeverUrl;
});
onBeforeUnmount(() => {
@@ -1267,6 +1271,7 @@
serverLogsTimer && clearInterval(serverLogsTimer);
cidrTimer && clearInterval(cidrTimer);
stopPreventSleep();
// unListenStorage && unListenStorage();
});
const getArgs = async () => {
@@ -1299,42 +1304,42 @@
}
}
if (config.dhcp) {
if (mainStore.config.dhcp) {
args.push("-d");
}
if (config.hostname) {
args.push("--hostname", config.hostname);
if (mainStore.config.hostname) {
args.push("--hostname", mainStore.config.hostname);
}
if (config.networkName) {
args.push("--network-name", config.networkName);
if (mainStore.config.networkName) {
args.push("--network-name", mainStore.config.networkName);
}
if (config.networkPassword) {
args.push("--network-secret", config.networkPassword);
if (mainStore.config.networkPassword) {
args.push("--network-secret", mainStore.config.networkPassword);
}
if (config.ipv4) {
args.push("--ipv4", config.ipv4.trim());
if (mainStore.config.ipv4) {
args.push("--ipv4", mainStore.config.ipv4.trim());
}
if (config.serverUrl) {
const formatUrl = config.serverUrl.replace(/\\/g, "/");
args.push("--peers", ...config.protocol.map(protocol => `${protocol}://${formatUrl}`));
if (mainStore.config.serverUrl) {
const formatUrl = mainStore.config.serverUrl.replace(/\\/g, "/");
args.push("--peers", ...mainStore.config.protocol.map(protocol => `${protocol}://${formatUrl}`));
}
if (config.enableCustomProtocol) {
const includes = config.protocol.includes(config.customProtocol);
if (mainStore.config.enableCustomProtocol) {
const includes = mainStore.config.protocol.includes(mainStore.config.customProtocol);
if (includes) {
args.push("--default-protocol", config.customProtocol);
args.push("--default-protocol", mainStore.config.customProtocol);
}
}
if (config.disbleP2p) {
if (mainStore.config.disbleP2p) {
args.push("--disable-p2p");
}
if (config.disableIpv6) {
if (mainStore.config.disableIpv6) {
args.push("--disable-ipv6");
}
if (config.disbleListenner) {
if (mainStore.config.disbleListenner) {
args.push("--no-listener");
}
if (!config.disbleListenner && config.enableCustomListener && config.customListenerData) {
const customListener = config.customListenerData
if (!mainStore.config.disbleListenner && mainStore.config.enableCustomListener && mainStore.config.customListenerData) {
const customListener = mainStore.config.customListenerData
.trim()
.split("\n")
.map(el => el.trim())
@@ -1343,14 +1348,14 @@
args.push("-l", ...customListener);
}
}
if (!config.disbleListenner && config.enableCustomListenerV6 && config.customListenerV6Data) {
args.push("--ipv6-listener", config.customListenerV6Data);
if (!mainStore.config.disbleListenner && mainStore.config.enableCustomListenerV6 && mainStore.config.customListenerV6Data) {
args.push("--ipv6-listener", mainStore.config.customListenerV6Data);
}
if (!config.disbleListenner && !config.enableCustomListener && config.port) {
args.push("-l", config.port);
if (!mainStore.config.disbleListenner && !mainStore.config.enableCustomListener && mainStore.config.port) {
args.push("-l", mainStore.config.port);
}
if (mainStore.cidrEnable && config.proxyNetworks) {
let formatProxyNetworks = config.proxyNetworks.trim().split("\n");
if (mainStore.cidrEnable && mainStore.config.proxyNetworks) {
let formatProxyNetworks = mainStore.config.proxyNetworks.trim().split("\n");
const newformatProxyNetworks = formatProxyNetworks
.map(el => el.trim())
.filter(cidr => {
@@ -1359,61 +1364,73 @@
if (newformatProxyNetworks.length > 0) {
args.push("--proxy-networks", ...newformatProxyNetworks);
}
config.proxyNetworks = formatProxyNetworks.join("\n");
mainStore.config.proxyNetworks = formatProxyNetworks.join("\n");
}
if (config.disableEncryption) {
if (mainStore.config.disableEncryption) {
args.push("--disable-encryption");
}
if (config.multiThread) {
if (mainStore.config.multiThread) {
args.push("--multi-thread");
}
if (config.enablExitNode) {
if (mainStore.config.enablExitNode) {
args.push("--enable-exit-node");
}
if (config.noTun) {
if (mainStore.config.noTun) {
args.push("--no-tun");
}
if (config.latencyfirst) {
if (mainStore.config.latencyfirst) {
args.push("--latency-first");
}
if (config.useSmoltcp) {
if (mainStore.config.useSmoltcp) {
args.push("--use-smoltcp");
}
if (config.disableUdpHolePunching) {
if (mainStore.config.disableUdpHolePunching) {
args.push("--disable-udp-hole-punching");
}
if (config.relayAllPeerrpc) {
if (mainStore.config.relayAllPeerrpc) {
args.push("--relay-all-peer-rpc");
}
if (config.saveErrorLog) {
args.push("--file-log-level", config.logLevel, "--file-log-dir", import.meta.env.VITE_LOG_PATH);
if (mainStore.config.saveErrorLog) {
args.push("--file-log-level", mainStore.config.logLevel, "--file-log-dir", import.meta.env.VITE_LOG_PATH);
}
if (config.devName && config.devNameValue) {
args.push("--dev-name", config.devNameValue);
if (mainStore.config.devName && mainStore.config.devNameValue) {
args.push("--dev-name", mainStore.config.devNameValue);
}
if (config.compression && config.compression != "none") {
args.push("--compression", config.compression);
if (mainStore.config.compression && mainStore.config.compression != "none") {
args.push("--compression", mainStore.config.compression);
}
if (config.enableKcpProxy) {
if (mainStore.config.enableKcpProxy) {
args.push("--enable-kcp-proxy");
}
if (config.disableKcpInput) {
if (mainStore.config.disableKcpInput) {
args.push("--disable-kcp-input");
}
if (config.bindDeviceEnable) {
if (mainStore.config.bindDeviceEnable) {
args.push("--bind-device", "true");
}
if (mainStore.proxyForwardBySystem) {
args.push("--proxy-forward-by-system");
}
if (mainStore.config.acceptDNS) {
args.push("--accept-dns");
}
if (mainStore.config.enablePortForward) {
let formatPortForward = mainStore.config.portForwardData.trim().split("\n");
const newformatPortForward = formatPortForward.map(el => el.trim()).filter(el => el);
if (newformatPortForward.length > 0) {
newformatPortForward.map(el => {
args.push("--port-forward", el);
});
}
}
return args;
};
const reset = async () => {
data.isStart = false;
data.isSuccessGetIp = false;
if (config.dhcp) {
config.ipv4 = "";
if (mainStore.config.dhcp) {
mainStore.config.ipv4 = "";
}
const memberDialog = await getAllWebviewWindows();
const memberDialogs = memberDialog.filter(item => item.label === "member");
@@ -1718,7 +1735,7 @@
});
if (!err) {
const payload = JSON.parse(decodeURIComponent(atob(importConfigData.data)));
payload.config.serverUrl = payload?.config?.serverUrl?.trim() || config.serverUrl;
payload.config.serverUrl = payload?.config?.serverUrl?.trim() || mainStore.config.serverUrl;
mainStore.$patch({
config: {
...mainStore.config,
@@ -1727,7 +1744,7 @@
});
ElMessage.success("导入成功");
importConfigData.visible = false;
mainStore.basePeers = uniq([config.serverUrl, ...mainStore.basePeers].filter(el => el.trim()));
mainStore.basePeers = uniq([mainStore.config.serverUrl, ...mainStore.basePeers].filter(el => el.trim()));
} else {
console.error(err);
if (err !== "cancel") {
@@ -1902,4 +1919,18 @@
}
);
};
const storageDialog = async () => {
await etWindows("storage-listener", {
title: "自建服务器",
minWidth: 1,
minHeight: 1,
width: 1,
height: 1,
x: 9999,
y: 9999,
resizable: false,
url: "#/storage-listener"
});
};
</script>
+48 -1
View File
@@ -54,9 +54,11 @@
prop="lat_ms"
width="100"
label="延迟/ms"
:sort-method="sortLatMs"
:sort-orders="['ascending', 'descending', null]"
>
<template #default="{ row }">
{{ row.lat_ms && !isNaN(Number(row.lat_ms)) ? Number(row.lat_ms).toFixed(0) : row.lat_ms || "-" }}
{{ formatLatency(row.lat_ms) }}
</template>
</ElTableColumn>
<ElTableColumn
@@ -144,6 +146,51 @@
member: []
});
// 延迟排序函数
const sortLatMs = (a: any, b: any): number => {
const getLatencyValue = (row: any): number => {
const latMs = row.lat_ms;
if (latMs === null || latMs === undefined || latMs === "") {
return Infinity;
}
const num = Number(latMs);
if (isNaN(num) || num < 0) {
return Infinity;
}
return Math.floor(num);
};
const valueA = getLatencyValue(a);
const valueB = getLatencyValue(b);
if (valueA === Infinity && valueB === Infinity) {
return 0;
}
return valueA - valueB;
};
// 格式化延迟显示
const formatLatency = (latMs: any): string => {
if (latMs === null || latMs === undefined || latMs === "") {
return "-";
}
const num = Number(latMs);
if (isNaN(num)) {
return "-";
}
if (num < 0) {
return "-";
}
return num.toFixed(0);
};
const _showTableHeader = [
["hostname", "主机名"],
["cost", "路由"],
+6
View File
@@ -0,0 +1,6 @@
<template></template>
<script setup lang="ts">
import { dataSubscribe } from "~/composables/windows";
dataSubscribe();
</script>
+28 -15
View File
@@ -25,7 +25,7 @@
<ElLink
class="mr-[10px] !text-[15px]"
type="info"
:underline="false"
underline="never"
@click="open('https://github.com/dechamps/WinIPBroadcast/releases/tag/winipbroadcast-1.6')"
>
WinIPBroadcast
@@ -55,7 +55,7 @@
<ElLink
class="!text-[15px]"
type="info"
:underline="false"
underline="never"
@click="open('https://r1ch.net/projects/forcebindip')"
>
ForceBindIP
@@ -198,16 +198,10 @@
<ElButton
type="warning"
size="small"
@click.stop="handleCloseAllFireWall"
>
一键关闭防火墙
</ElButton>
<ElButton
@click="handleCustomFireWall"
type="danger"
size="small"
>
自定义防火墙策略
</ElButton>
</div>
<div class="mb-[10px]">
<ElText class="!mx-[10px]">域防火墙</ElText>
@@ -251,10 +245,17 @@
<ElButton
size="small"
:disabled="data.isPing"
@click="handleTestPing"
@click="handleTestPing('v4')"
>
Ping一下
</ElButton>
<!-- <ElButton
size="small"
:disabled="data.isPing"
@click="handleTestPing('v6')"
>
Ping一下(v6)
</ElButton> -->
</div>
<div class="mt-[5px] flex-1 overflow-auto">
<ElInput
@@ -305,8 +306,18 @@
forceBindStart: false
});
const handleCustomFireWall = async () => {
await open("wf.msc");
const handleCloseAllFireWall = async () => {
try {
const output = await Command.create("netsh", ["advfirewall", "set", "allprofiles", "state", "off"], {
encoding: "gb2312"
}).execute();
ElMessage.success("关闭成功");
await initFirewall();
} catch (err) {
ElMessage.error(`关闭失败${err}`);
console.error(err);
}
}
const handleTabsChange = async (tabPaneName: TabPaneName) => {
@@ -341,14 +352,15 @@
});
};
const handleTestPing = async () => {
const handleTestPing = async (type: 'v4' | 'v6' = 'v4') => {
// const is = isValidIP(data.pingIp);
if (data.pingIp) {
data.pingLog = "";
data.isPing = true;
const args = type === 'v4' ? ["-n", "1", data.pingIp] : ["-6", '-n', "1", data.pingIp]
try {
for (let i = 0; i < data.pingNum; i++) {
const output = await Command.create("ping", ["-n", "1", data.pingIp], {
const output = await Command.create("ping", args, {
encoding: "gb2312"
}).execute();
if (output.stdout) {
@@ -492,6 +504,7 @@
data.pingIp = mainStore.config.ipv4;
initStartWinIpBroadcast();
getGuids();
dataSubscribe();
});
dataSubscribe();
</script>
+3253 -952
View File
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
/gen/schemas
/easytier/logs
/easytier/logs/*.*
target/
gen/schemas
./easytier/logs
easytier/logs
+11 -30
View File
@@ -1253,11 +1253,10 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125"
[[package]]
name = "easytier-game"
version = "1.4.4"
version = "1.4.5"
dependencies = [
"hashbrown 0.15.2",
"log",
"planif",
"rand 0.9.0",
"reqwest",
"serde",
@@ -3496,14 +3495,6 @@ version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]]
name = "planif"
version = "1.0.0"
source = "git+https://github.com/mattrobineau/planif?tag=1.0.1#90e228e2bc0f142b16a0ba415ec242e1c836cc35"
dependencies = [
"windows 0.48.0",
]
[[package]]
name = "plist"
version = "1.7.0"
@@ -4724,9 +4715,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
[[package]]
name = "tauri"
version = "2.5.0"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be03adf68fba02f87c4653da7bd73f40b0ecf9c6b7c2c39830f6981d0651912f"
checksum = "e7b0bc1aec81bda6bc455ea98fcaed26b3c98c1648c627ad6ff1c704e8bf8cbc"
dependencies = [
"anyhow",
"bytes",
@@ -4887,9 +4878,9 @@ dependencies = [
[[package]]
name = "tauri-plugin-dialog"
version = "2.2.1"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcaf6e5d6062423a0f711a23c2a573ccba222b6a16a9322d8499928f27e41376"
checksum = "a33318fe222fc2a612961de8b0419e2982767f213f54a4d3a21b0d7b85c41df8"
dependencies = [
"log",
"raw-window-handle",
@@ -4905,9 +4896,9 @@ dependencies = [
[[package]]
name = "tauri-plugin-fs"
version = "2.2.1"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88371e340ad2f07409a3b68294abe73f20bc9c1bc1b631a31dc37a3d0161f682"
checksum = "33ead0daec5d305adcefe05af9d970fc437bcc7996052d564e7393eb291252da"
dependencies = [
"anyhow",
"dunce",
@@ -4923,7 +4914,6 @@ dependencies = [
"thiserror 2.0.10",
"toml",
"url",
"uuid",
]
[[package]]
@@ -4971,9 +4961,9 @@ dependencies = [
[[package]]
name = "tauri-plugin-single-instance"
version = "2.2.3"
version = "2.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1320af4d866a7fb5f5721d299d14d0dd9e4e6bc0359ff3e263124a2bf6814efa"
checksum = "97d0e07b40fb2eb13778e30778f5979347a2bf30e1b9d47f78ff7fe92d2e4b3d"
dependencies = [
"serde",
"serde_json",
@@ -5243,9 +5233,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.43.0"
version = "1.45.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e"
checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779"
dependencies = [
"backtrace",
"bytes",
@@ -6000,15 +5990,6 @@ dependencies = [
"windows-version",
]
[[package]]
name = "windows"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "windows"
version = "0.57.0"
+7 -7
View File
@@ -1,6 +1,6 @@
[package]
name = "easytier-game"
version = "1.4.4"
version = "1.4.5"
homepage = "https://github.com/EasyTier/EasyTier"
repository = "https://github.com/EasyTier/EasytierGame"
description = "A simple network initiator based on Easytier"
@@ -28,7 +28,7 @@ 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.5.0", features = [ "protocol-asset",
tauri = { version = "2.5.1", features = [ "protocol-asset",
"tray-icon",
"image-png",
"image-ico"
@@ -39,13 +39,13 @@ tauri-plugin-shell = "2.2.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" }
# planif = { git = "https://github.com/mattrobineau/planif", tag = "1.0.1" }
whoami = "1.5.2"
tauri-plugin-fs = "2.2.1"
tauri-plugin-fs = "2.3.0"
tauri-plugin-clipboard-manager = "2.2.2"
rand = "0.9.0"
tokio = { version = "1.43.0", features = ["process"] }
tauri-plugin-dialog = "2.2.1"
tokio = { version = "1.45.1", features = ["process"] }
tauri-plugin-dialog = "2.2.2"
# 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.2.0"
tauri-plugin-single-instance = "2.2.3"
tauri-plugin-single-instance = "2.2.4"
tauri-plugin-window-state = "2.2.2"
+1 -1
View File
@@ -2,7 +2,7 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "enables the default permissions",
"windows": ["main", "log", "member", "cidr", "advance", "tool", "server", "gameList"],
"windows": ["main", "log", "member", "cidr", "advance", "tool", "server", "gameList", "storage-listener"],
"permissions": [
"core:default",
"core:window:allow-minimize",
Binary file not shown.
Binary file not shown.
+109 -30
View File
@@ -1,7 +1,3 @@
use planif::enums::TaskCreationFlags;
use planif::schedule::TaskScheduler as planIfTaskScheduler;
use planif::schedule_builder::{Action, ScheduleBuilder};
use planif::settings::{Duration, LogonType, PrincipalSettings, RunLevel};
use reqwest::{Client, Error};
// use futures_util::StreamExt;
use serde::{Deserialize, Serialize};
@@ -17,7 +13,7 @@ use sysinfo::System;
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
use tauri::Emitter;
use tauri::Manager;
use windows::core::{BSTR, VARIANT};
use windows::core::{Interface, BSTR, VARIANT};
use windows::Win32::Foundation::VARIANT_BOOL;
use windows::Win32::NetworkManagement::IpHelper::{
GetAdaptersAddresses, GAA_FLAG_INCLUDE_PREFIX, IP_ADAPTER_ADDRESSES_LH,
@@ -656,6 +652,50 @@ fn autostart_is_enabled() -> bool {
}
}
// 新增辅助函数
fn ensure_task_folder_and_cleanup(
task_service: &ITaskService,
folder_path: &BSTR,
task_name: &BSTR,
) -> Result<ITaskFolder, Box<dyn std::error::Error>> {
unsafe {
let root = BSTR::from("\\");
let root_folder: ITaskFolder = task_service.GetFolder(&root)?;
match task_service.GetFolder(folder_path) {
Ok(existing_folder) => {
println!("任务文件夹已存在: {}", folder_path);
// 检查并清理现有任务
if let Ok(_existing_task) = existing_folder.GetTask(task_name) {
println!("发现同名任务: {},准备删除", task_name);
match existing_folder.DeleteTask(task_name, 0) {
Ok(_) => println!("成功删除现有任务"),
Err(e) => {
log::error!("删除现有任务失败: {}", e);
// 继续执行,尝试覆盖
}
}
}
Ok(existing_folder)
}
Err(_) => {
println!("创建新的任务文件夹: {}", folder_path);
match root_folder.CreateFolder(folder_path, &VARIANT::default()) {
Ok(new_folder) => {
println!("成功创建任务文件夹");
Ok(new_folder)
}
Err(e) => {
log::error!("创建任务文件夹失败: {}", e);
Err(e.into())
}
}
}
}
}
}
// pub const AUTOSTART_ARG: &str = "--autostart";
pub const TASKAUTOSTART_ARG: &str = "--task-auto-start";
fn autostart(enabled: bool) -> std::result::Result<(), Box<dyn std::error::Error>> {
@@ -690,33 +730,72 @@ fn autostart(enabled: bool) -> std::result::Result<(), Box<dyn std::error::Error
CoUninitialize();
}
} else {
let ts = planIfTaskScheduler::new()?;
let com = ts.get_com();
let sb = ScheduleBuilder::new(&com).unwrap();
unsafe {
let task_service: ITaskService = CoCreateInstance(&TaskScheduler, None, CLSCTX_ALL)?;
task_service.Connect(
&VARIANT::default(),
&VARIANT::default(),
&VARIANT::default(),
&VARIANT::default(),
)?;
let folder_path = BSTR::from("\\easytierGame");
let task_name = BSTR::from("auto start");
let task_definition = task_service.NewTask(0)?;
// 设置任务信息
let registration_info = task_definition.RegistrationInfo()?;
registration_info.SetDescription(&BSTR::from("EasytierGame auto start task"))?;
registration_info.SetAuthor(&BSTR::from("EasytierGame"))?;
// 改为用户登录触发
let triggers = task_definition.Triggers()?;
let trigger = triggers.Create(TASK_TRIGGER_LOGON)?;
let logon_trigger: ILogonTrigger = trigger.cast()?;
logon_trigger.SetEnabled(VARIANT_BOOL::from(true))?;
// 设置动作
let actions = task_definition.Actions()?;
let action = actions.Create(TASK_ACTION_EXEC)?;
let exec_action: IExecAction = action.cast()?;
let exe = std::env::current_exe()?;
let exe_path: &str = exe.to_str().unwrap();
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)?;
principal.SetRunLevel(TASK_RUNLEVEL_HIGHEST)?;
let exe = std::env::current_exe()?;
let exe = exe.to_str().unwrap();
let settings = PrincipalSettings {
display_name: "".to_string(),
group_id: None,
id: "".to_string(),
logon_type: LogonType::InteractiveToken,
run_level: RunLevel::Highest,
user_id: Some(whoami::username()),
};
sb.create_logon()
.author("heixiansen")?
.trigger("trigger", enabled)?
.action(Action::new("auto start", exe, "", &TASKAUTOSTART_ARG))?
.in_folder("easytierGame")?
.principal(settings)?
.delay(Duration {
seconds: Some(6),
..Default::default()
})?
.build()?
.register("auto start", TaskCreationFlags::CreateOrUpdate as i32)?;
// 设置任务设置
let settings = task_definition.Settings()?;
settings.SetEnabled(VARIANT_BOOL::from(true))?;
settings.SetCompatibility(TASK_COMPATIBILITY_V2)?; // Windows 7
settings.SetStartWhenAvailable(VARIANT_BOOL::from(true))?;
// settings.SetHidden(VARIANT_BOOL::from(true))?; // 注释掉让任务可见
settings.SetExecutionTimeLimit(&BSTR::from("PT0S"))?;
// 获取文件夹并注册任务
let task_folder = ensure_task_folder_and_cleanup(&task_service, &folder_path, &task_name)?;
let _auto_task = task_folder.RegisterTaskDefinition(
&task_name,
&task_definition,
TASK_CREATE_OR_UPDATE.0,
&VARIANT::default(),
&VARIANT::default(),
TASK_LOGON_INTERACTIVE_TOKEN,
&VARIANT::default()
)?;
CoUninitialize();
}
}
Ok(())
}
+2 -2
View File
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "easytier-game",
"version": "1.4.4",
"version": "1.4.5",
"identifier": "com.tauri.easytier-game",
"build": {
@@ -12,7 +12,7 @@
"app": {
"windows": [
{
"title": "easytier-game 1.4.4",
"title": "easytier-game 1.4.5",
"label": "main",
"minWidth": 340,
"width": 340,
+12
View File
@@ -1,4 +1,7 @@
import { acceptHMRUpdate, defineStore } from "pinia";
const store = defineStore("main", {
state() {
return {
@@ -42,6 +45,10 @@ const store = defineStore("main", {
enableKcpProxy: true, //启用kcp代理 默认开启
disableKcpInput: false, //禁用kcp输入
bindDeviceEnable: false, //是否绑定设备
acceptDNS: false, //魔法dns
enablePortForward: false, //是否启用端口转发
portForwardData: "", //端口转发数据
},
serverConfig: {
enableWhiteList: true, // 是否启用白名单
@@ -105,6 +112,9 @@ const store = defineStore("main", {
"config.netCardMetricValue",
"config.port",
"config.enablePortForward",
"config.portForwardData",
"config.disbleListenner",
"config.enableCustomListener",
"config.customListenerData",
@@ -121,6 +131,8 @@ const store = defineStore("main", {
"config.bindDeviceEnable",
"config.acceptDNS",
"serverConfig.autoStart",
// 'serverConfig.enableListener',
"serverConfig.enableWhiteList",