Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
feat: 添加main中axios的proxy信息
Browse files Browse the repository at this point in the history
  • Loading branch information
ChingCdesu committed Aug 29, 2022
1 parent ab81041 commit 9a204b2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
16 changes: 15 additions & 1 deletion packages/main/componentManager/componentInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import fs from 'fs'
import path from 'path'
import logger from '@main/utils/logger'
import DownloadManager from '@main/downloadManager'
import detectSystemProxy from '@main/utils/proxy'
import WindowManager from '@main/windowManager'

interface DownloadHandle {
handleDownloadUpdate: (task: DownloadTask) => void
Expand Down Expand Up @@ -83,9 +85,21 @@ abstract class ComponentInstaller {
if (this.releaseTemp && Date.now() - this.releaseTemp.updated < 5 * 60 * 1000) {
return this.releaseTemp.data
}
const proxyUrl = await detectSystemProxy(new WindowManager().getWindow())
const { protocol, hostname, port, username, password } = new URL(proxyUrl)

const url = 'https://api.github.com/repos/MaaAssistantArknights/MaaAssistantArknights/releases'
const releaseResponse = await axios.get(url, {
adapter: require('axios/lib/adapters/http.js')
adapter: require('axios/lib/adapters/http.js'),
proxy: {
host: hostname,
port: Number(port),
protocol,
auth: {
username,
password
}
}
})
this.releaseTemp = { data: releaseResponse.data[0], updated: Date.now() }
return this.releaseTemp.data
Expand Down
1 change: 0 additions & 1 deletion packages/main/deviceDetector/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export async function getDeviceUuid (address: string, adbPath = defaultAdbPath):
const connectResult = (await $$(adbPath, ['connect', address])).stdout
if (connectResult.includes('connected')) {
const ret = await $`"${adbPath}" -s ${address} shell settings get secure android_id`
console.log(ret.stdout)
if (ret) return _.trim(ret.stdout)
}
return false
Expand Down
2 changes: 1 addition & 1 deletion packages/main/hooks/asst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export default function useAsstHooks (): void {
})

ipcMainHandle('main.CoreLoader:dispose', (_event) => {
core.dispose()
for (const eventName of Object.keys(asstHooks)) {
ipcMainRemove(eventName as IpcMainHandleEvent)
}
core.dispose()
})
}
9 changes: 9 additions & 0 deletions packages/main/utils/proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { BrowserWindow } from 'electron'

async function detectSystemProxy (window: BrowserWindow): Promise<string> {
const ses = window.webContents.session
const proxy = await ses.resolveProxy('https://www.google.com')
return `http://${proxy.replace('PROXY', '').trim()}`
}

export default detectSystemProxy

0 comments on commit 9a204b2

Please sign in to comment.