Skip to content

Commit

Permalink
refactor is Electron
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun-Murakami committed Oct 5, 2024
1 parent 5d054d7 commit e35b9b8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
14 changes: 9 additions & 5 deletions src/features/homepage/components/MessagePaper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
import { Paper, Typography, Stack, Button, Divider } from '@mui/material';
import { useAppStateStore } from '@/store/appStateStore';

const isElectron = navigator.userAgent.indexOf('Electron') >= 0;
const isElectron = navigator.userAgent.includes('Electron');

export const MessagePaper = () => {
const [currentVersion, setCurrentVersion] = useState('');
Expand All @@ -24,7 +24,7 @@ export const MessagePaper = () => {

// 現在のアプリバージョンを取得
const fetchCurrentVersion = async () => {
// @ts-expect-error ElectronAPI
//@ts-expect-error Electron
const version = await window.electron.getAppVersion();
setCurrentVersion(version);
};
Expand Down Expand Up @@ -72,7 +72,7 @@ export const MessagePaper = () => {

return (
<Stack sx={{ width: '100%', maxWidth: 400, margin: 'auto', marginTop: 4 }}>
{isWeb && (
{isWeb && !isElectron && (
<>
<Paper>
<Typography variant='body2' sx={{ textAlign: 'left', p: 2 }} gutterBottom>
Expand All @@ -96,7 +96,7 @@ export const MessagePaper = () => {
</>
)}
{isElectron && (
<Paper sx={{ maxWidth: 400, margin: 'auto', marginTop: 4 }}>
<Paper sx={{ width: '100%', maxWidth: 400, margin: 'auto', marginTop: 4 }}>
<Typography variant='body2' sx={{ textAlign: 'left', p: 2 }} gutterBottom>
ver{currentVersion}
</Typography>
Expand Down Expand Up @@ -130,7 +130,11 @@ export const MessagePaper = () => {
©{new Date().getFullYear()} Jun Murakami
</a>{' '}
|{' '}
<a href='https://github.com/Jun-Murakami/TaskTrees' target='_blank' rel='noreferrer'>
<a
href={isElectron ? 'https://github.com/Jun-Murakami/TaskTrees-Electron' : 'https://github.com/Jun-Murakami/TaskTrees'}
target='_blank'
rel='noreferrer'
>
GitHub
</a>{' '}
|{' '}
Expand Down
34 changes: 22 additions & 12 deletions src/features/homepage/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type UserComact = {
email: string | null;
};

const isElectron = navigator.userAgent.indexOf('Electron') >= 0;
const isElectron = navigator.userAgent.includes('Electron');

export const useAuth = () => {
const isOffline = useAppStateStore((state) => state.isOffline);
Expand Down Expand Up @@ -137,7 +137,7 @@ export const useAuth = () => {
setSystemMessage(null);
})
.catch((error) => {
setSystemMessage('ログインに失敗しました。Code:100\n\n' + error.code);
setSystemMessage('ログインに失敗しました。Code:99\n\n' + error);
setIsLoading(false);
});
}
Expand Down Expand Up @@ -175,11 +175,16 @@ export const useAuth = () => {
return;
}
} else if (isElectron) {
// @ts-expect-error ElectronAPI
await window.electron.openOAuthURL(`https://${import.meta.env.VITE_AUTH_DOMAIN}/auth/google`).then((credential) => {
handleCredentialLogin(credential);
}).catch((error: FirebaseError) => {
setSystemMessage('Googleログインに失敗しました。Code:102\n\n' + error.code);
//@ts-expect-error Electron
await window.electron.openOAuthURL(`https://${import.meta.env.VITE_AUTH_DOMAIN}/auth/google`).then((credential: OAuthCredential) => {
const googleCredential = GoogleAuthProvider.credential(credential.idToken, credential.accessToken);
handleCredentialLogin(googleCredential);
}).catch((error: Error) => {
if (error.message.includes('closed-by-user')) {
setSystemMessage('Googleログインがキャンセルされました。');
} else {
setSystemMessage('Googleログインに失敗しました。Code:102\n\n' + (error instanceof Error ? error.message : 'Unknown error'));
}
setIsLoading(false);
});
} else {
Expand Down Expand Up @@ -227,11 +232,16 @@ export const useAuth = () => {
return;
}
} else if (isElectron) {
// @ts-expect-error ElectronAPI
await window.electron.openOAuthURL(`https://${import.meta.env.VITE_AUTH_DOMAIN}/auth/apple`).then((credential) => {
handleCredentialLogin(credential);
}).catch((error: FirebaseError) => {
setSystemMessage('Appleログインに失敗しました。Code:107\n\n' + error.code);
//@ts-expect-error Electron
await window.electron.openOAuthURL(`https://${import.meta.env.VITE_AUTH_DOMAIN}/auth/apple`).then((credential: OAuthCredential) => {
const appleCredential = OAuthProvider.credentialFromJSON(credential);
handleCredentialLogin(appleCredential);
}).catch((error: Error) => {
if (error.message.includes('closed-by-user')) {
setSystemMessage('Appleログインがキャンセルされました。');
} else {
setSystemMessage('Appleログインに失敗しました。Code:107\n\n' + (error instanceof Error ? error.message : 'Unknown error'));
}
setIsLoading(false);
});
} else {
Expand Down

0 comments on commit e35b9b8

Please sign in to comment.