Skip to content

Commit

Permalink
feat: try no gui mode
Browse files Browse the repository at this point in the history
  • Loading branch information
starknt committed Jan 19, 2025
1 parent 3ae6282 commit 164532f
Show file tree
Hide file tree
Showing 12 changed files with 741 additions and 556 deletions.
10 changes: 9 additions & 1 deletion packages/core/src/expose.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,28 @@ function newServerStart ({ mitmproxyPath }) {
}
server.start = newServerStart
async function startup ({ mitmproxyPath }) {
let server
const conf = config.get()

if (conf.server.enabled) {
try {
await server.start({ mitmproxyPath })
server = await server.start({ mitmproxyPath })
} catch (err) {
log.error('代理服务启动失败:', err)
}
}

if (conf.proxy.enabled) {
try {
await proxy.start()
} catch (err) {
log.error('开启系统代理失败:', err)
}
}

try {
const plugins = []

for (const key in plugin) {
if (conf.plugin[key].enabled) {
const start = async () => {
Expand All @@ -72,12 +77,15 @@ async function startup ({ mitmproxyPath }) {
plugins.push(start())
}
}

if (plugins && plugins.length > 0) {
await Promise.all(plugins)
}
} catch (err) {
log.error('开启插件失败:', err)
}

return server
}

async function shutdown () {
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/modules/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const serverApi = {
return this.close()
}
},
async start ({ mitmproxyPath, plugins }) {
async start ({ mitmproxyPath, plugins, options }) {
const allConfig = config.get()
const serverConfig = lodash.cloneDeep(allConfig.server)

Expand Down Expand Up @@ -78,14 +78,15 @@ const serverApi = {
const runningConfigPath = path.join(basePath, '/running.json')
fs.writeFileSync(runningConfigPath, jsonApi.stringify(serverConfig))
log.info('保存 running.json 运行时配置文件成功:', runningConfigPath)
const serverProcess = fork(mitmproxyPath, [runningConfigPath])
const serverProcess = fork(mitmproxyPath, [runningConfigPath], options)
server = {
id: serverProcess.pid,
process: serverProcess,
close () {
serverProcess.send({ type: 'action', event: { key: 'close' } })
},
}

serverProcess.on('beforeExit', (code) => {
log.warn('server process beforeExit, code:', code)
})
Expand Down Expand Up @@ -113,7 +114,8 @@ const serverApi = {
event.fire('speed', msg.event)
}
})
return { port: serverConfig.port }

return { port: serverConfig.port, server }
},
async kill () {
if (server) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/util.logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function log4jsConfigure (categories) {

for (const category of categories) {
config.appenders[category] = { ...appenderConfig, filename: path.join(basePath, `/${category}.log`) }
config.categories[category] = { appenders: [category, 'std'], level }
config.categories[category] = { appenders: [category, ...process.env.NO_CONSOLE_LOG ? [] : ['std']], level }
}

log4js.configure(config)
Expand Down
8 changes: 8 additions & 0 deletions packages/gui/extra/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
____ _____ _ __
/ __ \___ _ __ / ___/(_)___/ /__ _________ ______
/ / / / _ \ | / /_____\__ \/ / __ / _ \/ ___/ __ `/ ___/
/ /_/ / __/ |/ /_____/__/ / / /_/ / __/ /__/ /_/ / /
/_____/\___/|___/ /____/_/\__,_/\___/\___/\__,_/_/


==================== 开发者边车 ====================
3 changes: 3 additions & 0 deletions packages/gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron": "vue-cli-service electron:serve",
"electron:headless": "cross-env ELECTRON_RUN_AS_NODE=1 vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps",
"electron:icons": "electron-icon-builder --input=./public/logo/win.png --output=build --flatten",
Expand All @@ -27,6 +28,7 @@
"@vscode/sudo-prompt": "^9.3.1",
"adm-zip": "^0.5.16",
"ant-design-vue": "^1.7.8",
"cac": "^6.7.14",
"electron-baidu-tongji": "^1.0.5",
"electron-updater": "^6.3.9",
"json5": "^2.2.3",
Expand All @@ -44,6 +46,7 @@
"@vue/babel-preset-jsx": "^1.4.0",
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-service": "^5.0.8",
"cross-env": "^7.0.3",
"electron": "^19.1.9",
"electron-builder": "^25.1.8",
"electron-icon-builder": "^2.0.1",
Expand Down
Loading

0 comments on commit 164532f

Please sign in to comment.