spacedrive/interface/hooks/useKeybindEventHandler.ts
Oscar Beaumont a238760c88
[ENG-1690] Upgrade to Tauri 2.0 (#2433)
* Most of it

* Cleanup menu

* fixes

* Fixed linux compilation, still not working though, as the app panic on start

* Add dialog permissions

* fix search keybind

* Fix linux
∙  - Disable linux-ipc-protocol feature, as that is causing panics due to trying to access some WebKit internal structures outside the main thread

* Update to Ubuntu 22.04, new tauri doesn't support ubuntu 20.04
>  - Add note to download page about deb's distro support

* Remove gen/schemas

* Update linux dependencies in setup.sh

* Fix linux deps again
 - Enable rt-tokio-crypto-rust feature in secret-service so clippy stops complaining

* Clippy + auto fmt

* Fix cache-factory
 - Create a devtools feature for desktop app, which is enabled by default on dev builds

* Fix minor error in patchTauri.mjs

* Fix some envvars that have been renamed on tauri v2

* Dont change the secrets

* Add missing linux dependency

---------

Co-authored-by: Vítor Vasconcellos <vasconcellos.dev@gmail.com>
2024-05-07 08:36:50 +00:00

59 lines
1.8 KiB
TypeScript

import { useEffect } from 'react';
import { useLocation, useNavigate } from 'react-router';
import { KeybindEvent } from '../util/keybind';
import { useQuickRescan } from './useQuickRescan';
import { getWindowState } from './useWindowState';
export const useKeybindEventHandler = (libraryId?: string) => {
const navigate = useNavigate();
const windowState = getWindowState();
const rescan = useQuickRescan();
const regex = new RegExp(
'/[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/location/'
);
const id = parseInt(useLocation().pathname.replace(regex, ''));
useEffect(() => {
const handler = (e: KeybindEvent) => {
e.preventDefault();
switch (e.detail.action) {
case 'new_library':
console.log('New Library!'); // TODO: Implement
break;
case 'new_file':
console.log('New File!'); // TODO: Implement
break;
case 'new_directory':
console.log('New Directory!'); // TODO: Implement
break;
case 'add_location':
console.log('Add Location!'); // TODO: Implement
break;
case 'open_settings':
libraryId && navigate(`/${libraryId}/settings/client/general`);
break;
case 'reload_explorer':
!isNaN(id) && rescan(id);
break;
// case 'open_overview':
// libraryId && navigate(`/${libraryId}/overview`);
// break;
case 'open_search':
document.dispatchEvent(new CustomEvent('open_search'));
break;
case 'window_fullscreened':
windowState.isFullScreen = true;
break;
case 'window_not_fullscreened':
windowState.isFullScreen = false;
break;
}
};
document.addEventListener('keybindexec', handler);
return () => document.removeEventListener('keybindexec', handler);
}, [navigate, libraryId, windowState, rescan, id]);
};