Skip to content

Commit 7b14836

Browse files
committed
feat: check specific default path platform dependant
1 parent 1995815 commit 7b14836

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

frontend/src/components/WelcomeScreen.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
import { FolderOpen, Search } from 'lucide-react';
25-
import { useState } from 'react';
25+
import { useEffect, useState } from 'react';
2626

2727
import { withErrorHandling } from '@/lib/errors';
2828
import useConfigStore from '@/stores/useConfigStore';
@@ -72,9 +72,15 @@ export default function WelcomeScreen() {
7272
const handleCloseScanModal = () => setScanModal(false);
7373
const handleShowScanModal = () => setScanModal(true);
7474

75-
EventsOn(entities.Action.ScanWithOptions, () => {
76-
handleShowScanModal();
77-
});
75+
useEffect(() => {
76+
const unsubScanWithOptions = EventsOn(entities.Action.ScanWithOptions, () => {
77+
handleShowScanModal();
78+
});
79+
80+
return () => {
81+
unsubScanWithOptions();
82+
};
83+
}, []);
7884

7985
return (
8086
<div className="flex h-screen w-screen flex-col items-center justify-center space-y-8 p-8">

frontend/src/lib/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,14 @@ export function truncatePath(path: string, maxLength: number = 30) {
4848
const last = parts[parts.length - 1];
4949
return `${first}/.../${last}`;
5050
}
51+
52+
export const isDefaultPath = (path: string, platform: string | undefined) => {
53+
switch (platform) {
54+
case 'darwin':
55+
return path === '/' || path === '/Users';
56+
case 'windows':
57+
return path === 'C:\\' || path === '';
58+
default:
59+
return path === '/' || path === '/home';
60+
}
61+
};

frontend/src/routes/root.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* SOFTWARE.
2222
*/
2323

24-
import { useState } from 'react';
24+
import { useEffect, useState } from 'react';
2525
import { Outlet } from 'react-router-dom';
2626

2727
import KeyboardShortcutsDialog from '@/components/KeyboardShortcutsDialog';
@@ -30,12 +30,15 @@ import Sidebar from '@/components/Sidebar';
3030
import StatusBar from '@/components/StatusBar';
3131
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from '@/components/ui/resizable';
3232
import WelcomeScreen from '@/components/WelcomeScreen';
33+
import useEnvironment from '@/hooks/useEnvironment';
34+
import { isDefaultPath } from '@/lib/utils';
3335
import useConfigStore from '@/stores/useConfigStore';
3436

3537
import { entities } from '../../wailsjs/go/models';
3638
import { EventsOn } from '../../wailsjs/runtime/runtime';
3739

3840
export default function Root() {
41+
const { environment } = useEnvironment();
3942
const scanRoot = useConfigStore((state) => state.scanRoot);
4043
const [showKeyboardShortcuts, setShowKeyboardShortcuts] = useState(false);
4144
const [scanModal, setScanModal] = useState(false);
@@ -47,14 +50,21 @@ export default function Root() {
4750
setScanModal(true);
4851
};
4952

50-
EventsOn(entities.Action.ShowKeyboardShortcutsModal, () => {
51-
setShowKeyboardShortcuts(true);
52-
});
53-
EventsOn(entities.Action.ScanWithOptions, () => {
54-
handleShowScanModal();
55-
});
53+
useEffect(() => {
54+
const unsubShowKeyboardShortcuts = EventsOn(entities.Action.ShowKeyboardShortcutsModal, () => {
55+
setShowKeyboardShortcuts(true);
56+
});
57+
const unsubScanWithOptions = EventsOn(entities.Action.ScanWithOptions, () => {
58+
handleShowScanModal();
59+
});
5660

57-
if (scanRoot === '/') {
61+
return () => {
62+
unsubShowKeyboardShortcuts();
63+
unsubScanWithOptions();
64+
};
65+
}, []);
66+
67+
if (isDefaultPath(scanRoot, environment?.platform)) {
5868
return <WelcomeScreen />;
5969
}
6070

0 commit comments

Comments
 (0)