refs #982 refactor: Standardize converting proxy configuration for megalodon

This commit is contained in:
AkiraFukushima 2019-10-27 17:27:00 +09:00
parent a47fbbcf6a
commit e231bb3cc0
2 changed files with 4 additions and 30 deletions

View File

@ -1001,7 +1001,7 @@ ipcMain.on('update-proxy-config', (event: IpcMainEvent, proxy: Proxy) => {
})
ipcMain.on('get-proxy-configuration', async (event: IpcMainEvent) => {
const proxy = await proxyConfiguration.getConfig()
const proxy = await proxyConfiguration.forMastodon()
event.sender.send('response-get-proxy-configuration', proxy)
})

View File

@ -11,7 +11,6 @@ import { RootState } from '@/store'
import { Notify } from '~/src/types/notify'
import { BaseConfig } from '~/src/types/preference'
import { Appearance } from '~/src/types/appearance'
import { ManualProxy, ProxyProtocol } from '~/src/types/proxy'
import { ProxyConfig } from 'megalodon'
export type AppState = {
@ -101,33 +100,8 @@ const mutations: MutationTree<AppState> = {
[MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS]: (state: AppState, hideAllAttachments: boolean) => {
state.hideAllAttachments = hideAllAttachments
},
[MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION]: (state, proxy: ManualProxy | false) => {
// TODO: use src/main/proxy.ts#forMastodon
if (!proxy) {
state.proxyConfiguration = false
} else {
let protocol = ProxyProtocol.http
if (proxy.protocol !== '') {
protocol = proxy.protocol
}
if (proxy.username.length > 0) {
state.proxyConfiguration = {
host: proxy.host,
port: parseInt(proxy.port, 10),
protocol: protocol,
auth: {
username: proxy.username,
password: proxy.password
}
}
} else {
state.proxyConfiguration = {
host: proxy.host,
port: parseInt(proxy.port, 10),
protocol: protocol
}
}
}
[MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION]: (state, proxy: ProxyConfig | false) => {
state.proxyConfiguration = proxy
}
}
@ -192,7 +166,7 @@ const actions: ActionTree<AppState, RootState> = {
},
loadProxy: ({ commit }) => {
return new Promise(resolve => {
ipcRenderer.once('response-get-proxy-configuration', (_, proxy: ManualProxy | false) => {
ipcRenderer.once('response-get-proxy-configuration', (_, proxy: ProxyConfig | false) => {
commit(MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION, proxy)
resolve(proxy)
})