Skip to content

Commit

Permalink
chore: always lint JS in docs/fiddles (#38108)
Browse files Browse the repository at this point in the history
* chore: always lint JS in docs/fiddles

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* chore: update patches

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 24, 2023
1 parent 00163df commit 9f028cc
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 99 deletions.
4 changes: 2 additions & 2 deletions docs/fiddles/features/notifications/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
27 changes: 18 additions & 9 deletions docs/fiddles/features/offscreen-rendering/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,35 @@ 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', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
5 changes: 2 additions & 3 deletions docs/fiddles/features/web-bluetooth/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')

let bluetoothPinCallback
let bluetoothPinCallback
let selectBluetoothCallback

function createWindow () {
Expand All @@ -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) => {
Expand Down
8 changes: 4 additions & 4 deletions docs/fiddles/features/web-bluetooth/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async function testIt () {

document.getElementById('clickme').addEventListener('click', testIt)

function cancelRequest() {
function cancelRequest () {
window.electronAPI.cancelBluetoothRequest()
}

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/fiddles/features/web-serial/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/web-usb/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function testIt () {
const grantedDevice = await navigator.usb.requestDevice({
filters: []
})
grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>`
grantedDeviceList += `<hr>${getDeviceDetails(grantedDevice)}</hr>`
} catch (ex) {
if (ex.name === 'NotFoundError') {
grantedDeviceList = noDevicesFoundMsg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
})
}
2 changes: 1 addition & 1 deletion docs/fiddles/system/clipboard/copy/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!')
})
4 changes: 2 additions & 2 deletions docs/fiddles/system/clipboard/paste/renderer.js
Original file line number Diff line number Diff line change
@@ -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
})
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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)
})
2 changes: 1 addition & 1 deletion docs/fiddles/tutorial-preload/renderer.js
Original file line number Diff line number Diff line change
@@ -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()})`
26 changes: 12 additions & 14 deletions docs/fiddles/windows/manage-windows/frameless-window/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 13 additions & 15 deletions docs/fiddles/windows/manage-windows/manage-window-state/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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
Expand Down
26 changes: 12 additions & 14 deletions docs/fiddles/windows/manage-windows/new-window/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 12 additions & 14 deletions docs/fiddles/windows/manage-windows/window-events/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down
2 changes: 1 addition & 1 deletion patches/chromium/cherry-pick-ec53103cc72d.patch
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Bot-Commit: chromium-autoroll <chromium-autoroll@skia-public.iam.gserviceaccount
Cr-Commit-Position: refs/heads/main@{#1129520}

diff --git a/DEPS b/DEPS
index 9977dd1a5f299d13d833e7bf266ebd5f3090ac22..1054192d132f42be5130bcc11a2aa9023fbb615a 100644
index 14b54b64292172381b677f0166f9d530c48d7b65..67300d129c39a5dfe89cb5a015afa203a291ad36 100644
--- a/DEPS
+++ b/DEPS
@@ -299,7 +299,7 @@ vars = {
Expand Down

0 comments on commit 9f028cc

Please sign in to comment.