mobile update

This commit is contained in:
arrelin
2026-03-10 13:54:27 +03:00
parent 6f679a5066
commit d7802cf584
76 changed files with 1503 additions and 10 deletions

View File

@@ -9,6 +9,9 @@
"version": "0.0.0",
"dependencies": {
"@tailwindcss/postcss": "^4.1.18",
"@tauri-apps/api": "^2.10.1",
"@tauri-apps/plugin-deep-link": "^2.4.7",
"@tauri-apps/plugin-shell": "^2.3.5",
"axios": "^1.13.2",
"i18next": "^25.8.0",
"i18next-browser-languagedetector": "^8.2.0",
@@ -1608,6 +1611,34 @@
"tailwindcss": "4.1.18"
}
},
"node_modules/@tauri-apps/api": {
"version": "2.10.1",
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.10.1.tgz",
"integrity": "sha512-hKL/jWf293UDSUN09rR69hrToyIXBb8CjGaWC7gfinvnQrBVvnLr08FeFi38gxtugAVyVcTa5/FD/Xnkb1siBw==",
"license": "Apache-2.0 OR MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/tauri"
}
},
"node_modules/@tauri-apps/plugin-deep-link": {
"version": "2.4.7",
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-deep-link/-/plugin-deep-link-2.4.7.tgz",
"integrity": "sha512-K0FQlLM6BoV7Ws2xfkh+Tnwi5VZVdkI4Vw/3AGLSf0Xvu2y86AMBzd9w/SpzKhw9ai2B6ES8di/OoGDCExkOzg==",
"license": "MIT OR Apache-2.0",
"dependencies": {
"@tauri-apps/api": "^2.10.1"
}
},
"node_modules/@tauri-apps/plugin-shell": {
"version": "2.3.5",
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-shell/-/plugin-shell-2.3.5.tgz",
"integrity": "sha512-jewtULhiQ7lI7+owCKAjc8tYLJr92U16bPOeAa472LHJdgaibLP83NcfAF2e+wkEcA53FxKQAZ7byDzs2eeizg==",
"license": "MIT OR Apache-2.0",
"dependencies": {
"@tauri-apps/api": "^2.10.1"
}
},
"node_modules/@types/babel__core": {
"version": "7.20.5",
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",

View File

@@ -11,6 +11,9 @@
},
"dependencies": {
"@tailwindcss/postcss": "^4.1.18",
"@tauri-apps/api": "^2.10.1",
"@tauri-apps/plugin-deep-link": "^2.4.7",
"@tauri-apps/plugin-shell": "^2.3.5",
"axios": "^1.13.2",
"i18next": "^25.8.0",
"i18next-browser-languagedetector": "^8.2.0",

View File

@@ -46,10 +46,16 @@ export const authApi = {
me: () =>
apiClient.get<User>('/me'),
getGoogleAuthUrl: (redirectUrl?: string) =>
getGoogleAuthUrl: (redirectUrl?: string, mobile?: boolean) =>
apiClient.get<OAuthUrlResponse>('/auth/google', {
params: redirectUrl ? { redirect_url: redirectUrl } : undefined,
params: {
...(redirectUrl ? { redirect_url: redirectUrl } : {}),
...(mobile ? { mobile: true } : {}),
},
}),
mobileCallback: (token: string) =>
apiClient.get('/auth/mobile-callback', { params: { token } }),
};
export const familyApi = {

View File

@@ -1,18 +1,62 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { authApi } from '../api/client';
import { useStore } from '../store/useStore';
import { Loader2, Wallet } from 'lucide-react';
import { FcGoogle } from 'react-icons/fc';
const isTauriEnv = () => typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
const DEEP_LINK_SCHEME = 'com.arrelin.family-budget-android://auth';
export default function Login() {
const { t } = useTranslation();
const { setUser } = useStore();
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
useEffect(() => {
if (!isTauriEnv()) return;
let unlisten: (() => void) | null = null;
const setupDeepLink = async () => {
const { onOpenUrl } = await import('@tauri-apps/plugin-deep-link');
unlisten = await onOpenUrl(async (urls) => {
const url = Array.isArray(urls) ? urls[0] : urls;
if (!url.startsWith(DEEP_LINK_SCHEME)) return;
const token = new URL(url).searchParams.get('token');
if (!token) return;
try {
setLoading(true);
await authApi.mobileCallback(token);
const me = await authApi.me();
setUser(me.data);
} catch {
setError(t('login.authError'));
setLoading(false);
}
});
};
setupDeepLink();
return () => { unlisten?.(); };
}, []);
const handleGoogleLogin = async () => {
try {
setLoading(true);
setError('');
if (isTauriEnv()) {
const { open } = await import('@tauri-apps/plugin-shell');
const response = await authApi.getGoogleAuthUrl(undefined, true);
await open(response.data.url);
return;
}
const currentUrl = window.location.origin;
const response = await authApi.getGoogleAuthUrl(currentUrl);
window.location.href = response.data.url;

View File

@@ -5,6 +5,7 @@ export default defineConfig({
plugins: [react()],
server: {
port: 5173,
host: process.env.TAURI_DEV_HOST || 'localhost',
proxy: {
'/api': {
target: 'http://localhost:8080',