Skip to content

Commit c8ae60e

Browse files
committed
Create smaller entrypoint icon
1 parent a8dde8f commit c8ae60e

11 files changed

Lines changed: 109 additions & 24 deletions

File tree

src/main/ipc/relinquish-focus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { app, ipcMain, Menu } from 'electron';
22

33
// TODO: implement and test
4-
export default function relinquishFocus() {
4+
export default function setupRelinquishFocus() {
55
ipcMain.handle('relinquish-focus', async () => {
66
if (process.platform === 'darwin') {
77
app.hide();

src/main/ipc/tool-size.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ipcMain } from 'electron';
2+
3+
export default function setupToolSize() {
4+
ipcMain.handle('set-tool-expanded', (_, expanded: boolean) => {
5+
console.log('set-tool-expanded', expanded);
6+
});
7+
}

src/main/preload.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const electronHandler = {
1818
listInstalledApps(): Promise<any[]> {
1919
return ipcRenderer.invoke('list-installed-apps');
2020
},
21+
expand(): Promise<void> {
22+
return ipcRenderer.invoke('set-tool-expanded', true);
23+
},
24+
collapse(): Promise<void> {
25+
return ipcRenderer.invoke('set-tool-expanded', false);
26+
},
2127
},
2228
};
2329

src/renderer/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
body {
22
user-select: none;
3-
background-color: grey;
3+
background-color: var(--mantine-color-gray-1);
44
position: relative;
55
app-region: drag;
66
height: 100vh;

src/renderer/App.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useNavigate } from 'react-router-dom';
2-
import { Suspense, useCallback, useEffect } from 'react';
2+
import { useCallback, useEffect } from 'react';
33
import PouchDb from 'pouchdb-browser';
44
import { StageEntity } from '../types/Stage';
55
import Loading from '../common/Loading';
@@ -16,21 +16,28 @@ export default function App() {
1616
// No root element found; redirecting to onboarding
1717
await navigate('/first-launch');
1818
} else {
19-
await navigate('/stage/0');
19+
await navigate('/root');
2020
}
2121
}, [navigate]);
2222

2323
useEffect(() => {
24-
window.electron.ipcRenderer.on('ipc--dev--flush-db', async (flush) => {
25-
if (!flush) return;
26-
const stageDB = new PouchDb<StageEntity>('stage');
27-
await stageDB.destroy();
28-
const configDB = new PouchDb<Config>('config');
29-
await configDB.destroy();
30-
await checkFirstTimeUser();
31-
});
24+
const unsub = window.electron.ipcRenderer.on(
25+
'ipc--dev--flush-db',
26+
async (flush) => {
27+
if (!flush) return;
28+
const stageDB = new PouchDb<StageEntity>('stage');
29+
await stageDB.destroy();
30+
const configDB = new PouchDb<Config>('config');
31+
await configDB.destroy();
32+
await checkFirstTimeUser();
33+
},
34+
);
3235

3336
checkFirstTimeUser();
37+
38+
return () => {
39+
unsub();
40+
};
3441
}, [checkFirstTimeUser]);
3542

3643
return <Loading />;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createContext } from 'react';
2+
3+
type ToolSizeContextType = {
4+
expand: () => void;
5+
collapse: () => void;
6+
};
7+
8+
const ToolSizeContext = createContext<ToolSizeContextType>({
9+
expand: () => {},
10+
collapse: () => {},
11+
});
12+
13+
export default ToolSizeContext;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { ReactNode } from 'react';
2+
import { useCallback, useMemo } from 'react';
3+
import ToolSizeContext from './ToolSizeContext';
4+
5+
export default function ToolSizeContextProvider({
6+
children,
7+
}: {
8+
children: ReactNode;
9+
}) {
10+
const expand = useCallback(() => {
11+
window.electron.ipcRenderer.expand();
12+
}, []);
13+
14+
const collapse = useCallback(() => {
15+
window.electron.ipcRenderer.collapse();
16+
}, []);
17+
18+
const value = useMemo(() => ({ expand, collapse }), [expand, collapse]);
19+
20+
return (
21+
<ToolSizeContext.Provider value={value}>
22+
{children}
23+
</ToolSizeContext.Provider>
24+
);
25+
}

src/renderer/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { MemoryRouter, Routes, Route } from 'react-router-dom';
44
import StageProvider from './layout/StageProvider';
55
import Onboarding from './onboarding/Onboarding';
66
import App from './App';
7+
import Root from './layout/Root';
78
import './App.css';
89
import '@mantine/core/styles.css';
10+
import ToolSizeContextProvider from './context/ToolSizeContextProvider';
911

1012
const theme = createTheme({
1113
primaryColor: 'teal',
@@ -16,11 +18,14 @@ const root = createRoot(container);
1618
root.render(
1719
<MantineProvider theme={theme} defaultColorScheme="dark">
1820
<MemoryRouter>
19-
<Routes>
20-
<Route path="/" element={<App />} />
21-
<Route path="/stage/:id" element={<StageProvider />} />
22-
<Route path="/first-launch" element={<Onboarding />} />
23-
</Routes>
21+
<ToolSizeContextProvider>
22+
<Routes>
23+
<Route path="/" element={<App />} />
24+
<Route path="/root" element={<Root />} />
25+
<Route path="/stage/:id" element={<StageProvider />} />
26+
<Route path="/first-launch" element={<Onboarding />} />
27+
</Routes>
28+
</ToolSizeContextProvider>
2429
</MemoryRouter>
2530
</MantineProvider>,
2631
);

src/renderer/layout/Root.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Center, UnstyledButton } from '@mantine/core';
2+
import { useNavigate } from 'react-router-dom';
3+
import Icon from '../../common/Icon';
4+
5+
export default function Root() {
6+
const navigate = useNavigate();
7+
return (
8+
<Center h="100%">
9+
<UnstyledButton onClick={() => navigate('/stage/0')}>
10+
<Icon icon="tabler:circle-plus" size="2rem" />
11+
</UnstyledButton>
12+
</Center>
13+
);
14+
}

src/renderer/layout/StageProvider.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MantineTransition, SimpleGrid, Transition } from '@mantine/core';
22
import PouchDB from 'pouchdb-browser';
3-
import { useEffect, useState } from 'react';
3+
import { useContext, useEffect, useState } from 'react';
44
import { useParams } from 'react-router-dom';
55
import { CENTER_INDEX } from '../../common/constants';
66
import ShortcutType from '../../common/enums/ShortcutType';
@@ -15,6 +15,7 @@ import Back from './shortcuts/Back';
1515
import Container from './shortcuts/Container';
1616
import Hotkey from './shortcuts/Hotkey';
1717
import Script from './shortcuts/Script';
18+
import ToolSizeContext from '../context/ToolSizeContext';
1819

1920
// prettier-ignore
2021
const TRANSITIONS = [
@@ -29,6 +30,7 @@ export default function StageProvider() {
2930
const { id: stageID } = useParams<{ id?: string }>();
3031
const [shortcuts, setShortcuts] = useState<Shortcut[]>([]);
3132
const [mounted, setMounted] = useState(false);
33+
const { expand } = useContext(ToolSizeContext);
3234

3335
const loadStage = async (id: string) => {
3436
setShortcuts([]);
@@ -52,6 +54,10 @@ export default function StageProvider() {
5254
}, 10);
5355
}, [stageID]);
5456

57+
useEffect(() => {
58+
expand();
59+
}, [expand]); // TODO: continue here
60+
5561
return (
5662
<SimpleGrid cols={3} h="100%" p="xs">
5763
{shortcuts.flatMap((shortcut, index) => {

0 commit comments

Comments
 (0)