docs: use electron/main & electron/renderer imports in fiddles (#39666)

This commit is contained in:
Milan Burda 2023-08-28 13:23:10 +02:00 committed by GitHub
parent d42a94ddde
commit f2f83a73fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
70 changed files with 78 additions and 88 deletions

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, nativeTheme } = require('electron')
const { app, BrowserWindow, ipcMain, nativeTheme } = require('electron/main')
const path = require('node:path')
function createWindow () {

View file

@ -1,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')
contextBridge.exposeInMainWorld('darkMode', {
toggle: () => ipcRenderer.invoke('dark-mode:toggle'),

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain } = require('electron')
const { app, BrowserWindow, ipcMain } = require('electron/main')
const path = require('node:path')
const fs = require('node:fs')
const https = require('node:https')

View file

@ -1,7 +1,5 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')
contextBridge.exposeInMainWorld('electron', {
startDrag: (fileName) => {
ipcRenderer.send('ondragstart', fileName)
}
startDrag: (fileName) => ipcRenderer.send('ondragstart', fileName)
})

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, globalShortcut } = require('electron')
const { app, BrowserWindow, globalShortcut } = require('electron/main')
function createWindow () {
const win = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
app.whenReady().then(() => {
const win = new BrowserWindow({ width: 800, height: 600 })

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, Menu, MenuItem } = require('electron')
const { app, BrowserWindow, Menu, MenuItem } = require('electron/main')
function createWindow () {
const win = new BrowserWindow({

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
function createWindow () {
// Create the browser window.

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, Menu } = require('electron')
const { app, BrowserWindow, Menu } = require('electron/main')
function createWindow () {
const win = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, Notification } = require('electron')
const { app, BrowserWindow, Notification } = require('electron/main')
function createWindow () {
const win = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
function createWindow () {
const win = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
const fs = require('node:fs')
const path = require('node:path')

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
function createWindow () {
const onlineStatusWindow = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
let progressInterval

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
const fs = require('node:fs')
const path = require('node:path')

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
const os = require('node:os')
function createWindow () {

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain } = require('electron')
const { app, BrowserWindow, ipcMain } = require('electron/main')
const path = require('node:path')
let bluetoothPinCallback

View file

@ -1,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')
contextBridge.exposeInMainWorld('electronAPI', {
cancelBluetoothRequest: (callback) => ipcRenderer.send('cancel-bluetooth-request', callback),

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
function createWindow () {
const mainWindow = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
function createWindow () {
const mainWindow = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
function createWindow () {
const mainWindow = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain } = require('electron')
const { app, BrowserWindow, ipcMain } = require('electron/main')
const path = require('node:path')
function createWindow () {

View file

@ -1,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')
contextBridge.exposeInMainWorld('electronAPI', {
setTitle: (title) => ipcRenderer.send('set-title', title)

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, dialog } = require('electron')
const { app, BrowserWindow, ipcMain, dialog } = require('electron/main')
const path = require('node:path')
async function handleFileOpen () {

View file

@ -1,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')
contextBridge.exposeInMainWorld('electronAPI', {
openFile: () => ipcRenderer.invoke('dialog:openFile')

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, Menu, ipcMain } = require('electron')
const { app, BrowserWindow, Menu, ipcMain } = require('electron/main')
const path = require('node:path')
function createWindow () {

View file

@ -1,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')
contextBridge.exposeInMainWorld('electronAPI', {
handleCounter: (callback) => ipcRenderer.on('update-counter', callback)

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
const path = require('node:path')
function createWindow () {

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const webview = document.getElementById('webview')
ipcRenderer.on('webview-new-window', (e, webContentsId, details) => {
console.log('webview-new-window', webContentsId, details)

View file

@ -1,4 +1,4 @@
const { BrowserWindow, app, screen, ipcMain, desktopCapturer } = require('electron')
const { BrowserWindow, app, screen, ipcMain, desktopCapturer } = require('electron/main')
let mainWindow = null

View file

@ -1,4 +1,4 @@
const { shell, ipcRenderer } = require('electron')
const { shell, ipcRenderer } = require('electron/renderer')
const fs = require('node:fs').promises
const os = require('node:os')

View file

@ -6,8 +6,9 @@ const {
ipcMain,
app,
shell,
dialog
} = require('electron')
dialog,
autoUpdater
} = require('electron/main')
const menu = new Menu()
menu.append(new MenuItem({ label: 'Hello' }))
@ -185,7 +186,7 @@ function addUpdateMenuItems (items, position) {
visible: false,
key: 'checkForUpdate',
click: () => {
require('electron').autoUpdater.checkForUpdates()
autoUpdater.checkForUpdates()
}
},
{
@ -194,7 +195,7 @@ function addUpdateMenuItems (items, position) {
visible: false,
key: 'restartToUpdate',
click: () => {
require('electron').autoUpdater.quitAndInstall()
autoUpdater.quitAndInstall()
}
}
]

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
// Tell main process to show the menu when demo button is clicked
const contextMenuBtn = document.getElementById('context-menu')

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, globalShortcut, dialog, shell } = require('electron')
const { app, BrowserWindow, globalShortcut, dialog, shell } = require('electron/main')
// 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.

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron')
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron/main')
// 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.

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const errorBtn = document.getElementById('error-dialog')

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron')
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron/main')
// 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.

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const informationBtn = document.getElementById('information-dialog')

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron')
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron/main')
// 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.

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const selectDirBtn = document.getElementById('select-directory')

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron')
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron/main')
// 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.

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const saveBtn = document.getElementById('save-dialog')

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, nativeImage, shell } = require('electron')
const { app, BrowserWindow, ipcMain, nativeImage, shell } = require('electron/main')
// 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.
let mainWindow

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const dragFileLink = document.getElementById('drag-file-link')

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, shell } = require('electron')
const { app, BrowserWindow, shell } = require('electron/main')
// 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.

View file

@ -1,4 +1,4 @@
const { shell } = require('electron')
const { shell } = require('electron/renderer')
const os = require('node:os')
const exLinksBtn = document.getElementById('open-ex-links')

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, shell } = require('electron')
const { app, BrowserWindow, shell } = require('electron/main')
// 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.

View file

@ -1,4 +1,4 @@
const { app, Tray, Menu, nativeImage } = require('electron')
const { app, Tray, Menu, nativeImage } = require('electron/main')
let tray

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
const path = require('node:path')
function createWindow () {

View file

@ -3,14 +3,11 @@
// For more info, see:
// https://www.electronjs.org/docs/latest/api/screen
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow, screen } = require('electron/main')
let mainWindow = null
app.whenReady().then(() => {
// We cannot require the screen module until the app is ready.
const { screen } = require('electron')
// Create a window that fills the screen's available work area.
const primaryDisplay = screen.getPrimaryDisplay()
const { width, height } = primaryDisplay.workAreaSize

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, clipboard } = require('electron')
const { app, BrowserWindow, ipcMain, clipboard } = require('electron/main')
const path = require('node:path')
let mainWindow = null

View file

@ -1,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')
contextBridge.exposeInMainWorld('clipboard', {
writeText: (text) => ipcRenderer.invoke('clipboard:writeText', text)

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, clipboard } = require('electron')
const { app, BrowserWindow, ipcMain, clipboard } = require('electron/main')
const path = require('node:path')
let mainWindow = null

View file

@ -1,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')
contextBridge.exposeInMainWorld('clipboard', {
readText: () => ipcRenderer.invoke('clipboard:readText'),

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, shell, dialog } = require('electron')
const { app, BrowserWindow, ipcMain, shell, dialog } = require('electron/main')
const path = require('node:path')
let mainWindow

View file

@ -1,11 +1,5 @@
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')
// Set up context bridge between the renderer process and the main process
contextBridge.exposeInMainWorld(
'shell',
{
open: () => ipcRenderer.send('shell:open')
}
)
contextBridge.exposeInMainWorld('shell', {
open: () => ipcRenderer.send('shell:open')
})

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, shell } = require('electron')
const { app, BrowserWindow, ipcMain, shell } = require('electron/main')
let mainWindow = null

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const appInfoBtn = document.getElementById('app-info')

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, shell } = require('electron')
const { app, BrowserWindow, shell } = require('electron/main')
let mainWindow = null

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
const createWindow = () => {
const win = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
const path = require('node:path')
const createWindow = () => {

View file

@ -1,4 +1,4 @@
const { contextBridge } = require('electron')
const { contextBridge } = require('electron/renderer')
contextBridge.exposeInMainWorld('versions', {
node: () => process.versions.node,

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, shell } = require('electron')
const { app, BrowserWindow, ipcMain, shell } = require('electron/main')
ipcMain.on('create-frameless-window', (event, { url }) => {
const win = new BrowserWindow({ frame: false })

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const newWindowBtn = document.getElementById('frameless-window')

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, shell } = require('electron')
const { app, BrowserWindow, ipcMain, shell } = require('electron/main')
ipcMain.on('create-demo-window', (event) => {
const win = new BrowserWindow({ width: 400, height: 275 })

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const manageWindowBtn = document.getElementById('manage-window')

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, shell } = require('electron')
const { app, BrowserWindow, ipcMain, shell } = require('electron/main')
ipcMain.on('new-window', (event, { url, width, height }) => {
const win = new BrowserWindow({ width, height })

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const newWindowBtn = document.getElementById('new-window')

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, shell } = require('electron')
const { app, BrowserWindow, ipcMain, shell } = require('electron/main')
function createWindow () {
// Create the browser window.

View file

@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')
const listenToWindowBtn = document.getElementById('listen-to-window')
const focusModalBtn = document.getElementById('focus-on-modal-window')