#Improve 修复更新时可以点击联机按钮 新增easytier发布页 新增wg协议选项 优化描述,删除不必要的代码和文件
@@ -0,0 +1,12 @@
|
|||||||
|
node_modules
|
||||||
|
*.log*
|
||||||
|
.nuxt
|
||||||
|
.nitro
|
||||||
|
.cache
|
||||||
|
.output
|
||||||
|
.env
|
||||||
|
dist
|
||||||
|
.fleet
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
release
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# 为了使用 ,您需要调整 使用以下任何一种方法,以便正确捆绑依赖项(参考:#6389):pnpm.npmrc
|
||||||
|
node-linker=hoisted
|
||||||
|
public-hoist-pattern=*
|
||||||
|
# shamefully-hoist=true # == public-hoist-pattern=*
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<template>
|
||||||
|
<NuxtLayout>
|
||||||
|
<NuxtPage />
|
||||||
|
</NuxtLayout>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
@tailwind base;
|
||||||
|
|
||||||
|
/*
|
||||||
|
用于进行主题更换,如果要更换elemenet-plus-ui的主题记得加上!important,不然更换会失败
|
||||||
|
*/
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
html {
|
||||||
|
font-family: "Helvetica Neue", "Luxi Sans", "DejaVu Sans", Tahoma, "Hiragino Sans GB", STHeiti, "Microsoft YaHei";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#__easytier {
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
background-color: #fff;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 3px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background-color: #0003;
|
||||||
|
border-radius: 10px;
|
||||||
|
transition: all 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
_self文件夹 用于存放“只和”本项目相关的方法,公用方法请在_self外面编写
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import { Menu, MenuItem, PredefinedMenuItem } from '@tauri-apps/api/menu'
|
||||||
|
import { TrayIcon } from '@tauri-apps/api/tray'
|
||||||
|
import { getCurrentWindow } from '@tauri-apps/api/window'
|
||||||
|
import pkg from '@/package.json'
|
||||||
|
|
||||||
|
const DEFAULT_TRAY_NAME = 'main'
|
||||||
|
|
||||||
|
async function toggleVisibility() {
|
||||||
|
if (await getCurrentWindow().isVisible()) {
|
||||||
|
await getCurrentWindow().hide()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await getCurrentWindow().show()
|
||||||
|
await getCurrentWindow().setFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function useTray(init: boolean = false) {
|
||||||
|
let tray
|
||||||
|
try {
|
||||||
|
tray = await TrayIcon.getById(DEFAULT_TRAY_NAME)
|
||||||
|
if (!tray) {
|
||||||
|
tray = await TrayIcon.new({
|
||||||
|
tooltip: `EasyTier\n${pkg.version}`,
|
||||||
|
title: `EasyTier\n${pkg.version}`,
|
||||||
|
id: DEFAULT_TRAY_NAME,
|
||||||
|
menu: await Menu.new({
|
||||||
|
id: 'main',
|
||||||
|
items: await generateMenuItem(),
|
||||||
|
}),
|
||||||
|
action: async () => {
|
||||||
|
toggleVisibility()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.warn('Error while creating tray icon:', error)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (init) {
|
||||||
|
tray.setTooltip(`EasyTier\n${pkg.version}`)
|
||||||
|
tray.setMenuOnLeftClick(false)
|
||||||
|
tray.setMenu(await Menu.new({
|
||||||
|
id: 'main',
|
||||||
|
items: await generateMenuItem(),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
return tray
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function generateMenuItem() {
|
||||||
|
return [
|
||||||
|
await MenuItemExit('Exit'),
|
||||||
|
await PredefinedMenuItem.new({ item: 'Separator' }),
|
||||||
|
await MenuItemShow('Show / Hide'),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function MenuItemExit(text: string) {
|
||||||
|
return await PredefinedMenuItem.new({
|
||||||
|
text,
|
||||||
|
item: 'Quit',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function MenuItemShow(text: string) {
|
||||||
|
return await MenuItem.new({
|
||||||
|
id: 'show',
|
||||||
|
text,
|
||||||
|
action: async () => {
|
||||||
|
await toggleVisibility()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setTrayMenu(items: (MenuItem | PredefinedMenuItem)[] | undefined = undefined) {
|
||||||
|
const tray = await useTray()
|
||||||
|
if (!tray)
|
||||||
|
return
|
||||||
|
const menu = await Menu.new({
|
||||||
|
id: 'main',
|
||||||
|
items: items || await generateMenuItem(),
|
||||||
|
})
|
||||||
|
tray.setMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setTrayRunState(isRunning: boolean = false) {
|
||||||
|
const tray = await useTray()
|
||||||
|
if (!tray)
|
||||||
|
return
|
||||||
|
tray.setIcon(isRunning ? 'icons/icon-inactive.ico' : 'icons/icon.ico')
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setTrayTooltip(tooltip: string) {
|
||||||
|
if (tooltip) {
|
||||||
|
const tray = await useTray()
|
||||||
|
if (!tray)
|
||||||
|
return
|
||||||
|
tray.setTooltip(`EasyTier\n${pkg.version}\n${tooltip}`)
|
||||||
|
tray.setTitle(`EasyTier\n${pkg.version}\n${tooltip}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<template>
|
||||||
|
<NuxtPage />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="tsx">
|
||||||
|
import { onBeforeUnmount } from "vue";
|
||||||
|
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
|
||||||
|
const appWindow = getCurrentWindow();
|
||||||
|
|
||||||
|
const unlisten = listen("window-close-event", (event) => {
|
||||||
|
closeApp();
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
unlisten.then((unlisten) => {
|
||||||
|
unlisten && unlisten instanceof Function && unlisten();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const closeApp = async () => {
|
||||||
|
appWindow.hide();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import { defineNuxtConfig } from "nuxt/config";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import vueJSX from "@vitejs/plugin-vue-jsx";
|
||||||
|
const isDev = process?.argv?.[2] == "_dev" || process?.argv?.[2] == "dev";
|
||||||
|
const optimizeDepsElementPlusIncludes = ["element-plus/es"];
|
||||||
|
fs.readdirSync("node_modules/element-plus/es/components").map(dirname => {
|
||||||
|
fs.access(`node_modules/element-plus/es/components/${dirname}/style/css.mjs`, err => {
|
||||||
|
if (!err) {
|
||||||
|
optimizeDepsElementPlusIncludes.push(`element-plus/es/components/${dirname}/style/css`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
export default defineNuxtConfig({
|
||||||
|
ssr: false,
|
||||||
|
|
||||||
|
devServer: {
|
||||||
|
port: 5000
|
||||||
|
},
|
||||||
|
|
||||||
|
imports: {
|
||||||
|
autoImport: false
|
||||||
|
},
|
||||||
|
|
||||||
|
css: ["~/assets/css/main.css"],
|
||||||
|
modules: ["@element-plus/nuxt", "@pinia/nuxt", "@pinia-plugin-persistedstate/nuxt", "@nuxtjs/tailwindcss"],
|
||||||
|
|
||||||
|
alias: {
|
||||||
|
"@": path.resolve(__dirname, "./")
|
||||||
|
},
|
||||||
|
|
||||||
|
experimental: {
|
||||||
|
payloadExtraction: false
|
||||||
|
},
|
||||||
|
|
||||||
|
devtools: {
|
||||||
|
enabled: false
|
||||||
|
},
|
||||||
|
|
||||||
|
router: {
|
||||||
|
options: {
|
||||||
|
hashMode: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
vite: {
|
||||||
|
plugins: [
|
||||||
|
vueJSX({}),
|
||||||
|
],
|
||||||
|
envDir: "env",
|
||||||
|
optimizeDeps: {
|
||||||
|
include: [...optimizeDepsElementPlusIncludes]
|
||||||
|
},
|
||||||
|
// prevent vite from obscuring rust errors
|
||||||
|
clearScreen: false,
|
||||||
|
// Tauri expects a fixed port, fail if that port is not available
|
||||||
|
server: {
|
||||||
|
strictPort: true
|
||||||
|
},
|
||||||
|
// to access the Tauri environment variables set by the CLI with information about the current target
|
||||||
|
envPrefix: ["VITE_", "TAURI_"],
|
||||||
|
build: {
|
||||||
|
// minify: "esbuild",
|
||||||
|
chunkSizeWarningLimit: 1500,
|
||||||
|
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
|
||||||
|
target: process.env.TAURI_PLATFORM == "windows" ? "chrome105" : "safari13",
|
||||||
|
// don't minify for debug builds
|
||||||
|
minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
|
||||||
|
// 为调试构建生成源代码映射 (sourcemap)
|
||||||
|
sourcemap: !!process.env.TAURI_DEBUG
|
||||||
|
},
|
||||||
|
esbuild: {
|
||||||
|
pure: ["console.log"],
|
||||||
|
drop: ["debugger"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
postcss: {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
app: {
|
||||||
|
rootId: "__easytier",
|
||||||
|
cdnURL: "./",
|
||||||
|
buildAssetsDir: "__easytier/",
|
||||||
|
head: {
|
||||||
|
meta: [
|
||||||
|
{
|
||||||
|
name: "viewport",
|
||||||
|
content: "width=device-width, initial-scale=1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
charset: "utf-8"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
title: "easytier-game"
|
||||||
|
// link: [],
|
||||||
|
// style: [],
|
||||||
|
// script: [],
|
||||||
|
// noscript: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"name": "easytier-game",
|
||||||
|
"private": true,
|
||||||
|
"author": "luoleixin@digisky.com",
|
||||||
|
"description": "A simple network initiator based on Easytier",
|
||||||
|
"version": "1.0.3",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "nuxt dev --dotenv env/.env.dev --host 0.0.0.0",
|
||||||
|
"build": "nuxt generate --dotenv env/.env.prod"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@element-plus/icons-vue": "^2.3.1",
|
||||||
|
"@element-plus/nuxt": "^1.0.9",
|
||||||
|
"@nuxtjs/tailwindcss": "^6.12.0",
|
||||||
|
"@pinia-plugin-persistedstate/nuxt": "^1.2.0",
|
||||||
|
"@pinia/nuxt": "^0.5.1",
|
||||||
|
"@tauri-apps/api": "^2.0.2",
|
||||||
|
"@tauri-apps/cli": "^2.0.2",
|
||||||
|
"@tauri-apps/plugin-cli": "^2.0.0",
|
||||||
|
"@tauri-apps/plugin-http": "^2.0.0",
|
||||||
|
"@tinymce/tinymce-vue": "^5.1.1",
|
||||||
|
"@types/lodash-es": "^4.17.12",
|
||||||
|
"@types/qs": "^6.9.15",
|
||||||
|
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
||||||
|
"dayjs": "^1.11.10",
|
||||||
|
"defu": "^6.1.4",
|
||||||
|
"element-plus": "^2.7.1",
|
||||||
|
"javascript-obfuscator": "^4.1.0",
|
||||||
|
"less": "^4.2.0",
|
||||||
|
"lodash-es": "^4.17.21",
|
||||||
|
"nuxt": "^3.11.2",
|
||||||
|
"pinia": "^2.1.7",
|
||||||
|
"postcss": "^8.4.38",
|
||||||
|
"qs": "^6.12.0",
|
||||||
|
"typescript": "^5.4.5",
|
||||||
|
"vue": "^3.4.24",
|
||||||
|
"vue-clipboard3": "^2.0.0",
|
||||||
|
"xlsx": "^0.18.5",
|
||||||
|
"@tauri-apps/plugin-shell": "~2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,425 @@
|
|||||||
|
<template>
|
||||||
|
<ElForm
|
||||||
|
size="small"
|
||||||
|
label-position="top"
|
||||||
|
:model="config">
|
||||||
|
<ElFormItem
|
||||||
|
label="服务器"
|
||||||
|
prop="serverUrl">
|
||||||
|
<template #label>
|
||||||
|
<div class="flex items-center gap-[0_5px]">
|
||||||
|
<div>服务器</div>
|
||||||
|
<span>-</span>
|
||||||
|
<ElTag
|
||||||
|
effect="dark"
|
||||||
|
:type="data.isSuccessGetIp ? 'success' : 'info'">
|
||||||
|
{{ data.isSuccessGetIp ? "联机成功" : "联机中" }}
|
||||||
|
</ElTag>
|
||||||
|
<ElButton
|
||||||
|
v-if="!data.coreVersion"
|
||||||
|
@click="getCoreVersion(true)"
|
||||||
|
>获取工具版本</ElButton
|
||||||
|
>
|
||||||
|
<ElTag
|
||||||
|
v-else
|
||||||
|
type="info"
|
||||||
|
>{{ data.coreVersion }}</ElTag
|
||||||
|
>
|
||||||
|
<ElButton
|
||||||
|
:disabled="data.isStart"
|
||||||
|
:loading="data.update"
|
||||||
|
type="warning"
|
||||||
|
@click="handleUpdateCore"
|
||||||
|
size="small"
|
||||||
|
>{{ data.coreVersion ? "更新" : "下载" }}</ElButton
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<ElSelect
|
||||||
|
allow-create
|
||||||
|
filterable
|
||||||
|
default-first-option
|
||||||
|
v-model="config.serverUrl"
|
||||||
|
@change="handleServerUrlChange">
|
||||||
|
<template #prefix>
|
||||||
|
<div :class="config.protocol && config.protocol.length > 1 ? 'w-[120px]' : 'w-[80px]'">
|
||||||
|
<ElSelect
|
||||||
|
placeholder="协议"
|
||||||
|
multiple
|
||||||
|
collapse-tags
|
||||||
|
v-model="config.protocol"
|
||||||
|
@change="handleServerUrlChange">
|
||||||
|
<ElOption
|
||||||
|
v-for="item in protocols"
|
||||||
|
:key="item"
|
||||||
|
:label="item"
|
||||||
|
:value="item"></ElOption>
|
||||||
|
</ElSelect>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<ElOption
|
||||||
|
v-for="item in mainStore.basePeers"
|
||||||
|
:key="item"
|
||||||
|
:label="item"
|
||||||
|
:value="item">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<span style="float: left">{{ item }}</span>
|
||||||
|
<ElButton
|
||||||
|
@click.stop="handleDeleteServerUrl(item)"
|
||||||
|
round
|
||||||
|
:icon="Delete"
|
||||||
|
type="danger"></ElButton></div
|
||||||
|
></ElOption>
|
||||||
|
</ElSelect>
|
||||||
|
</ElFormItem>
|
||||||
|
<div class="flex flex-wrap gap-[0_10px] items-center">
|
||||||
|
<div class="flex-1">
|
||||||
|
<ElFormItem label="网络名">
|
||||||
|
<template #label>
|
||||||
|
<div class="flex items-center">
|
||||||
|
网络名
|
||||||
|
<ElTooltip content="对应命令行参数 --network-name">
|
||||||
|
<ElIcon><QuestionFilled /></ElIcon>
|
||||||
|
</ElTooltip>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<ElInput
|
||||||
|
maxlength="100"
|
||||||
|
placeholder="请输入网络名"
|
||||||
|
v-model="config.networkName"></ElInput>
|
||||||
|
</ElFormItem>
|
||||||
|
</div>
|
||||||
|
<div class="flex-1">
|
||||||
|
<ElFormItem label="网络密码">
|
||||||
|
<template #label>
|
||||||
|
<div class="flex items-center">
|
||||||
|
网络密码
|
||||||
|
<ElTooltip content="对应命令行参数 --network-secret">
|
||||||
|
<ElIcon><QuestionFilled /></ElIcon>
|
||||||
|
</ElTooltip>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<ElInput
|
||||||
|
show-password
|
||||||
|
maxlength="100"
|
||||||
|
placeholder="请输入网络密码"
|
||||||
|
v-model="config.networkPassword"
|
||||||
|
type="password"></ElInput>
|
||||||
|
</ElFormItem>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-[0_10px]">
|
||||||
|
<ElFormItem label="主机名">
|
||||||
|
<template #label>
|
||||||
|
<div class="flex items-center">
|
||||||
|
主机名
|
||||||
|
<ElTooltip content="对应命令行参数 --hostname">
|
||||||
|
<ElIcon><QuestionFilled /></ElIcon>
|
||||||
|
</ElTooltip>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<ElInput
|
||||||
|
maxlength="100"
|
||||||
|
placeholder="例如: Player1"
|
||||||
|
v-model="config.hostname"></ElInput>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem
|
||||||
|
class="w-[70%]"
|
||||||
|
label="局域网IP">
|
||||||
|
<template #label>
|
||||||
|
<div class="flex items-center h-[20px]">
|
||||||
|
虚拟网IP
|
||||||
|
<ElTooltip content="对应命令行参数 --ipv4">
|
||||||
|
<ElIcon><QuestionFilled /></ElIcon>
|
||||||
|
</ElTooltip>
|
||||||
|
<ElSwitch
|
||||||
|
v-model="config.dhcp"
|
||||||
|
class="ml-[5px]"
|
||||||
|
inline-prompt
|
||||||
|
inactive-text="固定IP"
|
||||||
|
active-text="动态获取IP"
|
||||||
|
size="small"></ElSwitch>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<ElInput
|
||||||
|
maxlength="100"
|
||||||
|
:disabled="config.dhcp"
|
||||||
|
:placeholder="data.isStart ? '等待动态分配IP...' : '例如: 10.126.126.1'"
|
||||||
|
v-model="config.ipv4"></ElInput>
|
||||||
|
</ElFormItem>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-start gap-[0_30px]">
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<ElButton
|
||||||
|
:type="!data.isStart ? 'primary' : 'danger'"
|
||||||
|
:disabled="data.startLoading || !data.coreVersion || data.update"
|
||||||
|
@click="handleConnection"
|
||||||
|
size="default">
|
||||||
|
{{ !data.isStart ? "开始联机" : "停止联机" }}
|
||||||
|
</ElButton>
|
||||||
|
</div>
|
||||||
|
<div class="mt-[6px]">
|
||||||
|
<ElButton
|
||||||
|
type="info"
|
||||||
|
@click="handleShowDialog"
|
||||||
|
size="default">
|
||||||
|
日志信息
|
||||||
|
</ElButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<ElCheckbox
|
||||||
|
v-model="config.disbleP2p"
|
||||||
|
size="small">
|
||||||
|
禁用p2p
|
||||||
|
</ElCheckbox>
|
||||||
|
<ElCheckbox
|
||||||
|
v-model="config.disableIpv6"
|
||||||
|
size="small">
|
||||||
|
禁用ipv6
|
||||||
|
</ElCheckbox>
|
||||||
|
<ElCheckbox
|
||||||
|
v-model="config.disbleListenner"
|
||||||
|
size="small">
|
||||||
|
禁用端口监听
|
||||||
|
</ElCheckbox>
|
||||||
|
<ElLink
|
||||||
|
class="!text-[11px] pb-[2px] ml-[15px]"
|
||||||
|
type="info"
|
||||||
|
:underline="false"
|
||||||
|
@click="open('https://github.com/EasyTier/EasyTier/releases')">
|
||||||
|
easytier发布页
|
||||||
|
</ElLink>
|
||||||
|
<div>
|
||||||
|
<ElLink
|
||||||
|
class="!text-[11px]"
|
||||||
|
type="danger"
|
||||||
|
:underline="false"
|
||||||
|
@click="open('https://github.com/dechamps/WinIPBroadcast/releases/tag/winipbroadcast-1.6')">
|
||||||
|
找不到房间?建议安装WinIPBroadcast
|
||||||
|
</ElLink>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ElForm>
|
||||||
|
<ElDialog
|
||||||
|
title="日志信息"
|
||||||
|
top="0"
|
||||||
|
v-model="data.visible"
|
||||||
|
width="100%"
|
||||||
|
class="!h-full !m-0">
|
||||||
|
<ElInput
|
||||||
|
type="textarea"
|
||||||
|
rows="10"
|
||||||
|
v-model="data.log"
|
||||||
|
resize="none"
|
||||||
|
readonly />
|
||||||
|
</ElDialog>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
import { open } from "@tauri-apps/plugin-shell";
|
||||||
|
import { QuestionFilled, Delete } from "@element-plus/icons-vue";
|
||||||
|
import { reactive, onBeforeUnmount, onMounted } from "vue";
|
||||||
|
import { useTray } from "~/composables/tray";
|
||||||
|
import useMainStore from "@/stores/index";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
|
||||||
|
useTray(true);
|
||||||
|
const mainStore = useMainStore();
|
||||||
|
const config = mainStore.config;
|
||||||
|
const protocols = ["tcp", "udp", "ws", "wss", "wg"];
|
||||||
|
const data = reactive({
|
||||||
|
visible: false,
|
||||||
|
log: "",
|
||||||
|
update: false,
|
||||||
|
releaseList: [],
|
||||||
|
coreVersion: "",
|
||||||
|
isSuccessGetIp: false,
|
||||||
|
startLoading: false,
|
||||||
|
isStart: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleDeleteServerUrl = (url: string) => {
|
||||||
|
const newBasePeers = [...mainStore.basePeers];
|
||||||
|
const idx = newBasePeers.indexOf(url);
|
||||||
|
if (idx >= 0) {
|
||||||
|
if (config.serverUrl === url) {
|
||||||
|
config.serverUrl = "";
|
||||||
|
}
|
||||||
|
newBasePeers.splice(idx, 1);
|
||||||
|
}
|
||||||
|
mainStore.basePeers = [...new Set([...newBasePeers])];
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleServerUrlChange = () => {
|
||||||
|
mainStore.basePeers = [...new Set([config.serverUrl, ...mainStore.basePeers])];
|
||||||
|
};
|
||||||
|
|
||||||
|
const listenObj: { [key: string]: any } = {
|
||||||
|
unListenOutPut: null,
|
||||||
|
unListenThreadId: null,
|
||||||
|
unListenReleaseList: null,
|
||||||
|
thread_id: null,
|
||||||
|
async listenOutput() {
|
||||||
|
const unListen = await listen("command-output", (event) => {
|
||||||
|
data.isStart = true;
|
||||||
|
if (event.payload) {
|
||||||
|
data.startLoading = false;
|
||||||
|
let ipv4 = /new: Some\((\d+\.\d+\.\d+\.\d+)\/.*\)/g.exec(event.payload as string)?.[1];
|
||||||
|
if (ipv4) {
|
||||||
|
data.isSuccessGetIp = true;
|
||||||
|
config.ipv4 = ipv4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.log += (event.payload as string) + "\n";
|
||||||
|
});
|
||||||
|
this.unListenOutPut = unListen;
|
||||||
|
},
|
||||||
|
async listenThreadId() {
|
||||||
|
const unListen = await listen("thread-id", (event) => {
|
||||||
|
if (event.payload) {
|
||||||
|
this.thread_id = event.payload;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.unListenThreadId = unListen;
|
||||||
|
},
|
||||||
|
|
||||||
|
async releaseListListener() {
|
||||||
|
const unListen = await listen("release-list", (event) => {
|
||||||
|
if (event.payload) {
|
||||||
|
console.log(event.payload);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.unListenReleaseList = unListen;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const unListenAll = async () => {
|
||||||
|
listenObj.unListenOutPut && (await listenObj.unListenOutPut());
|
||||||
|
await invoke("stop_command", { child_id: listenObj.thread_id || 0 });
|
||||||
|
listenObj.thread_id = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCoreVersion = async (isClick = false) => {
|
||||||
|
const coreVersion = await invoke("get_core_version");
|
||||||
|
if (!coreVersion && isClick) {
|
||||||
|
ElMessage.error("获取失败");
|
||||||
|
}
|
||||||
|
data.coreVersion = (coreVersion as string).replace("easytier-core ", "");
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkUpdate = async () => {
|
||||||
|
await getReleaseList();
|
||||||
|
const latestVersionFileName = data.releaseList?.[0]?.[0]?.[1] as string;
|
||||||
|
if (latestVersionFileName) {
|
||||||
|
console.log(latestVersionFileName, /\-v(\d+\.\d+\.\d+)/g.exec(latestVersionFileName));
|
||||||
|
const latestVersion = /\-v(\d+\.\d+\.\d+)/g.exec(latestVersionFileName)?.[1];
|
||||||
|
const currentVersion = /(\d+\.\d+\.\d+)/g.exec(data.coreVersion || "")?.[1];
|
||||||
|
if (latestVersion && currentVersion != latestVersion) {
|
||||||
|
console.log({ currentVersion, latestVersion });
|
||||||
|
ElMessage.success(`更新 -> ${latestVersion}`);
|
||||||
|
const downloadUrl = data.releaseList?.[0]?.[0]?.[2];
|
||||||
|
return [true, downloadUrl, latestVersionFileName];
|
||||||
|
} else if (currentVersion === latestVersion) {
|
||||||
|
ElMessage.success(`当前是最新版`);
|
||||||
|
return [false, null, null];
|
||||||
|
} else {
|
||||||
|
ElMessage.error(`获取版本失败`);
|
||||||
|
return [false, null, null];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [false, null, null];
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpdateCore = async () => {
|
||||||
|
// easytier-windows-x86_64-v2.0.3.zip
|
||||||
|
data.update = true;
|
||||||
|
await getCoreVersion();
|
||||||
|
const [isNeedUpdate, downloadUrl, latestVersionFileName] = await checkUpdate();
|
||||||
|
if (isNeedUpdate) {
|
||||||
|
await reset();
|
||||||
|
console.log(downloadUrl);
|
||||||
|
await invoke("download_easytier_zip", { download_url: downloadUrl, file_name: latestVersionFileName });
|
||||||
|
}
|
||||||
|
await getCoreVersion();
|
||||||
|
data.update = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getReleaseList = async () => {
|
||||||
|
const list = await invoke("fetch_easytier_list");
|
||||||
|
data.releaseList = list as never[];
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
// await handleUpdateCore(); //默认不自动更新
|
||||||
|
await getCoreVersion();
|
||||||
|
await listenObj.releaseListListener();
|
||||||
|
await listenObj.listenThreadId();
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
unListenAll();
|
||||||
|
listenObj.unListenReleaseList && listenObj.unListenReleaseList();
|
||||||
|
});
|
||||||
|
|
||||||
|
const getArgs = () => {
|
||||||
|
const args = [];
|
||||||
|
if (config.dhcp) {
|
||||||
|
args.push("-d");
|
||||||
|
}
|
||||||
|
if (config.hostname) {
|
||||||
|
args.push("--hostname", config.hostname);
|
||||||
|
}
|
||||||
|
if (config.networkName) {
|
||||||
|
args.push("--network-name", config.networkName);
|
||||||
|
}
|
||||||
|
if (config.networkPassword) {
|
||||||
|
args.push("--network-secret", config.networkPassword);
|
||||||
|
}
|
||||||
|
if (config.ipv4) {
|
||||||
|
args.push("--ipv4", config.ipv4);
|
||||||
|
}
|
||||||
|
if (config.serverUrl) {
|
||||||
|
const formatUrl = config.serverUrl.replace(/\\/g, "/");
|
||||||
|
args.push("--peers", ...config.protocol.map((protocol) => `${protocol}://${formatUrl}`));
|
||||||
|
}
|
||||||
|
if (config.disbleP2p) {
|
||||||
|
args.push("--disable-p2p");
|
||||||
|
}
|
||||||
|
if (config.disableIpv6) {
|
||||||
|
args.push("--disable-ipv6");
|
||||||
|
}
|
||||||
|
if (config.disbleListenner) {
|
||||||
|
args.push("--no-listener");
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
};
|
||||||
|
|
||||||
|
const reset = async () => {
|
||||||
|
data.isStart = false;
|
||||||
|
data.isSuccessGetIp = false;
|
||||||
|
config.ipv4 = "";
|
||||||
|
await unListenAll();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleConnection = async () => {
|
||||||
|
if (data.isStart) {
|
||||||
|
await reset();
|
||||||
|
} else {
|
||||||
|
data.startLoading = true;
|
||||||
|
await unListenAll();
|
||||||
|
await listenObj.listenOutput();
|
||||||
|
const args = getArgs();
|
||||||
|
await invoke("run_command", {
|
||||||
|
args,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleShowDialog = async () => {
|
||||||
|
data.visible = true;
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { createPersistedState } from "pinia-plugin-persistedstate";
|
||||||
|
import { defineNuxtPlugin } from "nuxt/app";
|
||||||
|
export default defineNuxtPlugin((nuxtApp: any) => {
|
||||||
|
nuxtApp.$pinia.use(
|
||||||
|
createPersistedState({
|
||||||
|
storage: localStorage,
|
||||||
|
key: id => `__glj_persisted_${id}`
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "../.nuxt/tsconfig.server.json"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
/gen/schemas
|
||||||
|
/easytier-windows-x86_64-v2.0.3.zip
|
||||||
|
/easytier-windows-x86_64/
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
[package]
|
||||||
|
name = "easytier-game"
|
||||||
|
version = "1.0.3"
|
||||||
|
description = "A simple network initiator based on Easytier"
|
||||||
|
authors = ["you"]
|
||||||
|
license = ""
|
||||||
|
repository = ""
|
||||||
|
edition = "2021"
|
||||||
|
rust-version = "1.77.2"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "app_lib"
|
||||||
|
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
tauri-build = { version = "2.0.1", features = [] }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde_json = "1.0"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
log = "0.4"
|
||||||
|
tauri = { version = "2.0.2", features = [
|
||||||
|
"tray-icon",
|
||||||
|
"image-png",
|
||||||
|
"image-ico",
|
||||||
|
] }
|
||||||
|
tauri-plugin-log = "2.0.0-rc"
|
||||||
|
tauri-plugin-shell = "2"
|
||||||
|
reqwest = { version = "0.12", features = ["json"] }
|
||||||
|
zip = "2.2.0"
|
||||||
|
|
||||||
|
[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
|
||||||
|
tauri-plugin-single-instance = "2"
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
fn main() {
|
||||||
|
let mut windows = tauri_build::WindowsAttributes::new();
|
||||||
|
windows = windows.app_manifest(
|
||||||
|
r#"
|
||||||
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||||
|
<dependency>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity
|
||||||
|
type="win32"
|
||||||
|
name="Microsoft.Windows.Common-Controls"
|
||||||
|
version="6.0.0.0"
|
||||||
|
processorArchitecture="*"
|
||||||
|
publicKeyToken="6595b64144ccf1df"
|
||||||
|
language="*"
|
||||||
|
/>
|
||||||
|
</dependentAssembly>
|
||||||
|
</dependency>
|
||||||
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<security>
|
||||||
|
<requestedPrivileges>
|
||||||
|
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||||
|
</requestedPrivileges>
|
||||||
|
</security>
|
||||||
|
</trustInfo>
|
||||||
|
</assembly>
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
tauri_build::try_build(tauri_build::Attributes::new().windows_attributes(windows))
|
||||||
|
.expect("failed to run build script");
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"$schema": "../gen/schemas/desktop-schema.json",
|
||||||
|
"identifier": "default",
|
||||||
|
"description": "enables the default permissions",
|
||||||
|
"windows": [
|
||||||
|
"main"
|
||||||
|
],
|
||||||
|
"permissions": [
|
||||||
|
"core:default",
|
||||||
|
"core:window:allow-minimize",
|
||||||
|
"core:window:allow-hide",
|
||||||
|
"core:window:allow-close",
|
||||||
|
"shell:allow-open"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 43 KiB |
@@ -0,0 +1,329 @@
|
|||||||
|
use reqwest::{Client, Error};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::fs::{self, File};
|
||||||
|
use std::io::{BufRead, BufReader, Write};
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
use std::sync::{
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
|
mpsc, Arc,
|
||||||
|
};
|
||||||
|
use std::{path, thread};
|
||||||
|
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
|
||||||
|
use tauri::Emitter;
|
||||||
|
use tauri::{Manager, WindowEvent};
|
||||||
|
|
||||||
|
// 定义GitHub Release的结构体
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct Release {
|
||||||
|
pub tag_name: String,
|
||||||
|
pub name: String,
|
||||||
|
pub prerelease: bool,
|
||||||
|
pub id: u64,
|
||||||
|
pub assets: Vec<Asset>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定义GitHub Asset的结构体
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct Asset {
|
||||||
|
pub browser_download_url: String,
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取GitHub Release列表的函数
|
||||||
|
pub async fn fetch_releases() -> Result<Vec<Release>, Error> {
|
||||||
|
// 创建HTTP客户端
|
||||||
|
let client = Client::new();
|
||||||
|
// 构建请求的URL
|
||||||
|
let url = format!("https://api.github.com/repos/easytier/easytier/releases",);
|
||||||
|
|
||||||
|
// 发送HTTP GET请求
|
||||||
|
let response = client
|
||||||
|
.get(&url)
|
||||||
|
.header("User-Agent", "Tauri-fetch")
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
// 反序列化响应体为Release列表
|
||||||
|
response.json::<Vec<Release>>().await
|
||||||
|
}
|
||||||
|
|
||||||
|
static mut IS_CLOSE: bool = false;
|
||||||
|
|
||||||
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
fn my_commit_output(commit_msg: String, window: tauri::Window) -> Result<bool, String> {
|
||||||
|
println!("{}", commit_msg);
|
||||||
|
unsafe {
|
||||||
|
IS_CLOSE = true;
|
||||||
|
}
|
||||||
|
window.close().unwrap();
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
fn force_close(window: tauri::Window) {
|
||||||
|
unsafe {
|
||||||
|
IS_CLOSE = true;
|
||||||
|
}
|
||||||
|
window.close().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
fn get_core_version() -> String {
|
||||||
|
match Command::new("easytier-core.exe")
|
||||||
|
.arg("--version")
|
||||||
|
.creation_flags(0x08000000)
|
||||||
|
.output()
|
||||||
|
{
|
||||||
|
Ok(output) => {
|
||||||
|
let output_str = String::from_utf8_lossy(&output.stdout);
|
||||||
|
return output_str.trim().to_string();
|
||||||
|
}
|
||||||
|
Err(_e) => return "".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
async fn download_easytier_zip(download_url: String, file_name: String) {
|
||||||
|
let target = format!("https://ghp.ci/?q={}",download_url);
|
||||||
|
let response = reqwest::get(target)
|
||||||
|
.await
|
||||||
|
.expect("error to download easytier url");
|
||||||
|
let file_path = format!("./{}", file_name);
|
||||||
|
let path = path::Path::new(&file_path);
|
||||||
|
|
||||||
|
let mut file = match File::create(&path) {
|
||||||
|
Err(why) => panic!("couldn't create {}", why),
|
||||||
|
Ok(file) => file,
|
||||||
|
};
|
||||||
|
|
||||||
|
let content = response.bytes().await.expect("error to bytes easytier");
|
||||||
|
println!("下载完成,开始写入");
|
||||||
|
file.write_all(&content).expect("error to write easytier");
|
||||||
|
println!("写入完成");
|
||||||
|
unzip(path);
|
||||||
|
match fs::remove_file(path) {
|
||||||
|
Ok(_) => println!("删除zip文件成功"),
|
||||||
|
Err(_) => println!("删除zip文件失败"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unzip(fname: &path::Path) {
|
||||||
|
let zipfile = std::fs::File::open(fname).unwrap();
|
||||||
|
|
||||||
|
let mut archive = zip::ZipArchive::new(zipfile).unwrap();
|
||||||
|
|
||||||
|
for i in 0..archive.len() {
|
||||||
|
let mut file = archive.by_index(i).unwrap();
|
||||||
|
let outpath = match file.enclosed_name() {
|
||||||
|
Some(path) => path,
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
let comment = file.comment();
|
||||||
|
if !comment.is_empty() {
|
||||||
|
println!("File {i} comment: {comment}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"File {} extracted to \"{}\" ({} bytes)",
|
||||||
|
i,
|
||||||
|
outpath.display(),
|
||||||
|
file.size()
|
||||||
|
);
|
||||||
|
// if let Some(p) = outpath.parent() {
|
||||||
|
// if !p.exists() {
|
||||||
|
// fs::create_dir_all(p).unwrap();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
let out_file_path = path::Path::new("./").join(outpath.file_name().clone().unwrap());
|
||||||
|
println!("outFilePath: {}", out_file_path.display());
|
||||||
|
let mut outfile = fs::File::create(&out_file_path).unwrap();
|
||||||
|
std::io::copy(&mut file, &mut outfile).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
fn run_command(
|
||||||
|
app_handle: tauri::AppHandle,
|
||||||
|
args: Vec<String>,
|
||||||
|
stop_signal: tauri::State<Arc<AtomicBool>>,
|
||||||
|
) {
|
||||||
|
// if !path::Path::new("easytier-core.exe").exists() {
|
||||||
|
// app_handle.emit("command-output", "easytier-core.exe 不存在");
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
let (tx, rx) = mpsc::channel();
|
||||||
|
stop_signal.store(false, Ordering::Relaxed);
|
||||||
|
let app_handle1 = app_handle.clone();
|
||||||
|
let app_handle2 = app_handle.clone();
|
||||||
|
let stop_signal = Arc::clone(&stop_signal);
|
||||||
|
let args2 = args.clone();
|
||||||
|
thread::spawn(move || {
|
||||||
|
let mut child = Command::new("easytier-core.exe")
|
||||||
|
.args(args)
|
||||||
|
.creation_flags(0x08000000)
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.expect("failed to execute process");
|
||||||
|
|
||||||
|
println!("child id: {}", child.id());
|
||||||
|
app_handle1
|
||||||
|
.emit("thread-id", child.id())
|
||||||
|
.expect("failed to emit id event");
|
||||||
|
app_handle1
|
||||||
|
.emit("command-output", args2.join(" "))
|
||||||
|
.expect("error output args");
|
||||||
|
let stdout = child.stdout.take().expect("failed to capture stdout");
|
||||||
|
let reader = BufReader::new(stdout);
|
||||||
|
|
||||||
|
for line in reader.lines() {
|
||||||
|
match line {
|
||||||
|
Ok(line) => {
|
||||||
|
tx.send(line).expect("failed to send line");
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("error reading line: {}", e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("end");
|
||||||
|
});
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
|
while let Ok(line) = rx.recv() {
|
||||||
|
if stop_signal.load(Ordering::Relaxed) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
app_handle2
|
||||||
|
.emit("command-output", line)
|
||||||
|
.expect("failed to emit event");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
fn stop_command(child_id: u32, stop_signal: tauri::State<Arc<AtomicBool>>) {
|
||||||
|
println!("stop command");
|
||||||
|
if child_id != 0 {
|
||||||
|
let output = Command::new("taskkill")
|
||||||
|
.arg("/F")
|
||||||
|
.arg("/PID") // 使用 -9 信号强制终止进程
|
||||||
|
.arg(child_id.to_string())
|
||||||
|
.creation_flags(0x08000000)
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
// 检查命令执行的结果
|
||||||
|
if output.status.success() {
|
||||||
|
println!("Process {} terminated successfully.", child_id);
|
||||||
|
} else {
|
||||||
|
eprintln!("Failed to terminate process {}.", child_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop_signal.store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command(rename_all = "snake_case")]
|
||||||
|
async fn fetch_easytier_list() -> Vec<Vec<[String; 3]>> {
|
||||||
|
// 获取release列表
|
||||||
|
if let Ok(release) = fetch_releases().await {
|
||||||
|
let mut release_list = Vec::new();
|
||||||
|
for re in release {
|
||||||
|
let mut assets_list = Vec::new();
|
||||||
|
for asset in re.assets {
|
||||||
|
if asset.name.contains("windows-x86_64") {
|
||||||
|
assets_list.push([
|
||||||
|
re.tag_name.clone(),
|
||||||
|
asset.name.clone(),
|
||||||
|
asset.browser_download_url.clone(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
release_list.push(assets_list);
|
||||||
|
}
|
||||||
|
return release_list;
|
||||||
|
} else {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn toggle_window_visibility<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
|
||||||
|
if let Some(window) = app.get_webview_window("main") {
|
||||||
|
if window.is_visible().unwrap_or_default() {
|
||||||
|
let _ = window.hide();
|
||||||
|
} else {
|
||||||
|
let _ = window.show();
|
||||||
|
let _ = window.set_focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
|
pub fn run() {
|
||||||
|
let stop_signal = Arc::new(AtomicBool::new(false)); // 创建一个原子布尔值,用于控制命令的停止
|
||||||
|
let stop_signal_clone = Arc::clone(&stop_signal); // 创建一个原子布尔值的克隆,用于传递给命令
|
||||||
|
let context = tauri::generate_context!();
|
||||||
|
tauri::Builder::default()
|
||||||
|
.plugin(tauri_plugin_shell::init())
|
||||||
|
.on_window_event(move |window, event| {
|
||||||
|
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||||
|
unsafe {
|
||||||
|
if !IS_CLOSE {
|
||||||
|
api.prevent_close();
|
||||||
|
window.emit("window-close-event", "").unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
|
||||||
|
let _ = app
|
||||||
|
.get_webview_window("main")
|
||||||
|
.expect("no main window")
|
||||||
|
.set_focus();
|
||||||
|
}))
|
||||||
|
.setup(|app| {
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
app.handle().plugin(
|
||||||
|
tauri_plugin_log::Builder::default()
|
||||||
|
.level(log::LevelFilter::Info)
|
||||||
|
.build(),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
let _tray_menu = TrayIconBuilder::with_id("main")
|
||||||
|
.menu_on_left_click(false)
|
||||||
|
.on_tray_icon_event(|tray, event| {
|
||||||
|
if let TrayIconEvent::Click {
|
||||||
|
button: MouseButton::Left,
|
||||||
|
button_state: MouseButtonState::Up,
|
||||||
|
..
|
||||||
|
} = event
|
||||||
|
{
|
||||||
|
let app = tray.app_handle();
|
||||||
|
toggle_window_visibility(app);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.icon(tauri::image::Image::from_bytes(include_bytes!(
|
||||||
|
"../icons/icon.png"
|
||||||
|
))?)
|
||||||
|
.icon_as_template(false)
|
||||||
|
.build(app)?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.manage(stop_signal_clone)
|
||||||
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
my_commit_output,
|
||||||
|
force_close,
|
||||||
|
run_command,
|
||||||
|
stop_command,
|
||||||
|
get_core_version,
|
||||||
|
fetch_easytier_list,
|
||||||
|
download_easytier_zip
|
||||||
|
])
|
||||||
|
.run(context)
|
||||||
|
.expect("error while running tauri application");
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
app_lib::run();
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
||||||
|
"productName": "easytier-game",
|
||||||
|
"version": "1.0.3",
|
||||||
|
"identifier": "com.tauri.easytier-game",
|
||||||
|
|
||||||
|
"build": {
|
||||||
|
"frontendDist": "../dist",
|
||||||
|
"devUrl": "http://localhost:5000",
|
||||||
|
"beforeBuildCommand": "pnpm build",
|
||||||
|
"beforeDevCommand": "pnpm dev"
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"windows": [
|
||||||
|
{
|
||||||
|
"title": "easytier-game",
|
||||||
|
"width": 331,
|
||||||
|
"height": 285,
|
||||||
|
"resizable": false,
|
||||||
|
"fullscreen": false,
|
||||||
|
"decorations": true,
|
||||||
|
"maximizable": false,
|
||||||
|
"center": true,
|
||||||
|
"transparent": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"security": {
|
||||||
|
"csp": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bundle": {
|
||||||
|
"active": false,
|
||||||
|
"targets": "all",
|
||||||
|
"createUpdaterArtifacts": false,
|
||||||
|
"icon": ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { defineStore } from "pinia";
|
||||||
|
export default defineStore("main", {
|
||||||
|
state() {
|
||||||
|
return {
|
||||||
|
config: {
|
||||||
|
protocol: ["tcp", "udp"], // 网络协议
|
||||||
|
serverUrl: "public.easytier.top:11010",
|
||||||
|
networkName: "",
|
||||||
|
networkPassword: "",
|
||||||
|
hostname: "",
|
||||||
|
ipv4: "",
|
||||||
|
disableIpv6: false, // 是否禁用IPv6
|
||||||
|
disbleListenner: false, // 是否禁用监听
|
||||||
|
disbleP2p: true, // 是否使用P2P
|
||||||
|
dhcp: true, // 是否使用DHCP
|
||||||
|
},
|
||||||
|
basePeers: ["public.easytier.top:11010"],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
persist: {
|
||||||
|
paths: [
|
||||||
|
"basePeers",
|
||||||
|
"config.serverUrl",
|
||||||
|
"config.networkName",
|
||||||
|
"config.protocol",
|
||||||
|
"config.networkPassword",
|
||||||
|
"config.disbleP2p",
|
||||||
|
"config.disableIpv6",
|
||||||
|
"config.disbleListenner",
|
||||||
|
"config.hostname",
|
||||||
|
"config.dhcp",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
/** @type {import('tailwindcss/plugin')} */
|
||||||
|
|
||||||
|
const plugin = require("tailwindcss/plugin");
|
||||||
|
module.exports = {
|
||||||
|
content: ["./components/**/*.{js,vue,ts}", "./layouts/**/*.vue", "./pages/**/*.vue", "./plugins/**/*.{js,ts}", "./app.vue", "./error.vue"],
|
||||||
|
theme: {
|
||||||
|
extend: {}
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
plugin(function ({ matchVariant, addUtilities, matchUtilities, theme }) {
|
||||||
|
addUtilities({
|
||||||
|
".app-drag": {
|
||||||
|
"-webkit-app-region": "drag"
|
||||||
|
},
|
||||||
|
".app-nodrag": {
|
||||||
|
"-webkit-app-region": "no-drag"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
]
|
||||||
|
};
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
// https://nuxt.com/docs/guide/concepts/typescript
|
||||||
|
"extends": "./.nuxt/tsconfig.json",
|
||||||
|
"exclude": ["node_modules", "dist", ".output"],
|
||||||
|
"include": [
|
||||||
|
"components/**/*.ts",
|
||||||
|
"components/**/*.js",
|
||||||
|
"components/**/*.vue",
|
||||||
|
"pages/**/*.ts",
|
||||||
|
"pages/**/*.js",
|
||||||
|
"pages/**/*.vue",
|
||||||
|
"layouts/**/*.ts",
|
||||||
|
"layouts/**/*.js",
|
||||||
|
"layouts/**/*.vue",
|
||||||
|
"plugins/**/*.ts",
|
||||||
|
"plugins/**/*.js",
|
||||||
|
"store/**/*.ts",
|
||||||
|
"store/**/*.js",
|
||||||
|
"utils/**/*.ts",
|
||||||
|
"utils/**/*.js",
|
||||||
|
"typings/**/*.d.ts",
|
||||||
|
// "composables/**/*.ts",
|
||||||
|
// "composables/**/*.js",
|
||||||
|
// "api/**/*.ts",
|
||||||
|
// "api/**/*.js"
|
||||||
|
],
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "ESNext",
|
||||||
|
// "types": ["element-plus/global"]
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
// 从 Vue 3.4 开始,Vue 不再隐式注册全局 JSX 命名空间。要指示 TypeScript 使用 Vue 的 JSX 类型定义,请确保在你的 tsconfig.json 中包含以下内容
|
||||||
|
"jsx": "preserve",
|
||||||
|
"jsxImportSource": "vue",
|
||||||
|
"types": ["@pinia/nuxt", "vite/client", "element-plus/global"],
|
||||||
|
"allowJs": true, // 允许编译器编译JS,JSX文件
|
||||||
|
"checkJs": true, // 允许在JS文件中报错,通常与allowJS一起使用
|
||||||
|
"esModuleInterop": true, // 允许export=导出,由import from 导入
|
||||||
|
|
||||||
|
"lib": ["DOM", "ESNext"],
|
||||||
|
"allowSyntheticDefaultImports": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
_self文件夹 用于存放“只和”本项目相关的方法,公用方法请在_self外面编写
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import { ElMessageBox } from "element-plus";
|
||||||
|
import { ATJ } from "./index";
|
||||||
|
import { h, type VNode } from "vue";
|
||||||
|
type Opt = { action?: string; confirmButtonText?: string; cancelButtonText?: string; VNode?: VNode | null }
|
||||||
|
export const ElConfirmDanger = (
|
||||||
|
content: string,
|
||||||
|
title: string,
|
||||||
|
opt: Opt = {
|
||||||
|
action: "",
|
||||||
|
confirmButtonText: "确定",
|
||||||
|
cancelButtonText: "取消",
|
||||||
|
VNode: null
|
||||||
|
}
|
||||||
|
): Promise<any | [any, any]> => {
|
||||||
|
const { action = "", confirmButtonText = "确定", cancelButtonText = "取消", VNode = null } = opt;
|
||||||
|
const formatContentArr = content.split("{action}");
|
||||||
|
const action_length = formatContentArr.length - 1;
|
||||||
|
const messageArr = [];
|
||||||
|
if (action_length > 0) {
|
||||||
|
for (let i = 0; i < action_length; i++) {
|
||||||
|
messageArr.push(`${formatContentArr[i]}`);
|
||||||
|
messageArr.push(h("span", { class: "text-[var(--el-color-danger)]" }, action));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
messageArr.push(`${formatContentArr[action_length]}`);
|
||||||
|
let message = h("p", null, messageArr);
|
||||||
|
if (VNode) {
|
||||||
|
message = h("div", null, [message, VNode]);
|
||||||
|
}
|
||||||
|
return ATJ(
|
||||||
|
ElMessageBox.confirm(message, title, {
|
||||||
|
cancelButtonText,
|
||||||
|
confirmButtonText,
|
||||||
|
confirmButtonClass: "el-button--danger"
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ElConfirmSucces = (
|
||||||
|
content: string,
|
||||||
|
title: string,
|
||||||
|
opt: Opt = {
|
||||||
|
action: "",
|
||||||
|
confirmButtonText: "确定",
|
||||||
|
cancelButtonText: "取消",
|
||||||
|
VNode: null
|
||||||
|
}
|
||||||
|
): Promise<any | [any, any]> => {
|
||||||
|
const { action = "", confirmButtonText = "确定", cancelButtonText = "取消", VNode = null } = opt;
|
||||||
|
const formatContentArr = content.split("{action}");
|
||||||
|
const action_length = formatContentArr.length - 1;
|
||||||
|
const messageArr = [];
|
||||||
|
if (action_length > 0) {
|
||||||
|
for (let i = 0; i < action_length; i++) {
|
||||||
|
messageArr.push(`${formatContentArr[i]}`);
|
||||||
|
messageArr.push(h("span", { class: "text-[var(--el-color-success)]" }, action));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
messageArr.push(`${formatContentArr[action_length]}`);
|
||||||
|
let message = h("p", null, messageArr);
|
||||||
|
if (VNode) {
|
||||||
|
message = h("div", null, [message, VNode]);
|
||||||
|
}
|
||||||
|
return ATJ(
|
||||||
|
ElMessageBox.confirm(message, title, {
|
||||||
|
cancelButtonText,
|
||||||
|
confirmButtonText,
|
||||||
|
confirmButtonClass: "el-button--success"
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ElConfirmPrimary = (
|
||||||
|
content: string,
|
||||||
|
title: string,
|
||||||
|
opt: Opt = {
|
||||||
|
action: "",
|
||||||
|
confirmButtonText: "确定",
|
||||||
|
cancelButtonText: "取消",
|
||||||
|
VNode: null
|
||||||
|
}
|
||||||
|
): Promise<any | [any, any]> => {
|
||||||
|
const { action = "", confirmButtonText = "确定", cancelButtonText = "取消", VNode = null } = opt;
|
||||||
|
const formatContentArr = content.split("{action}");
|
||||||
|
const action_length = formatContentArr.length - 1;
|
||||||
|
const messageArr = [];
|
||||||
|
if (action_length > 0) {
|
||||||
|
for (let i = 0; i < action_length; i++) {
|
||||||
|
messageArr.push(`${formatContentArr[i]}`);
|
||||||
|
messageArr.push(h("span", { class: "text-[var(--el-color-primary)]" }, action));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
messageArr.push(`${formatContentArr[action_length]}`);
|
||||||
|
let message = h("p", null, messageArr);
|
||||||
|
if (VNode) {
|
||||||
|
message = h("div", null, [message, VNode]);
|
||||||
|
}
|
||||||
|
return ATJ(
|
||||||
|
ElMessageBox.confirm(message, title, {
|
||||||
|
cancelButtonText,
|
||||||
|
confirmButtonText,
|
||||||
|
confirmButtonClass: "el-button--primary"
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
import Clipboard from "vue-clipboard3";
|
||||||
|
|
||||||
|
export const ENV = import.meta.env;
|
||||||
|
|
||||||
|
export const clipBoardCopy = async (text: string) => {
|
||||||
|
const { toClipboard } = Clipboard();
|
||||||
|
try {
|
||||||
|
await toClipboard(text);
|
||||||
|
ElMessage.success("复制成功");
|
||||||
|
} catch (e) {
|
||||||
|
ElMessage.error("复制失败");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//防抖
|
||||||
|
export const bounce = (time = 3000) => {
|
||||||
|
let bounceTimer: NodeJS.Timeout | null = null;
|
||||||
|
return (cb: Function) => {
|
||||||
|
bounceTimer && clearTimeout(bounceTimer);
|
||||||
|
bounceTimer = setTimeout(() => {
|
||||||
|
cb();
|
||||||
|
}, time);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} size byte number
|
||||||
|
* @param {number} fixed 小数点后几位
|
||||||
|
*/
|
||||||
|
export const SizeFormat = (size: number, fixed: number = 1) => {
|
||||||
|
const _unit = ["B", "KB", "MB", "GB", "TB"];
|
||||||
|
const max = _unit.length - 1;
|
||||||
|
const endAdd = 8; //取小数点后 fixed + endAdd 位小数,目的是尽量保证不发生进位,endAdd越大,越可以保证不发生进位
|
||||||
|
const c = 1024; // 1000或者1024
|
||||||
|
let n = 0;
|
||||||
|
for (; n < max; n++) {
|
||||||
|
if (size < c) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
size = size / c;
|
||||||
|
}
|
||||||
|
const result = Number(size).toFixed(fixed + endAdd);
|
||||||
|
return `${result.slice(0, result.length - endAdd)}${_unit[n]}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const numAddZero = (num: Number) => {
|
||||||
|
const newNum = Number(num);
|
||||||
|
return String(newNum > 9 ? newNum : `0${newNum}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const numRemoveZero = (num: Number) => {
|
||||||
|
if (String(num).startsWith("0")) {
|
||||||
|
const numArr = [].slice.call(num);
|
||||||
|
numArr.splice(0, 1);
|
||||||
|
return Number(numArr.join(""));
|
||||||
|
}
|
||||||
|
return Number(num);
|
||||||
|
};
|
||||||
|
|
||||||
|
// await-to-js
|
||||||
|
export const ATJ = (promise: Promise<any>, errorExt: string | undefined = undefined) => {
|
||||||
|
return promise
|
||||||
|
.then(data => [null, data])
|
||||||
|
.catch(err => {
|
||||||
|
if (errorExt) {
|
||||||
|
if (typeof errorExt !== "object") {
|
||||||
|
return [errorExt, undefined];
|
||||||
|
} else {
|
||||||
|
const parsedError = Object.assign({}, err, errorExt);
|
||||||
|
return [parsedError, undefined];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [err, undefined];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const openBrowser = (key: string) => {
|
||||||
|
// logger.info(`${import.meta.env.VITE_BROWSER_JOB_URL}${key}`)
|
||||||
|
// _launcherApi.openBrowser(`${import.meta.env.VITE_BROWSER_JOB_URL}${key}`);
|
||||||
|
};
|
||||||