Skip to content

Commit

Permalink
docs: use electron/main & electron/renderer imports in fiddles (elect…
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak authored Aug 28, 2023
1 parent d42a94d commit f2f83a7
Show file tree
Hide file tree
Showing 70 changed files with 78 additions and 88 deletions.
2 changes: 1 addition & 1 deletion docs/fiddles/features/dark-mode/main.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/dark-mode/preload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')

contextBridge.exposeInMainWorld('darkMode', {
toggle: () => ipcRenderer.invoke('dark-mode:toggle'),
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/drag-and-drop/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/main')
const path = require('node:path')
const fs = require('node:fs')
const https = require('node:https')
Expand Down
6 changes: 2 additions & 4 deletions docs/fiddles/features/drag-and-drop/preload.js
Original file line number Diff line number Diff line change
@@ -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)
})
2 changes: 1 addition & 1 deletion docs/fiddles/features/keyboard-shortcuts/global/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow, globalShortcut } = require('electron')
const { app, BrowserWindow, globalShortcut } = require('electron/main')

function createWindow () {
const win = new BrowserWindow({
Expand Down
Original file line number Diff line number Diff line change
@@ -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 })
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
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/keyboard-shortcuts/web-apis/main.js
Original file line number Diff line number Diff line change
@@ -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.
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
@@ -1,4 +1,4 @@
const { app, BrowserWindow, Menu } = require('electron')
const { app, BrowserWindow, Menu } = require('electron/main')

function createWindow () {
const win = new BrowserWindow({
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/notifications/main/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow, Notification } = require('electron')
const { app, BrowserWindow, Notification } = require('electron/main')

function createWindow () {
const win = new BrowserWindow({
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/notifications/renderer/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')

function createWindow () {
const win = new BrowserWindow({
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/offscreen-rendering/main.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/online-detection/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')

function createWindow () {
const onlineStatusWindow = new BrowserWindow({
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/progress-bar/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')

let progressInterval

Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/recent-documents/main.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/represented-file/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
const os = require('node:os')

function createWindow () {
Expand Down
2 changes: 1 addition & 1 deletion 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/main')
const path = require('node:path')

let bluetoothPinCallback
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
@@ -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),
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/web-hid/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')

function createWindow () {
const mainWindow = new BrowserWindow({
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/web-serial/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')

function createWindow () {
const mainWindow = new BrowserWindow({
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/features/web-usb/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')

function createWindow () {
const mainWindow = new BrowserWindow({
Expand Down
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/main')
const path = require('node: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,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')

contextBridge.exposeInMainWorld('electronAPI', {
setTitle: (title) => ipcRenderer.send('set-title', title)
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/ipc/pattern-2/main.js
Original file line number Diff line number Diff line change
@@ -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 () {
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,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')

contextBridge.exposeInMainWorld('electronAPI', {
openFile: () => ipcRenderer.invoke('dialog:openFile')
Expand Down
2 changes: 1 addition & 1 deletion 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/main')
const path = require('node:path')

function createWindow () {
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/ipc/pattern-3/preload.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/ipc/webview-new-window/main.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/ipc/webview-new-window/preload.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/media/screenshot/take-screenshot/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { BrowserWindow, app, screen, ipcMain, desktopCapturer } = require('electron')
const { BrowserWindow, app, screen, ipcMain, desktopCapturer } = require('electron/main')

let mainWindow = null

Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/media/screenshot/take-screenshot/renderer.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
9 changes: 5 additions & 4 deletions docs/fiddles/menus/customize-menus/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }))
Expand Down Expand Up @@ -185,7 +186,7 @@ function addUpdateMenuItems (items, position) {
visible: false,
key: 'checkForUpdate',
click: () => {
require('electron').autoUpdater.checkForUpdates()
autoUpdater.checkForUpdates()
}
},
{
Expand All @@ -194,7 +195,7 @@ function addUpdateMenuItems (items, position) {
visible: false,
key: 'restartToUpdate',
click: () => {
require('electron').autoUpdater.quitAndInstall()
autoUpdater.quitAndInstall()
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/menus/customize-menus/renderer.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/menus/shortcuts/main.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/native-ui/dialogs/error-dialog/main.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/native-ui/dialogs/error-dialog/renderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')

const errorBtn = document.getElementById('error-dialog')

Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/native-ui/dialogs/information-dialog/main.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')

const informationBtn = document.getElementById('information-dialog')

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')

const selectDirBtn = document.getElementById('select-directory')

Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/native-ui/dialogs/save-dialog/main.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/native-ui/dialogs/save-dialog/renderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')

const saveBtn = document.getElementById('save-dialog')

Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/native-ui/drag-and-drop/main.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/native-ui/drag-and-drop/renderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ipcRenderer } = require('electron')
const { ipcRenderer } = require('electron/renderer')

const dragFileLink = document.getElementById('drag-file-link')

Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/native-ui/external-links-file-manager/main.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/native-ui/notifications/main.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/native-ui/tray/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/fiddles/quick-start/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')
const path = require('node:path')

function createWindow () {
Expand Down
5 changes: 1 addition & 4 deletions docs/fiddles/screen/fit-screen/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/system/clipboard/copy/main.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/system/clipboard/copy/preload.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/system/clipboard/paste/main.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/fiddles/system/clipboard/paste/preload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { contextBridge, ipcRenderer } = require('electron')
const { contextBridge, ipcRenderer } = require('electron/renderer')

contextBridge.exposeInMainWorld('clipboard', {
readText: () => ipcRenderer.invoke('clipboard:readText'),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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')
})
Loading

0 comments on commit f2f83a7

Please sign in to comment.