chore: update show me examples (#1527) · electron/fiddle@fe192ae · GitHub
Skip to content

Commit fe192ae

Browse files
authored
chore: update show me examples (#1527)
1 parent 54d9012 commit fe192ae

34 files changed

Lines changed: 84 additions & 101 deletions

File tree

‎static/show-me/app/main.js‎

Lines changed: 1 addition & 1 deletion

‎static/show-me/autoupdater/main.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For more info, see:
44
// https://electronjs.org/docs/api/auto-updater
55

6-
const { app, autoUpdater } = require('electron')
6+
const { app, autoUpdater } = require('electron/main')
77

88
app.whenReady().then(() => {
99
const server = 'https://your-deployment-url.com'

‎static/show-me/browserview/main.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66
// https://electronjs.org/docs/api/browser-view
77

88
// In the main process.
9-
const { BrowserView, BrowserWindow, app } = require('electron')
9+
const { BrowserView, BrowserWindow, app } = require('electron/main')
1010

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

17-
const view = new BrowserView({
18-
webPreferences: {
19-
nodeIntegration: false
20-
}
21-
})
17+
const view = new BrowserView()
2218

2319
win.setBrowserView(view)
2420
view.setBounds({ x: 0, y: 0, width: 300, height: 300 })

‎static/show-me/browserwindow/main.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// For more info, see:
55
// https://electronjs.org/docs/api/browser-window
66

7-
const { app, BrowserWindow } = require('electron')
7+
const { app, BrowserWindow } = require('electron/main')
88

99
const windows = []
1010

‎static/show-me/clipboard/main.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// For more info, see:
44
// https://electronjs.org/docs/api/clipboard
55

6-
const { app, BrowserWindow, ipcMain, clipboard } = require('electron')
7-
const path = require('path')
6+
const { app, BrowserWindow, ipcMain, clipboard } = require('electron/main')
7+
const path = require('node:path')
88

99
ipcMain.handle('clipboard:readText', () => {
1010
return clipboard.readText()

‎static/show-me/clipboard/preload.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { contextBridge, ipcRenderer } = require('electron')
1+
const { contextBridge, ipcRenderer } = require('electron/renderer')
22

33
contextBridge.exposeInMainWorld('clipboard', {
44
readText: () => ipcRenderer.invoke('clipboard:readText'),

‎static/show-me/contenttracing/main.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
// For more info, see:
99
// https://electronjs.org/docs/api/content-tracing
1010

11-
const { app, contentTracing } = require('electron')
11+
const { app, contentTracing } = require('electron/main')
1212

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

19-
contentTracing.startRecording(options, () => {
19+
contentTracing.startRecording(options).then(() => {
2020
console.log('Tracing started')
21-
22-
setTimeout(() => {
23-
contentTracing.stopRecording('', (path) => {
24-
console.log('Tracing data recorded to ' + path)
25-
})
26-
}, 5000)
2721
})
22+
23+
setTimeout(() => {
24+
contentTracing.stopRecording().then((path) => {
25+
console.log('Tracing data recorded to ' + path)
26+
})
27+
}, 5000)
2828
})

‎static/show-me/cookies/main.js‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,41 @@
33
// For more info, see:
44
// https://electronjs.org/docs/api/cookies
55

6-
const { app, BrowserWindow, session } = require('electron')
6+
const { app, BrowserWindow, session } = require('electron/main')
77

88
app.whenReady().then(() => {
99
const mainWindow = new BrowserWindow({
1010
height: 600,
11-
width: 600,
12-
webPreferences: {
13-
nodeIntegration: false
14-
}
11+
width: 600
1512
})
1613

1714
// Once the window has finished loading, let's check out
1815
// the cookies
19-
mainWindow.webContents.on('did-finish-load', () => {
16+
mainWindow.webContents.on('did-finish-load', async () => {
2017
// Query all cookies.
21-
session.defaultSession.cookies.get({}, (error, cookies) => {
22-
console.log(error, cookies)
23-
})
18+
try {
19+
const cookies = await session.defaultSession.cookies.get({})
20+
console.log(cookies)
21+
} catch (error) {
22+
console.error(error)
23+
}
2424

2525
// Query all cookies associated with a specific url.
26-
session.defaultSession.cookies.get({ url: 'http://www.github.com' }, (error, cookies) => {
27-
console.log(error, cookies)
28-
})
26+
try {
27+
const cookies = await session.defaultSession.cookies.get({ url: 'http://www.github.com' })
28+
console.log(cookies)
29+
} catch (error) {
30+
console.error(error)
31+
}
2932

3033
// Set a cookie with the given cookie data;
3134
// may overwrite equivalent cookies if they exist.
32-
const cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' }
33-
session.defaultSession.cookies.set(cookie, (error) => {
34-
if (error) console.error(error)
35-
})
35+
try {
36+
const cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' }
37+
await session.defaultSession.cookies.set(cookie)
38+
} catch (error) {
39+
console.error(error)
40+
}
3641
})
3742

3843
mainWindow.loadURL('https://electronjs.org')

‎static/show-me/crashreporter/main.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
// For more info, see:
44
// https://electronjs.org/docs/api/crash-reporter
55

6-
const { app, BrowserWindow, crashReporter } = require('electron')
7-
const path = require('path')
6+
const { app, BrowserWindow, crashReporter } = require('electron/main')
7+
const path = require('node:path')
88

99
crashReporter.start({
1010
productName: 'YourName',
11-
companyName: 'YourCompany',
11+
globalExtra: {
12+
_companyName: 'YourCompany'
13+
},
1214
submitURL: 'https://your-domain.com/url-to-submit',
1315
uploadToServer: true
1416
})
@@ -18,14 +20,12 @@ app.whenReady().then(() => {
1820
height: 600,
1921
width: 600,
2022
webPreferences: {
21-
nodeIntegration: false, // default in Electron >= 5
22-
contextIsolation: true, // default in Electron >= 12
2323
preload: path.join(__dirname, 'preload.js')
2424
}
2525
})
2626
mainWindow.loadFile('index.html')
2727

28-
mainWindow.webContents.on('crashed', () => {
28+
mainWindow.webContents.on('render-process-gone', () => {
2929
console.log('Window crashed!')
3030
})
3131
})

‎static/show-me/debugger/main.js‎

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)