refs #2872 Add reset menu to reset preferences
This commit is contained in:
parent
e7580d9dac
commit
f220b2ba81
|
@ -169,6 +169,9 @@
|
|||
"other": {
|
||||
"title": "Other options",
|
||||
"launch": "Launch app on login"
|
||||
},
|
||||
"reset": {
|
||||
"button": "Reset preferences"
|
||||
}
|
||||
},
|
||||
"appearance": {
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
import DisplayStyle from '~/src/constants/displayStyle'
|
||||
import Theme from '~/src/constants/theme'
|
||||
import Language from '~/src/constants/language'
|
||||
import TimeFormat from '~/src/constants/timeFormat'
|
||||
import { LightTheme } from '~/src/constants/themeColor'
|
||||
import DefaultFonts from '~/src/renderer/utils/fonts'
|
||||
import { Sound } from '~/src/types/sound'
|
||||
import { Timeline } from '~/src/types/timeline'
|
||||
import { Notify } from '~/src/types/notify'
|
||||
import { Appearance } from '~/src/types/appearance'
|
||||
import { Language as LanguageSet } from '~/src/types/language'
|
||||
import { General, State, Notification, BaseConfig, Other, Menu } from '~/src/types/preference'
|
||||
import { Proxy, ProxySource } from '~/src/types/proxy'
|
||||
|
||||
const sound: Sound = {
|
||||
fav_rb: true,
|
||||
toot: true
|
||||
}
|
||||
|
||||
const timeline: Timeline = {
|
||||
cw: false,
|
||||
nsfw: false,
|
||||
hideAllAttachments: false,
|
||||
useMarker: false
|
||||
}
|
||||
|
||||
const other: Other = {
|
||||
launch: false
|
||||
}
|
||||
|
||||
const general: General = {
|
||||
sound: sound,
|
||||
timeline: timeline,
|
||||
other: other
|
||||
}
|
||||
|
||||
const state: State = {
|
||||
collapse: false,
|
||||
hideGlobalHeader: false
|
||||
}
|
||||
|
||||
const notify: Notify = {
|
||||
reply: true,
|
||||
reblog: true,
|
||||
favourite: true,
|
||||
follow: true,
|
||||
follow_request: true,
|
||||
reaction: true,
|
||||
status: true,
|
||||
poll_vote: true,
|
||||
poll_expired: true
|
||||
}
|
||||
|
||||
const language: LanguageSet = {
|
||||
language: Language.en.key,
|
||||
spellchecker: {
|
||||
enabled: true,
|
||||
languages: [Language.en.key]
|
||||
}
|
||||
}
|
||||
|
||||
const notification: Notification = {
|
||||
notify: notify
|
||||
}
|
||||
|
||||
const appearance: Appearance = {
|
||||
theme: Theme.System.key,
|
||||
fontSize: 14,
|
||||
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
|
||||
timeFormat: TimeFormat.Absolute.value,
|
||||
customThemeColor: LightTheme,
|
||||
font: DefaultFonts[0],
|
||||
tootPadding: 8
|
||||
}
|
||||
|
||||
const proxy: Proxy = {
|
||||
source: ProxySource.system,
|
||||
manualProxyConfig: {
|
||||
protocol: '',
|
||||
host: '',
|
||||
port: '',
|
||||
username: '',
|
||||
password: ''
|
||||
}
|
||||
}
|
||||
|
||||
const menu: Menu = {
|
||||
autoHideMenu: false
|
||||
}
|
||||
|
||||
export const Base: BaseConfig = {
|
||||
general: general,
|
||||
state: state,
|
||||
language: language,
|
||||
notification: notification,
|
||||
appearance: appearance,
|
||||
proxy: proxy,
|
||||
menu: menu
|
||||
}
|
|
@ -1034,6 +1034,12 @@ ipcMain.handle('update-preferences', async (_: IpcMainInvokeEvent, data: any) =>
|
|||
return conf
|
||||
})
|
||||
|
||||
ipcMain.handle('reset-preferences', async (_: IpcMainInvokeEvent) => {
|
||||
const preferences = new Preferences(preferencesDBPath)
|
||||
const conf = await preferences.reset()
|
||||
return conf
|
||||
})
|
||||
|
||||
ipcMain.handle('system-use-dark-theme', async (_: IpcMainInvokeEvent) => {
|
||||
return nativeTheme.shouldUseDarkColors
|
||||
})
|
||||
|
|
|
@ -1,105 +1,8 @@
|
|||
import storage from 'electron-json-storage'
|
||||
import log from 'electron-log'
|
||||
import objectAssignDeep from 'object-assign-deep'
|
||||
import DisplayStyle from '../constants/displayStyle'
|
||||
import Theme from '../constants/theme'
|
||||
import Language from '../constants/language'
|
||||
import TimeFormat from '../constants/timeFormat'
|
||||
import { LightTheme } from '~/src/constants/themeColor'
|
||||
import DefaultFonts from '../renderer/utils/fonts'
|
||||
import { Sound } from '~/src/types/sound'
|
||||
import { Timeline } from '~/src/types/timeline'
|
||||
import { Notify } from '~/src/types/notify'
|
||||
import { Appearance } from '~/src/types/appearance'
|
||||
import { Language as LanguageSet } from '~/src/types/language'
|
||||
import { General, State, Notification, BaseConfig, Other, Menu } from '~/src/types/preference'
|
||||
import { Proxy, ProxySource } from '~/src/types/proxy'
|
||||
|
||||
const sound: Sound = {
|
||||
fav_rb: true,
|
||||
toot: true
|
||||
}
|
||||
|
||||
const timeline: Timeline = {
|
||||
cw: false,
|
||||
nsfw: false,
|
||||
hideAllAttachments: false,
|
||||
useMarker: false
|
||||
}
|
||||
|
||||
const other: Other = {
|
||||
launch: false
|
||||
}
|
||||
|
||||
const general: General = {
|
||||
sound: sound,
|
||||
timeline: timeline,
|
||||
other: other
|
||||
}
|
||||
|
||||
const state: State = {
|
||||
collapse: false,
|
||||
hideGlobalHeader: false
|
||||
}
|
||||
|
||||
const notify: Notify = {
|
||||
reply: true,
|
||||
reblog: true,
|
||||
favourite: true,
|
||||
follow: true,
|
||||
follow_request: true,
|
||||
reaction: true,
|
||||
status: true,
|
||||
poll_vote: true,
|
||||
poll_expired: true
|
||||
}
|
||||
|
||||
const language: LanguageSet = {
|
||||
language: Language.en.key,
|
||||
spellchecker: {
|
||||
enabled: true,
|
||||
languages: [Language.en.key]
|
||||
}
|
||||
}
|
||||
|
||||
const notification: Notification = {
|
||||
notify: notify
|
||||
}
|
||||
|
||||
const appearance: Appearance = {
|
||||
theme: Theme.System.key,
|
||||
fontSize: 14,
|
||||
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
|
||||
timeFormat: TimeFormat.Absolute.value,
|
||||
customThemeColor: LightTheme,
|
||||
font: DefaultFonts[0],
|
||||
tootPadding: 8
|
||||
}
|
||||
|
||||
const proxy: Proxy = {
|
||||
source: ProxySource.system,
|
||||
manualProxyConfig: {
|
||||
protocol: '',
|
||||
host: '',
|
||||
port: '',
|
||||
username: '',
|
||||
password: ''
|
||||
}
|
||||
}
|
||||
|
||||
const menu: Menu = {
|
||||
autoHideMenu: false
|
||||
}
|
||||
|
||||
const Base: BaseConfig = {
|
||||
general: general,
|
||||
state: state,
|
||||
language: language,
|
||||
notification: notification,
|
||||
appearance: appearance,
|
||||
proxy: proxy,
|
||||
menu: menu
|
||||
}
|
||||
import { BaseConfig } from '~/src/types/preference'
|
||||
import { Base } from '~/src/constants/initializer/preferences'
|
||||
|
||||
export default class Preferences {
|
||||
private path: string
|
||||
|
@ -142,4 +45,8 @@ export default class Preferences {
|
|||
const result = await this._save(data)
|
||||
return result
|
||||
}
|
||||
|
||||
public async reset(): Promise<BaseConfig> {
|
||||
return this.update(Base)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,9 @@
|
|||
<el-switch id="launch" v-model="other_launch" active-color="#13ce66"> </el-switch>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-form class="reset section">
|
||||
<el-button type="info" @click="reset">{{ $t('preferences.general.reset.button') }}</el-button>
|
||||
</el-form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -130,6 +133,21 @@ export default {
|
|||
type: 'error'
|
||||
})
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
reset() {
|
||||
this.$store
|
||||
.dispatch('Preferences/General/reset')
|
||||
.then(language => {
|
||||
this.$i18n.i18next.changeLanguage(language)
|
||||
})
|
||||
.catch(() => {
|
||||
this.$message({
|
||||
message: this.$t('message.preferences_load_error'),
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -97,6 +97,18 @@ const actions: ActionTree<GeneralState, RootState> = {
|
|||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as General)
|
||||
dispatch('App/loadPreferences', null, { root: true })
|
||||
await win.ipcRenderer.invoke('change-auto-launch', newOther.launch)
|
||||
},
|
||||
reset: async ({ commit, dispatch }): Promise<string> => {
|
||||
commit(MUTATION_TYPES.CHANGE_LOADING, true)
|
||||
try {
|
||||
const conf: BaseConfig = await win.ipcRenderer.invoke('reset-preferences')
|
||||
await dispatch('Preferences/Language/changeLanguage', conf.language.language, { root: true })
|
||||
await dispatch('App/loadPreferences', null, { root: true })
|
||||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as General)
|
||||
return conf.language.language
|
||||
} finally {
|
||||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue