Skip to content

Commit

Permalink
优化代理启动、增加table筛选等
Browse files Browse the repository at this point in the history
  • Loading branch information
putyy committed Nov 18, 2024
1 parent d7e34d9 commit edd0978
Show file tree
Hide file tree
Showing 14 changed files with 445 additions and 319 deletions.
2 changes: 2 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {}
declare module 'vue' {
export interface GlobalComponents {
ElButton: typeof import('element-plus/es')['ElButton']
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
ElContainer: typeof import('element-plus/es')['ElContainer']
ElFooter: typeof import('element-plus/es')['ElFooter']
ElForm: typeof import('element-plus/es')['ElForm']
Expand All @@ -20,6 +21,7 @@ declare module 'vue' {
ElMenu: typeof import('element-plus/es')['ElMenu']
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
ElOption: typeof import('element-plus/es')['ElOption']
ElPopover: typeof import('element-plus/es')['ElPopover']
ElSelect: typeof import('element-plus/es')['ElSelect']
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
Footer: typeof import('./src/components/layout/Footer.vue')['default']
Expand Down
99 changes: 55 additions & 44 deletions electron/main/cert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,62 @@ export function checkCertInstalled() {
return fs.existsSync(CONFIG.INSTALL_CERT_FLAG)
}

export async function installCert(checkInstalled = true) {
if (checkInstalled && checkCertInstalled()) {
return;
export function installCert(checkInstalled = true) {
try {
if (checkInstalled && checkCertInstalled()) {
return;
}
mkdirp.sync(path.dirname(CONFIG.INSTALL_CERT_FLAG))

if (process.platform === 'darwin') {
handleMacCertInstallation()
} else if (process.platform === 'win32') {
handleWindowsCertInstallation()
} else {
handleOtherCertInstallation()
}
} catch (e) {
handleOtherCertInstallation()
}
mkdirp.sync(path.dirname(CONFIG.INSTALL_CERT_FLAG))

if (process.platform === 'darwin') {
return new Promise((resolve, reject) => {
clipboard.writeText(
`echo "输入本地登录密码" && sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "${CONFIG.CERT_PUBLIC_PATH}" && touch ${CONFIG.INSTALL_CERT_FLAG} && echo "安装完成"`,
)
dialog.showMessageBoxSync({
type: "info",
message: `命令已复制到剪贴板,粘贴命令到终端并运行以安装并信任证书`,
});

reject()
});
} else if (process.platform === 'linux') {
return new Promise((resolve, reject) => {
clipboard.writeText(
"https://github.com/putyy/res-downloader/blob/master/electron/res/keys/public.pem",
)
dialog.showMessageBoxSync({
type: "info",
message: `Linux系统请手动安装证书,已复制下载地址`,
});

reject()
});
}


// MacOS 证书安装处理
function handleMacCertInstallation() {
clipboard.writeText(
`echo "输入本地登录密码" && sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "${CONFIG.CERT_PUBLIC_PATH}" && touch ${CONFIG.INSTALL_CERT_FLAG} && echo "安装完成"`
);

dialog.showMessageBoxSync({
type: 'info',
message: '命令已复制到剪贴板,粘贴到终端并运行以安装并信任证书',
});
}

// Linux 证书安装处理
function handleOtherCertInstallation() {
clipboard.writeText(CONFIG.CERT_PUBLIC_PATH);

dialog.showMessageBoxSync({
type: "info",
message: `请手动安装证书,证书文件路径:${CONFIG.CERT_PUBLIC_PATH} 已复制到剪贴板`,
});
}

// Windows 证书安装处理
function handleWindowsCertInstallation() {
const result = spawn.sync(CONFIG.WIN_CERT_INSTALL_HELPER, [
'-c',
'-add',
CONFIG.CERT_PUBLIC_PATH,
'-s',
'root',
]);

if (result.stdout.toString().includes('Succeeded')) {
fs.writeFileSync(CONFIG.INSTALL_CERT_FLAG, '');
} else {
return new Promise((resolve: any, reject) => {
const result = spawn.sync(CONFIG.WIN_CERT_INSTALL_HELPER, [
'-c',
'-add',
CONFIG.CERT_PUBLIC_PATH,
'-s',
'root',
]);
if (result.stdout.toString().indexOf('Succeeded') > -1) {
fs.writeFileSync(CONFIG.INSTALL_CERT_FLAG, '')
resolve()
} else {
reject()
}
})
handleOtherCertInstallation();
}
}

44 changes: 40 additions & 4 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {closeProxy} from "./setProxy"
import log from "electron-log"
import path from 'path'
import {spawn} from 'child_process'
import {startServer} from "./proxyServer";
import fs from "fs";

// The built directory structure
//
Expand Down Expand Up @@ -56,6 +58,16 @@ const preload = join(__dirname, '../preload/index.js')
const url = process.env.VITE_DEV_SERVER_URL
const indexHtml = join(process.env.DIST, 'index.html')

global.videoList = {}
global.isStartProxy = false
global.isSettingProxy = false
global.resdConfig = {
save_dir: "",
quality: "-1",
proxy: "",
port: 8899,
}

// app.whenReady().then(createWindow)

app.on('window-all-closed', () => {
Expand Down Expand Up @@ -100,8 +112,10 @@ function createWindow() {
mainWindow = new BrowserWindow({
title: 'Main window',
icon: join(process.env.VITE_PUBLIC, 'favicon.ico'),
width: 800,
height: 600,
width: 1024,
minWidth: 960,
height: 768,
minHeight: 640,
webPreferences: {
preload,
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
Expand Down Expand Up @@ -206,10 +220,32 @@ function createAria2Process() {
}
}

function initConfig(){
const configPath = path.join(app.getPath('userData'), 'resd_config.json')
if (!fs.existsSync(configPath)) {
return
}
fs.readFile(configPath, (err, data) => {
if (!err) {
try {
const jsonData = JSON.parse(data)
console.log("jsonData:", jsonData)
global.resdConfig = Object.assign({}, global.resdConfig, jsonData)
if (!global.resdConfig.proxy) {
global.resdConfig.proxy = "8899"
}
} catch (parseErr) {
}
}
});
}

app.whenReady().then(() => {
initIPC()
createWindow()
createPreviewWindow(mainWindow)
createAria2Process()
setWin(mainWindow, previewWin)
initConfig()
initIPC()
startServer(mainWindow)
createAria2Process()
})
59 changes: 44 additions & 15 deletions electron/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import {hexMD5} from '../../src/common/md5'
import {Aria2RPC} from './aria2Rpc'
import fs from "fs"
import urlTool from "url";
import {setProxy} from "./setProxy";
import path from 'path'

let win: BrowserWindow
let previewWin: BrowserWindow
let isStartProxy = false

const aria2RpcClient = new Aria2RPC()

export default function initIPC() {
Expand All @@ -21,23 +23,50 @@ export default function initIPC() {

ipcMain.handle('invoke_init_app', (event, arg) => {
// 开始 初始化应用 安装证书相关
installCert(false).then(r => {
})
installCert(false)
})

ipcMain.handle('invoke_set_config', (event, data) => {
const filePath = path.join(app.getPath('userData'), 'resd_config.json');
fs.writeFile(filePath, JSON.stringify(data), ()=>{})
global.resdConfig = Object.assign({}, global.resdConfig, data)
global.resdConfig.port = parseInt(global.resdConfig.port)
return true
})

ipcMain.handle('invoke_start_proxy', (event, arg) => {
ipcMain.handle('invoke_set_proxy', async (event, arg) => {
// 启动代理服务
if (isStartProxy) {
return
if (!global.isStartProxy) {
dialog.showMessageBoxSync({
type: "error",
message: "代理未启动",
});
return false
}
isStartProxy = true
return startServer({
win: win,
upstreamProxy: arg.upstream_proxy ? arg.upstream_proxy : "",
setProxyErrorCallback: err => {
console.log('setProxyErrorCallback', err)
},
})
try {
await setProxy('127.0.0.1', global.resdConfig.proxy)
return true
} catch (err) {
console.error(err);
dialog.showMessageBoxSync({
type: "error",
message: err.toString(),
});
return false
}
// let upstream_proxy = ""
// if (arg.upstream_proxy && !arg.upstream_proxy.includes(':8899')) {
// upstream_proxy = arg.upstream_proxy
// }
//
// global.isStartProxy = true
// return startServer({
// win: win,
// upstreamProxy: upstream_proxy,
// setProxyErrorCallback: err => {
// console.log('setProxyErrorCallback', err)
// },
// })
})

ipcMain.handle('invoke_select_down_dir', async (event, arg) => {
Expand Down Expand Up @@ -72,7 +101,7 @@ export default function initIPC() {
resolve(false);
});
}
if(quality === "0" && data.decode_key){
if (quality === "0" && data.decode_key) {
const urlInfo = urlTool.parse(down_url, true);
console.log('urlInfo', urlInfo)
if (urlInfo.query["token"] && urlInfo.query["encfilekey"]) {
Expand Down
Loading

0 comments on commit edd0978

Please sign in to comment.