diff --git a/src/App.tsx b/src/App.tsx
index b92af20..571641c 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,10 +1,11 @@
-import { defineComponent, watch } from 'vue'
+import { defineComponent, watch, computed } from 'vue'
import { useMagicKeys, useDebounceFn, whenever } from '@vueuse/core'
import { useAppStore } from '@/store/app'
import { usePageStore } from '@/store/page'
import { useQuerySync } from '@/composables/useQuerySync'
import { focusInputPassword, setCSSVariable } from '@/utils/helper'
import { hotkeys, toMagicKeyCombo } from '@/utils/hotkeys'
+import { initTimer } from '@/utils/time'
export default defineComponent({
name: 'MainApp',
@@ -19,7 +20,13 @@ export default defineComponent({
}
const initKeybinds = () => {
- hotkeys.forEach(({ keys: keyList, callback }) => whenever(keys[toMagicKeyCombo(keyList)]!, callback))
+ hotkeys.forEach(({ keys: keyList, callback }) => {
+ if (!callback) return
+ whenever(
+ computed(() => !!(keys[toMagicKeyCombo(keyList)]?.value) && appStore.hotkeysEnabled),
+ callback
+ )
+ })
whenever(keys.escape!, () => {
const isFocusPassword = document.querySelector('#password:focus') as HTMLInputElement
@@ -44,6 +51,7 @@ export default defineComponent({
})
}
+ initTimer()
appStore.setUpSettings()
useQuerySync()
initKeybinds()
diff --git a/src/components/base/LoginComponent.tsx b/src/components/base/LoginComponent.tsx
index b3ee642..7174e93 100644
--- a/src/components/base/LoginComponent.tsx
+++ b/src/components/base/LoginComponent.tsx
@@ -1,6 +1,8 @@
import { defineComponent, computed, onMounted } from 'vue'
import { usePageStore } from '@/store/page'
+import { useAppStore } from '@/store/app'
import UserAvatar from './UserAvatar'
+import UserClock from './UserClock'
import UserInput from './UserInput'
import { focusInputPassword } from '@/utils/helper'
@@ -8,6 +10,7 @@ export default defineComponent({
name: 'LoginComponent',
setup() {
const pageStore = usePageStore()
+ const appStore = useAppStore()
const activeBlock = computed(() => pageStore.activeBlock)
@@ -18,6 +21,7 @@ export default defineComponent({
return () => (
+ {appStore.showTime && }
diff --git a/src/components/base/UserClock.tsx b/src/components/base/UserClock.tsx
new file mode 100644
index 0000000..317c4d0
--- /dev/null
+++ b/src/components/base/UserClock.tsx
@@ -0,0 +1,20 @@
+import { defineComponent, computed } from 'vue'
+import { useAppStore } from '@/store/app'
+import { usePageStore } from '@/store/page'
+import timeRef, { timePresets, type TimePreset } from '@/utils/time'
+
+export default defineComponent({
+ name: 'UserClock',
+ setup() {
+ const appStore = useAppStore()
+ const pageStore = usePageStore()
+
+ const formatted = computed(() => {
+ const preset = (appStore.timeFormat as TimePreset) || 'HH:mm'
+ const options = timePresets[preset] ?? timePresets['HH:mm']
+ return new Intl.DateTimeFormat(pageStore.locale, options).format(timeRef.time)
+ })
+
+ return () =>
{formatted.value}
+ }
+})
diff --git a/src/utils/time.ts b/src/utils/time.ts
index 84d3e08..b1b7ac2 100644
--- a/src/utils/time.ts
+++ b/src/utils/time.ts
@@ -1,38 +1,19 @@
import { reactive } from 'vue'
-import { usePageStore } from '@/store/page'
-const timeRef = reactive({
- time: new Date(),
- shortTime: '',
- longTime: ''
-})
+export const timePresets = {
+ 'HH:mm': { hour: 'numeric', minute: 'numeric', hour12: false },
+ 'HH:mm:ss': { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false },
+ 'short': { weekday: 'short', day: 'numeric', month: 'short', hour: 'numeric', minute: 'numeric', hour12: false },
+ 'long': { weekday: 'long', day: 'numeric', month: 'long', hour: 'numeric', minute: 'numeric', hour12: false },
+} as const satisfies Record
-const formatTime = (type: 'long' | 'short' = 'short') => {
- const options: Intl.DateTimeFormatOptions = {
- month: 'short',
- day: 'numeric',
- hour: 'numeric',
- minute: 'numeric',
- hour12: false
- }
+export type TimePreset = keyof typeof timePresets
- if (type === 'long') {
- options.month = 'long'
- options.weekday = 'long'
- }
-
- return new Intl.DateTimeFormat(usePageStore().locale, options).format(new Date())
-}
-
-const updateTime = () => {
- timeRef.time = new Date()
- timeRef.shortTime = formatTime('short')
- timeRef.longTime = formatTime('long')
-}
+const timeRef = reactive({ time: new Date() })
export const initTimer = () => {
- updateTime()
- setInterval(updateTime, 1000)
+ timeRef.time = new Date()
+ setInterval(() => { timeRef.time = new Date() }, 1000)
}
export default timeRef