✨ 禁用启用代理
This commit is contained in:
parent
707b9c4b9e
commit
550c552643
@ -320,13 +320,21 @@ export const generateConfig = (
|
||||
const { currentVersion } = config;
|
||||
let filename = null;
|
||||
let configContent = "";
|
||||
const filtered = proxys
|
||||
.map(m => {
|
||||
if (m.status == null || m.status == undefined) {
|
||||
m.status = true;
|
||||
}
|
||||
return m;
|
||||
})
|
||||
.filter(f => f.status);
|
||||
if (currentVersion < 124395282) {
|
||||
// 版本小于v0.52.0
|
||||
filename = "frp.ini";
|
||||
configContent = genIniConfig(config, proxys);
|
||||
configContent = genIniConfig(config, filtered);
|
||||
} else {
|
||||
filename = "frp.toml";
|
||||
configContent = genTomlConfig(config, proxys);
|
||||
configContent = genTomlConfig(config, filtered);
|
||||
}
|
||||
const configPath = path.join(app.getPath("userData"), filename);
|
||||
log.info(`生成配置成功 配置路径:${configPath}`);
|
||||
|
@ -4,12 +4,11 @@ import {
|
||||
getProxyById,
|
||||
insertProxy,
|
||||
listProxy,
|
||||
updateProxyById
|
||||
updateProxyById,
|
||||
updateProxyStatus
|
||||
} from "../storage/proxy";
|
||||
import { reloadFrpcProcess } from "./frpc";
|
||||
|
||||
|
||||
|
||||
export const initProxyApi = () => {
|
||||
ipcMain.on("proxy.getProxys", async (event, args) => {
|
||||
listProxy((err, documents) => {
|
||||
@ -24,7 +23,7 @@ export const initProxyApi = () => {
|
||||
delete args["_id"];
|
||||
insertProxy(args, (err, documents) => {
|
||||
if (!err) {
|
||||
reloadFrpcProcess()
|
||||
reloadFrpcProcess();
|
||||
}
|
||||
event.reply("Proxy.insertProxy.hook", {
|
||||
err: err,
|
||||
@ -36,7 +35,7 @@ export const initProxyApi = () => {
|
||||
ipcMain.on("proxy.deleteProxyById", async (event, args) => {
|
||||
deleteProxyById(args, (err, documents) => {
|
||||
if (!err) {
|
||||
reloadFrpcProcess()
|
||||
reloadFrpcProcess();
|
||||
}
|
||||
event.reply("Proxy.deleteProxyById.hook", {
|
||||
err: err,
|
||||
@ -58,7 +57,7 @@ export const initProxyApi = () => {
|
||||
if (!args._id) return;
|
||||
updateProxyById(args, (err, documents) => {
|
||||
if (!err) {
|
||||
reloadFrpcProcess()
|
||||
reloadFrpcProcess();
|
||||
}
|
||||
event.reply("Proxy.updateProxy.hook", {
|
||||
err: err,
|
||||
@ -68,7 +67,16 @@ export const initProxyApi = () => {
|
||||
});
|
||||
|
||||
ipcMain.on("proxy.updateProxyStatus", async (event, args) => {
|
||||
console.log("更新状态", args);
|
||||
if (!args._id) return;
|
||||
|
||||
updateProxyStatus(args._id, args.status, (err, documents) => {
|
||||
if (!err) {
|
||||
reloadFrpcProcess();
|
||||
}
|
||||
event.reply("Proxy.updateProxyStatus.hook", {
|
||||
err: err,
|
||||
data: documents
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -68,6 +68,24 @@ export const getProxyById = (
|
||||
proxyDB.findOne({ _id: id }, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* 清空代理
|
||||
* @param cb
|
||||
*/
|
||||
export const clearProxy = (cb?: (err: Error | null, n: number) => void) => {
|
||||
proxyDB.remove({}, { multi: true }, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* 更新代理状态
|
||||
* @param id id
|
||||
* @param st 状态
|
||||
* @param cb 回调
|
||||
*/
|
||||
export const updateProxyStatus = (
|
||||
id: string,
|
||||
st: boolean,
|
||||
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
||||
) => {
|
||||
proxyDB.update({ _id: id }, { $set: { status: st } }, {}, cb);
|
||||
};
|
||||
|
@ -197,6 +197,13 @@ const handleInitHook = () => {
|
||||
InsertOrUpdateHook("修改成功", args);
|
||||
});
|
||||
|
||||
ipcRenderer.on("Proxy.updateProxyStatus.hook", (event, args) => {
|
||||
if (args.data > 0) {
|
||||
handleLoadProxys();
|
||||
}
|
||||
console.log("更新结果", args);
|
||||
});
|
||||
|
||||
ipcRenderer.on("local.getLocalPorts.hook", (event, args) => {
|
||||
loading.value.localPorts--;
|
||||
localPorts.value = args.data;
|
||||
@ -254,7 +261,11 @@ const handleOpenUpdate = (proxy: Proxy) => {
|
||||
};
|
||||
|
||||
const handleReversalUpdate = (proxy: Proxy) => {
|
||||
proxy.status = !proxy.status;
|
||||
console.log("更新", proxy);
|
||||
ipcRenderer.send("proxy.updateProxyStatus", {
|
||||
_id: proxy._id,
|
||||
status: !proxy.status
|
||||
});
|
||||
};
|
||||
|
||||
const handleLoadLocalPorts = () => {
|
||||
@ -300,6 +311,7 @@ onMounted(() => {
|
||||
onUnmounted(() => {
|
||||
ipcRenderer.removeAllListeners("Proxy.insertProxy.hook");
|
||||
ipcRenderer.removeAllListeners("Proxy.updateProxy.hook");
|
||||
ipcRenderer.removeAllListeners("Proxy.updateProxyStatus.hook");
|
||||
ipcRenderer.removeAllListeners("Proxy.deleteProxyById.hook");
|
||||
ipcRenderer.removeAllListeners("Proxy.getProxys.hook");
|
||||
ipcRenderer.removeAllListeners("local.getLocalPorts.hook");
|
||||
|
Loading…
Reference in New Issue
Block a user