Skip to content

Commit 345a7b3

Browse files
authored
Merge pull request #145 from arduino/bugfix/windows-focus
Bugfix Windows missing cursor on editor
2 parents 20fcc7a + c5e69e8 commit 345a7b3

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

backend/ipc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
getAllFiles
77
} = require('./helpers.js')
88

9-
module.exports = function registerIPCHandlers(win, ipcMain, app) {
9+
module.exports = function registerIPCHandlers(win, ipcMain, app, dialog) {
1010
ipcMain.handle('open-folder', async (event) => {
1111
console.log('ipcMain', 'open-folder')
1212
const folder = await openFolderDialog(win)
@@ -123,6 +123,12 @@ module.exports = function registerIPCHandlers(win, ipcMain, app) {
123123
return app.getAppPath()
124124
})
125125

126+
ipcMain.handle('open-dialog', (event, opt) => {
127+
console.log('ipcMain', 'open-dialog', opt)
128+
const response = dialog.showMessageBoxSync(win, opt)
129+
return response != opt.cancelId
130+
})
131+
126132
win.on('close', (event) => {
127133
console.log('BrowserWindow', 'close')
128134
event.preventDefault()

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { app, BrowserWindow, ipcMain } = require('electron')
1+
const { app, BrowserWindow, ipcMain, dialog } = require('electron')
22
const path = require('path')
33
const fs = require('fs')
44

@@ -49,7 +49,7 @@ function createWindow () {
4949
win.show()
5050
})
5151

52-
registerIPCHandlers(win, ipcMain, app)
52+
registerIPCHandlers(win, ipcMain, app, dialog)
5353
registerMenu(win)
5454

5555
app.on('activate', () => {

preload.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ const Window = {
157157
},
158158
beforeClose: (callback) => ipcRenderer.on('check-before-close', callback),
159159
confirmClose: () => ipcRenderer.invoke('confirm-close'),
160-
isPackaged: () => ipcRenderer.invoke('is-packaged')
160+
isPackaged: () => ipcRenderer.invoke('is-packaged'),
161+
openDialog: (opt) => ipcRenderer.invoke('open-dialog', opt)
161162
}
162163

163164

ui/arduino/store.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ const newFileContent = `# This program was created in Arduino Lab for MicroPytho
88
print('Hello, MicroPython!')
99
`
1010

11+
async function confirm(msg, cancelMsg, confirmMsg) {
12+
cancelMsg = cancelMsg || 'Cancel'
13+
confirmMsg = confirmMsg || 'Yes'
14+
let response = await win.openDialog({
15+
type: 'question',
16+
buttons: [cancelMsg, confirmMsg],
17+
cancelId: 0,
18+
message: msg
19+
})
20+
console.log('confirm', response)
21+
return Promise.resolve(response)
22+
}
23+
1124
async function store(state, emitter) {
1225
win.setWindowSize(720, 640)
1326

@@ -313,7 +326,7 @@ async function store(state, emitter) {
313326
}
314327

315328
if (willOverwrite) {
316-
const confirmation = confirm(`You are about to overwrite the file ${openFile.fileName} on your ${openFile.source}.\n\n Are you sure you want to proceed?`, 'Cancel', 'Yes')
329+
const confirmation = await confirm(`You are about to overwrite the file ${openFile.fileName} on your ${openFile.source}.\n\n Are you sure you want to proceed?`, 'Cancel', 'Yes')
317330
if (!confirmation) {
318331
state.isSaving = false
319332
openFile.parentFolder = oldParentFolder
@@ -366,11 +379,11 @@ async function store(state, emitter) {
366379
state.editingFile = id
367380
emitter.emit('render')
368381
})
369-
emitter.on('close-tab', (id) => {
382+
emitter.on('close-tab', async (id) => {
370383
log('close-tab', id)
371384
const currentTab = state.openFiles.find(f => f.id === id)
372385
if (currentTab.hasChanges) {
373-
let response = confirm("Your file has unsaved changes. Are you sure you want to proceed?")
386+
let response = await confirm("Your file has unsaved changes. Are you sure you want to proceed?")
374387
if (!response) return false
375388
}
376389
state.openFiles = state.openFiles.filter(f => f.id !== id)
@@ -474,7 +487,7 @@ async function store(state, emitter) {
474487
fileName: value
475488
})
476489
if (willOverwrite) {
477-
const confirmAction = confirm(`You are about to overwrite the file ${value} on your board.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
490+
const confirmAction = await confirm(`You are about to overwrite the file ${value} on your board.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
478491
if (!confirmAction) {
479492
state.creatingFile = null
480493
emitter.emit('render')
@@ -497,7 +510,7 @@ async function store(state, emitter) {
497510
fileName: value
498511
})
499512
if (willOverwrite) {
500-
const confirmAction = confirm(`You are about to overwrite the file ${value} on your disk.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
513+
const confirmAction = await confirm(`You are about to overwrite the file ${value} on your disk.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
501514
if (!confirmAction) {
502515
state.creatingFile = null
503516
emitter.emit('render')
@@ -545,7 +558,7 @@ async function store(state, emitter) {
545558
fileName: value
546559
})
547560
if (willOverwrite) {
548-
const confirmAction = confirm(`You are about to overwrite ${value} on your board.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
561+
const confirmAction = await confirm(`You are about to overwrite ${value} on your board.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
549562
if (!confirmAction) {
550563
state.creatingFolder = null
551564
emitter.emit('render')
@@ -574,7 +587,7 @@ async function store(state, emitter) {
574587
fileName: value
575588
})
576589
if (willOverwrite) {
577-
const confirmAction = confirm(`You are about to overwrite ${value} on your disk.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
590+
const confirmAction = await confirm(`You are about to overwrite ${value} on your disk.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
578591
if (!confirmAction) {
579592
state.creatingFolder = null
580593
emitter.emit('render')
@@ -631,7 +644,7 @@ async function store(state, emitter) {
631644
}
632645

633646
message += `Are you sure you want to proceed?`
634-
const confirmAction = confirm(message, 'Cancel', 'Yes')
647+
const confirmAction = await confirm(message, 'Cancel', 'Yes')
635648
if (!confirmAction) {
636649
state.isRemoving = false
637650
emitter.emit('render')
@@ -719,7 +732,7 @@ async function store(state, emitter) {
719732
let message = `You are about to overwrite the following file/folder on your board:\n\n`
720733
message += `${value}\n\n`
721734
message += `Are you sure you want to proceed?`
722-
const confirmAction = confirm(message, 'Cancel', 'Yes')
735+
const confirmAction = await confirm(message, 'Cancel', 'Yes')
723736
if (!confirmAction) {
724737
state.isSaving = false
725738
state.renamingFile = null
@@ -758,7 +771,7 @@ async function store(state, emitter) {
758771
let message = `You are about to overwrite the following file/folder on your disk:\n\n`
759772
message += `${value}\n\n`
760773
message += `Are you sure you want to proceed?`
761-
const confirmAction = confirm(message, 'Cancel', 'Yes')
774+
const confirmAction = await confirm(message, 'Cancel', 'Yes')
762775
if (!confirmAction) {
763776
state.isSaving = false
764777
state.renamingFile = null
@@ -913,7 +926,7 @@ async function store(state, emitter) {
913926
}
914927

915928
if (willOverwrite) {
916-
const confirmation = confirm(`You are about to overwrite the file ${openFile.fileName} on your ${openFile.source}.\n\n Are you sure you want to proceed?`, 'Cancel', 'Yes')
929+
const confirmation = await confirm(`You are about to overwrite the file ${openFile.fileName} on your ${openFile.source}.\n\n Are you sure you want to proceed?`, 'Cancel', 'Yes')
917930
if (!confirmation) {
918931
state.renamingTab = null
919932
state.isSaving = false
@@ -1175,7 +1188,7 @@ async function store(state, emitter) {
11751188
willOverwrite.forEach(f => message += `${f.fileName}\n`)
11761189
message += `\n`
11771190
message += `Are you sure you want to proceed?`
1178-
const confirmAction = confirm(message, 'Cancel', 'Yes')
1191+
const confirmAction = await confirm(message, 'Cancel', 'Yes')
11791192
if (!confirmAction) {
11801193
state.isTransferring = false
11811194
emitter.emit('render')
@@ -1240,7 +1253,7 @@ async function store(state, emitter) {
12401253
willOverwrite.forEach(f => message += `${f.fileName}\n`)
12411254
message += `\n`
12421255
message += `Are you sure you want to proceed?`
1243-
const confirmAction = confirm(message, 'Cancel', 'Yes')
1256+
const confirmAction = await confirm(message, 'Cancel', 'Yes')
12441257
if (!confirmAction) {
12451258
state.isTransferring = false
12461259
emitter.emit('render')
@@ -1327,7 +1340,7 @@ async function store(state, emitter) {
13271340
win.beforeClose(async () => {
13281341
const hasChanges = !!state.openFiles.find(f => f.hasChanges)
13291342
if (hasChanges) {
1330-
const response = await confirm('You may have unsaved changes. Are you sure you want to proceed?', 'Yes', 'Cancel')
1343+
const response = await confirm('You may have unsaved changes. Are you sure you want to proceed?', 'Cancel', 'Yes')
13311344
if (!response) return false
13321345
}
13331346
await win.confirmClose()

0 commit comments

Comments
 (0)