Skip to content

Bugfix Windows missing cursor on editor #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion backend/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
getAllFiles
} = require('./helpers.js')

module.exports = function registerIPCHandlers(win, ipcMain, app) {
module.exports = function registerIPCHandlers(win, ipcMain, app, dialog) {
ipcMain.handle('open-folder', async (event) => {
console.log('ipcMain', 'open-folder')
const folder = await openFolderDialog(win)
Expand Down Expand Up @@ -123,6 +123,12 @@ module.exports = function registerIPCHandlers(win, ipcMain, app) {
return app.getAppPath()
})

ipcMain.handle('open-dialog', (event, opt) => {
console.log('ipcMain', 'open-dialog', opt)
const response = dialog.showMessageBoxSync(win, opt)
return response != opt.cancelId
})

win.on('close', (event) => {
console.log('BrowserWindow', 'close')
event.preventDefault()
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain } = require('electron')
const { app, BrowserWindow, ipcMain, dialog } = require('electron')
const path = require('path')
const fs = require('fs')

Expand Down Expand Up @@ -49,7 +49,7 @@ function createWindow () {
win.show()
})

registerIPCHandlers(win, ipcMain, app)
registerIPCHandlers(win, ipcMain, app, dialog)
registerMenu(win)

app.on('activate', () => {
Expand Down
3 changes: 2 additions & 1 deletion preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ const Window = {
},
beforeClose: (callback) => ipcRenderer.on('check-before-close', callback),
confirmClose: () => ipcRenderer.invoke('confirm-close'),
isPackaged: () => ipcRenderer.invoke('is-packaged')
isPackaged: () => ipcRenderer.invoke('is-packaged'),
openDialog: (opt) => ipcRenderer.invoke('open-dialog', opt)
}


Expand Down
41 changes: 27 additions & 14 deletions ui/arduino/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ const newFileContent = `# This program was created in Arduino Lab for MicroPytho
print('Hello, MicroPython!')
`

async function confirm(msg, cancelMsg, confirmMsg) {
cancelMsg = cancelMsg || 'Cancel'
confirmMsg = confirmMsg || 'Yes'
let response = await win.openDialog({
type: 'question',
buttons: [cancelMsg, confirmMsg],
cancelId: 0,
message: msg
})
console.log('confirm', response)
return Promise.resolve(response)
}

async function store(state, emitter) {
win.setWindowSize(720, 640)

Expand Down Expand Up @@ -313,7 +326,7 @@ async function store(state, emitter) {
}

if (willOverwrite) {
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')
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')
if (!confirmation) {
state.isSaving = false
openFile.parentFolder = oldParentFolder
Expand Down Expand Up @@ -366,11 +379,11 @@ async function store(state, emitter) {
state.editingFile = id
emitter.emit('render')
})
emitter.on('close-tab', (id) => {
emitter.on('close-tab', async (id) => {
log('close-tab', id)
const currentTab = state.openFiles.find(f => f.id === id)
if (currentTab.hasChanges) {
let response = confirm("Your file has unsaved changes. Are you sure you want to proceed?")
let response = await confirm("Your file has unsaved changes. Are you sure you want to proceed?")
if (!response) return false
}
state.openFiles = state.openFiles.filter(f => f.id !== id)
Expand Down Expand Up @@ -474,7 +487,7 @@ async function store(state, emitter) {
fileName: value
})
if (willOverwrite) {
const confirmAction = confirm(`You are about to overwrite the file ${value} on your board.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
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')
if (!confirmAction) {
state.creatingFile = null
emitter.emit('render')
Expand All @@ -497,7 +510,7 @@ async function store(state, emitter) {
fileName: value
})
if (willOverwrite) {
const confirmAction = confirm(`You are about to overwrite the file ${value} on your disk.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
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')
if (!confirmAction) {
state.creatingFile = null
emitter.emit('render')
Expand Down Expand Up @@ -545,7 +558,7 @@ async function store(state, emitter) {
fileName: value
})
if (willOverwrite) {
const confirmAction = confirm(`You are about to overwrite ${value} on your board.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
const confirmAction = await confirm(`You are about to overwrite ${value} on your board.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
if (!confirmAction) {
state.creatingFolder = null
emitter.emit('render')
Expand Down Expand Up @@ -574,7 +587,7 @@ async function store(state, emitter) {
fileName: value
})
if (willOverwrite) {
const confirmAction = confirm(`You are about to overwrite ${value} on your disk.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
const confirmAction = await confirm(`You are about to overwrite ${value} on your disk.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
if (!confirmAction) {
state.creatingFolder = null
emitter.emit('render')
Expand Down Expand Up @@ -631,7 +644,7 @@ async function store(state, emitter) {
}

message += `Are you sure you want to proceed?`
const confirmAction = confirm(message, 'Cancel', 'Yes')
const confirmAction = await confirm(message, 'Cancel', 'Yes')
if (!confirmAction) {
state.isRemoving = false
emitter.emit('render')
Expand Down Expand Up @@ -719,7 +732,7 @@ async function store(state, emitter) {
let message = `You are about to overwrite the following file/folder on your board:\n\n`
message += `${value}\n\n`
message += `Are you sure you want to proceed?`
const confirmAction = confirm(message, 'Cancel', 'Yes')
const confirmAction = await confirm(message, 'Cancel', 'Yes')
if (!confirmAction) {
state.isSaving = false
state.renamingFile = null
Expand Down Expand Up @@ -758,7 +771,7 @@ async function store(state, emitter) {
let message = `You are about to overwrite the following file/folder on your disk:\n\n`
message += `${value}\n\n`
message += `Are you sure you want to proceed?`
const confirmAction = confirm(message, 'Cancel', 'Yes')
const confirmAction = await confirm(message, 'Cancel', 'Yes')
if (!confirmAction) {
state.isSaving = false
state.renamingFile = null
Expand Down Expand Up @@ -913,7 +926,7 @@ async function store(state, emitter) {
}

if (willOverwrite) {
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')
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')
if (!confirmation) {
state.renamingTab = null
state.isSaving = false
Expand Down Expand Up @@ -1175,7 +1188,7 @@ async function store(state, emitter) {
willOverwrite.forEach(f => message += `${f.fileName}\n`)
message += `\n`
message += `Are you sure you want to proceed?`
const confirmAction = confirm(message, 'Cancel', 'Yes')
const confirmAction = await confirm(message, 'Cancel', 'Yes')
if (!confirmAction) {
state.isTransferring = false
emitter.emit('render')
Expand Down Expand Up @@ -1240,7 +1253,7 @@ async function store(state, emitter) {
willOverwrite.forEach(f => message += `${f.fileName}\n`)
message += `\n`
message += `Are you sure you want to proceed?`
const confirmAction = confirm(message, 'Cancel', 'Yes')
const confirmAction = await confirm(message, 'Cancel', 'Yes')
if (!confirmAction) {
state.isTransferring = false
emitter.emit('render')
Expand Down Expand Up @@ -1327,7 +1340,7 @@ async function store(state, emitter) {
win.beforeClose(async () => {
const hasChanges = !!state.openFiles.find(f => f.hasChanges)
if (hasChanges) {
const response = await confirm('You may have unsaved changes. Are you sure you want to proceed?', 'Yes', 'Cancel')
const response = await confirm('You may have unsaved changes. Are you sure you want to proceed?', 'Cancel', 'Yes')
if (!response) return false
}
await win.confirmClose()
Expand Down