ux: macOS (#251)

This commit is contained in:
Carlos Valente
2022-11-12 07:57:12 +01:00
committed by GitHub
parent b5a521f625
commit dfef6d4e79
9 changed files with 288 additions and 109 deletions
+16 -17
View File
@@ -7,6 +7,7 @@ import ErrorBoundary from 'common/components/errorBoundary/ErrorBoundary';
import { AppContextProvider } from './common/context/AppContext';
import SocketProvider from './common/context/socketContext';
import useElectronEvent from './common/hooks/useElectronEvent';
import theme from './theme/theme';
import AppRouter from './AppRouter';
@@ -15,30 +16,28 @@ import('typeface-open-sans');
export const ontimeQueryClient = new QueryClient();
function App() {
const { isElectron, sendToElectron } = useElectronEvent();
// Handle keyboard shortcuts
const handleKeyPress = useCallback((e) => {
// handle held key
if (e.repeat) return;
// check if the alt key is pressed
if (e.altKey) {
if (e.key === 't' || e.key === 'T') {
// if we are in electron
if (window.process?.type === 'renderer') {
const handleKeyPress = useCallback((event) => {
// handle held key
if (event.repeat) return;
// check if the alt key is pressed
if (event.altKey) {
if (event.code === 'KeyT') {
// ask to see debug
window.ipcRenderer.send('set-window', 'show-dev');
sendToElectron('set-window', 'show-dev');
}
}
}
}, []);
},[]);
useEffect(() => {
// attach the event listener
document.addEventListener('keydown', handleKeyPress);
// remove the event listener
if (isElectron) {
document.addEventListener('keydown', handleKeyPress);
}
return () => {
document.removeEventListener('keydown', handleKeyPress);
if (isElectron) {
document.removeEventListener('keydown', handleKeyPress);
}
};
}, [handleKeyPress]);
+11 -11
View File
@@ -39,34 +39,34 @@ export default function EventList(props) {
// Handle keyboard shortcuts
const handleKeyPress = useCallback(
(e) => {
(event) => {
// handle held key
if (e.repeat) return;
if (event.repeat) return;
// Check if the alt key is pressed
if (e.altKey && (!e.ctrlKey || !e.shiftKey)) {
if (event.altKey && (!event.ctrlKey || !event.shiftKey)) {
// Arrow down
if (e.keyCode === 40) {
if (event.keyCode === 40) {
if (cursor < events.length - 1) moveCursorDown();
}
// Arrow up
if (e.keyCode === 38) {
if (event.keyCode === 38) {
if (cursor > 0) moveCursorUp();
}
// E
if (e.key === 'e' || e.key === 'E') {
e.preventDefault();
if (event.code === "KeyE") {
event.preventDefault();
if (cursor == null) return;
insertAtCursor('event', cursor);
}
// D
if (e.key === 'd' || e.key === 'D') {
e.preventDefault();
if (event.code === "KeyD") {
event.preventDefault();
if (cursor == null) return;
insertAtCursor('delay', cursor);
}
// B
if (e.key === 'b' || e.key === 'B') {
e.preventDefault();
if (event.code === "KeyB") {
event.preventDefault();
if (cursor == null) return;
insertAtCursor('block', cursor);
}
+10 -10
View File
@@ -63,29 +63,29 @@ export default function MenuBar(props: MenuBarProps) {
// Handle keyboard shortcuts
const handleKeyPress = useCallback(
(event: KeyboardEvent) => {
// skip if not electron
if (!isElectron) return;
// handle held key
if (event.repeat) return;
// check if the ctrl key is pressed
if (event.ctrlKey) {
if (event.ctrlKey || event.metaKey) {
// ctrl + , (settings)
if (event.key === ',') {
if (isElectron) {
// open if not open
isSettingsOpen ? onSettingsClose() : onSettingsOpen();
}
// open if not open
isSettingsOpen ? onSettingsClose() : onSettingsOpen();
}
}
},
[isElectron, isSettingsOpen, onSettingsClose, onSettingsOpen]
[isElectron, isSettingsOpen, onSettingsClose, onSettingsOpen],
);
useEffect(() => {
document.addEventListener('keydown', handleKeyPress);
if (isElectron) {
document.addEventListener('keydown', handleKeyPress);
}
return () => {
document.removeEventListener('keydown', handleKeyPress);
if (isElectron) {
document.removeEventListener('keydown', handleKeyPress);
}
};
}, [handleKeyPress]);