Skip to content

Commit

Permalink
ux: macOS (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente authored Nov 12, 2022
1 parent b5a521f commit dfef6d4
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 109 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ontime-ui",
"version": "1.9.5",
"version": "1.9.6",
"private": true,
"dependencies": {
"@chakra-ui/react": "^2.3.2",
Expand Down
33 changes: 16 additions & 17 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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]);

Expand Down
22 changes: 11 additions & 11 deletions client/src/features/editors/list/EventList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Empty file.
20 changes: 10 additions & 10 deletions client/src/features/menu/MenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
12 changes: 12 additions & 0 deletions server/electron.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
appIni: {
mainWindowWait: 2000,
},
reactAppUrl: {
development: 'http://localhost:3000/editor',
production: 'http://localhost:4001/editor',
},
externalUrls: {
help: 'https://cpvalente.gitbook.io/ontime/',
},
};
Loading

0 comments on commit dfef6d4

Please sign in to comment.