-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for pinning menu items + global keyboard shortcuts
- Loading branch information
Showing
8 changed files
with
221 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { SettingsContextStateKey } from "@/providers/SettingsContextProvider"; | ||
import { injectStrict } from "@/lib/utils"; | ||
import { | ||
register, | ||
unregister, | ||
unregisterAll, | ||
} from "@tauri-apps/api/globalShortcut"; | ||
import { useRouter } from "vue-router"; | ||
|
||
export const GlobalShortcutRegisterShortcutsKey: InjectionKey<() => void> = | ||
Symbol("GlobalShortcutRegisterShortcuts"); | ||
|
||
export default { | ||
name: "GlobalShortcutProvider", | ||
async setup() { | ||
const state = reactive({ | ||
shortcuts: [] as string[], | ||
}); | ||
|
||
const { settings } = injectStrict(SettingsContextStateKey); | ||
const router = useRouter(); | ||
|
||
const registerShortcuts = async () => { | ||
await clearShortcuts(); | ||
|
||
settings.value.pinnedResources.forEach((resource, index) => { | ||
if (index > 8) return; | ||
|
||
register("CommandOrControl+" + (index + 1), () => { | ||
router.push({ | ||
path: `/${resource.name}`, | ||
query: { resource: resource.name }, | ||
}); | ||
}); | ||
state.shortcuts.push("CommandOrControl+" + (index + 1)); | ||
}); | ||
}; | ||
|
||
provide(GlobalShortcutRegisterShortcutsKey, registerShortcuts); | ||
|
||
const clearShortcuts = async () => { | ||
state.shortcuts.forEach((shortcut) => { | ||
unregister(shortcut); | ||
}); | ||
state.shortcuts = []; | ||
}; | ||
|
||
unregisterAll(); | ||
registerShortcuts(); | ||
}, | ||
render(): any { | ||
return this.$slots.default(); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters