From 39a8685f0d299ee81234d7ff6ea6724e2973a664 Mon Sep 17 00:00:00 2001 From: Natsumi Date: Thu, 20 Nov 2025 21:07:42 +1100 Subject: [PATCH] Clean up keyboard bindings and reload locale Co-Authored-By: kubectl --- src/plugin/i18n.js | 9 +- src/stores/ui.js | 106 +++++++++++++----- src/stores/vrcx.js | 44 -------- .../Settings/components/Tabs/AdvancedTab.vue | 4 +- .../components/Tabs/AppearanceTab.vue | 17 ++- 5 files changed, 106 insertions(+), 74 deletions(-) diff --git a/src/plugin/i18n.js b/src/plugin/i18n.js index 9ac1a4cd..d8bbe0ab 100644 --- a/src/plugin/i18n.js +++ b/src/plugin/i18n.js @@ -20,4 +20,11 @@ const i18n = createI18n({ fallbackWarn: false }); -export { i18n }; +async function updateLocalizedStrings() { + const newStrings = await getLocalizationStrings(); + Object.entries(newStrings).forEach(([key, value]) => { + i18n.global.setLocaleMessage(key.replaceAll('_', '-'), value); + }); +} + +export { i18n, updateLocalizedStrings }; diff --git a/src/stores/ui.js b/src/stores/ui.js index cf512155..1f1113b7 100644 --- a/src/stores/ui.js +++ b/src/stores/ui.js @@ -1,44 +1,88 @@ import { ref, watch } from 'vue'; +import { ElMessage } from 'element-plus'; import { defineStore } from 'pinia'; +import { useMagicKeys } from '@vueuse/core'; import { useRouter } from 'vue-router'; +import { AppDebug } from '../service/appConfig'; +import { refreshCustomCss } from '../shared/utils/base/ui'; +import { updateLocalizedStrings } from '../plugin/i18n'; import { useNotificationStore } from './notification'; import { useSearchStore } from './search'; export const useUiStore = defineStore('Ui', () => { const notificationStore = useNotificationStore(); const router = useRouter(); - const search = useSearchStore(); + const keys = useMagicKeys(); + const { directAccessPaste } = useSearchStore(); - document.addEventListener('keydown', function (e) { - if (e.shiftKey) { - shiftHeld.value = true; - } - if (e.ctrlKey && e.key === 'd') { - e.preventDefault(); - search.directAccessPaste(); - } - }); - - document.addEventListener('keyup', function (e) { - if (!e.shiftKey) { - shiftHeld.value = false; - } - }); + const ctrlR = keys['Ctrl+R']; + const ctrlD = keys['Ctrl+D']; + const shift = keys['Shift']; + const ctrlShiftI = keys['Ctrl+Shift+I']; + const altShiftR = keys['Alt+Shift+R']; const notifiedMenus = ref([]); const shiftHeld = ref(false); const trayIconNotify = ref(false); - function notifyMenu(index) { - const currentRouteName = router.currentRoute.value?.name; - if ( - index !== currentRouteName && - !notifiedMenus.value.includes(index) - ) { - notifiedMenus.value.push(index); - updateTrayIconNotify(); + watch(ctrlR, (isPressed) => { + if (isPressed) { + location.reload(); } + }); + + watch(ctrlD, (isPressed) => { + if (isPressed) { + directAccessPaste(); + } + }); + + watch(shift, (isHeld) => { + shiftHeld.value = isHeld; + }); + + watch(ctrlShiftI, (isPressed) => { + if (isPressed) { + showConsole(); + } + }); + + watch(altShiftR, (isPressed) => { + if (isPressed) { + refreshCustomCss(); + updateLocalizedStrings(); + ElMessage({ + message: 'Custom CSS and localization strings refreshed', + type: 'success' + }); + } + }); + + // Make sure file drops outside of the screenshot manager don't navigate to the file path dropped. + // This issue persists on prompts created with prompt(), unfortunately. Not sure how to fix that. + document.body.addEventListener('drop', function (e) { + e.preventDefault(); + }); + + function showConsole() { + AppApi.ShowDevTools(); + if ( + AppDebug.debug || + AppDebug.debugWebRequests || + AppDebug.debugWebSocket || + AppDebug.debugUserDiff + ) { + return; + } + console.log( + '%cCareful! This might not do what you think.', + 'background-color: red; color: yellow; font-size: 32px; font-weight: bold' + ); + console.log( + '%cIf someone told you to copy-paste something here, it can give them access to your account.', + 'font-size: 20px;' + ); } watch( @@ -54,6 +98,17 @@ export const useUiStore = defineStore('Ui', () => { } ); + function notifyMenu(index) { + const currentRouteName = router.currentRoute.value?.name; + if ( + index !== currentRouteName && + !notifiedMenus.value.includes(index) + ) { + notifiedMenus.value.push(index); + updateTrayIconNotify(); + } + } + function removeNotify(index) { notifiedMenus.value = notifiedMenus.value.filter((i) => i !== index); updateTrayIconNotify(); @@ -80,6 +135,7 @@ export const useUiStore = defineStore('Ui', () => { shiftHeld, notifyMenu, - removeNotify + removeNotify, + showConsole }; }); diff --git a/src/stores/vrcx.js b/src/stores/vrcx.js index 0a1e77d1..7864e93f 100644 --- a/src/stores/vrcx.js +++ b/src/stores/vrcx.js @@ -9,7 +9,6 @@ import { debounce, parseLocation } from '../shared/utils'; import { AppDebug } from '../service/appConfig'; import { database } from '../service/database'; import { failedGetRequests } from '../service/request'; -import { refreshCustomCss } from '../shared/utils/base/ui'; import { useAdvancedSettingsStore } from './settings/advanced'; import { useAvatarProviderStore } from './avatarProvider'; import { useAvatarStore } from './avatar'; @@ -150,48 +149,6 @@ export const useVrcxStore = defineStore('Vrcx', () => { init(); - // Make sure file drops outside of the screenshot manager don't navigate to the file path dropped. - // This issue persists on prompts created with prompt(), unfortunately. Not sure how to fix that. - document.body.addEventListener('drop', function (e) { - e.preventDefault(); - }); - - document.addEventListener('keyup', function (e) { - if (e.ctrlKey) { - if (e.key === 'I') { - showConsole(); - } else if (e.key === 'r') { - location.reload(); - } - } else if (e.altKey && e.key === 'R') { - refreshCustomCss(); - ElMessage({ - message: 'Custom CSS refreshed', - type: 'success' - }); - } - }); - - function showConsole() { - AppApi.ShowDevTools(); - if ( - AppDebug.debug || - AppDebug.debugWebRequests || - AppDebug.debugWebSocket || - AppDebug.debugUserDiff - ) { - return; - } - console.log( - '%cCareful! This might not do what you think.', - 'background-color: red; color: yellow; font-size: 32px; font-weight: bold' - ); - console.log( - '%cIf someone told you to copy-paste something here, it can give them access to your account.', - 'font-size: 20px;' - ); - } - async function updateDatabaseVersion() { // requires dbVars.userPrefix to be already set const databaseVersion = 13; @@ -775,7 +732,6 @@ export const useVrcxStore = defineStore('Vrcx', () => { ipcEnabled, clearVRCXCacheFrequency, maxTableSize, - showConsole, clearVRCXCache, eventVrcxMessage, eventLaunchCommand, diff --git a/src/views/Settings/components/Tabs/AdvancedTab.vue b/src/views/Settings/components/Tabs/AdvancedTab.vue index 51a1e139..5563cfc8 100644 --- a/src/views/Settings/components/Tabs/AdvancedTab.vue +++ b/src/views/Settings/components/Tabs/AdvancedTab.vue @@ -405,6 +405,7 @@ useLaunchStore, useNotificationsSettingsStore, usePhotonStore, + useUiStore, useUserStore, useVRCXUpdaterStore, useVrStore, @@ -430,7 +431,8 @@ const { showLaunchOptions } = useLaunchStore(); const { enablePrimaryPasswordChange } = useAuthStore(); const { cachedConfig } = storeToRefs(useAuthStore()); - const { showConsole, clearVRCXCache, showRegistryBackupDialog } = useVrcxStore(); + const { clearVRCXCache, showRegistryBackupDialog } = useVrcxStore(); + const { showConsole } = useUiStore(); const { disableGameLogDialog } = useGameLogStore(); const { cachedUsers } = useUserStore(); diff --git a/src/views/Settings/components/Tabs/AppearanceTab.vue b/src/views/Settings/components/Tabs/AppearanceTab.vue index 1b64fa7f..2c8f86f4 100644 --- a/src/views/Settings/components/Tabs/AppearanceTab.vue +++ b/src/views/Settings/components/Tabs/AppearanceTab.vue @@ -361,7 +361,7 @@