Migrate from window.electron to tauri IPC functions across components
- Replaced `window.electron.invoke` calls with equivalent `tauri` function calls for all IPC interactions. - Removed `electron.d.ts` TypeScript definitions as they are no longer needed. - Updated related logic for offline/online state synchronization. - Added `types.rs` and `shared/mod.rs` modules to support Tauri IPC integration with Rust enums and shared logic. - Refactored IPC request queues to use updated handler names for consistency with Tauri.
This commit is contained in:
@@ -5,6 +5,7 @@ import { SessionContext } from '@/context/SessionContext';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faLock, faShieldAlt, faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons';
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
interface OfflinePinSetupProps {
|
||||
onClose?: () => void;
|
||||
@@ -53,15 +54,13 @@ export default function OfflinePinSetup({ onClose, onSuccess, showOnFirstLogin }
|
||||
setError('');
|
||||
|
||||
try {
|
||||
if (window.electron) {
|
||||
const result = await window.electron.offlinePinSet(pin);
|
||||
const result = await tauri.offlinePinSet(pin);
|
||||
|
||||
if (result.success) {
|
||||
await window.electron.offlineModeSet(true, 30); // 30 days sync interval
|
||||
onSuccess?.();
|
||||
} else {
|
||||
setError(result.error || t('offline.pin.errors.setupFailed'));
|
||||
}
|
||||
if (result.success) {
|
||||
await tauri.offlineModeSet(true, 30);
|
||||
onSuccess?.();
|
||||
} else {
|
||||
setError(result.error || t('offline.pin.errors.setupFailed'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[OfflinePin] Error setting PIN:', error);
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useTranslations } from 'next-intl';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faLock, faWifi, faEye, faEyeSlash, faSignOutAlt } from '@fortawesome/free-solid-svg-icons';
|
||||
import System from '@/lib/models/System';
|
||||
import * as tauri from '@/lib/tauri';
|
||||
|
||||
interface OfflinePinVerifyProps {
|
||||
onSuccess: (userId: string) => void;
|
||||
@@ -29,20 +30,18 @@ export default function OfflinePinVerify({ onSuccess, onCancel }: OfflinePinVeri
|
||||
setError('');
|
||||
|
||||
try {
|
||||
if (window.electron) {
|
||||
const result = await window.electron.offlinePinVerify(pin);
|
||||
const result = await tauri.offlinePinVerify(pin);
|
||||
|
||||
if (result.success && result.userId) {
|
||||
onSuccess(result.userId);
|
||||
if (result.success && result.userId) {
|
||||
onSuccess(result.userId);
|
||||
} else {
|
||||
setAttempts(prev => prev + 1);
|
||||
setPin('');
|
||||
|
||||
if (attempts >= 2) {
|
||||
setError(t('offline.pin.verify.tooManyAttempts'));
|
||||
} else {
|
||||
setAttempts(prev => prev + 1);
|
||||
setPin('');
|
||||
|
||||
if (attempts >= 2) {
|
||||
setError(t('offline.pin.verify.tooManyAttempts'));
|
||||
} else {
|
||||
setError(result.error || t('offline.pin.verify.incorrect'));
|
||||
}
|
||||
setError(result.error || t('offline.pin.verify.incorrect'));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -60,8 +59,8 @@ export default function OfflinePinVerify({ onSuccess, onCancel }: OfflinePinVeri
|
||||
|
||||
const handleLogout = async () => {
|
||||
System.removeCookie("token");
|
||||
await window.electron.removeToken();
|
||||
window.electron.logout();
|
||||
await tauri.removeToken();
|
||||
tauri.logout();
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -8,7 +8,7 @@ import { faWifi, faCircle } from '@fortawesome/free-solid-svg-icons';
|
||||
export default function OfflineToggle() {
|
||||
const { offlineMode, toggleOfflineMode } = useContext(OfflineContext);
|
||||
|
||||
if (!window.electron || !offlineMode.isDatabaseInitialized) {
|
||||
if (!offlineMode.isDatabaseInitialized) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user