Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Misieq01 committed Dec 12, 2024
1 parent db89d6a commit 18abb60
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
2 changes: 2 additions & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions src/containers/main/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import { DashboardContentContainer } from './styles';
import { useEffect } from 'react';

Check warning on line 4 in src/containers/main/Dashboard/Dashboard.tsx

View workflow job for this annotation

GitHub Actions / Run linters

'useEffect' is defined but never used. Allowed unused vars must match /^_/u

export default function Dashboard() {
const { testNotification } = useNotifcations();

useEffect(() => {
testNotification();
}, [testNotification]);

return (
<DashboardContentContainer layout>
<MiningView />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ 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',
START = 'start-mining',
}

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);
Expand All @@ -40,6 +43,7 @@ export default function MiningButton() {
}, [isMining, isMiningInitiated]);

const handleClick = useCallback(async () => {
await testNotification();
if (!isMining) {
await startMining();
} else {
Expand Down
16 changes: 16 additions & 0 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { invoke } from '@tauri-apps/api/core';
import { useCallback } from 'react';
import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/plugin-notification';

Check failure on line 3 in src/hooks/useNotifications.ts

View workflow job for this annotation

GitHub Actions / tauri-build

Cannot find module '@tauri-apps/plugin-notification' or its corresponding type declarations.

export const useNotifcations = () => {
const winNotification = useCallback(async (winAmount: string) => {
Expand All @@ -11,6 +12,21 @@ export const useNotifcations = () => {

const testNotification = useCallback(async () => {
console.log('testNotification');

Check warning on line 14 in src/hooks/useNotifications.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected console statement
// Do you have permission to send a notification?
let permissionGranted = await isPermissionGranted();

console.log('permissionGranted', permissionGranted);

Check warning on line 18 in src/hooks/useNotifications.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected console statement
// 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.',
Expand Down

0 comments on commit 18abb60

Please sign in to comment.