Skip to content

Commit

Permalink
chore: initial linting fixes for JS in docs/fiddles (#37838)
Browse files Browse the repository at this point in the history
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
  • Loading branch information
trop[bot] and dsanders11 committed Apr 17, 2023
1 parent 85ad784 commit 4a9f347
Show file tree
Hide file tree
Showing 45 changed files with 122 additions and 134 deletions.
14 changes: 7 additions & 7 deletions docs/fiddles/features/drag-and-drop/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { app, BrowserWindow, ipcMain, nativeImage, NativeImage } = require('electron')
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const fs = require('fs')
const https = require('https')

function createWindow() {
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
Expand All @@ -15,23 +15,23 @@ function createWindow() {
win.loadFile('index.html')
}

const iconName = path.join(__dirname, 'iconForDragAndDrop.png');
const icon = fs.createWriteStream(iconName);
const iconName = path.join(__dirname, 'iconForDragAndDrop.png')
const icon = fs.createWriteStream(iconName)

// Create a new file to copy - you can also copy existing files.
fs.writeFileSync(path.join(__dirname, 'drag-and-drop-1.md'), '# First file to test drag and drop')
fs.writeFileSync(path.join(__dirname, 'drag-and-drop-2.md'), '# Second file to test drag and drop')

https.get('https://img.icons8.com/ios/452/drag-and-drop.png', (response) => {
response.pipe(icon);
});
response.pipe(icon)
})

app.whenReady().then(createWindow)

ipcMain.on('ondragstart', (event, filePath) => {
event.sender.startDrag({
file: path.join(__dirname, filePath),
icon: iconName,
icon: iconName
})
})

Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/keyboard-shortcuts/global/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { app, BrowserWindow, globalShortcut } = require('electron')
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
height: 600
})

win.loadFile('index.html')
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/keyboard-shortcuts/local/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { app, BrowserWindow, Menu, MenuItem } = require('electron')
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
height: 600
})

win.loadFile('index.html')
Expand Down
6 changes: 2 additions & 4 deletions docs/fiddles/features/keyboard-shortcuts/web-apis/main.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')
const { app, BrowserWindow } = require('electron')

function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
height: 600
})

// and load the index.html of the app.
mainWindow.loadFile('index.html')

}

// This method will be called when Electron has finished
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function handleKeyPress (event) {
// You can put code here to handle the keypress.
document.getElementById("last-keypress").innerText = event.key
document.getElementById('last-keypress').innerText = event.key
console.log(`You pressed ${event.key}`)
}

Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/macos-dock-menu/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { app, BrowserWindow, Menu } = require('electron')
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
height: 600
})

win.loadFile('index.html')
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/notifications/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ const NOTIFICATION_BODY = 'Notification from the Renderer process. Click to log
const CLICK_MESSAGE = 'Notification clicked!'

new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY })
.onclick = () => document.getElementById("output").innerText = CLICK_MESSAGE
.onclick = () => document.getElementById('output').innerText = CLICK_MESSAGE
2 changes: 1 addition & 1 deletion docs/fiddles/features/represented-file/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { app, BrowserWindow } = require('electron')
const os = require('os');
const os = require('os')

function createWindow () {
const win = new BrowserWindow({
Expand Down
3 changes: 1 addition & 2 deletions docs/fiddles/features/web-bluetooth/main.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 } = require('electron')
const path = require('path')

let bluetoothPinCallback
Expand Down Expand Up @@ -38,7 +38,6 @@ function createWindow () {
})

mainWindow.webContents.session.setBluetoothPairingHandler((details, callback) => {

bluetoothPinCallback = callback
// Send a message to the renderer to prompt the user to confirm the pairing.
mainWindow.webContents.send('bluetooth-pairing-request', details)
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/web-bluetooth/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ contextBridge.exposeInMainWorld('electronAPI', {
cancelBluetoothRequest: (callback) => ipcRenderer.send('cancel-bluetooth-request', callback),
bluetoothPairingRequest: (callback) => ipcRenderer.on('bluetooth-pairing-request', callback),
bluetoothPairingResponse: (response) => ipcRenderer.send('bluetooth-pairing-response', response)
})
})
6 changes: 3 additions & 3 deletions docs/fiddles/features/web-bluetooth/renderer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
async function testIt() {
async function testIt () {
const device = await navigator.bluetooth.requestDevice({
acceptAllDevices: true
})
document.getElementById('device-name').innerHTML = device.name || `ID: ${device.id}`
}

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

function cancelRequest() {
window.electronAPI.cancelBluetoothRequest()
Expand Down Expand Up @@ -37,4 +37,4 @@ window.electronAPI.bluetoothPairingRequest((event, details) => {
}

window.electronAPI.bluetoothPairingResponse(response)
})
})
11 changes: 5 additions & 6 deletions docs/fiddles/features/web-hid/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const {app, BrowserWindow} = require('electron')
const path = require('path')
const { app, BrowserWindow } = require('electron')

