forked from janhq/jan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request janhq#4146 from janhq/fix/app-rerender-issues
fix: app re-render issues caused by bad state handling
- Loading branch information
Showing
13 changed files
with
198 additions
and
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use client' | ||
|
||
import { PropsWithChildren, useCallback, useEffect, useState } from 'react' | ||
|
||
import Loader from '@/containers/Loader' | ||
|
||
import { setupCoreServices } from '@/services/coreService' | ||
import { | ||
isCoreExtensionInstalled, | ||
setupBaseExtensions, | ||
} from '@/services/extensionService' | ||
|
||
import { extensionManager } from '@/extension' | ||
|
||
export const CoreConfigurator = ({ children }: PropsWithChildren) => { | ||
const [setupCore, setSetupCore] = useState(false) | ||
const [activated, setActivated] = useState(false) | ||
const [settingUp, setSettingUp] = useState(false) | ||
|
||
const setupExtensions = useCallback(async () => { | ||
// Register all active extensions | ||
await extensionManager.registerActive() | ||
|
||
setTimeout(async () => { | ||
if (!isCoreExtensionInstalled()) { | ||
setSettingUp(true) | ||
await setupBaseExtensions() | ||
return | ||
} | ||
|
||
extensionManager.load() | ||
setSettingUp(false) | ||
setActivated(true) | ||
}, 500) | ||
}, []) | ||
|
||
// Services Setup | ||
useEffect(() => { | ||
setupCoreServices() | ||
setSetupCore(true) | ||
return () => { | ||
extensionManager.unload() | ||
} | ||
}, []) | ||
|
||
useEffect(() => { | ||
if (setupCore) { | ||
// Electron | ||
if (window && window.core?.api) { | ||
setupExtensions() | ||
} else { | ||
// Host | ||
setActivated(true) | ||
} | ||
} | ||
}, [setupCore, setupExtensions]) | ||
|
||
return ( | ||
<> | ||
{settingUp && <Loader description="Preparing Update..." />} | ||
{setupCore && activated && <>{children}</>} | ||
</> | ||
) | ||
} |
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
Oops, something went wrong.