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 1
1
import { createPopupMenu } from '../../components/menu'
2
2
import { dialog , ipcMain } from 'electron'
3
- import type { ContextMenuPayload , ContextMenuResponse } from '../../types'
3
+ import type {
4
+ ContextMenuAction ,
5
+ ContextMenuPayload ,
6
+ ContextMenuResponse
7
+ } from '../../types'
4
8
5
9
export const subscribeToContextMenu = ( ) => {
6
10
ipcMain . handle < ContextMenuPayload , ContextMenuResponse > (
@@ -41,4 +45,56 @@ export const subscribeToContextMenu = () => {
41
45
} )
42
46
}
43
47
)
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
+ )
44
100
}
Original file line number Diff line number Diff line change @@ -2,16 +2,25 @@ import type { AppStore, PreferencesStore } from '../store/module/types'
2
2
import type { DB , Folder , Tag , Snippet } from './db'
3
3
4
4
type 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
+
6
13
type CombineWithChannelSubject <
7
14
T extends ChannelSubject ,
8
15
U extends string
9
16
> = `${U } :${T } `
17
+
10
18
export type ContextMenuChannel = CombineWithChannelSubject <
11
19
ChannelSubject ,
12
20
'context-menu'
13
21
>
14
- export type Channel = ContextMenuChannel
22
+
23
+ export type Channel = 'restart' | ContextMenuChannel
15
24
export interface ContextMenuPayload {
16
25
name ?: string
17
26
}
You can’t perform that action at this time.
0 commit comments