refs #982 refactor: Standardize converting proxy configuration for megalodon
This commit is contained in:
parent
a47fbbcf6a
commit
e231bb3cc0
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue