mirror of
https://github.com/Kvan7/Exiled-Exchange-2.git
synced 2026-09-25 06:05:54 +00:00
refactor
This commit is contained in:
@@ -214,3 +214,10 @@ export const KeyToElectron = {
|
||||
Alt: 'Alt',
|
||||
Shift: 'Shift'
|
||||
}
|
||||
|
||||
export const forbidden = [
|
||||
'Ctrl + C', 'Ctrl + V', 'Ctrl + A', 'Ctrl + F', 'Ctrl + Enter',
|
||||
'Home', 'Delete', 'Enter',
|
||||
'ArrowUp', 'ArrowRight', 'ArrowLeft'
|
||||
]
|
||||
export const forbiddenCtrl = ['C', 'V', 'A', 'F', 'Enter']
|
||||
|
||||
+27
-31
@@ -2,6 +2,7 @@ import Store from 'electron-store'
|
||||
import { ipcMain } from 'electron'
|
||||
import isDeepEq from 'fast-deep-equal'
|
||||
import { Config, defaultConfig } from '@/ipc/types'
|
||||
import { forbidden, forbiddenCtrl } from '@/ipc/KeyToCode'
|
||||
import { GET_CONFIG, PUSH_CONFIG, CLOSE_SETTINGS_WINDOW } from '@/ipc/ipc-event'
|
||||
import { overlayWindow } from './overlay-window'
|
||||
import { logger } from './logger'
|
||||
@@ -25,53 +26,48 @@ export function setupConfigEvents () {
|
||||
}
|
||||
|
||||
export const config = (() => {
|
||||
const config = new Store<Config>({
|
||||
const store = new Store<Config>({
|
||||
name: 'config',
|
||||
cwd: 'apt-data',
|
||||
defaults: defaultConfig
|
||||
})
|
||||
const config = store.store
|
||||
|
||||
const forbidden = ['Ctrl + C', 'Ctrl + V', 'Ctrl + A', 'Ctrl + F']
|
||||
if (forbidden.includes(config.get('priceCheckLocked') as string)) { config.set('priceCheckLocked', null) }
|
||||
if (forbidden.includes(config.get('wikiKey') as string)) { config.set('wikiKey', null) }
|
||||
if (forbidden.includes(config.get('mapCheckKey') as string)) { config.set('mapCheckKey', null) }
|
||||
const comands = config.get('commands')
|
||||
for (const c of comands) {
|
||||
if (forbidden.includes(config.priceCheckLocked as string)) { config.priceCheckLocked = null }
|
||||
if (forbidden.includes(config.wikiKey as string)) { config.wikiKey = null }
|
||||
if (forbidden.includes(config.mapCheckKey as string)) { config.mapCheckKey = null }
|
||||
if (config.priceCheckKeyHold === 'Ctrl' && forbiddenCtrl.includes(config.priceCheckKey as string)) {
|
||||
config.priceCheckKey = null
|
||||
}
|
||||
for (const c of config.commands) {
|
||||
if (forbidden.includes(c.hotkey as string)) { c.hotkey = null }
|
||||
}
|
||||
config.set('commands', comands)
|
||||
|
||||
if (config.get('priceCheckKeyHold') === 'Ctrl') {
|
||||
if (['C', 'V', 'A', 'F'].includes(config.get('priceCheckKey') as string)) {
|
||||
config.set('priceCheckKey', null)
|
||||
if (typeof config.fontSize !== 'number') {
|
||||
config.fontSize = defaultConfig.fontSize
|
||||
}
|
||||
|
||||
{
|
||||
const mapWidget = config.widgets.find(w => w.wmType === 'map-check')!
|
||||
if (mapWidget.wmZorder !== 'exclusive') {
|
||||
mapWidget.wmZorder = 'exclusive'
|
||||
mapWidget.selectedStats = mapWidget.selectedStats.map((legacy: { text: string, markedAs: string }) => ({
|
||||
matchRef: legacy.text,
|
||||
invert: false,
|
||||
valueWarning: legacy.markedAs === 'warning' ? '+' : '',
|
||||
valueDanger: legacy.markedAs === 'danger' ? '+' : '',
|
||||
valueDesirable: legacy.markedAs === 'desirable' ? '+' : ''
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof config.get('fontSize') !== 'number') {
|
||||
config.set('fontSize', defaultConfig.fontSize)
|
||||
}
|
||||
|
||||
const widgets = config.get('widgets')
|
||||
const mapWidget = widgets.find(w => w.wmType === 'map-check')!
|
||||
if (mapWidget.wmZorder !== 'exclusive') {
|
||||
mapWidget.wmZorder = 'exclusive'
|
||||
mapWidget.selectedStats = mapWidget.selectedStats.map((legacy: { text: string, markedAs: string }) => ({
|
||||
matchRef: legacy.text,
|
||||
invert: false,
|
||||
valueWarning: legacy.markedAs === 'warning' ? '+' : '',
|
||||
valueDanger: legacy.markedAs === 'danger' ? '+' : '',
|
||||
valueDesirable: legacy.markedAs === 'desirable' ? '+' : ''
|
||||
}))
|
||||
config.set('widgets', widgets)
|
||||
}
|
||||
|
||||
return config
|
||||
store.store = config
|
||||
return store
|
||||
})()
|
||||
|
||||
export function batchUpdateConfig (upd: Config, push = true) {
|
||||
// for (const key in upd) {
|
||||
// config.set(key as keyof Config, upd[key as keyof Config])
|
||||
// }
|
||||
config.store = upd
|
||||
logger.verbose('Saved', { source: 'config', push })
|
||||
if (push) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { KeyToCode } from '@/ipc/KeyToCode'
|
||||
import { KeyToCode, forbidden } from '@/ipc/KeyToCode'
|
||||
|
||||
export default {
|
||||
props: {
|
||||
@@ -17,7 +17,7 @@ export default {
|
||||
},
|
||||
forbidden: {
|
||||
type: Array,
|
||||
default: () => ['Ctrl + C', 'Ctrl + V', 'Ctrl + A', 'Ctrl + F']
|
||||
default: () => forbidden
|
||||
},
|
||||
required: {
|
||||
type: Boolean,
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<button :class="{ border: config.priceCheckKeyHold === 'Ctrl', 'line-through': config.priceCheckKey === null }" @click="config.priceCheckKeyHold = 'Ctrl'; config.priceCheckKey = null" class="rounded px-1 bg-gray-900 leading-none mr-1">Ctrl</button>
|
||||
<button :class="{ border: config.priceCheckKeyHold === 'Alt', 'line-through': config.priceCheckKey === null }" @click="config.priceCheckKeyHold = 'Alt'; config.priceCheckKey = null" class="rounded px-1 bg-gray-900 leading-none">Alt</button>
|
||||
<span class="mx-4">+</span>
|
||||
<hotkey-input v-model="config.priceCheckKey" :forbidden="['Ctrl','Shift','Alt', ...(config.priceCheckKeyHold === 'Ctrl' ? ['C','V','A','F'] : [])]" class="w-20" />
|
||||
<hotkey-input v-model="config.priceCheckKey" :forbidden="['Ctrl','Shift','Alt', ...(config.priceCheckKeyHold === 'Ctrl' ? ['C','V','A','F','Enter'] : [])]" class="w-20" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right mt-2">
|
||||
|
||||
Reference in New Issue
Block a user