Clean up keyboard bindings and reload locale

Co-Authored-By: kubectl <me@kube.moe>
This commit is contained in:
Natsumi
2025-11-20 21:07:42 +11:00
parent 506b709a21
commit 39a8685f0d
5 changed files with 106 additions and 74 deletions

View File

@@ -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
};
});