Skip to content

Commit 3116dbb

Browse files
committed
feat: open file with quick look on macos
1 parent 4c26883 commit 3116dbb

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/main/lib/message.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ declare module '@commas/electron-ipc' {
2929
'stop-finding': (type: Parameters<WebContents['stopFindInPage']>[0]) => void,
3030
'read-file': typeof readFile,
3131
'show-file': (file: string) => void,
32+
'preview-file': (file: string) => void,
3233
'add-file': (file: string) => void,
3334
'open-path': (uri: string) => void,
3435
'open-url': (uri: string) => void,
@@ -208,6 +209,11 @@ function handleMessages() {
208209
ipcMain.handle('show-file', (event, file) => {
209210
shell.showItemInFolder(file)
210211
})
212+
ipcMain.handle('preview-file', (event, file) => {
213+
const frame = BrowserWindow.fromWebContents(event.sender)
214+
if (!frame) return
215+
frame.previewFile(file)
216+
})
211217
ipcMain.handle('add-file', async (event, file) => {
212218
const stat = await fs.promises.stat(file)
213219
if (stat.isDirectory()) {

src/renderer/compositions/shell.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,58 @@ export async function confirmClosing() {
6969
return response === 0
7070
}
7171

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+
72117
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+
}
73124
return globalHandler.invoke('global-renderer:open-file', file)
74125
}
75126

0 commit comments

Comments
 (0)