From 87eca555a2d1cc51357d2b6564ce46846d358a05 Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 16 May 2025 14:17:52 +0700 Subject: [PATCH] remove notifi --- src/main/index.ts | 8 +++ src/renderer/src/App.tsx | 55 +++++++-------------- src/renderer/src/components/ConfigModal.tsx | 5 -- src/renderer/src/utils/Notificaton.ts | 27 ---------- 4 files changed, 26 insertions(+), 69 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 67039dc..24a7a7d 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -203,3 +203,11 @@ ipcMain.handle('get-config-file', async () => { return null } }) + +ipcMain.handle('show-window', async () => { + mainWindow?.show() +}) + +ipcMain.handle('hide-window', async () => { + mainWindow?.hide() +}) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index d35e19f..555e6da 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -8,7 +8,6 @@ import { LoadingOverlay, MantineProvider, Skeleton, - Text, Title, Tooltip } from '@mantine/core' @@ -18,18 +17,13 @@ import { Notifications } from '@mantine/notifications' import '@mantine/notifications/styles.css' import { Product } from '@renderer/types/Product' import { IconDotsVertical } from '@tabler/icons-react' -import moment from 'moment' import { Suspense, useCallback, useEffect, useState } from 'react' import { listHotItem } from './api/products' import CardItem from './components/CardItem' import ConfigModal from './components/ConfigModal' import { pusher } from './pusher' import { theme } from './theme' -import { - myNotificationStore, - playNotificationSound, - prependNotification -} from './utils/Notificaton' +import { myNotificationStore, playNotificationSound } from './utils/Notificaton' const PUSHER_CHANNEL = import.meta.env.VITE_PUSHER_CHANNEL const PUSHER_EVENT = 'App\\Events\\MessagePushed' @@ -38,7 +32,7 @@ function App(): React.JSX.Element { const [newItems, setnewItems] = useState>([]) const [hotItem, setHotItem] = useState([]) const [isLoading, setIsLoading] = useState(false) - const [timeout, setTimeout] = useState(2000) + const [timeoutNoti, setTimeoutNoti] = useState(2000) const [opened, { open, close }] = useDisclosure(false) @@ -51,7 +45,7 @@ function App(): React.JSX.Element { return } - setTimeout(data.noti_timeout * 1000) + setTimeoutNoti(data.noti_timeout * 1000) } catch (error) { console.log('%csrc/renderer/src/App.tsx:48 error', 'color: #007acc;', error) } @@ -66,35 +60,22 @@ function App(): React.JSX.Element { if (data.data && data.data?.id) { setnewItems((prev: Array) => [data.data, ...prev]) - // Show notification - prependNotification( - { - title: ( - - {data.data?.title} - - ), - message: ( - - - Price: ${data.data?.price}, - Site: {data.data?.from_site}, - Seller: {data.data?.seller} - - - - {moment(new Date()).format('HH:mm A')} - - - ), - autoClose: isHotItem(data.data) ? false : timeout, - color: 'orange' - }, - () => isHotItem(data.data) - ) - // Play sound effect playNotificationSound() + + window.electron.ipcRenderer.invoke('show-window') + + let timeoutId: NodeJS.Timeout | null = null + + if (timeoutId) { + clearTimeout(timeoutId) + } + + if (isHotItem(data.data)) return + + timeoutId = setTimeout(() => { + window.electron.ipcRenderer.invoke('hide-window') + }, timeoutNoti) } } @@ -105,7 +86,7 @@ function App(): React.JSX.Element { pusher.unsubscribe(PUSHER_CHANNEL) } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [timeout, hotItem]) + }, [timeoutNoti, hotItem]) useEffect(() => { // load timeout config form local diff --git a/src/renderer/src/components/ConfigModal.tsx b/src/renderer/src/components/ConfigModal.tsx index 96afdc5..bacba52 100644 --- a/src/renderer/src/components/ConfigModal.tsx +++ b/src/renderer/src/components/ConfigModal.tsx @@ -41,11 +41,6 @@ export default function ConfigModal(props: IConfigModalProps) { try { const data = await window.electron.ipcRenderer.invoke('get-config-file') - console.log( - '%csrc/renderer/src/components/ConfigModal.tsx:44 data', - 'color: #007acc;', - data - ) if (!data) return form.setValues({ timeout: data?.noti_timeout }) diff --git a/src/renderer/src/utils/Notificaton.ts b/src/renderer/src/utils/Notificaton.ts index 5cd3ec7..85cfe7a 100644 --- a/src/renderer/src/utils/Notificaton.ts +++ b/src/renderer/src/utils/Notificaton.ts @@ -1,30 +1,3 @@ -// /* eslint-disable @typescript-eslint/explicit-function-return-type */ -// import { createNotificationsStore, NotificationData } from '@mantine/notifications' -// import notifySound from '../assets/notifty.mp3' - -// export const myNotificationStore = createNotificationsStore() - -// export function prependNotification(notification: NotificationData, callback?: () => boolean) { -// const id = notification.id ?? crypto.randomUUID() -// myNotificationStore.updateState((current) => { -// const existing = current.notifications.filter((n) => n.id !== id) -// return { -// ...current, -// notifications: [ -// { -// ...notification, -// id -// }, -// ...existing -// ] -// } -// }) -// } - -// export const playNotificationSound = () => { -// const audio = new Audio(notifySound) -// audio.play().catch((e) => console.error('Audio play failed:', e)) -// } /* eslint-disable @typescript-eslint/explicit-function-return-type */ import { createNotificationsStore, NotificationData } from '@mantine/notifications' import notifySound from '../assets/notifty.mp3'