mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-07-10 16:27:05 +02:00
aba07c27b8
Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: FabianLars <fabianlars@fabianlars.de> Co-authored-by: FabianLars <FabianLars@users.noreply.github.com> Co-authored-by: Alexandre Dang <124160233+vdang-crabnebula@users.noreply.github.com> Co-authored-by: Ludea <ludovicw35@hotmail.com> Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com> Co-authored-by: Duke Jones <104690+dukejones@users.noreply.github.com> Co-authored-by: NaokiM03 <37442712+NaokiM03@users.noreply.github.com> Co-authored-by: Thibault <thibault_poisson@orange.fr> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: David Blythe <49919035+writeDavid@users.noreply.github.com> Co-authored-by: Lucas Nogueira <lucas@tauri.studio> fix(stronghold): change wrong argument name for `remove` (#422) fix(window-state): correctly set decoration state if no saved state exists, fixes #421 (#424) fix(stronghold): return null if there is no record (#129) fix(window-state): propagate promise (#435) closes #432 fix(window-state): manual default implentation (#425) fix(window-state): manual default implentation, closes #421 fix(deps): update rust crate iota-crypto to 0.21 (#438) fix readme example (#447) fix: handle recursive directory correctly (#455) fix(deps): update rust crate sqlx to 0.7. plugin-sql msrv is now 1.65 (#464) fix(persisted-scope): separately save asset protocol patterns (#459) fix(deps): update rust crate iota-crypto to 0.22 (#475) fix(deps): update tauri monorepo to v1.4.0 (#482) resolve to v15.1.0 (#489) fix(deps): update rust crate iota-crypto to 0.23 (#495)
126 lines
3.4 KiB
TypeScript
126 lines
3.4 KiB
TypeScript
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
/**
|
|
* Register global shortcuts.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
declare global {
|
|
interface Window {
|
|
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
|
__TAURI__: {
|
|
transformCallback: <T>(cb: (payload: T) => void) => number;
|
|
};
|
|
}
|
|
}
|
|
|
|
export type ShortcutHandler = (shortcut: string) => void;
|
|
|
|
/**
|
|
* Register a global shortcut.
|
|
* @example
|
|
* ```typescript
|
|
* import { register } from '@tauri-apps/plugin-global-shortcut';
|
|
* await register('CommandOrControl+Shift+C', () => {
|
|
* console.log('Shortcut triggered');
|
|
* });
|
|
* ```
|
|
*
|
|
* @param shortcut Shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q
|
|
* @param handler Shortcut handler callback - takes the triggered shortcut as argument
|
|
*
|
|
* @since 2.0.0
|
|
*/
|
|
async function register(
|
|
shortcut: string,
|
|
handler: ShortcutHandler,
|
|
): Promise<void> {
|
|
return await window.__TAURI_INVOKE__("plugin:globalShortcut|register", {
|
|
shortcut,
|
|
handler: window.__TAURI__.transformCallback(handler),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Register a collection of global shortcuts.
|
|
* @example
|
|
* ```typescript
|
|
* import { registerAll } from '@tauri-apps/plugin-global-shortcut';
|
|
* await registerAll(['CommandOrControl+Shift+C', 'Ctrl+Alt+F12'], (shortcut) => {
|
|
* console.log(`Shortcut ${shortcut} triggered`);
|
|
* });
|
|
* ```
|
|
*
|
|
* @param shortcuts Array of shortcut definitions, modifiers and key separated by "+" e.g. CmdOrControl+Q
|
|
* @param handler Shortcut handler callback - takes the triggered shortcut as argument
|
|
*
|
|
* @since 2.0.0
|
|
*/
|
|
async function registerAll(
|
|
shortcuts: string[],
|
|
handler: ShortcutHandler,
|
|
): Promise<void> {
|
|
return await window.__TAURI_INVOKE__("plugin:globalShortcut|register_all", {
|
|
shortcuts,
|
|
handler: window.__TAURI__.transformCallback(handler),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Determines whether the given shortcut is registered by this application or not.
|
|
*
|
|
* If the shortcut is registered by another application, it will still return `false`.
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* import { isRegistered } from '@tauri-apps/plugin-global-shortcut';
|
|
* const isRegistered = await isRegistered('CommandOrControl+P');
|
|
* ```
|
|
*
|
|
* @param shortcut shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q
|
|
*
|
|
* @since 2.0.0
|
|
*/
|
|
async function isRegistered(shortcut: string): Promise<boolean> {
|
|
return await window.__TAURI_INVOKE__("plugin:globalShortcut|is_registered", {
|
|
shortcut,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Unregister a global shortcut.
|
|
* @example
|
|
* ```typescript
|
|
* import { unregister } from '@tauri-apps/plugin-global-shortcut';
|
|
* await unregister('CmdOrControl+Space');
|
|
* ```
|
|
*
|
|
* @param shortcut shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q
|
|
*
|
|
* @since 2.0.0
|
|
*/
|
|
async function unregister(shortcut: string): Promise<void> {
|
|
return await window.__TAURI_INVOKE__("plugin:globalShortcut|unregister", {
|
|
shortcut,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Unregisters all shortcuts registered by the application.
|
|
* @example
|
|
* ```typescript
|
|
* import { unregisterAll } from '@tauri-apps/plugin-global-shortcut';
|
|
* await unregisterAll();
|
|
* ```
|
|
*
|
|
* @since 2.0.0
|
|
*/
|
|
async function unregisterAll(): Promise<void> {
|
|
return await window.__TAURI_INVOKE__("plugin:globalShortcut|unregister_all");
|
|
}
|
|
|
|
export { register, registerAll, isRegistered, unregister, unregisterAll };
|