File tree Expand file tree Collapse file tree 2 files changed +68
-3
lines changed Expand file tree Collapse file tree 2 files changed +68
-3
lines changed Original file line number Diff line number Diff line change 11import { createPopupMenu } from '../../components/menu'
22import { dialog , ipcMain } from 'electron'
3- import type { ContextMenuPayload , ContextMenuResponse } from '../../types'
3+ import type {
4+ ContextMenuAction ,
5+ ContextMenuPayload ,
6+ ContextMenuResponse
7+ } from '../../types'
48
59export const subscribeToContextMenu = ( ) => {
610 ipcMain . handle < ContextMenuPayload , ContextMenuResponse > (
@@ -41,4 +45,56 @@ export const subscribeToContextMenu = () => {
4145 } )
4246 }
4347 )
48+
49+ ipcMain . handle < ContextMenuPayload , ContextMenuResponse > (
50+ 'context-menu:snippet' ,
51+ async ( ) => {
52+ return new Promise ( resolve => {
53+ let action : ContextMenuAction = 'none'
54+
55+ const menu = createPopupMenu ( [
56+ {
57+ label : 'Add to Favorites' ,
58+ click : ( ) => {
59+ action = 'favorites'
60+ resolve ( {
61+ action,
62+ data : { }
63+ } )
64+ }
65+ } ,
66+ { type : 'separator' } ,
67+ {
68+ label : 'Duplicate' ,
69+ click : ( ) => {
70+ action = 'duplicate'
71+ resolve ( {
72+ action,
73+ data : { }
74+ } )
75+ }
76+ } ,
77+ {
78+ label : 'Delete' ,
79+ click : ( ) => {
80+ action = 'delete'
81+ resolve ( {
82+ action,
83+ data : { }
84+ } )
85+ }
86+ }
87+ ] )
88+
89+ menu . on ( 'menu-will-close' , async ( ) => {
90+ setImmediate ( ( ) => {
91+ resolve ( {
92+ action,
93+ data : { }
94+ } )
95+ } )
96+ } )
97+ } )
98+ }
99+ )
44100}
Original file line number Diff line number Diff line change @@ -2,16 +2,25 @@ import type { AppStore, PreferencesStore } from '../store/module/types'
22import type { DB , Folder , Tag , Snippet } from './db'
33
44type ChannelSubject = 'snippet' | 'snippet-fragment' | 'folder'
5- type ContextMenuAction = 'rename' | 'delete' | 'duplicate'
5+
6+ type ContextMenuAction =
7+ | 'rename'
8+ | 'delete'
9+ | 'duplicate'
10+ | 'favorites'
11+ | 'none'
12+
613type CombineWithChannelSubject <
714 T extends ChannelSubject ,
815 U extends string
916> = `${U } :${T } `
17+
1018export type ContextMenuChannel = CombineWithChannelSubject <
1119ChannelSubject ,
1220'context-menu'
1321>
14- export type Channel = ContextMenuChannel
22+
23+ export type Channel = 'restart' | ContextMenuChannel
1524export interface ContextMenuPayload {
1625 name ?: string
1726}
You can’t perform that action at this time.
0 commit comments