refs #982 Save proxy configuration in db
This commit is contained in:
parent
ffdc55d619
commit
671cca8878
|
@ -213,7 +213,8 @@
|
||||||
"socks5": "socks5",
|
"socks5": "socks5",
|
||||||
"socks5h": "socks5h"
|
"socks5h": "socks5h"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"save": "Save"
|
||||||
},
|
},
|
||||||
"language": {
|
"language": {
|
||||||
"title": "Language",
|
"title": "Language",
|
||||||
|
|
|
@ -44,6 +44,7 @@ import { StreamingError } from '~/src/errors/streamingError'
|
||||||
import HashtagCache from './cache/hashtag'
|
import HashtagCache from './cache/hashtag'
|
||||||
import AccountCache from './cache/account'
|
import AccountCache from './cache/account'
|
||||||
import { InsertAccountCache } from '~/src/types/insertAccountCache'
|
import { InsertAccountCache } from '~/src/types/insertAccountCache'
|
||||||
|
import { Proxy } from '~/src/types/proxy'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context menu
|
* Context menu
|
||||||
|
@ -966,6 +967,22 @@ ipcMain.on('get-global-header', (event: Event) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// proxy
|
||||||
|
ipcMain.on('update-proxy-config', (event: Event, proxy: Proxy) => {
|
||||||
|
const preferences = new Preferences(preferencesDBPath)
|
||||||
|
preferences
|
||||||
|
.update({
|
||||||
|
proxy: proxy
|
||||||
|
})
|
||||||
|
.then(conf => {
|
||||||
|
event.sender.send('response-update-proxy-config', conf)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
log.error(err)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// language
|
||||||
ipcMain.on('change-language', (event: Event, value: string) => {
|
ipcMain.on('change-language', (event: Event, value: string) => {
|
||||||
const preferences = new Preferences(preferencesDBPath)
|
const preferences = new Preferences(preferencesDBPath)
|
||||||
preferences
|
preferences
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { Notify } from '~/src/types/notify'
|
||||||
import { Appearance } from '~/src/types/appearance'
|
import { Appearance } from '~/src/types/appearance'
|
||||||
import { Language as LanguageSet } from '~/src/types/language'
|
import { Language as LanguageSet } from '~/src/types/language'
|
||||||
import { General, State, Notification, BaseConfig, Other } from '~/src/types/preference'
|
import { General, State, Notification, BaseConfig, Other } from '~/src/types/preference'
|
||||||
|
import { Proxy, ProxySource } from '~/src/types/proxy'
|
||||||
|
|
||||||
const sound: Sound = {
|
const sound: Sound = {
|
||||||
fav_rb: true,
|
fav_rb: true,
|
||||||
|
@ -64,12 +65,22 @@ const appearance: Appearance = {
|
||||||
tootPadding: 8
|
tootPadding: 8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const proxy: Proxy = {
|
||||||
|
source: ProxySource.no,
|
||||||
|
manualProxyConfig: {
|
||||||
|
protocol: '',
|
||||||
|
host: '',
|
||||||
|
port: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Base: BaseConfig = {
|
const Base: BaseConfig = {
|
||||||
general: general,
|
general: general,
|
||||||
state: state,
|
state: state,
|
||||||
language: language,
|
language: language,
|
||||||
notification: notification,
|
notification: notification,
|
||||||
appearance: appearance
|
appearance: appearance,
|
||||||
|
proxy: proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Preferences {
|
export default class Preferences {
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
<el-form-item for="proxyPort" :label="$t('preferences.network.proxy.port')">
|
<el-form-item for="proxyPort" :label="$t('preferences.network.proxy.port')">
|
||||||
<el-input v-model="proxyPort" :disabled="!manualProxyConfiguration" placeholder="8080"></el-input>
|
<el-input v-model="proxyPort" :disabled="!manualProxyConfiguration" placeholder="8080"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="onSave">{{ $t('preferences.network.save') }}</el-button>
|
||||||
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -70,6 +73,19 @@ export default {
|
||||||
this.$store.dispatch('Preferences/Network/updatePort', value)
|
this.$store.dispatch('Preferences/Network/updatePort', value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.$store.dispatch('Preferences/Network/loadProxy').catch(() => {
|
||||||
|
this.$message({
|
||||||
|
message: this.$t('message.preferences_load_error'),
|
||||||
|
type: 'error'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onSave() {
|
||||||
|
this.$store.dispatch('Preferences/Network/saveProxyConfig')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
|
import { ipcRenderer } from 'electron'
|
||||||
import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'
|
import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'
|
||||||
import { RootState } from '@/store'
|
import { RootState } from '@/store'
|
||||||
|
import { BaseConfig } from '~/src/types/preference'
|
||||||
|
import { Proxy, ProxySource, ProxyProtocol } from '~/src/types/proxy'
|
||||||
|
|
||||||
export type NetworkState = {
|
export type NetworkState = {
|
||||||
source: 'no' | 'system' | 'manual'
|
source: ProxySource
|
||||||
proxy: {
|
proxy: {
|
||||||
protocol: string
|
protocol: '' | ProxyProtocol
|
||||||
host: string
|
host: string
|
||||||
port: string
|
port: string
|
||||||
}
|
}
|
||||||
|
@ -12,7 +15,7 @@ export type NetworkState = {
|
||||||
|
|
||||||
const state = (): NetworkState => {
|
const state = (): NetworkState => {
|
||||||
return {
|
return {
|
||||||
source: 'no',
|
source: ProxySource.no,
|
||||||
proxy: {
|
proxy: {
|
||||||
protocol: '',
|
protocol: '',
|
||||||
host: '',
|
host: '',
|
||||||
|
@ -22,6 +25,7 @@ const state = (): NetworkState => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MUTATION_TYPES = {
|
export const MUTATION_TYPES = {
|
||||||
|
UPDATE_PROXY: 'updateProxy',
|
||||||
CHANGE_SOURCE: 'changeSource',
|
CHANGE_SOURCE: 'changeSource',
|
||||||
UPDATE_PROTOCOL: 'updateProtocol',
|
UPDATE_PROTOCOL: 'updateProtocol',
|
||||||
UPDATE_HOST: 'updateHost',
|
UPDATE_HOST: 'updateHost',
|
||||||
|
@ -29,11 +33,47 @@ export const MUTATION_TYPES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const mutations: MutationTree<NetworkState> = {
|
const mutations: MutationTree<NetworkState> = {
|
||||||
[MUTATION_TYPES.CHANGE_SOURCE]: (state, source: 'no' | 'system' | 'manual') => {
|
[MUTATION_TYPES.UPDATE_PROXY]: (state, config: Proxy) => {
|
||||||
state.source = source
|
state.source = config.source
|
||||||
|
state.proxy = config.manualProxyConfig
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.UPDATE_PROTOCOL]: (state, protocol: string) => {
|
[MUTATION_TYPES.CHANGE_SOURCE]: (state, source: 'no' | 'system' | 'manual') => {
|
||||||
state.proxy.protocol = protocol
|
switch (source) {
|
||||||
|
case 'no':
|
||||||
|
state.source = ProxySource.no
|
||||||
|
break
|
||||||
|
case 'system':
|
||||||
|
state.source = ProxySource.system
|
||||||
|
break
|
||||||
|
case 'manual':
|
||||||
|
state.source = ProxySource.manual
|
||||||
|
break
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[MUTATION_TYPES.UPDATE_PROTOCOL]: (state, protocol: '' | 'http' | 'https' | 'socks4' | 'socks4a' | 'socks5' | 'socks5h') => {
|
||||||
|
switch (protocol) {
|
||||||
|
case 'http':
|
||||||
|
state.proxy.protocol = ProxyProtocol.http
|
||||||
|
break
|
||||||
|
case 'https':
|
||||||
|
state.proxy.protocol = ProxyProtocol.https
|
||||||
|
break
|
||||||
|
case 'socks4':
|
||||||
|
state.proxy.protocol = ProxyProtocol.socks4
|
||||||
|
break
|
||||||
|
case 'socks4a':
|
||||||
|
state.proxy.protocol = ProxyProtocol.socks4a
|
||||||
|
break
|
||||||
|
case 'socks5':
|
||||||
|
state.proxy.protocol = ProxyProtocol.socks5
|
||||||
|
break
|
||||||
|
case 'socks5h':
|
||||||
|
state.proxy.protocol = ProxyProtocol.socks5h
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
state.proxy.protocol = ''
|
||||||
|
break
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.UPDATE_HOST]: (state, host: string) => {
|
[MUTATION_TYPES.UPDATE_HOST]: (state, host: string) => {
|
||||||
state.proxy.host = host
|
state.proxy.host = host
|
||||||
|
@ -44,6 +84,20 @@ const mutations: MutationTree<NetworkState> = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const actions: ActionTree<NetworkState, RootState> = {
|
const actions: ActionTree<NetworkState, RootState> = {
|
||||||
|
loadProxy: ({ commit }) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ipcRenderer.send('get-preferences')
|
||||||
|
ipcRenderer.once('error-get-preferences', (_, err: Error) => {
|
||||||
|
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||||
|
reject(err)
|
||||||
|
})
|
||||||
|
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||||
|
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||||
|
commit(MUTATION_TYPES.UPDATE_PROXY, conf.proxy as Proxy)
|
||||||
|
resolve(conf)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
changeSource: ({ commit }, source: string) => {
|
changeSource: ({ commit }, source: string) => {
|
||||||
commit(MUTATION_TYPES.CHANGE_SOURCE, source)
|
commit(MUTATION_TYPES.CHANGE_SOURCE, source)
|
||||||
},
|
},
|
||||||
|
@ -55,6 +109,9 @@ const actions: ActionTree<NetworkState, RootState> = {
|
||||||
},
|
},
|
||||||
updatePort: ({ commit }, port: string) => {
|
updatePort: ({ commit }, port: string) => {
|
||||||
commit(MUTATION_TYPES.UPDATE_PORT, port)
|
commit(MUTATION_TYPES.UPDATE_PORT, port)
|
||||||
|
},
|
||||||
|
saveProxyConfig: ({ state }) => {
|
||||||
|
ipcRenderer.send('update-proxy-config', state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { Timeline } from '~/src/types/timeline'
|
||||||
import { Notify } from '~/src/types/notify'
|
import { Notify } from '~/src/types/notify'
|
||||||
import { Appearance } from '~/src/types/appearance'
|
import { Appearance } from '~/src/types/appearance'
|
||||||
import { Language } from '~/src/types/language'
|
import { Language } from '~/src/types/language'
|
||||||
|
import { Proxy } from '~/src/types/proxy'
|
||||||
|
|
||||||
export type Other = {
|
export type Other = {
|
||||||
launch: boolean
|
launch: boolean
|
||||||
|
@ -29,4 +30,5 @@ export type BaseConfig = {
|
||||||
language: Language
|
language: Language
|
||||||
notification: Notification
|
notification: Notification
|
||||||
appearance: Appearance
|
appearance: Appearance
|
||||||
|
proxy: Proxy
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
export enum ProxySource {
|
||||||
|
no = 'no',
|
||||||
|
system = 'system',
|
||||||
|
manual = 'manual'
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ProxyProtocol {
|
||||||
|
http = 'http',
|
||||||
|
https = 'https',
|
||||||
|
socks4 = 'socks4',
|
||||||
|
socks4a = 'socks4a',
|
||||||
|
socks5 = 'socks5',
|
||||||
|
socks5h = 'socks5h'
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Proxy = {
|
||||||
|
source: ProxySource
|
||||||
|
manualProxyConfig: {
|
||||||
|
protocol: '' | ProxyProtocol
|
||||||
|
host: string
|
||||||
|
port: string
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue