refs #1542 Fix proxy configuration in preferences

This commit is contained in:
AkiraFukushima 2020-06-30 23:48:55 +09:00
parent 87303ba457
commit 5a99be907b
3 changed files with 19 additions and 32 deletions

View File

@ -1049,7 +1049,7 @@ ipcMain.on('get-global-header', (event: IpcMainEvent) => {
})
// proxy
ipcMain.on('update-proxy-config', async (event: IpcMainEvent, proxy: Proxy) => {
ipcMain.handle('update-proxy-config', async (_event: IpcMainInvokeEvent, proxy: Proxy) => {
const preferences = new Preferences(preferencesDBPath)
try {
const conf = await preferences.update({
@ -1061,15 +1061,11 @@ ipcMain.on('update-proxy-config', async (event: IpcMainEvent, proxy: Proxy) => {
} else {
await mainWindow?.webContents.session.setProxy({})
}
event.sender.send('response-update-proxy-config', conf)
return conf
} catch (err) {
log.error(err)
}
})
ipcMain.on('get-proxy-configuration', async (event: IpcMainEvent) => {
const proxy = await proxyConfiguration.forMastodon()
event.sender.send('response-get-proxy-configuration', proxy)
return null
})
// language

View File

@ -10,7 +10,6 @@ import { RootState } from '@/store'
import { Notify } from '~/src/types/notify'
import { BaseConfig } from '~/src/types/preference'
import { Appearance } from '~/src/types/appearance'
import { ProxyConfig } from 'megalodon'
import { MyWindow } from '~/src/types/global'
const win = (window as any) as MyWindow
@ -27,7 +26,6 @@ export type AppState = {
ignoreNFSW: boolean
hideAllAttachments: boolean
tootPadding: number
proxyConfiguration: ProxyConfig | false
userAgent: string
}
@ -50,7 +48,6 @@ const state = (): AppState => ({
ignoreCW: false,
ignoreNFSW: false,
hideAllAttachments: false,
proxyConfiguration: false,
userAgent: 'Whalebird'
})
@ -65,8 +62,7 @@ const MUTATION_TYPES = {
ADD_FONT: 'addFont',
UPDATE_IGNORE_CW: 'updateIgnoreCW',
UPDATE_IGNORE_NFSW: 'updateIgnoreNFSW',
UPDATE_HIDE_ALL_ATTACHMENTS: 'updateHideAllAttachments',
UPDATE_PROXY_CONFIGURATION: 'updateProxyConfiguration'
UPDATE_HIDE_ALL_ATTACHMENTS: 'updateHideAllAttachments'
}
const mutations: MutationTree<AppState> = {
@ -103,9 +99,6 @@ const mutations: MutationTree<AppState> = {
},
[MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS]: (state: AppState, hideAllAttachments: boolean) => {
state.hideAllAttachments = hideAllAttachments
},
[MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION]: (state, proxy: ProxyConfig | false) => {
state.proxyConfiguration = proxy
}
}
@ -167,16 +160,16 @@ const actions: ActionTree<AppState, RootState> = {
commit(MUTATION_TYPES.UPDATE_THEME, LightTheme)
break
}
},
loadProxy: ({ commit }) => {
return new Promise(resolve => {
win.ipcRenderer.once('response-get-proxy-configuration', (_, proxy: ProxyConfig | false) => {
commit(MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION, proxy)
resolve(proxy)
})
win.ipcRenderer.send('get-proxy-configuration')
})
}
// loadProxy: ({ commit }) => {
// return new Promise(resolve => {
// win.ipcRenderer.once('response-get-proxy-configuration', (_, proxy: ProxyConfig | false) => {
// commit(MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION, proxy)
// resolve(proxy)
// })
// win.ipcRenderer.send('get-proxy-configuration')
// })
// }
}
const App: Module<AppState, RootState> = {

View File

@ -124,18 +124,16 @@ const actions: ActionTree<NetworkState, RootState> = {
updatePassword: ({ commit }, password: string) => {
commit(MUTATION_TYPES.UPDATE_PASSWORD, password)
},
saveProxyConfig: ({ state, dispatch }) => {
saveProxyConfig: async ({ state }) => {
const proxy: Proxy = {
source: state.source,
manualProxyConfig: state.proxy
}
win.ipcRenderer.once('response-update-proxy-config', async () => {
dispatch('App/loadProxy', {}, { root: true })
// Originally we have to restart all streamings after user change proxy configuration.
// But streamings are restart after close preferences.
// So we don't have to restart streaming here.
})
win.ipcRenderer.send('update-proxy-config', proxy)
// Originally we have to restart all streamings after user change proxy configuration.
// But streamings are restart after close preferences.
// So we don't have to restart streaming here.
// And we have to update webContents session, but it is care in main process.
await win.ipcRenderer.invoke('update-proxy-config', proxy)
}
}