File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { subscribeToContextMenu } from './context-menu'
2+ import { subscribeToNotification } from './notifications'
23
34export const subscribeToChannels = ( ) => {
45 subscribeToContextMenu ( )
6+ subscribeToNotification ( )
57}
Original file line number Diff line number Diff line change 1+ import type { NotificationPayload } from '../../types'
2+ import { ipcMain , Notification } from 'electron'
3+
4+ export const subscribeToNotification = ( ) => {
5+ if ( ! Notification . isSupported ( ) ) return
6+
7+ ipcMain . handle < NotificationPayload > ( 'notification' , ( event , payload ) => {
8+ return new Promise ( resolve => {
9+ const { body } = payload
10+ const notification = new Notification ( {
11+ title : 'massCode' ,
12+ body
13+ } )
14+ notification . show ( )
15+ resolve ( )
16+ } )
17+ } )
18+ }
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ ChannelSubject,
2525'context-menu'
2626>
2727
28- export type Channel = 'restart' | ContextMenuChannel
28+ export type Channel = 'restart' | 'notification' | ContextMenuChannel
2929export interface ContextMenuPayload {
3030 name ?: string
3131 type : ContextMenuType
@@ -39,6 +39,10 @@ export interface ContextMenuResponse {
3939 data : any
4040}
4141
42+ export interface NotificationPayload {
43+ body : string
44+ }
45+
4246interface EventCallback {
4347 ( event ?: IpcRendererEvent , ...args : any [ ] ) : void
4448}
@@ -59,7 +63,7 @@ interface StoreProperties<T> {
5963
6064export interface ElectronBridge {
6165 ipc : {
62- invoke < T , U > ( channel : Channel , payload : U ) : Promise < T >
66+ invoke < T , U = any > ( channel : Channel , payload : U ) : Promise < T >
6367 on ( channel : Channel , cb : EventCallback ) : void
6468 once ( channel : Channel , cb : EventCallback ) : void
6569 }
Original file line number Diff line number Diff line change 1- import type {
2- ContextMenuChannel ,
3- ContextMenuPayload ,
4- ElectronBridge ,
5- Channel
6- } from '.'
1+ import type { ElectronBridge , Channel } from '.'
72
8- // TODO: почему то нет автокомплита для ContextMenuPayload
93declare global {
104 interface Window {
115 electron : ElectronBridge
126 }
137
148 namespace Electron {
159 interface IpcMain {
16- handle < T , U > (
10+ handle < T , U = void > (
1711 channel : Channel ,
1812 listener : ( event : IpcMainInvokeEvent , payload : T ) => Promise < U >
1913 ) : void
You can’t perform that action at this time.
0 commit comments