mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
feat(core): globalShortcut API (#1232)
This commit is contained in:
committed by
GitHub
parent
772d83e8fd
commit
855effadd9
@@ -9,6 +9,7 @@ import * as shell from './shell'
|
||||
import * as tauri from './tauri'
|
||||
import * as window from './window'
|
||||
import * as notification from './notification'
|
||||
import * as globalShortcut from './globalShortcut'
|
||||
|
||||
export {
|
||||
cli,
|
||||
@@ -20,5 +21,6 @@ export {
|
||||
shell,
|
||||
tauri,
|
||||
window,
|
||||
notification
|
||||
notification,
|
||||
globalShortcut
|
||||
}
|
||||
|
||||
39
api/src/globalShortcut.ts
Normal file
39
api/src/globalShortcut.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { promisified, transformCallback } from './tauri'
|
||||
|
||||
/**
|
||||
* register a global shortcut
|
||||
* @param shortcut shortcut definition, modifiers and key separated by "+" e.g. Alt+Q
|
||||
* @param handler shortcut handler callback
|
||||
*/
|
||||
async function registerShortcut(
|
||||
shortcut: string,
|
||||
handler: () => void
|
||||
): Promise<void> {
|
||||
return await promisified({
|
||||
module: 'GlobalShortcut',
|
||||
message: {
|
||||
cmd: 'register',
|
||||
shortcut,
|
||||
handler: transformCallback(handler)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister a global shortcut
|
||||
* @param shortcut shortcut definition, modifiers and key separated by "+" e.g. Alt+Q
|
||||
*/
|
||||
async function unregisterShortcut(shortcut: string): Promise<void> {
|
||||
return await promisified({
|
||||
module: 'GlobalShortcut',
|
||||
message: {
|
||||
cmd: 'unregister',
|
||||
shortcut
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
registerShortcut,
|
||||
unregisterShortcut
|
||||
}
|
||||
@@ -155,11 +155,4 @@ async function deleteRequest<T>(
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
request,
|
||||
get,
|
||||
post,
|
||||
put,
|
||||
patch,
|
||||
deleteRequest as httpDelete,
|
||||
}
|
||||
export { request, get, post, put, patch, deleteRequest as httpDelete }
|
||||
|
||||
@@ -187,7 +187,7 @@ function resize(width: number, height: number): void {
|
||||
message: {
|
||||
cmd: 'resize',
|
||||
width,
|
||||
height,
|
||||
height
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user