c83f836faf
* docs: add references to app.whenReady() in isReady * refactor: prefer app.whenReady() In the docs, specs, and lib, replace instances of `app.once('ready')` (seen occasionally) and `app.on('ready')` (extremely common) with `app.whenReady()`. It's better to encourage users to use whenReady(): 1. it handles the edge case of registering for 'ready' after it's fired 2. it avoids the minor wart of leaving an active listener alive for an event that wll never fire again
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
const { app, session } = require('electron')
|
|
|
|
app.whenReady().then(async function () {
|
|
const url = 'http://foo.bar'
|
|
const persistentSession = session.fromPartition('persist:ence-test')
|
|
const name = 'test'
|
|
const value = 'true'
|
|
|
|
const set = () => persistentSession.cookies.set({
|
|
url,
|
|
name,
|
|
value,
|
|
expirationDate: Date.now() + 60000
|
|
})
|
|
|
|
const get = () => persistentSession.cookies.get({
|
|
url
|
|
})
|
|
|
|
const maybeRemove = async (pred) => new Promise(async (resolve, reject) => {
|
|
try {
|
|
if (pred()) {
|
|
await persistentSession.cookies.remove(url, name)
|
|
}
|
|
resolve()
|
|
} catch (error) {
|
|
reject(error)
|
|
}
|
|
})
|
|
|
|
try {
|
|
await maybeRemove(() => process.env.PHASE === 'one')
|
|
const one = await get()
|
|
await set()
|
|
const two = await get()
|
|
await maybeRemove(() => process.env.PHASE === 'two')
|
|
const three = await get()
|
|
|
|
process.stdout.write(`${one.length}${two.length}${three.length}`)
|
|
} catch (e) {
|
|
process.stdout.write('ERROR')
|
|
} finally {
|
|
process.stdout.end()
|
|
|
|
app.quit()
|
|
}
|
|
})
|