diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 9342eca63..27f023c98 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -20,6 +20,8 @@ "notification:allow-show", "notification:allow-request-permission", "notification:allow-permission-state", - "notification:allow-notify" + "notification:allow-notify", + "notification:allow-is-permission-granted", + "notification:default" ] } diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 03991eb2e..de156be20 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -32,6 +32,7 @@ use crate::gpu_miner_adapter::{GpuMinerStatus, GpuNodeSource}; use crate::hardware::hardware_status_monitor::{HardwareStatusMonitor, PublicDeviceProperties}; use crate::internal_wallet::{InternalWallet, PaperWalletConfig}; use crate::node_manager::NodeManagerError; +use crate::notification_manager::NotificationManager; use crate::p2pool::models::{Connections, Stats}; use crate::progress_tracker::ProgressTracker; use crate::tor_adapter::TorConfig; @@ -532,6 +533,7 @@ pub async fn trigger_notification( app: tauri::AppHandle, ) -> Result<(), String> { let timer = Instant::now(); + // NotificationManager::current().trigger_notification(&summary, &body).map_err(|e| e.to_string())?; let notification = app.notification().builder() .title(summary) .body(body) diff --git a/src/containers/main/Dashboard/Dashboard.tsx b/src/containers/main/Dashboard/Dashboard.tsx index 3ceae0fa3..c8947b54b 100644 --- a/src/containers/main/Dashboard/Dashboard.tsx +++ b/src/containers/main/Dashboard/Dashboard.tsx @@ -4,12 +4,6 @@ import { DashboardContentContainer } from './styles'; import { useEffect } from 'react'; export default function Dashboard() { - const { testNotification } = useNotifcations(); - - useEffect(() => { - testNotification(); - }, [testNotification]); - return ( diff --git a/src/containers/main/SideBar/components/MiningButton/MiningButton.tsx b/src/containers/main/SideBar/components/MiningButton/MiningButton.tsx index 4aa174225..ceba1f21f 100644 --- a/src/containers/main/SideBar/components/MiningButton/MiningButton.tsx +++ b/src/containers/main/SideBar/components/MiningButton/MiningButton.tsx @@ -12,6 +12,7 @@ import LoadingSvg from '@app/components/svgs/LoadingSvg.tsx'; import ButtonOrbitAnimation from '../../Miner/components/ButtonOrbitAnimation.tsx'; import { IconWrapper, StyledButton, ButtonWrapper } from './MiningButton.styles.ts'; import { SpinnerIcon } from '@app/components/elements/loaders/SpinnerIcon.tsx'; +import { useNotifcations } from '@app/hooks/useNotifications.ts'; enum MiningButtonStateText { STARTED = 'stop-mining', @@ -19,6 +20,8 @@ enum MiningButtonStateText { } export default function MiningButton() { + const { testNotification } = useNotifcations(); + const { t } = useTranslation('mining-view', { useSuspense: false }); const startMining = useMiningStore((s) => s.startMining); const stopMining = useMiningStore((s) => s.stopMining); @@ -40,6 +43,7 @@ export default function MiningButton() { }, [isMining, isMiningInitiated]); const handleClick = useCallback(async () => { + await testNotification(); if (!isMining) { await startMining(); } else { diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts index e61020e37..d763631c2 100644 --- a/src/hooks/useNotifications.ts +++ b/src/hooks/useNotifications.ts @@ -1,5 +1,6 @@ import { invoke } from '@tauri-apps/api/core'; import { useCallback } from 'react'; +import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/plugin-notification'; export const useNotifcations = () => { const winNotification = useCallback(async (winAmount: string) => { @@ -11,6 +12,21 @@ export const useNotifcations = () => { const testNotification = useCallback(async () => { console.log('testNotification'); + // Do you have permission to send a notification? + let permissionGranted = await isPermissionGranted(); + + console.log('permissionGranted', permissionGranted); + // If not we need to request it + if (!permissionGranted) { + const permission = await requestPermission(); + permissionGranted = permission === 'granted'; + } + + // Once permission has been granted we can send the notification + if (permissionGranted) { + sendNotification({ title: 'Tauri', body: 'Tauri is awesome!' }); + } + await invoke('trigger_notification', { summary: 'Test Notification', body: 'This is a test notification.',