dialog.showOpenDialogSync()
๐ก Electron ํ๋ ์์ํฌ์์ ์ ๊ณต๋๋ ๋ฉ์๋
- ์ฌ์ฉ์์๊ฒ ํ์ผ ์ ํ ๋ํ ์์๋ฅผ ํ์ํ๊ณ ํ์ผ์ ์ ํํ ์ ์์
- ์ฃผ๋ก ๋ฉ์ธ ํ๋ก์ธ์ค์์ ์ฌ์ฉ
์ฌ์ฉ ์์
const { dialog } = require('electron');
// ํ์ผ ์ ํ ๋ํ ์์ ์ต์
์ค์
const options = {
title: 'Open File', // ๋ํ ์์ ์ ๋ชฉ
defaultPath: '/path/to/default', // ๊ธฐ๋ณธ ๊ฒฝ๋ก
buttonLabel: 'Open', // ํ์ธ ๋ฒํผ ๋ ์ด๋ธ
filters: [
{ name: 'Text Files', extensions: ['txt'] }, // ํ์ผ ํํฐ
{ name: 'All Files', extensions: ['*'] }
],
properties: ['openFile'] // ์ด๊ธฐ ๊ฐ๋ฅํ ํ์ผ ์ ํ
};
// ํ์ผ ์ ํ ๋ํ ์์ ํ์
dialog.showOpenDialog(options)
.then(result => {
console.log(result.filePaths);
})
.catch(err => {
console.error(err);
});
- showOpenDialog()์ ์ฌ์ฉํ๋ฉด ๋ ๋๋ฌ ํ๋ก์ธ์ค์์ ๋น๋๊ธฐ์ ์ผ๋ก ํ์ผ ์ ํ ๋ํ ์์๋ฅผ ํ์ํ ์ ์์.
- ๋ฉ์ธ ํ๋ก์ธ์ค์์ ํต์ ์ ์ํด IPC(Inter-Process Communication)๋ฅผ ์ฌ์ฉํ ํ์๊ฐ ์์.
- ์ฌ์ฉ์๋ก๋ถํฐ ํ์ผ์ ์ ํํ๊ณ , ์ ํํ ํ์ผ์ ๊ฒฝ๋ก๋ฅผ Promise์ ๊ฒฐ๊ณผ๋ก ์ป์ ์ ์์.
'Development > Electron' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Electron] SyntaxError: Cannot use import statement outside a module (0) | 2023.06.17 |
---|---|
[Electron] ipcRenderer.invoke & ipcMin.handle (0) | 2023.06.15 |
[Electron] electron ์์ด์ฝ ๋ฃ๊ธฐ (0) | 2023.01.25 |
[Electron] Electron + React ์ฐ๋ํ๊ธฐ (0) | 2023.01.13 |
[Electron]Electron-forge (0) | 2023.01.12 |
๋๊ธ