diff --git a/docs/fiddles/features/notifications/renderer/renderer.js b/docs/fiddles/features/notifications/renderer/renderer.js index 3b782f1f1788..09099326b084 100644 --- a/docs/fiddles/features/notifications/renderer/renderer.js +++ b/docs/fiddles/features/notifications/renderer/renderer.js @@ -2,5 +2,5 @@ const NOTIFICATION_TITLE = 'Title' const NOTIFICATION_BODY = 'Notification from the Renderer process. Click to log to console.' const CLICK_MESSAGE = 'Notification clicked!' -new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }) - .onclick = () => document.getElementById('output').innerText = CLICK_MESSAGE +new window.Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }) + .onclick = () => { document.getElementById('output').innerText = CLICK_MESSAGE } diff --git a/docs/fiddles/features/offscreen-rendering/main.js b/docs/fiddles/features/offscreen-rendering/main.js index 10ad35d3d9a8..e4a25a47cda5 100644 --- a/docs/fiddles/features/offscreen-rendering/main.js +++ b/docs/fiddles/features/offscreen-rendering/main.js @@ -4,16 +4,31 @@ const path = require('path') app.disableHardwareAcceleration() -let win +function createWindow () { + const win = new BrowserWindow({ + width: 800, + height: 600, + webPreferences: { + offscreen: true + } + }) -app.whenReady().then(() => { - win = new BrowserWindow({ webPreferences: { offscreen: true } }) win.loadURL('https://github.com') win.webContents.on('paint', (event, dirty, image) => { fs.writeFileSync('ex.png', image.toPNG()) }) win.webContents.setFrameRate(60) console.log(`The screenshot has been successfully saved to ${path.join(process.cwd(), 'ex.png')}`) +} + +app.whenReady().then(() => { + createWindow() + + app.on('activate', () => { + if (BrowserWindow.getAllWindows().length === 0) { + createWindow() + } + }) }) app.on('window-all-closed', () => { @@ -21,9 +36,3 @@ app.on('window-all-closed', () => { app.quit() } }) - -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow() - } -}) diff --git a/docs/fiddles/features/web-bluetooth/main.js b/docs/fiddles/features/web-bluetooth/main.js index e5fd0110ba85..a8ed8f5720d0 100644 --- a/docs/fiddles/features/web-bluetooth/main.js +++ b/docs/fiddles/features/web-bluetooth/main.js @@ -1,7 +1,7 @@ const { app, BrowserWindow, ipcMain } = require('electron') const path = require('path') -let bluetoothPinCallback +let bluetoothPinCallback let selectBluetoothCallback function createWindow () { @@ -24,13 +24,12 @@ function createWindow () { } else { // The device wasn't found so we need to either wait longer (eg until the // device is turned on) or until the user cancels the request - } + } }) ipcMain.on('cancel-bluetooth-request', (event) => { selectBluetoothCallback('') }) - // Listen for a message from the renderer to get the response for the Bluetooth pairing. ipcMain.on('bluetooth-pairing-response', (event, response) => { diff --git a/docs/fiddles/features/web-bluetooth/renderer.js b/docs/fiddles/features/web-bluetooth/renderer.js index 24f8cec1fc67..ca14ef972387 100644 --- a/docs/fiddles/features/web-bluetooth/renderer.js +++ b/docs/fiddles/features/web-bluetooth/renderer.js @@ -7,7 +7,7 @@ async function testIt () { document.getElementById('clickme').addEventListener('click', testIt) -function cancelRequest() { +function cancelRequest () { window.electronAPI.cancelBluetoothRequest() } @@ -18,15 +18,15 @@ window.electronAPI.bluetoothPairingRequest((event, details) => { switch (details.pairingKind) { case 'confirm': { - response.confirmed = confirm(`Do you want to connect to device ${details.deviceId}?`) + response.confirmed = window.confirm(`Do you want to connect to device ${details.deviceId}?`) break } case 'confirmPin': { - response.confirmed = confirm(`Does the pin ${details.pin} match the pin displayed on device ${details.deviceId}?`) + response.confirmed = window.confirm(`Does the pin ${details.pin} match the pin displayed on device ${details.deviceId}?`) break } case 'providePin': { - const pin = prompt(`Please provide a pin for ${details.deviceId}.`) + const pin = window.prompt(`Please provide a pin for ${details.deviceId}.`) if (pin) { response.pin = pin response.confirmed = true diff --git a/docs/fiddles/features/web-serial/main.js b/docs/fiddles/features/web-serial/main.js index 55d40d203805..dc760c1a417e 100644 --- a/docs/fiddles/features/web-serial/main.js +++ b/docs/fiddles/features/web-serial/main.js @@ -23,6 +23,7 @@ function createWindow () { if (portList && portList.length > 0) { callback(portList[0].portId) } else { + // eslint-disable-next-line standard/no-callback-literal callback('') // Could not find any matching devices } }) diff --git a/docs/fiddles/features/web-usb/renderer.js b/docs/fiddles/features/web-usb/renderer.js index d55b0ccef742..cf20c24cc956 100644 --- a/docs/fiddles/features/web-usb/renderer.js +++ b/docs/fiddles/features/web-usb/renderer.js @@ -20,7 +20,7 @@ async function testIt () { const grantedDevice = await navigator.usb.requestDevice({ filters: [] }) - grantedDeviceList += `
${getDeviceDetails(device)}` + grantedDeviceList += `
${getDeviceDetails(grantedDevice)}` } catch (ex) { if (ex.name === 'NotFoundError') { grantedDeviceList = noDevicesFoundMsg diff --git a/docs/fiddles/native-ui/external-links-file-manager/external-links/renderer.js b/docs/fiddles/native-ui/external-links-file-manager/external-links/renderer.js index 14ed2d979f62..8a9b14505a07 100644 --- a/docs/fiddles/native-ui/external-links-file-manager/external-links/renderer.js +++ b/docs/fiddles/native-ui/external-links-file-manager/external-links/renderer.js @@ -5,17 +5,3 @@ const exLinksBtn = document.getElementById('open-ex-links') exLinksBtn.addEventListener('click', (event) => { shell.openExternal('https://electronjs.org') }) - -const OpenAllOutboundLinks = () => { - const links = document.querySelectorAll('a[href]') - - Array.prototype.forEach.call(links, (link) => { - const url = link.getAttribute('href') - if (url.indexOf('http') === 0) { - link.addEventListener('click', (e) => { - e.preventDefault() - shell.openExternal(url) - }) - } - }) -} diff --git a/docs/fiddles/system/clipboard/copy/renderer.js b/docs/fiddles/system/clipboard/copy/renderer.js index d9af9ce044c1..cc2069adff95 100644 --- a/docs/fiddles/system/clipboard/copy/renderer.js +++ b/docs/fiddles/system/clipboard/copy/renderer.js @@ -4,5 +4,5 @@ const copyInput = document.getElementById('copy-to-input') copyBtn.addEventListener('click', () => { if (copyInput.value !== '') copyInput.value = '' copyInput.placeholder = 'Copied! Paste here to see.' - clipboard.writeText('Electron Demo!') + window.clipboard.writeText('Electron Demo!') }) diff --git a/docs/fiddles/system/clipboard/paste/renderer.js b/docs/fiddles/system/clipboard/paste/renderer.js index a1562b4f085b..a4c75790f938 100644 --- a/docs/fiddles/system/clipboard/paste/renderer.js +++ b/docs/fiddles/system/clipboard/paste/renderer.js @@ -1,7 +1,7 @@ const pasteBtn = document.getElementById('paste-to') pasteBtn.addEventListener('click', async () => { - await clipboard.writeText('What a demo!') - const message = `Clipboard contents: ${await clipboard.readText()}` + await window.clipboard.writeText('What a demo!') + const message = `Clipboard contents: ${await window.clipboard.readText()}` document.getElementById('paste-from').innerHTML = message }) diff --git a/docs/fiddles/system/system-app-user-information/app-information/renderer.js b/docs/fiddles/system/system-app-user-information/app-information/renderer.js index 6a348da87183..d209e29021ec 100644 --- a/docs/fiddles/system/system-app-user-information/app-information/renderer.js +++ b/docs/fiddles/system/system-app-user-information/app-information/renderer.js @@ -1,7 +1,7 @@ -const { ipcRenderer } = require('electron') +const { ipcRenderer, shell } = require('electron') const appInfoBtn = document.getElementById('app-info') -const electron_doc_link = document.querySelectorAll('a[href]') +const electronDocLink = document.querySelectorAll('a[href]') appInfoBtn.addEventListener('click', () => { ipcRenderer.send('get-app-path') @@ -12,7 +12,8 @@ ipcRenderer.on('got-app-path', (event, path) => { document.getElementById('got-app-info').innerHTML = message }) -electron_doc_link.addEventListener('click', (e) => { +electronDocLink.addEventListener('click', (e) => { e.preventDefault() + const url = e.target.getAttribute('href') shell.openExternal(url) }) diff --git a/docs/fiddles/tutorial-preload/renderer.js b/docs/fiddles/tutorial-preload/renderer.js index df60659df268..6c8c471aa339 100644 --- a/docs/fiddles/tutorial-preload/renderer.js +++ b/docs/fiddles/tutorial-preload/renderer.js @@ -1,2 +1,2 @@ const information = document.getElementById('info') -information.innerText = `This app is using Chrome (v${versions.chrome()}), Node.js (v${versions.node()}), and Electron (v${versions.electron()})` +information.innerText = `This app is using Chrome (v${window.versions.chrome()}), Node.js (v${window.versions.node()}), and Electron (v${window.versions.electron()})` diff --git a/docs/fiddles/windows/manage-windows/frameless-window/main.js b/docs/fiddles/windows/manage-windows/frameless-window/main.js index 60a9c08d4fa3..13951c82067f 100644 --- a/docs/fiddles/windows/manage-windows/frameless-window/main.js +++ b/docs/fiddles/windows/manage-windows/frameless-window/main.js @@ -23,23 +23,21 @@ function createWindow () { // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.whenReady().then(createWindow) +app.whenReady().then(() => { + createWindow() -// Quit when all windows are closed. -app.on('window-all-closed', function () { - // On macOS it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q - if (process.platform !== 'darwin') { - app.quit() - } + app.on('activate', function () { + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) createWindow() + }) }) -app.on('activate', function () { - // On macOS it is common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (mainWindow === null) { - createWindow() - } +// Quit when all windows are closed, except on macOS. There, it's common +// for applications and their menu bar to stay active until the user quits +// explicitly with Cmd + Q. +app.on('window-all-closed', function () { + if (process.platform !== 'darwin') app.quit() }) // In this file you can include the rest of your app's specific main process diff --git a/docs/fiddles/windows/manage-windows/manage-window-state/main.js b/docs/fiddles/windows/manage-windows/manage-window-state/main.js index 81bb22fdde10..111c3242b17b 100644 --- a/docs/fiddles/windows/manage-windows/manage-window-state/main.js +++ b/docs/fiddles/windows/manage-windows/manage-window-state/main.js @@ -18,7 +18,7 @@ ipcMain.on('create-demo-window', (event) => { function createWindow () { // Create the browser window. - mainWindow = new BrowserWindow({ + const mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { @@ -33,23 +33,21 @@ function createWindow () { // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.whenReady().then(createWindow) +app.whenReady().then(() => { + createWindow() -// Quit when all windows are closed. -app.on('window-all-closed', function () { - // On macOS it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q - if (process.platform !== 'darwin') { - app.quit() - } + app.on('activate', function () { + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) createWindow() + }) }) -app.on('activate', function () { - // On macOS it is common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (mainWindow === null) { - createWindow() - } +// Quit when all windows are closed, except on macOS. There, it's common +// for applications and their menu bar to stay active until the user quits +// explicitly with Cmd + Q. +app.on('window-all-closed', function () { + if (process.platform !== 'darwin') app.quit() }) // In this file you can include the rest of your app's specific main process diff --git a/docs/fiddles/windows/manage-windows/new-window/main.js b/docs/fiddles/windows/manage-windows/new-window/main.js index 2e51387e37ac..457cc5535780 100644 --- a/docs/fiddles/windows/manage-windows/new-window/main.js +++ b/docs/fiddles/windows/manage-windows/new-window/main.js @@ -23,23 +23,21 @@ function createWindow () { // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.whenReady().then(createWindow) +app.whenReady().then(() => { + createWindow() -// Quit when all windows are closed. -app.on('window-all-closed', function () { - // On macOS it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q - if (process.platform !== 'darwin') { - app.quit() - } + app.on('activate', function () { + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) createWindow() + }) }) -app.on('activate', function () { - // On macOS it is common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (mainWindow === null) { - createWindow() - } +// Quit when all windows are closed, except on macOS. There, it's common +// for applications and their menu bar to stay active until the user quits +// explicitly with Cmd + Q. +app.on('window-all-closed', function () { + if (process.platform !== 'darwin') app.quit() }) // In this file you can include the rest of your app's specific main process diff --git a/docs/fiddles/windows/manage-windows/window-events/main.js b/docs/fiddles/windows/manage-windows/window-events/main.js index 3effec304fc4..e773c726b21f 100644 --- a/docs/fiddles/windows/manage-windows/window-events/main.js +++ b/docs/fiddles/windows/manage-windows/window-events/main.js @@ -41,23 +41,21 @@ function createWindow () { // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.whenReady().then(createWindow) +app.whenReady().then(() => { + createWindow() -// Quit when all windows are closed. -app.on('window-all-closed', function () { - // On macOS it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q - if (process.platform !== 'darwin') { - app.quit() - } + app.on('activate', function () { + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) createWindow() + }) }) -app.on('activate', function () { - // On macOS it is common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (mainWindow === null) { - createWindow() - } +// Quit when all windows are closed, except on macOS. There, it's common +// for applications and their menu bar to stay active until the user quits +// explicitly with Cmd + Q. +app.on('window-all-closed', function () { + if (process.platform !== 'darwin') app.quit() }) // In this file you can include the rest of your app's specific main process diff --git a/package.json b/package.json index 28cd13e4eab2..8460dc3d956b 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "lint:objc": "node ./script/lint.js --objc", "lint:py": "node ./script/lint.js --py", "lint:gn": "node ./script/lint.js --gn", - "lint:docs": "remark docs -qf && npm run lint:js-in-markdown && npm run create-typescript-definitions && npm run lint:docs-relative-links && npm run lint:markdownlint", + "lint:docs": "remark docs -qf && npm run lint:js-in-markdown && npm run create-typescript-definitions && npm run lint:docs-fiddles && npm run lint:docs-relative-links && npm run lint:markdownlint", "lint:docs-fiddles": "standard \"docs/fiddles/**/*.js\"", "lint:docs-relative-links": "ts-node script/lint-docs-links.ts", "lint:markdownlint": "markdownlint -r ./script/markdownlint-emd001.js \"*.md\" \"docs/**/*.md\"",