File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ declare module '@commas/electron-ipc' {
29
29
'stop-finding' : ( type : Parameters < WebContents [ 'stopFindInPage' ] > [ 0 ] ) => void ,
30
30
'read-file' : typeof readFile ,
31
31
'show-file' : ( file : string ) => void ,
32
+ 'preview-file' : ( file : string ) => void ,
32
33
'add-file' : ( file : string ) => void ,
33
34
'open-path' : ( uri : string ) => void ,
34
35
'open-url' : ( uri : string ) => void ,
@@ -208,6 +209,11 @@ function handleMessages() {
208
209
ipcMain . handle ( 'show-file' , ( event , file ) => {
209
210
shell . showItemInFolder ( file )
210
211
} )
212
+ ipcMain . handle ( 'preview-file' , ( event , file ) => {
213
+ const frame = BrowserWindow . fromWebContents ( event . sender )
214
+ if ( ! frame ) return
215
+ frame . previewFile ( file )
216
+ } )
211
217
ipcMain . handle ( 'add-file' , async ( event , file ) => {
212
218
const stat = await fs . promises . stat ( file )
213
219
if ( stat . isDirectory ( ) ) {
Original file line number Diff line number Diff line change @@ -69,7 +69,58 @@ export async function confirmClosing() {
69
69
return response === 0
70
70
}
71
71
72
+ /**
73
+ * {@link https://en.wikipedia.org/wiki/Quick_Look#Supported_file_types_by_default }
74
+ */
75
+ const QUICK_LOOK_EXTENSIONS = [
76
+ '.aac' ,
77
+ '.psd' ,
78
+ '.aiff' ,
79
+ '.icns' ,
80
+ '.avi' ,
81
+ '.bmp' ,
82
+ '.dae' ,
83
+ '.c4d' ,
84
+ '.gif' ,
85
+ // '.html',
86
+ '.ichat' ,
87
+ '.jpg' ,
88
+ '.jpeg' ,
89
+ '.jp2' ,
90
+ '.xls' ,
91
+ '.xlsx' ,
92
+ '.ppt' ,
93
+ '.pptx' ,
94
+ '.doc' ,
95
+ '.docx' ,
96
+ '.midi' ,
97
+ '.mp3' ,
98
+ '.mp4' ,
99
+ '.mpo' ,
100
+ '.pdf' ,
101
+ '.pictureclipping' ,
102
+ '.pict' ,
103
+ '.pct' ,
104
+ '.pic' ,
105
+ '.png' ,
106
+ '.mov' ,
107
+ '.movie' ,
108
+ '.qt' ,
109
+ '.rtf' ,
110
+ // '.svg',
111
+ // '.txt',
112
+ '.textclipping' ,
113
+ '.tiff' ,
114
+ '.wav' ,
115
+ ]
116
+
72
117
export function openFile ( file : string ) {
118
+ if ( process . platform === 'darwin' ) {
119
+ const ext = path . extname ( file ) . toLowerCase ( )
120
+ if ( QUICK_LOOK_EXTENSIONS . includes ( ext ) ) {
121
+ return ipcRenderer . invoke ( 'preview-file' , file )
122
+ }
123
+ }
73
124
return globalHandler . invoke ( 'global-renderer:open-file' , file )
74
125
}
75
126
You can’t perform that action at this time.
0 commit comments