function createWindow () {
const mainWindow = new BrowserWindow({
Expand All @@ -8,16 +7,16 @@ function createWindow () {
})

mainWindow.webContents.session.on('select-hid-device', (event, details, callback) => {
//Add events to handle devices being added or removed before the callback on
//`select-hid-device` is called.
// Add events to handle devices being added or removed before the callback on
// `select-hid-device` is called.
mainWindow.webContents.session.on('hid-device-added', (event, device) => {
console.log('hid-device-added FIRED WITH', device)
//Optionally update details.deviceList
// Optionally update details.deviceList
})

mainWindow.webContents.session.on('hid-device-removed', (event, device) => {
console.log('hid-device-removed FIRED WITH', device)
//Optionally update details.deviceList
// Optionally update details.deviceList
})

event.preventDefault()
Expand Down
6 changes: 3 additions & 3 deletions docs/fiddles/features/web-hid/renderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async function testIt() {
async function testIt () {
const grantedDevices = await navigator.hid.getDevices()
let grantedDeviceList = ''
grantedDevices.forEach(device => {
Expand All @@ -10,10 +10,10 @@ async function testIt() {
})

grantedDeviceList = ''
grantedDevices2.forEach(device => {
grantedDevices2.forEach(device => {
grantedDeviceList += `<hr>${device.productName}</hr>`
})
document.getElementById('granted-devices2').innerHTML = grantedDeviceList
}

document.getElementById('clickme').addEventListener('click',testIt)
document.getElementById('clickme').addEventListener('click', testIt)
14 changes: 6 additions & 8 deletions docs/fiddles/features/web-serial/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const {app, BrowserWindow} = require('electron')
const path = require('path')
const { app, BrowserWindow } = require('electron')

function createWindow () {
const mainWindow = new BrowserWindow({
Expand All @@ -8,24 +7,23 @@ function createWindow () {
})

mainWindow.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {

//Add listeners to handle ports being added or removed before the callback for `select-serial-port`
//is called.
// Add listeners to handle ports being added or removed before the callback for `select-serial-port`
// is called.
mainWindow.webContents.session.on('serial-port-added', (event, port) => {
console.log('serial-port-added FIRED WITH', port)
//Optionally update portList to add the new port
// Optionally update portList to add the new port
})

mainWindow.webContents.session.on('serial-port-removed', (event, port) => {
console.log('serial-port-removed FIRED WITH', port)
//Optionally update portList to remove the port
// Optionally update portList to remove the port
})

event.preventDefault()
if (portList && portList.length > 0) {
callback(portList[0].portId)
} else {
callback('') //Could not find any matching devices
callback('') // Could not find any matching devices
}
})

Expand Down
10 changes: 5 additions & 5 deletions docs/fiddles/features/web-serial/renderer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
async function testIt() {
async function testIt () {
const filters = [
{ usbVendorId: 0x2341, usbProductId: 0x0043 },
{ usbVendorId: 0x2341, usbProductId: 0x0001 }
];
]
try {
const port = await navigator.serial.requestPort({filters});
const portInfo = port.getInfo();
const port = await navigator.serial.requestPort({ filters })
const portInfo = port.getInfo()
document.getElementById('device-name').innerHTML = `vendorId: ${portInfo.usbVendorId} | productId: ${portInfo.usbProductId} `
} catch (ex) {
if (ex.name === 'NotFoundError') {
Expand All @@ -16,4 +16,4 @@ async function testIt() {
}
}

document.getElementById('clickme').addEventListener('click',testIt)
document.getElementById('clickme').addEventListener('click', testIt)
15 changes: 7 additions & 8 deletions docs/fiddles/features/web-usb/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const {app, BrowserWindow} = require('electron')
const path = require('path')
const { app, BrowserWindow } = require('electron')

function createWindow () {
const mainWindow = new BrowserWindow({
Expand All @@ -10,22 +9,22 @@ function createWindow () {
let grantedDeviceThroughPermHandler

mainWindow.webContents.session.on('select-usb-device', (event, details, callback) => {
//Add events to handle devices being added or removed before the callback on
//`select-usb-device` is called.
// Add events to handle devices being added or removed before the callback on
// `select-usb-device` is called.
mainWindow.webContents.session.on('usb-device-added', (event, device) => {
console.log('usb-device-added FIRED WITH', device)
//Optionally update details.deviceList
// Optionally update details.deviceList
})

mainWindow.webContents.session.on('usb-device-removed', (event, device) => {
console.log('usb-device-removed FIRED WITH', device)
//Optionally update details.deviceList
// Optionally update details.deviceList
})

event.preventDefault()
if (details.deviceList && details.deviceList.length > 0) {
const deviceToReturn = details.deviceList.find((device) => {
if (!grantedDeviceThroughPermHandler || (device.deviceId != grantedDeviceThroughPermHandler.deviceId)) {
const deviceToReturn = details.deviceList.find((device) => {
if (!grantedDeviceThroughPermHandler || (device.deviceId !== grantedDeviceThroughPermHandler.deviceId)) {
return true
}
})
Expand Down
7 changes: 3 additions & 4 deletions docs/fiddles/features/web-usb/renderer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function getDeviceDetails(device) {
function getDeviceDetails (device) {
return device.productName || `Unknown device ${device.deviceId}`
}

async function testIt() {
async function testIt () {
const noDevicesFoundMsg = 'No devices found'
const grantedDevices = await navigator.usb.getDevices()
let grantedDeviceList = ''
Expand All @@ -21,7 +21,6 @@ async function testIt() {
filters: []
})
grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>`

} catch (ex) {
if (ex.name === 'NotFoundError') {
grantedDeviceList = noDevicesFoundMsg
Expand All @@ -30,4 +29,4 @@ async function testIt() {
document.getElementById('granted-devices2').innerHTML = grantedDeviceList
}

document.getElementById('clickme').addEventListener('click',testIt)
document.getElementById('clickme').addEventListener('click', testIt)
2 changes: 1 addition & 1 deletion docs/fiddles/ipc/pattern-1/main.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 } = require('electron')
const path = require('path')

function createWindow () {
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/ipc/pattern-1/preload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('electronAPI', {
setTitle: (title) => ipcRenderer.send('set-title', title)
setTitle: (title) => ipcRenderer.send('set-title', title)
})
6 changes: 3 additions & 3 deletions docs/fiddles/ipc/pattern-1/renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const setButton = document.getElementById('btn')
const titleInput = document.getElementById('title')
setButton.addEventListener('click', () => {
const title = titleInput.value
window.electronAPI.setTitle(title)
});
const title = titleInput.value
window.electronAPI.setTitle(title)
})
6 changes: 3 additions & 3 deletions docs/fiddles/ipc/pattern-2/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const {app, BrowserWindow, ipcMain, dialog} = require('electron')
const { app, BrowserWindow, ipcMain, dialog } = require('electron')
const path = require('path')

async function handleFileOpen() {
async function handleFileOpen () {
const { canceled, filePaths } = await dialog.showOpenDialog()
if (canceled) {
return

} else {
return filePaths[0]
}
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/ipc/pattern-2/preload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('electronAPI',{
contextBridge.exposeInMainWorld('electronAPI', {
openFile: () => ipcRenderer.invoke('dialog:openFile')
})
18 changes: 9 additions & 9 deletions docs/fiddles/ipc/pattern-3/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {app, BrowserWindow, Menu, ipcMain} = require('electron')
const { app, BrowserWindow, Menu, ipcMain } = require('electron')
const path = require('path')

function createWindow () {
Expand All @@ -12,14 +12,14 @@ function createWindow () {
{
label: app.name,
submenu: [
{
click: () => mainWindow.webContents.send('update-counter', 1),
label: 'Increment',
},
{
click: () => mainWindow.webContents.send('update-counter', -1),
label: 'Decrement',
}
{
click: () => mainWindow.webContents.send('update-counter', 1),
label: 'Increment'
},
{
click: () => mainWindow.webContents.send('update-counter', -1),
label: 'Decrement'
}
]
}

Expand Down

0 comments on commit 4a9f347

Please sign in to comment.