Skip to content

Commit

Permalink
make sub windows child window. add cancel button.
Browse files Browse the repository at this point in the history
  • Loading branch information
mintnick committed Jan 12, 2023
1 parent 8904cd9 commit 24cd89b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
24 changes: 13 additions & 11 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ function createWindow () {
// bounds.
win = new BrowserWindow(options)

// win.setResizable(false);

win.webContents.openDevTools()
win.setResizable(false);
// win.webContents.openDevTools()

win.loadFile('./src/views/index.html')

Expand All @@ -54,6 +53,7 @@ app.whenReady().then(() => {
await win.reload()
await overwrite(args)
})
ipcMain.on('cancelSelected', () => { selectWin.close() })

createWindow()

Expand Down Expand Up @@ -93,7 +93,7 @@ async function openDescriptionDialog(args) {
"ok": locale.buttons.confirm,
"cancel": locale.buttons.cancel
}
})
}, win)

return description
}
Expand All @@ -112,28 +112,30 @@ function openNotificationWindow() {

async function openSelectWindow(args) {
const mainWinBounds = win.getBounds()
const savedBounds = AppConfig.readSettings('selectWinBounds')
// const savedBounds = AppConfig.readSettings('selectWinBounds')
const bounds = {
...savedBounds,
// ...savedBounds,
width: 500,
height: 480,
height: 500,
x: mainWinBounds.x + 100,
y: mainWinBounds.y + 100,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false,
},
parent: win,
modal: true
}
selectWin = new BrowserWindow(bounds)
win.setResizable(false);
// selectWin.webContents.openDevTools()

// save position when close
selectWin.on('close', () => {
const selectWinBounds = selectWin.getBounds();
AppConfig.saveSettings('selectWinBounds', selectWinBounds)
})
// selectWin.on('close', () => {
// const selectWinBounds = selectWin.getBounds();
// AppConfig.saveSettings('selectWinBounds', selectWinBounds)
// })

await selectWin.loadFile('./src/views/select.html')
selectWin.webContents.send('loadSelect', args)
Expand Down
3 changes: 2 additions & 1 deletion src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ window.electronAPI = {
openSelectWindow: (args) => ipcRenderer.send('dialog:SelectTargets', args),
// onLoadSelect: (args) => ipcRenderer.on('loadSelect', args)
// closeSelectWindow: () => ipcRenderer.send('dialog:CloseSelect'),
returnSelected: (args) => ipcRenderer.send('returnSelected', args)
returnSelected: (args) => ipcRenderer.send('returnSelected', args),
cancelSelected: () => ipcRenderer.send('cancelSelected')
}
13 changes: 12 additions & 1 deletion src/views/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
<div class="w-100">
<h1 id="select-title">Title</h1>
<select id="target-select" class="form-select w-100 mb-3" size="20" multiple></select>
<button id="confirm-btn" type="button" class="btn btn-success w-50">overwrite accounts</button> </div>
<div class="d-flex justify-content-around">
<button id="confirm-btn" type="button" class="btn btn-success w-25">overwrite accounts</button>
<button id="cancel-btn" type="button" class="btn btn-outline-warning w-25">cancel</button>
</div>
</div>
</body>
</html>

Expand All @@ -38,8 +42,10 @@ <h1 id="select-title">Title</h1>
const selectTitle = $('#select-title')
const select = $('#target-select')
const confirmBtn = $('#confirm-btn')
const cancelBtn = $('#cancel-btn')
confirmBtn.text(locale.buttons.confirm)
selectTitle.text(locale.titles.selectOverwriteTargets)
cancelBtn.text(locale.buttons.cancel)
ipcRenderer.on('loadSelect', (event, args) => {
localArgs = args
const options = args.targets
Expand All @@ -58,4 +64,9 @@ <h1 id="select-title">Title</h1>
localArgs.targets = selected
window.electronAPI.returnSelected(localArgs)
})

cancelBtn.on('click', (e) => {
e.preventDefault()
window.electronAPI.cancelSelected()
})
</script>

0 comments on commit 24cd89b

Please sign in to comment.