From 3ffc0746f37d70f4c4f03490ffb8b691947dd34d Mon Sep 17 00:00:00 2001 From: an-lee Date: Fri, 2 Feb 2024 12:46:40 +0800 Subject: [PATCH] Fix: cannot login in Windows (#248) * fix view-load failed in windows * refactor --- enjoy/src/renderer/components/login-form.tsx | 56 ++++++++------------ 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/enjoy/src/renderer/components/login-form.tsx b/enjoy/src/renderer/components/login-form.tsx index a140eb0a..41f365ec 100644 --- a/enjoy/src/renderer/components/login-form.tsx +++ b/enjoy/src/renderer/components/login-form.tsx @@ -23,27 +23,13 @@ export const LoginForm = () => { const { EnjoyApp, login, webApi, user } = useContext( AppSettingsProviderContext ); - const [webviewVisible, setWebviewVisible] = useState(false); + const [webviewUrl, setWebviewUrl] = useState(); const containerRef = useRef(null); const handleLogin = (provider: "mixin" | "github") => { const url = `${webApi.baseUrl}/sessions/new?provider=${provider}`; - setWebviewVisible(true); - - const rect = containerRef.current.getBoundingClientRect(); - EnjoyApp.view.load( - url, - { - x: rect.x, - y: rect.y, - width: rect.width, - height: rect.height, - }, - { - navigatable: true, - } - ); + setWebviewUrl(url); }; const onViewState = (event: { @@ -56,7 +42,7 @@ export const LoginForm = () => { if (error) { toast.error(error); - setWebviewVisible(false); + setWebviewUrl(null); return; } @@ -80,34 +66,36 @@ export const LoginForm = () => { toast.error(err.message); }) .finally(() => { - setWebviewVisible(false); + setWebviewUrl(null); }); } } }; useEffect(() => { - if (!webviewVisible) return; + if (!webviewUrl) return; EnjoyApp.view.onViewState((_event, state) => onViewState(state)); + const rect = containerRef.current.getBoundingClientRect(); + EnjoyApp.view.load( + webviewUrl, + { + x: Math.round(rect.x), + y: Math.round(rect.y), + width: Math.round(rect.width), + height: Math.round(rect.height), + }, + { + navigatable: true, + } + ); + return () => { EnjoyApp.view.removeViewStateListeners(); EnjoyApp.view.remove(); }; - }, [webApi, webviewVisible]); - - useEffect(() => { - if (!webviewVisible) return; - - const rect = containerRef.current.getBoundingClientRect(); - EnjoyApp.view.show({ - x: rect.x, - y: rect.y, - width: rect.width, - height: rect.height, - }); - }, [webviewVisible]); + }, [webApi, webviewUrl]); if (user) { return ( @@ -175,11 +163,11 @@ export const LoginForm = () => {
-