2018-11-29 18:51:13 +00:00
|
|
|
const { app, session } = require('electron')
|
|
|
|
|
|
|
|
app.on('ready', async function () {
|
|
|
|
const url = 'http://foo.bar'
|
|
|
|
const persistentSession = session.fromPartition('persist:ence-test')
|
2019-01-25 18:11:35 +00:00
|
|
|
const name = 'test'
|
|
|
|
const value = 'true'
|
2018-11-29 18:51:13 +00:00
|
|
|
|
2019-01-25 18:11:35 +00:00
|
|
|
const set = () => persistentSession.cookies.set({
|
|
|
|
url,
|
|
|
|
name,
|
|
|
|
value,
|
|
|
|
expirationDate: Date.now() + 60000
|
|
|
|
})
|
2018-11-29 18:51:13 +00:00
|
|
|
|
2019-01-25 18:11:35 +00:00
|
|
|
const get = () => persistentSession.cookies.get({
|
|
|
|
url
|
|
|
|
})
|
2018-11-29 18:51:13 +00:00
|
|
|
|
2019-01-25 18:11:35 +00:00
|
|
|
const maybeRemove = async (pred) => new Promise(async (resolve, reject) => {
|
|
|
|
try {
|
2018-11-29 18:51:13 +00:00
|
|
|
if (pred()) {
|
2019-01-25 18:11:35 +00:00
|
|
|
await persistentSession.cookies.remove(url, name)
|
2018-11-29 18:51:13 +00:00
|
|
|
}
|
2019-01-25 18:11:35 +00:00
|
|
|
resolve()
|
|
|
|
} catch (error) {
|
|
|
|
reject(error)
|
|
|
|
}
|
|
|
|
})
|
2018-11-29 18:51:13 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2019-12-13 09:57:02 +00:00
|
|
|
app.quit()
|
2018-11-29 18:51:13 +00:00
|
|
|
}
|
|
|
|
})
|