1.0.3版本

This commit is contained in:
刘嘉伟 2024-07-17 14:21:31 +08:00
parent a3f00437e9
commit 7ab26bcfb0
9 changed files with 244 additions and 76 deletions

View File

@ -22,6 +22,7 @@
</div>
## 里程碑
- 2024-07-17: 发布v1.0.3版本 修复已知bug 增加开机自启 增加删除frp版本
- 2024-01-29: 发布v1.0.2版本 增加Linux客户端和代理模式
- 2023-12-01: 发布v1.0.1版本
- 2023-11-28: 发布v1.0版本

View File

@ -1,6 +1,6 @@
import {app, ipcMain, Notification} from "electron";
import {Config, getConfig} from "../storage/config";
import {listProxy} from "../storage/proxy";
import {listProxy, Proxy} from "../storage/proxy";
import {getVersionById} from "../storage/version";
import treeKill from "tree-kill";
@ -25,43 +25,42 @@ const getFrpcVersionWorkerPath = (
) => {
getVersionById(versionId, (err2, version) => {
if (!err2) {
callback(version["frpcVersionPath"]);
if (version) {
callback(version["frpcVersionPath"]);
}
}
});
};
/**
*
* toml配置文件
* @param config
* @param proxys
*/
export const generateConfig = (
config: Config,
callback: (configPath: string) => void
) => {
listProxy((err3, proxys) => {
if (!err3) {
const proxyToml = proxys.map(m => {
let toml = `
const genTomlConfig = (config: Config, proxys: Proxy[]) => {
const proxyToml = proxys.map(m => {
let toml = `
[[proxies]]
name = "${m.name}"
type = "${m.type}"
localIP = "${m.localIp}"
localPort = ${m.localPort}
`;
switch (m.type) {
case "tcp":
toml += `remotePort = ${m.remotePort}`;
break;
case "http":
case "https":
toml += `customDomains=[${m.customDomains.map(m => `"${m}"`)}]`;
break;
default:
break;
}
switch (m.type) {
case "tcp":
toml += `remotePort = ${m.remotePort}`;
break;
case "http":
case "https":
toml += `customDomains=[${m.customDomains.map(m => `"${m}"`)}]`;
break;
default:
break;
}
return toml;
});
let toml = `
return toml;
});
const toml = `
serverAddr = "${config.serverAddr}"
serverPort = ${config.serverPort}
auth.method = "${config.authMethod}"
@ -82,17 +81,92 @@ ${config.proxyConfigEnable ? `
transport.proxyURL = "${config.proxyConfigProxyUrl}"
` : ""}
${proxyToml.join("")}
`;
return toml;
}
// const configPath = path.join("frp.toml");
const filename = "frp.toml";
/**
* ini配置
* @param config
* @param proxys
*/
const genIniConfig = (config: Config, proxys: Proxy[]) => {
const proxyIni = proxys.map(m => {
let ini = `
[${m.name}]
type = "${m.type}"
local_ip = "${m.localIp}"
local_port = ${m.localPort}
`;
switch (m.type) {
case "tcp":
ini += `remote_port = ${m.remotePort}`;
break;
case "http":
case "https":
ini += `custom_domains=[${m.customDomains.map(m => `"${m}"`)}]`;
break;
default:
break;
}
return ini;
});
const ini = `
[common]
server_addr = ${config.serverAddr}
server_port = ${config.serverPort}
authentication_method = "${config.authMethod}"
auth_token = "${config.authToken}"
log_file = "frpc.log"
log_level = ${config.logLevel}
log_max_days = ${config.logMaxDays}
admin_addr = 127.0.0.1
admin_port = 57400
tls_enable = ${config.tlsConfigEnable}
${config.tlsConfigEnable ? `
tls_cert_file = ${config.tlsConfigCertFile}
tls_key_file = ${config.tlsConfigKeyFile}
tls_trusted_ca_file = ${config.tlsConfigTrustedCaFile}
tls_server_name = ${config.tlsConfigServerName}
` : ""}
${config.proxyConfigEnable ? `
http_proxy = "${config.proxyConfigProxyUrl}"
` : ""}
${proxyIni.join("")}
`
return ini;
}
/**
*
*/
export const generateConfig = (
config: Config,
callback: (configPath: string) => void
) => {
listProxy((err3, proxys) => {
if (!err3) {
console.log(config, 'config')
const {currentVersion} = config;
let filename = null;
let configContent = "";
if (currentVersion < 124395282) {
// 版本小于v0.52.0
filename = "frp.ini";
configContent = genIniConfig(config, proxys)
} else {
filename = "frp.toml";
configContent = genTomlConfig(config, proxys)
}
const configPath = path.join(app.getPath("userData"), filename)
console.debug("生成配置成功", configPath)
fs.writeFile(
configPath, // 配置文件目录
toml, // 配置文件内容
configContent, // 配置文件内容
{flag: "w"},
err => {
if (!err) {
@ -111,6 +185,7 @@ ${proxyToml.join("")}
* @param configPath
*/
const startFrpcProcess = (commandPath: string, configPath: string) => {
console.log(commandPath, 'commandP')
const command = `${commandPath} -c ${configPath}`;
console.info("启动", command)
frpcProcess = spawn(command, {
@ -124,7 +199,8 @@ const startFrpcProcess = (commandPath: string, configPath: string) => {
});
frpcProcess.stdout.on("error", data => {
console.log("启动错误", data)
stopFrpcProcess()
stopFrpcProcess(() => {
})
});
frpcStatusListener = setInterval(() => {
const status = frpcProcessStatus()
@ -196,6 +272,35 @@ export const frpcProcessStatus = () => {
}
}
/**
* frpc流程
* @param config
*/
export const startFrpWorkerProcess = (config: Config) => {
getFrpcVersionWorkerPath(
config.currentVersion,
(frpcVersionPath: string) => {
console.log(1, '1')
if (frpcVersionPath) {
generateConfig(config, configPath => {
const platform = process.platform;
if (platform === 'win32') {
startFrpcProcess(
path.join(frpcVersionPath, "frpc.exe"),
configPath
);
} else {
startFrpcProcess(
path.join(frpcVersionPath, "frpc"),
configPath
);
}
});
}
}
);
}
export const initFrpcApi = () => {
ipcMain.handle("frpc.running", async (event, args) => {
@ -206,38 +311,21 @@ export const initFrpcApi = () => {
getConfig((err1, config) => {
if (!err1) {
if (config) {
getFrpcVersionWorkerPath(
config.currentVersion,
(frpcVersionPath: string) => {
generateConfig(config, configPath => {
const platform = process.platform;
if (platform === 'win32') {
startFrpcProcess(
path.join(frpcVersionPath, "frpc.exe"),
configPath
);
} else {
startFrpcProcess(
path.join(frpcVersionPath, "frpc"),
configPath
);
}
});
}
);
startFrpWorkerProcess(config)
} else {
event.reply(
"Home.frpc.start.error.hook",
"请先前往设置页面,修改配置后再启动"
"Home.frpc.start.error.hook", "请先前往设置页面,修改配置后再启动"
);
}
}
});
});
ipcMain.on("frpc.stop", () => {
if (frpcProcess && !frpcProcess.killed) {
stopFrpcProcess()
stopFrpcProcess(() => {
})
}
});
};

View File

@ -1,5 +1,5 @@
import {app, BrowserWindow, ipcMain, net, shell} from "electron";
import {insertVersion} from "../storage/version";
import {deleteVersionById, insertVersion} from "../storage/version";
const fs = require("fs");
const path = require("path");
@ -86,7 +86,7 @@ export const initGitHubApi = () => {
ipcMain.on("github.getFrpVersions", async event => {
const request = net.request({
method: "get",
url: "https://api.github.com/repos/fatedier/frp/releases"
url: "https://api.github.com/repos/fatedier/frp/releases?page=1&per_page=1000"
});
request.on("response", response => {
let responseData: Buffer = Buffer.alloc(0);
@ -104,6 +104,7 @@ export const initGitHubApi = () => {
const asset = getAdaptiveAsset(m.id);
if (asset) {
const absPath = `${downloadPath}/${asset.name}`;
m.absPath = absPath;
m.download_completed = fs.existsSync(absPath);
}
return m;
@ -163,6 +164,23 @@ export const initGitHubApi = () => {
});
});
/**
*
*/
ipcMain.on("github.deleteVersion", async (event, args) => {
const {absPath, id} = args;
console.log('删除下载', args)
if (fs.existsSync(absPath)) {
deleteVersionById(id, () => {
fs.unlinkSync(absPath)
})
}
event.reply("Download.deleteVersion.hook", {
err: null,
data: "删除成功"
});
})
/**
* GitHub
*/

View File

@ -4,9 +4,10 @@ import node_path, {join} from "node:path";
import {initGitHubApi} from "../api/github";
import {initConfigApi} from "../api/config";
import {initProxyApi} from "../api/proxy";
import {initFrpcApi, stopFrpcProcess} from "../api/frpc";
import {initFrpcApi, startFrpWorkerProcess, stopFrpcProcess} from "../api/frpc";
import {initLoggerApi} from "../api/logger";
import {initFileApi} from "../api/file";
import {getConfig} from "../storage/config";
// The built directory structure
//
// ├─┬ dist-electron
@ -135,6 +136,16 @@ export const createTray = () => {
tray.on('double-click', () => {
win.show();
})
getConfig((err, config) => {
if (!err) {
if (config) {
if (config.systemStartupConnect) {
startFrpWorkerProcess(config)
}
}
}
})
}
app.whenReady().then(() => {

View File

@ -1,11 +1,11 @@
import Datastore from "nedb";
import path from "path";
import { Proxy } from "./proxy";
import { app } from "electron";
import {Proxy} from "./proxy";
import {app} from "electron";
const versionDB = new Datastore({
autoload: true,
filename: path.join(app.getPath("userData"), "version.db")
autoload: true,
filename: path.join(app.getPath("userData"), "version.db")
});
/**
@ -14,10 +14,10 @@ const versionDB = new Datastore({
* @param cb
*/
export const insertVersion = (
version: any,
cb?: (err: Error | null, document: any) => void
version: any,
cb?: (err: Error | null, document: any) => void
) => {
versionDB.insert(version, cb);
versionDB.insert(version, cb);
};
/**
@ -25,14 +25,18 @@ export const insertVersion = (
* @param cb
*/
export const listVersion = (
callback: (err: Error | null, documents: any[]) => void
callback: (err: Error | null, documents: any[]) => void
) => {
versionDB.find({}, callback);
versionDB.find({}, callback);
};
export const getVersionById = (
id: string,
callback: (err: Error | null, document: any) => void
id: string,
callback: (err: Error | null, document: any) => void
) => {
versionDB.findOne({ id: id }, callback);
versionDB.findOne({id: id}, callback);
};
export const deleteVersionById = (id: string, callback: (err: Error | null, document: any) => void) => {
versionDB.remove({id: id}, callback);
}

View File

@ -1,6 +1,6 @@
{
"name": "Frpc-Desktop",
"version": "1.0.2",
"version": "1.0.3",
"main": "dist-electron/main/index.js",
"description": "一个frpc桌面客户端",
"author": "刘嘉伟 <8473136@qq.com>",
@ -54,7 +54,7 @@
"vite-plugin-electron-renderer": "^0.14.5",
"vue": "^3.3.4",
"vue-router": "^4.2.4",
"vue-tsc": "^1.8.8",
"vue-tsc": "^2.0.22",
"vue-types": "^5.1.1"
},
"dependencies": {

View File

@ -19,7 +19,7 @@ const currentRoute = computed(() => {
* 菜单切换
* @param mi 菜单索引
*/
const handleMenuChange = (route: RouteRecordRaw) => {
const handleMenuChange = (route: any) => {
if (currentRoute.value.name === route.name) {
return;
}

View File

@ -1,5 +1,6 @@
$main-bg: #F3F3F3;
$primary-color: #5F3BB0;
$danger-color: #F56C6C;
.main-container {
background: $main-bg;
@ -84,3 +85,7 @@ $primary-color: #5F3BB0;
.primary-text {
color: $primary-color;
}
.danger-text {
color: $danger-color !important;
}

View File

@ -4,6 +4,7 @@ import {ipcRenderer} from "electron";
import moment from "moment";
import Breadcrumb from "@/layout/compoenets/Breadcrumb.vue";
import {Icon} from "@iconify/vue";
import {ElMessage} from "element-plus";
defineComponent({
name: "Download"
@ -18,6 +19,7 @@ type Version = {
name: string;
published_at: string;
download_completed: boolean;
absPath: string;
assets: Asset[]
};
@ -42,6 +44,17 @@ const handleDownload = (version: Version) => {
downloading.value.set(version.id, 0);
};
/**
* 删除下载
* @param version
*/
const handleDeleteVersion = (version: Version) => {
ipcRenderer.send("github.deleteVersion", {
id: version.id,
absPath: version.absPath
});
}
const handleInitDownloadHook = () => {
ipcRenderer.on("Download.frpVersionHook", (event, args) => {
loading.value--;
@ -49,6 +62,7 @@ const handleInitDownloadHook = () => {
m.published_at = moment(m.published_at).format("YYYY-MM-DD HH:mm:ss")
return m as Version;
}) as Array<Version>;
console.log(versions, 'versions')
});
//
ipcRenderer.on("Download.frpVersionDownloadOnProgress", (event, args) => {
@ -67,6 +81,18 @@ const handleInitDownloadHook = () => {
version.download_completed = true;
}
});
ipcRenderer.on("Download.deleteVersion.hook", (event, args) => {
const {err, data} = args
if (!err) {
loading.value++;
ElMessage({
type: "success",
message: "删除成功"
});
handleLoadVersions();
}
})
};
onMounted(() => {
@ -81,6 +107,7 @@ onUnmounted(() => {
ipcRenderer.removeAllListeners("Download.frpVersionDownloadOnProgress");
ipcRenderer.removeAllListeners("Download.frpVersionDownloadOnCompleted");
ipcRenderer.removeAllListeners("Download.frpVersionHook");
ipcRenderer.removeAllListeners("Download.deleteVersion.hook");
});
</script>
<template>
@ -96,7 +123,7 @@ onUnmounted(() => {
<div class="left">
<div class="mb-2">
<el-tag>{{ version.name }}</el-tag>
<!-- <el-tag class="ml-2">原文件名{{ version.assets[0]?.name }}</el-tag>-->
<!-- <el-tag class="ml-2">原文件名{{ version.assets[0]?.name }}</el-tag>-->
</div>
<div class="text-sm">
发布时间<span class="text-gray-00">{{
@ -106,11 +133,25 @@ onUnmounted(() => {
</div>
</div>
<div class="right">
<span
class="primary-text text-sm font-bold ml-2"
v-if="version.download_completed"
>已下载</span
>
<div v-if="version.download_completed">
<el-button type="text">已下载</el-button>
<!-- <span-->
<!-- class="primary-text text-sm font-bold ml-2"-->
<!-- >已下载</span>-->
<el-button type="text" class="danger-text" @click="handleDeleteVersion(version)">
<Icon class="mr-1" icon="material-symbols:delete"/>
删除
</el-button>
<!-- <div>-->
<!-- <Icon class="mr-1" icon="material-symbols:download-2"/>-->
<!-- <span-->
<!-- class="danger-text text-sm font-bold ml-2"-->
<!-- >删除下载</span>-->
<!-- </div>-->
</div>
<template v-else>
<div class="w-32" v-if="downloading.has(version.id)">
<el-progress