Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update show me examples #1527

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion static/show-me/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// For more info, see:
// https://electronjs.org/docs/api/app

const { app } = require('electron')
const { app } = require('electron/main')

app.whenReady().then(() => console.log('The app is now ready for action'))

Expand Down
2 changes: 1 addition & 1 deletion static/show-me/autoupdater/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// For more info, see:
// https://electronjs.org/docs/api/auto-updater

const { app, autoUpdater } = require('electron')
const { app, autoUpdater } = require('electron/main')

app.whenReady().then(() => {
const server = 'https://your-deployment-url.com'
Expand Down
8 changes: 2 additions & 6 deletions static/show-me/browserview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@
// https://electronjs.org/docs/api/browser-view

// In the main process.
const { BrowserView, BrowserWindow, app } = require('electron')
const { BrowserView, BrowserWindow, app } = require('electron/main')

app.whenReady().then(() => {
let win = new BrowserWindow({ width: 800, height: 600 })
win.on('closed', () => {
win = null
})

const view = new BrowserView({
webPreferences: {
nodeIntegration: false
}
})
const view = new BrowserView()

win.setBrowserView(view)
view.setBounds({ x: 0, y: 0, width: 300, height: 300 })
Expand Down
2 changes: 1 addition & 1 deletion static/show-me/browserwindow/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// For more info, see:
// https://electronjs.org/docs/api/browser-window

const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')

const windows = []

Expand Down
4 changes: 2 additions & 2 deletions static/show-me/clipboard/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// For more info, see:
// https://electronjs.org/docs/api/clipboard

const { app, BrowserWindow, ipcMain, clipboard } = require('electron')
const path = require('path')
const { app, BrowserWindow, ipcMain, clipboard } = require('electron/main')
const path = require('node:path')

ipcMain.handle('clipboard:readText', () => {
return clipboard.readText()
Expand Down
2 changes: 1 addition & 1 deletion static/show-me/clipboard/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
16 changes: 8 additions & 8 deletions static/show-me/contenttracing/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
// For more info, see:
// https://electronjs.org/docs/api/content-tracing

const { app, contentTracing } = require('electron')
const { app, contentTracing } = require('electron/main')

app.whenReady().then(() => {
const options = {
categoryFilter: '*',
traceOptions: 'record-until-full,enable-sampling'
}

contentTracing.startRecording(options, () => {
contentTracing.startRecording(options).then(() => {
console.log('Tracing started')

setTimeout(() => {
contentTracing.stopRecording('', (path) => {
console.log('Tracing data recorded to ' + path)
})
}, 5000)
})

setTimeout(() => {
contentTracing.stopRecording().then((path) => {
console.log('Tracing data recorded to ' + path)
})
}, 5000)
})
37 changes: 21 additions & 16 deletions static/show-me/cookies/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,41 @@
// For more info, see:
// https://electronjs.org/docs/api/cookies

const { app, BrowserWindow, session } = require('electron')
const { app, BrowserWindow, session } = require('electron/main')

app.whenReady().then(() => {
const mainWindow = new BrowserWindow({
height: 600,
width: 600,
webPreferences: {
nodeIntegration: false
}
width: 600
})

// Once the window has finished loading, let's check out
// the cookies
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.on('did-finish-load', async () => {
// Query all cookies.
session.defaultSession.cookies.get({}, (error, cookies) => {
console.log(error, cookies)
})
try {
const cookies = await session.defaultSession.cookies.get({})
console.log(cookies)
} catch (error) {
console.error(error)
}

// Query all cookies associated with a specific url.
session.defaultSession.cookies.get({ url: 'http://www.github.com' }, (error, cookies) => {
console.log(error, cookies)
})
try {
const cookies = await session.defaultSession.cookies.get({ url: 'http://www.github.com' })
console.log(cookies)
} catch (error) {
console.error(error)
}

// Set a cookie with the given cookie data;
// may overwrite equivalent cookies if they exist.
const cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' }
session.defaultSession.cookies.set(cookie, (error) => {
if (error) console.error(error)
})
try {
const cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' }
await session.defaultSession.cookies.set(cookie)
} catch (error) {
console.error(error)
}
})

mainWindow.loadURL('https://electronjs.org')
Expand Down
12 changes: 6 additions & 6 deletions static/show-me/crashreporter/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// For more info, see:
// https://electronjs.org/docs/api/crash-reporter

const { app, BrowserWindow, crashReporter } = require('electron')
const path = require('path')
const { app, BrowserWindow, crashReporter } = require('electron/main')
const path = require('node:path')

crashReporter.start({
productName: 'YourName',
companyName: 'YourCompany',
globalExtra: {
_companyName: 'YourCompany'
},
submitURL: 'https://your-domain.com/url-to-submit',
uploadToServer: true
})
Expand All @@ -18,14 +20,12 @@ app.whenReady().then(() => {
height: 600,
width: 600,
webPreferences: {
nodeIntegration: false, // default in Electron >= 5
contextIsolation: true, // default in Electron >= 12
preload: path.join(__dirname, 'preload.js')
}
})
mainWindow.loadFile('index.html')

mainWindow.webContents.on('crashed', () => {
mainWindow.webContents.on('render-process-gone', () => {
console.log('Window crashed!')
})
})
2 changes: 1 addition & 1 deletion static/show-me/debugger/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// For more info, see:
// https://electronjs.org/docs/api/debugger

const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow } = require('electron/main')

app.whenReady().then(() => {
const mainWindow = new BrowserWindow({ height: 600, width: 600 })
Expand Down
6 changes: 2 additions & 4 deletions static/show-me/desktopcapturer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
// For more info, see:
// https://electronjs.org/docs/api/desktop-capturer

const { app, BrowserWindow, desktopCapturer } = require('electron')
const path = require('path')
const { app, BrowserWindow, desktopCapturer } = require('electron/main')
const path = require('node:path')

app.whenReady().then(() => {
const mainWindow = new BrowserWindow({
height: 600,
width: 600,
webPreferences: {
nodeIntegration: false, // default in Electron >= 5
contextIsolation: true, // default in Electron >= 12
preload: path.join(__dirname, 'preload.js')
}
})
Expand Down
3 changes: 1 addition & 2 deletions static/show-me/desktopcapturer/preload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { desktopCapturer } = require('electron')
const { ipcRenderer } = require('electron')
const { desktopCapturer, ipcRenderer } = require('electron/renderer')

// The following example shows how to capture video from
// the screen. It also grabs each window, so you could
Expand Down
19 changes: 10 additions & 9 deletions static/show-me/dialog/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
// For more info, see:
// https://electronjs.org/docs/api/dialog

const { app, BrowserWindow, dialog } = require('electron')
const { app, BrowserWindow, dialog } = require('electron/main')

app.whenReady().then(() => {
app.whenReady().then(async () => {
const mainWindow = new BrowserWindow({ height: 600, width: 600 })

// Show an "Open File" dialog and attempt to open
// the chosen file in our window.
dialog.showOpenDialog(mainWindow, {
properties: ['openFile']
}).then(result => {
if (result.canceled) {
try {
const { filePaths, canceled } = await dialog.showOpenDialog(mainWindow, {
properties: ['openFile']
})
if (canceled) {
console.log('Dialog was canceled')
} else {
const file = result.filePaths[0]
const file = filePaths[0]
mainWindow.loadURL(`file://${file}`)
}
}).catch(err => {
} catch (err) {
console.log(err)
})
}
})
2 changes: 1 addition & 1 deletion static/show-me/globalshortcut/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// https://electronjs.org/docs/api/accelerator
// https://electronjs.org/docs/api/global-shortcut

const { app, globalShortcut } = require('electron')
const { app, globalShortcut } = require('electron/main')

app.whenReady().then(() => {
// Register a 'CommandOrControl+Y' shortcut listener.
Expand Down
2 changes: 1 addition & 1 deletion static/show-me/inapppurchase/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// For more info, see:
// https://electronjs.org/docs/api/in-app-purchase

const { app, inAppPurchase } = require('electron')
const { app, inAppPurchase } = require('electron/main')

app.whenReady().then(() => {
// Can the user can make a payment?
Expand Down
6 changes: 2 additions & 4 deletions static/show-me/ipc/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
// https://electronjs.org/docs/api/ipc-main
// https://electronjs.org/docs/api/ipc-renderer

const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const { app, BrowserWindow, ipcMain } = require('electron/main')
const path = require('node:path')

app.whenReady().then(() => {
const mainWindow = new BrowserWindow({
height: 600,
width: 600,
webPreferences: {
nodeIntegration: false, // default in Electron >= 5
contextIsolation: true, // default in Electron >= 12
preload: path.join(__dirname, 'preload.js')
}
})
Expand Down
2 changes: 1 addition & 1 deletion static/show-me/ipc/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')

// prints "pong"
console.log(ipcRenderer.sendSync('synchronous-message', 'ping'))
Expand Down
2 changes: 1 addition & 1 deletion static/show-me/menu/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// For more info, see:
// https://electronjs.org/docs/api/menu

const { app, BrowserWindow, Menu } = require('electron')
const { app, BrowserWindow, Menu } = require('electron/main')

app.whenReady().then(() => {
const mainWindow = new BrowserWindow({ height: 600, width: 600 })
Expand Down
2 changes: 1 addition & 1 deletion static/show-me/nativeimage/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 static/show-me/net/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// For more info, see:
// https://electronjs.org/docs/api/net

const { app, net } = require('electron')
const { app, net } = require('electron/main')

app.whenReady().then(() => {
const request = net.request('https://github.com')
Expand Down
6 changes: 2 additions & 4 deletions static/show-me/notification/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
// https://electronjs.org/docs/api/notification
// https://electronjs.org/docs/tutorial/notifications

const { app, BrowserWindow, Notification } = require('electron')
const path = require('path')
const { app, BrowserWindow, Notification } = require('electron/main')
const path = require('node:path')

app.whenReady().then(() => {
const mainWindow = new BrowserWindow({
height: 600,
width: 600,
webPreferences: {
nodeIntegration: false, // default in Electron >= 5
contextIsolation: true, // default in Electron >= 12
preload: path.join(__dirname, 'preload.js')
}
})
Expand Down
6 changes: 1 addition & 5 deletions static/show-me/powermonitor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
// For more info, see:
// https://electronjs.org/docs/api/power-monitor

const { app } = require('electron')
const { app, powerMonitor } = require('electron/main')

app.whenReady().then(() => {
// We cannot require the "ready" module until
// the app is ready
const { powerMonitor } = require('electron')

powerMonitor.on('suspend', () => {
console.log('The system is going to sleep')
})
Expand Down
2 changes: 1 addition & 1 deletion static/show-me/powersaveblocker/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// For more info, see:
// https://electronjs.org/docs/api/power-save-blocker

const { app, powerSaveBlocker } = require('electron')
const { app, powerSaveBlocker } = require('electron/main')

app.whenReady().then(() => {
const id = powerSaveBlocker.start('prevent-display-sleep')
Expand Down
10 changes: 2 additions & 8 deletions static/show-me/screen/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
// For more info, see:
// https://electronjs.org/docs/api/screen

const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const { app, BrowserWindow, ipcMain, screen } = require('electron/main')
const path = require('node:path')

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()
Expand All @@ -20,8 +16,6 @@ app.whenReady().then(() => {
width,
height,
webPreferences: {
nodeIntegration: false, // default in Electron >= 5
contextIsolation: true, // default in Electron >= 12
preload: path.join(__dirname, 'preload.js')
}
})
Expand Down
Loading