-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James
committed
May 9, 2024
1 parent
0406b51
commit 0888839
Showing
10 changed files
with
189 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
import { app } from 'electron' | ||
|
||
export const setupReactDevTool = async () => { | ||
if (!app.isPackaged) { | ||
// Which means you're running from source code | ||
const { default: installExtension, REACT_DEVELOPER_TOOLS } = await import( | ||
'electron-devtools-installer' | ||
) // Don't use import on top level, since the installer package is dev-only | ||
try { | ||
const name = await installExtension(REACT_DEVELOPER_TOOLS) | ||
console.debug(`Added Extension: ${name}`) | ||
} catch (err) { | ||
console.error('An error occurred while installing devtools:', err) | ||
// Only log the error and don't throw it because it's not critical | ||
} | ||
// Which means you're running from source code | ||
const { default: installExtension, REACT_DEVELOPER_TOOLS } = await import( | ||
'electron-devtools-installer' | ||
) // Don't use import on top level, since the installer package is dev-only | ||
try { | ||
const name = await installExtension(REACT_DEVELOPER_TOOLS) | ||
console.debug(`Added Extension: ${name}`) | ||
} catch (err) { | ||
console.error('An error occurred while installing devtools:', err) | ||
// Only log the error and don't throw it because it's not critical | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Modal, ModalContent, ModalHeader, ModalTitle } from '@janhq/uikit' | ||
import { atom, useAtomValue } from 'jotai' | ||
|
||
export type LoadingInfo = { | ||
title: string | ||
message: string | ||
} | ||
|
||
export const loadingModalVisibilityAtom = atom<LoadingInfo | undefined>( | ||
undefined | ||
) | ||
|
||
const ResettingModal: React.FC = () => { | ||
const loadingInfo = useAtomValue(loadingModalVisibilityAtom) | ||
|
||
return ( | ||
<Modal open={loadingInfo != null}> | ||
<ModalContent> | ||
<ModalHeader> | ||
<ModalTitle>{loadingInfo?.title}</ModalTitle> | ||
</ModalHeader> | ||
<p className="text-muted-foreground">{loadingInfo?.message}</p> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default ResettingModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Fragment, ReactNode } from 'react' | ||
|
||
import { useSetAtom } from 'jotai' | ||
|
||
import { useDebouncedCallback } from 'use-debounce' | ||
|
||
import { useGetHFRepoData } from '@/hooks/useGetHFRepoData' | ||
|
||
import { loadingModalVisibilityAtom as loadingModalInfoAtom } from '../LoadingModal' | ||
import { toaster } from '../Toast' | ||
|
||
import { | ||
importHuggingFaceModelStageAtom, | ||
importingHuggingFaceRepoDataAtom, | ||
} from '@/helpers/atoms/HuggingFace.atom' | ||
type Props = { | ||
children: ReactNode | ||
} | ||
|
||
const DeepLinkListener: React.FC<Props> = ({ children }) => { | ||
const { getHfRepoData } = useGetHFRepoData() | ||
const setLoadingInfo = useSetAtom(loadingModalInfoAtom) | ||
const setImportingHuggingFaceRepoData = useSetAtom( | ||
importingHuggingFaceRepoDataAtom | ||
) | ||
const setImportHuggingFaceModelStage = useSetAtom( | ||
importHuggingFaceModelStageAtom | ||
) | ||
|
||
const debounced = useDebouncedCallback(async (searchText) => { | ||
if (searchText.indexOf('/') === -1) { | ||
toaster({ | ||
title: 'Failed to get Hugging Face models', | ||
description: 'Invalid Hugging Face model URL', | ||
type: 'error', | ||
}) | ||
return | ||
} | ||
|
||
try { | ||
setLoadingInfo({ | ||
title: 'Getting Hugging Face models', | ||
message: 'Please wait..', | ||
}) | ||
const data = await getHfRepoData(searchText) | ||
setImportingHuggingFaceRepoData(data) | ||
setImportHuggingFaceModelStage('REPO_DETAIL') | ||
setLoadingInfo(undefined) | ||
} catch (err) { | ||
setLoadingInfo(undefined) | ||
let errMessage = 'Unexpected Error' | ||
if (err instanceof Error) { | ||
errMessage = err.message | ||
} | ||
toaster({ | ||
title: 'Failed to get Hugging Face models', | ||
description: errMessage, | ||
type: 'error', | ||
}) | ||
console.error(err) | ||
} | ||
}, 300) | ||
window.electronAPI?.onDeepLink((_event: string, input: string) => { | ||
window.core?.api?.ackDeepLink() | ||
const url = input.replaceAll('jan://', '') | ||
debounced(url) | ||
}) | ||
|
||
return <Fragment>{children}</Fragment> | ||
} | ||
|
||
export default DeepLinkListener |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters