docs: enable contextIsolation in fiddles (#39613)
This commit is contained in:
parent
2e79f34c84
commit
9280b79112
61 changed files with 206 additions and 233 deletions
|
@ -96,9 +96,6 @@ ipcMain.on('open-information-dialog', (event) => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// You can also require other files to run in this process
|
||||
require("./renderer.js");
|
||||
</script>
|
||||
<script src="renderer.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Modules to control application life and create native browser window
|
||||
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron/main')
|
||||
const path = require('node:path')
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
|
@ -11,8 +12,7 @@ function createWindow () {
|
|||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
contextIsolation: false,
|
||||
nodeIntegration: true
|
||||
preload: path.join(__dirname, 'preload.js')
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -59,16 +59,14 @@ app.on('activate', function () {
|
|||
}
|
||||
})
|
||||
|
||||
ipcMain.on('open-information-dialog', event => {
|
||||
ipcMain.handle('open-information-dialog', async () => {
|
||||
const options = {
|
||||
type: 'info',
|
||||
title: 'Information',
|
||||
message: "This is an information dialog. Isn't it nice?",
|
||||
buttons: ['Yes', 'No']
|
||||
}
|
||||
dialog.showMessageBox(options, index => {
|
||||
event.sender.send('information-dialog-selection', index)
|
||||
})
|
||||
return (await dialog.showMessageBox(options)).response
|
||||
})
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
const { contextBridge, ipcRenderer } = require('electron/renderer')
|
||||
|
||||
contextBridge.exposeInMainWorld('electronAPI', {
|
||||
openInformationDialog: () => ipcRenderer.invoke('open-information-dialog')
|
||||
})
|
|
@ -1,14 +1,7 @@
|
|||
const { ipcRenderer } = require('electron/renderer')
|
||||
|
||||
const informationBtn = document.getElementById('information-dialog')
|
||||
|
||||
informationBtn.addEventListener('click', event => {
|
||||
ipcRenderer.send('open-information-dialog')
|
||||
})
|
||||
|
||||
ipcRenderer.on('information-dialog-selection', (event, index) => {
|
||||
let message = 'You selected '
|
||||
if (index === 0) message += 'yes.'
|
||||
else message += 'no.'
|
||||
informationBtn.addEventListener('click', async () => {
|
||||
const index = await window.electronAPI.openInformationDialog()
|
||||
const message = `You selected: ${index === 0 ? 'yes' : 'no'}`
|
||||
document.getElementById('info-selection').innerHTML = message
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue