feat(core): globalShortcut API (#1232)

This commit is contained in:
Lucas Fernandes Nogueira
2021-02-14 17:34:23 -03:00
committed by GitHub
parent 772d83e8fd
commit 855effadd9
22 changed files with 481 additions and 15 deletions

View File

@@ -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
View 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
}

View File

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

View File

@@ -187,7 +187,7 @@ function resize(width: number, height: number): void {
message: {
cmd: 'resize',
width,
height,
height
}
})
}