Skip to content

Commit

Permalink
ctrl-arrow keybind mac only fixes #101 + macos tray fix
Browse files Browse the repository at this point in the history
ctrl+arrow mac only
  • Loading branch information
jackschedel committed Jan 14, 2024
1 parent 7618060 commit 65b36fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
28 changes: 17 additions & 11 deletions electron/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ contextMenu({
function handleSetCloseToTray(event, setting) {
closeToTray = setting;

if (closeToTray && trayExists) {
winTray.destroy();
trayExists = false;
}
if (process.platform !== 'darwin') {
if (closeToTray && trayExists) {
winTray.destroy();
trayExists = false;
}

if (closeToTray && !trayExists) {
createTray(win);
trayExists = true;
if (closeToTray && !trayExists) {
createTray(win);
trayExists = true;
}
}
}

Expand Down Expand Up @@ -126,10 +128,8 @@ const createTray = (window) => {

winTray.on('click', () => {
if (win) {
if (!win.isVisible()) win.show();

if (win.isMinimized()) win.restore();

if (!win.isVisible()) win.show();
win.focus();
}
});
Expand All @@ -139,8 +139,14 @@ const createTray = (window) => {
return winTray;
};

app.on('activate', () => {
if (win) {
win.show();
}
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
if (!(process.platform === 'darwin' && closeToTray)) {
app.quit();
}
});
Expand Down
22 changes: 12 additions & 10 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ChatInterface } from '@type/chat';
import { Theme } from '@type/theme';
import ApiPopup from '@components/ApiPopup';
import Toast from '@components/Toast';
import isElectron from '@utils/electron';
import isElectron, { isMac } from '@utils/electron';

function App() {
const setChats = useStore((state) => state.setChats);
Expand Down Expand Up @@ -121,16 +121,18 @@ function App() {
pasteSubmit();
}

// ctrl+left - Previous chat
if (e.ctrlKey && e.key === 'ArrowLeft') {
e.preventDefault();
goBack();
}
if (isMac()) {
// ctrl+left - Previous chat
if (e.ctrlKey && e.key === 'ArrowLeft') {
e.preventDefault();
goBack();
}

// ctrl+right - Next chat
if (e.ctrlKey && e.key === 'ArrowRight') {
e.preventDefault();
goForward();
// ctrl+right - Next chat
if (e.ctrlKey && e.key === 'ArrowRight') {
e.preventDefault();
goForward();
}
}
};

Expand Down
7 changes: 7 additions & 0 deletions src/utils/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export default function isElectron() {
return false;
}

export function isMac(): boolean {
if (typeof navigator !== 'undefined') {
return /Mac|iMac|Macintosh/.test(navigator.platform);
}
return false;
}

declare global {
interface Window {
electronAPI: {
Expand Down

0 comments on commit 65b36fa

Please sign in to comment.