mirror of
https://github.com/kunkunsh/kunkun.git
synced 2025-04-20 05:29:17 +00:00
Feature: register hotkey in main window (#60)
* feat: enhance hotkey registration and initialization process * fix: jsr test (cherrypicked from another branch) * fix: fix nuxt tailwind version, the latest verison has bug * update pnpm lock
This commit is contained in:
parent
d73ae6542c
commit
0b1658228b
@ -1,6 +1,6 @@
|
|||||||
import { getAllWindows } from "@tauri-apps/api/window"
|
import { getAllWindows } from "@tauri-apps/api/window"
|
||||||
import { isRegistered, register, unregister } from "@tauri-apps/plugin-global-shortcut"
|
import { isRegistered, register, unregister } from "@tauri-apps/plugin-global-shortcut"
|
||||||
import { debug, info } from "@tauri-apps/plugin-log"
|
import { debug, info, warn } from "@tauri-apps/plugin-log"
|
||||||
import { sendNotificationWithPermission } from "./notification"
|
import { sendNotificationWithPermission } from "./notification"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,7 +16,7 @@ export function mapKeyToTauriKey(key: string): string {
|
|||||||
|
|
||||||
export async function registerAppHotkey(hotkeyStr: string) {
|
export async function registerAppHotkey(hotkeyStr: string) {
|
||||||
if (await isRegistered(hotkeyStr)) {
|
if (await isRegistered(hotkeyStr)) {
|
||||||
debug(`Hotkey (${hotkeyStr}) already registered`)
|
warn(`Hotkey (${hotkeyStr}) already registered`)
|
||||||
await unregister(hotkeyStr)
|
await unregister(hotkeyStr)
|
||||||
}
|
}
|
||||||
info(`Registering hotkey: ${hotkeyStr}`)
|
info(`Registering hotkey: ${hotkeyStr}`)
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
import { appConfig } from "@/stores"
|
||||||
import { getCurrentWindow } from "@tauri-apps/api/window"
|
import { getCurrentWindow } from "@tauri-apps/api/window"
|
||||||
|
import { info } from "@tauri-apps/plugin-log"
|
||||||
import { dev } from "$app/environment"
|
import { dev } from "$app/environment"
|
||||||
|
import { mapKeyToTauriKey, registerAppHotkey } from "./hotkey"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the app
|
* Initialize the app
|
||||||
@ -19,11 +22,15 @@ export function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function initMainWindow() {
|
export function initMainWindow() {
|
||||||
// const window = getCurrentWindow()
|
/* -------------------------------------------------------------------------- */
|
||||||
// if (window.label === "main") {
|
/* Register App Hotkey */
|
||||||
// window.onCloseRequested((event) => {
|
/* -------------------------------------------------------------------------- */
|
||||||
// event.preventDefault()
|
const triggerHotkey = appConfig.get().triggerHotkey
|
||||||
// window.hide()
|
if (triggerHotkey && triggerHotkey.length > 0) {
|
||||||
// })
|
const hotkeyStr = triggerHotkey.map(mapKeyToTauriKey).join("+")
|
||||||
// }
|
info(`Registering hotkey: ${hotkeyStr}`)
|
||||||
|
registerAppHotkey(hotkeyStr)
|
||||||
|
} else {
|
||||||
|
console.log("No hotkey found in confi")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user