Added openFile example
This commit is contained in:
1 parent
5ab988dab1
commit
f310d94d9f
6 files changed
+58
-13
No files matched your search
+17
-1
@@ -1,4 +1,4 @@
|
||||
import { ipcMain, shell, IpcMainEvent } from 'electron'
|
||||
import { ipcMain, shell, IpcMainEvent, dialog } from 'electron'
|
||||
import Constants from './utils/Constants'
|
||||
|
||||
/*
|
||||
@@ -15,5 +15,21 @@ export default class IPCs {
|
||||
ipcMain.on('msgOpenExternalLink', async (event: IpcMainEvent, url: string) => {
|
||||
await shell.openExternal(url)
|
||||
})
|
||||
|
||||
// Open file
|
||||
ipcMain.handle('msgOpenFile', async (event, filter: string) => {
|
||||
const filters = []
|
||||
if (filter === 'text') {
|
||||
filters.push({ name: 'Text', extensions: ['txt', 'json'] })
|
||||
}
|
||||
if (filter === 'zip') {
|
||||
filters.push({ name: 'Zip', extensions: ['zip'] })
|
||||
}
|
||||
const dialogResult = await dialog.showOpenDialog({
|
||||
properties: ['openFile'],
|
||||
filters
|
||||
})
|
||||
return dialogResult
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user