diff --git a/composables/configJson.ts b/composables/configJson.ts index a0ce63a..d9ee8e8 100644 --- a/composables/configJson.ts +++ b/composables/configJson.ts @@ -22,6 +22,9 @@ export const updateConfigJson = async (configJsonSeverUrl: Array | strin saveErrorLog, logLevel, serverUrl, + port, + enableCustomListener, + customListenerData, ...otherConfig } = mainStore.config; let writeServerUrl: Array | string = serverUrl; diff --git a/composables/server.ts b/composables/server.ts index 6a282ed..11c53ff 100644 --- a/composables/server.ts +++ b/composables/server.ts @@ -14,9 +14,8 @@ export const getServerArgs = () => { .split("\n") .map(el => el.trim()) .filter(el => el) - .join(" "); if (whiteList && mainStore.serverConfig.enableWhiteList) { - args.push("--relay-network-whitelist", whiteList); + args.push("--relay-network-whitelist", ...whiteList); } if (!whiteList && mainStore.serverConfig.enableWhiteList) { args.push("--relay-network-whitelist"); diff --git a/composables/windows.ts b/composables/windows.ts index 0b8d77c..a9034fc 100644 --- a/composables/windows.ts +++ b/composables/windows.ts @@ -2,6 +2,8 @@ import { type UnlistenFn } from "@tauri-apps/api/event"; import { getCurrentWindow, PhysicalPosition, type WindowOptions, Window, currentMonitor } from "@tauri-apps/api/window"; 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"; const _listenersMaps: { [key: string]: [UnlistenFn | null, UnlistenFn | null] } = {}; @@ -61,3 +63,27 @@ export default async ( } } }; + +export const dataSubscribe = async (cb?: (...args: any) => any) => { + if (!cb) return; + const mainStore = useMainStore(); + const currentWindow = getCurrentWindow(); + let removeSubscribe = mainStore.$subscribe(async (...args) => { + const emitData = await cb(args); + await currentWindow.emitTo({ kind: "Window", label: "main" }, "config", emitData); + }); + const unlisten = currentWindow.listen("global-main-store", event => { + console.log('global-main-store') + console.log(event); + removeSubscribe && removeSubscribe(); + mainStore.$patch({ ...event.payload.store }); // 更新全局状态 + removeSubscribe = mainStore.$subscribe(async (...args) => { + const emitData = await cb(args); + await currentWindow.emitTo({ kind: "Window", label: "main" }, "config", emitData); + }); + }); + onBeforeUnmount(async () => { + unlisten && (await unlisten)(); + removeSubscribe && removeSubscribe(); + }); +}; diff --git a/package.json b/package.json index 4c1862b..4319433 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "author": "leizi97", "description": "A simple network initiator based on Easytier", - "version": "1.2.8", + "version": "1.2.9", "scripts": { "dev": "nuxt dev --dotenv env/.env.dev --host 0.0.0.0", "build": "nuxt generate --dotenv env/.env.prod", @@ -16,7 +16,6 @@ "@pinia/nuxt": "0.8.0", "@tauri-apps/api": "^2.1.1", "@tauri-apps/cli": "^2.1.0", - "@tauri-apps/plugin-autostart": "~2", "@tauri-apps/plugin-cli": "^2.0.0", "@tauri-apps/plugin-clipboard-manager": "^2.0.0", "@tauri-apps/plugin-fs": "~2", diff --git a/pages/advance.vue b/pages/advance.vue index 03cb785..c870307 100644 --- a/pages/advance.vue +++ b/pages/advance.vue @@ -1,7 +1,29 @@ diff --git a/pages/index.vue b/pages/index.vue index 0792f8b..3f5957d 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -83,9 +83,10 @@ :value="item" >
- +

{{ item }}

+

{{ item }}

> }>({ logVisible: false, cidrVisible: false, @@ -734,13 +735,18 @@ this.unListenServerThreadId = unListen; }, async listenConfigStart() { + const appWindow = getCurrentWindow(); const unListen = await listen("config", event => { // console.error("config", event.payload); const ipv4 = config.ipv4; mainStore.$patch(event.payload as any); config.ipv4 = ipv4; + appWindow.emitTo({ kind: "Any" }, "global-main-store", { store: { ...mainStore.$state } }); }); - this.unListenConfigStart = unListen; + const unListen2 = mainStore.$subscribe(() => { + appWindow.emitTo({ kind: "Any" }, "global-main-store", { store: { ...mainStore.$state } }); + }) + this.unListenConfigStart = [unListen, unListen2]; }, async listenStartStopServer() { const unListen = await listen<{ args: Array }>("startStopServer", async event => { @@ -945,12 +951,12 @@ const mountedShow = async () => { const args = await getMatches(); - if(!args.args?.['task-auto-start']?.value) { + if (!args.args?.["task-auto-start"]?.value) { const appWindow = getCurrentWindow(); await appWindow.show(); await appWindow.setFocus(); } - } + }; let logsTimer: NodeJS.Timeout | null = null; let serverLogsTimer: NodeJS.Timeout | null = null; @@ -975,7 +981,8 @@ onBeforeUnmount(() => { unListenAll(); listenObj.unListenReleaseList && listenObj.unListenReleaseList(); - listenObj.unListenConfigStart && listenObj.unListenConfigStart(); + listenObj.unListenConfigStart && listenObj.unListenConfigStart[0](); + listenObj.unListenConfigStart && listenObj.unListenConfigStart[1](); listenObj.unListenStartStopServer && listenObj.unListenStartStopServer(); logsTimer && clearInterval(logsTimer); serverLogsTimer && clearInterval(serverLogsTimer); @@ -1030,6 +1037,12 @@ const formatUrl = config.serverUrl.replace(/\\/g, "/"); args.push("--peers", ...config.protocol.map(protocol => `${protocol}://${formatUrl}`)); } + if (config.enableCustonProtocol) { + const includes = config.protocol.includes(config.customProtocol); + if (includes) { + args.push("--default-protocol", config.customProtocol); + } + } if (config.disbleP2p) { args.push("--disable-p2p"); } @@ -1039,6 +1052,19 @@ if (config.disbleListenner) { args.push("--no-listener"); } + if (!config.disbleListenner && config.enableCustomListener && config.customListenerData) { + const customListener = config.customListenerData + .trim() + .split("\n") + .map(el => el.trim()) + .filter(el => el); + if (customListener.length > 0) { + args.push("-l", ...customListener); + } + } + if (!config.disbleListenner && !config.enableCustomListener && config.port) { + args.push("-l", config.port); + } if (mainStore.cidrEnable && config.proxyNetworks) { // console.error(config.proxyNetworks); const reg = /\d+\.\d+\.\d+\.\d+\/\d+/g; @@ -1182,22 +1208,6 @@ } if (command === "create_server") { await handleShowServerDialog(); - // if (data.isStart) { - // const [error] = await ElConfirmDanger("切换会停止{action},是否继续?", "提示", { - // action: "`联机/服务`", - // confirmButtonText: "继续", - // cancelButtonText: "取消" - // }); - // if (!error) await reset(); - // } - // mainStore.enableCreateServer = !mainStore.enableCreateServer; - // if (mainStore.config.relayAllPeerrpc && !mainStore.enableCreateServer) { - // const [error] = await ElConfirmPrimary("是否关闭RPC流量转发?", "提示", { - // confirmButtonText: "关闭", - // cancelButtonText: "取消" - // }); - // if (!error) mainStore.config.relayAllPeerrpc = false; - // } } }; @@ -1285,7 +1295,7 @@ data.logVisible = true; logsTimer && clearInterval(logsTimer); logsTimer = setInterval(() => { - appWindow.emitTo("log", "logs", data.log); + appWindow.emitTo({ kind: "WebviewWindow", label: "log" }, "logs", data.log); }, 650); }, () => { @@ -1368,7 +1378,10 @@ data.serverVisible = true; serverLogsTimer && clearInterval(serverLogsTimer); serverLogsTimer = setInterval(() => { - appWindow.emitTo("server", "server_logs", { log: data.serverLog, threadId: listenObj.server_thread_id.value }); + appWindow.emitTo({ kind: "WebviewWindow", label: "server" }, "server_logs", { + log: data.serverLog, + threadId: listenObj.server_thread_id.value + }); }, 650); }, () => { diff --git a/pages/server.vue b/pages/server.vue index c57c540..0a36999 100644 --- a/pages/server.vue +++ b/pages/server.vue @@ -85,6 +85,7 @@ import { getCurrentWindow } from "@tauri-apps/api/window"; import { listen, type UnlistenFn } from "@tauri-apps/api/event"; import { getServerArgs } from "@/composables/server"; + import { dataSubscribe } from "@/composables/windows"; const appWindow = getCurrentWindow(); const mainStore = useMainStore(); @@ -122,7 +123,8 @@ await appWindow.emitTo("main", "startStopServer", { args }); }; - mainStore.$subscribe(async (...a) => { - await appWindow.emitTo("main", "config", { serverConfig: { ...mainStore.serverConfig }}); + dataSubscribe(async (...a) => { + return { serverConfig: { ...mainStore.serverConfig }}; }); + diff --git a/pages/tool.vue b/pages/tool.vue index 12df71d..cffb0a5 100644 --- a/pages/tool.vue +++ b/pages/tool.vue @@ -181,8 +181,8 @@ import { onMounted, reactive } from "vue"; import useMainStore from "@/stores/index"; import { handleWinipBcStart, initStartWinIpBroadcast } from "@/composables/netcard"; - import { getCurrentWindow } from "@tauri-apps/api/window"; import { isValidIP } from "~/utils"; + import { dataSubscribe } from "~/composables/windows"; const mainStore = useMainStore(); const data = reactive({ @@ -328,10 +328,9 @@ } }; - const appWindow = getCurrentWindow(); - mainStore.$subscribe((...a) => { - // console.error("subscribe", a); - appWindow.emitTo("main", "config", { winIpBcAutoStart: mainStore.winIpBcAutoStart, config: { ...mainStore.config } }); + + dataSubscribe(async (...a) => { + return { winIpBcAutoStart: mainStore.winIpBcAutoStart, config: { ...mainStore.config } }; }); onMounted(() => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5f8e40c..ebbbf1f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,9 +26,6 @@ importers: '@tauri-apps/cli': specifier: ^2.1.0 version: 2.1.0 - '@tauri-apps/plugin-autostart': - specifier: ~2 - version: 2.0.0 '@tauri-apps/plugin-cli': specifier: ^2.0.0 version: 2.0.0 @@ -1147,9 +1144,6 @@ packages: engines: {node: '>= 10'} hasBin: true - '@tauri-apps/plugin-autostart@2.0.0': - resolution: {integrity: sha512-NEwOQWVasZ8RczXkMLNJokRDujneuMH/UFA5t84DLkbNZUmiD3G7HZWhgSd1YQ0BFU9h9w+h2B/py3y6bzWg4Q==} - '@tauri-apps/plugin-cli@2.0.0': resolution: {integrity: sha512-glQmlL1IiCGEa1FHYa/PTPSeYhfu56omLRgHXWlJECDt6DbJyRuJWVgtkQfUxtqnVdYnnU+DGIGeiInoEqtjLw==} @@ -4991,10 +4985,6 @@ snapshots: '@tauri-apps/cli-win32-ia32-msvc': 2.1.0 '@tauri-apps/cli-win32-x64-msvc': 2.1.0 - '@tauri-apps/plugin-autostart@2.0.0': - dependencies: - '@tauri-apps/api': 2.1.1 - '@tauri-apps/plugin-cli@2.0.0': dependencies: '@tauri-apps/api': 2.1.1 diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index e4d60af..ec4f096 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -355,17 +355,6 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" -[[package]] -name = "auto-launch" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f012b8cc0c850f34117ec8252a44418f2e34a2cf501de89e29b241ae5f79471" -dependencies = [ - "dirs 4.0.0", - "thiserror 1.0.64", - "winreg 0.10.1", -] - [[package]] name = "autocfg" version = "1.4.0" @@ -1139,33 +1128,13 @@ dependencies = [ "subtle", ] -[[package]] -name = "dirs" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" -dependencies = [ - "dirs-sys 0.3.7", -] - [[package]] name = "dirs" version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ - "dirs-sys 0.4.1", -] - -[[package]] -name = "dirs-sys" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" -dependencies = [ - "libc", - "redox_users", - "winapi", + "dirs-sys", ] [[package]] @@ -1258,7 +1227,7 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "easytier-game" -version = "1.2.8" +version = "1.2.9" dependencies = [ "log", "planif", @@ -1268,7 +1237,6 @@ dependencies = [ "sysinfo", "tauri", "tauri-build", - "tauri-plugin-autostart", "tauri-plugin-cli", "tauri-plugin-clipboard-manager", "tauri-plugin-fs", @@ -1299,7 +1267,7 @@ dependencies = [ "rustc_version", "toml 0.8.2", "vswhom", - "winreg 0.52.0", + "winreg", ] [[package]] @@ -4402,7 +4370,7 @@ checksum = "e545de0a2dfe296fa67db208266cd397c5a55ae782da77973ef4c4fac90e9f2c" dependencies = [ "anyhow", "bytes", - "dirs 5.0.1", + "dirs", "dunce", "embed_plist", "futures-util", @@ -4453,7 +4421,7 @@ checksum = "7bd2a4bcfaf5fb9f4be72520eefcb61ae565038f8ccba2a497d8c28f463b8c01" dependencies = [ "anyhow", "cargo_toml", - "dirs 5.0.1", + "dirs", "glob", "heck 0.5.0", "json-patch", @@ -4525,21 +4493,6 @@ dependencies = [ "walkdir", ] -[[package]] -name = "tauri-plugin-autostart" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bba6bb936e0fd0a58ed958b49e2e423dd40949c9d9425cc991be996959e3838e" -dependencies = [ - "auto-launch", - "log", - "serde", - "serde_json", - "tauri", - "tauri-plugin", - "thiserror 1.0.64", -] - [[package]] name = "tauri-plugin-cli" version = "2.0.1" @@ -5039,7 +4992,7 @@ checksum = "533fc2d4105e0e3d96ce1c71f2d308c9fbbe2ef9c587cab63dd627ab5bde218f" dependencies = [ "core-graphics 0.24.0", "crossbeam-channel", - "dirs 5.0.1", + "dirs", "libappindicator", "muda", "objc2", @@ -5898,15 +5851,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - [[package]] name = "winreg" version = "0.52.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 33db545..efbc788 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "easytier-game" -version = "1.2.8" +version = "1.2.9" homepage = "https://github.com/EasyTier/EasyTier" repository = "https://github.com/EasyTier/EasytierGame" description = "A simple network initiator based on Easytier" @@ -50,7 +50,6 @@ version = "0.58.0" features = ["Win32_System_TaskScheduler"] [target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies] -tauri-plugin-autostart = "2.0.1" tauri-plugin-cli = "2" tauri-plugin-single-instance = "2.0.1" tauri-plugin-window-state = "2" diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 18899c0..3991351 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -30,10 +30,6 @@ "core:webview:allow-webview-show", "core:webview:allow-webview-hide", "core:webview:allow-webview-close", - "autostart:default", - "autostart:allow-enable", - "autostart:allow-disable", - "autostart:allow-is-enabled", "core:tray:allow-get-by-id", "core:tray:allow-set-icon", "core:tray:allow-new", diff --git a/src-tauri/capabilities/desktop.json b/src-tauri/capabilities/desktop.json deleted file mode 100644 index a33e9fd..0000000 --- a/src-tauri/capabilities/desktop.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "identifier": "desktop-capability", - "platforms": [ - "macOS", - "windows", - "linux" - ], - "windows": [ - "main" - ], - "permissions": [ - "cli:default" - ] -} \ No newline at end of file diff --git a/src-tauri/easytier/config_template.json b/src-tauri/easytier/config_template.json index 4552edb..322b90d 100644 --- a/src-tauri/easytier/config_template.json +++ b/src-tauri/easytier/config_template.json @@ -21,6 +21,8 @@ "dhcp": false, // 动态分配IP "devName": false, // 是否启用自定义网卡名 "devNameValue": "", // 网卡名(启用devName之后才生效) + "enableCustonProtocol": false, // 是否启用自定义协议 + "customProtocol": "tcp", // 自定义协议类型 "enableNetCardMetric": false, // 自定义easytier每次生成的网卡跃点 "netCardMetricValue": 1 // 网卡跃点数量(1-9999) } \ No newline at end of file diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index afa0af4..1ddab89 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -15,7 +15,6 @@ use sysinfo::System; use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent}; use tauri::Emitter; use tauri::Manager; -use tauri_plugin_autostart::MacosLauncher; use windows::core::{BSTR, VARIANT}; use windows::Win32::Foundation::VARIANT_BOOL; use windows::Win32::System::Com::*; diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index af3a341..6b57621 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "easytier-game", - "version": "1.2.8", + "version": "1.2.9", "identifier": "com.tauri.easytier-game", "build": { @@ -13,7 +13,7 @@ "app": { "windows": [ { - "title": "easytier-game 1.2.8", + "title": "easytier-game 1.2.9", "label": "main", "minWidth": 340, "width": 340, diff --git a/stores/index.ts b/stores/index.ts index 538d93e..382fd56 100644 --- a/stores/index.ts +++ b/stores/index.ts @@ -13,6 +13,9 @@ export default defineStore("main", { autoStart: false, // 是否自动启动 connectAfterStart: false, //软件打开后,是否自动连接 disableIpv6: false, // 是否禁用IPv6 + port: "11010", // 监听端口号 + enableCustomListener: false, // 是否自定义监听 + customListenerData: "", // 自定义监听地址 disbleListenner: false, // 是否禁用监听 disableEncryption: true, // 是否禁用加密 multiThread: false, //使用多线程 @@ -28,6 +31,8 @@ export default defineStore("main", { logLevel: "error", //日志等级 devName: false, //自定义网卡名 devNameValue: "", //自定义网卡名 + enableCustonProtocol: false, //自定义默认协议 + customProtocol: "tcp", //自定义默认协议 enableNetCardMetric: false, //启用网卡自定义跃点 netCardMetricValue: 1 //自定义网卡跃点值 }, @@ -37,7 +42,7 @@ export default defineStore("main", { serverWhiteList: "", // 服务器流量转发白名单 // enableListener: true, // 是否启用监听 autoStart: false, //随软件自启 - port: "11010", // 服务器端口 + port: "11010" // 服务器端口 }, cidrEnable: false, basePeers: ["public.easytier.top:11010"], @@ -48,7 +53,6 @@ export default defineStore("main", { createConfigInEasytier: false, //在easytier目录生成config.json文件吗 githubFastUrl: "https://ghproxy.cc/", - winipBcPid: 0, winipBcStart: false }; @@ -83,14 +87,18 @@ export default defineStore("main", { "config.devNameValue", "config.enableNetCardMetric", "config.netCardMetricValue", + "config.port", + "config.enableCustomListener", + "config.customListenerData", + "config.enableCustonProtocol", + "config.customProtocol", "serverConfig.autoStart", // 'serverConfig.enableListener', - 'serverConfig.enableWhiteList', - 'serverConfig.relayAllPeerrpc', - 'serverConfig.serverWhiteList', - 'serverConfig.port', - + "serverConfig.enableWhiteList", + "serverConfig.relayAllPeerrpc", + "serverConfig.serverWhiteList", + "serverConfig.port", "cidrEnable", "basePeers", @@ -99,8 +107,8 @@ export default defineStore("main", { "configPath", "winIpBcAutoStart", "createConfigInEasytier", - "githubFastUrl", - ], + "githubFastUrl" + ] // // 除了这些,其他都要存下来 // omit: ["winipBcPid", "winipBcStart"] } diff --git a/utils/index.ts b/utils/index.ts index 5ceaaee..5cd1316 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -64,6 +64,12 @@ export const ATJ = (promise: Promise, errorExt: string | undefined = undefi }); }; +const _supportProtocols = ["tcp", "udp", "ws", "wss", "quic"]; + +export const supportProtocols = () => { + return _supportProtocols.slice(); +} + export const parsePeerInfo = (content: string) => { if(!content) return []; // 将表格字符串分割成行