|
@ -1,23 +1,21 @@ |
|
|
// @flow
|
|
|
// @flow
|
|
|
|
|
|
|
|
|
import fs from 'fs' |
|
|
|
|
|
import { shell, remote } from 'electron' |
|
|
import { shell, remote } from 'electron' |
|
|
import path from 'path' |
|
|
|
|
|
import rimraf from 'rimraf' |
|
|
|
|
|
import resolveUserDataDirectory from 'helpers/resolveUserDataDirectory' |
|
|
import resolveUserDataDirectory from 'helpers/resolveUserDataDirectory' |
|
|
import { disable as disableDBMiddleware } from 'middlewares/db' |
|
|
import { disable as disableDBMiddleware } from 'middlewares/db' |
|
|
import db from 'helpers/db' |
|
|
import db from 'helpers/db' |
|
|
import { delay } from 'helpers/promise' |
|
|
import { delay } from 'helpers/promise' |
|
|
import killInternalProcess from 'commands/killInternalProcess' |
|
|
import killInternalProcess from 'commands/killInternalProcess' |
|
|
import { DBNotReset } from '@ledgerhq/errors' |
|
|
import libcoreReset from 'commands/libcoreReset' |
|
|
|
|
|
|
|
|
async function resetLibcoreDatabase() { |
|
|
async function resetLibcore() { |
|
|
await killInternalProcess.send().toPromise() |
|
|
// we need to stop everything that is happening right now, like syncs
|
|
|
const dbpath = path.resolve(resolveUserDataDirectory(), 'sqlite/') |
|
|
await killInternalProcess |
|
|
rimraf.sync(dbpath, { glob: false }) |
|
|
.send() |
|
|
if (fs.existsSync(dbpath)) { |
|
|
.toPromise() |
|
|
throw new DBNotReset() |
|
|
.catch(() => {}) // this is a normal error due to the crash of the process, we ignore it
|
|
|
} |
|
|
// we can now ask libcore to reset itself
|
|
|
|
|
|
await libcoreReset.send().toPromise() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function reload() { |
|
|
function reload() { |
|
@ -30,7 +28,7 @@ export async function hardReset() { |
|
|
disableDBMiddleware() |
|
|
disableDBMiddleware() |
|
|
db.resetAll() |
|
|
db.resetAll() |
|
|
await delay(500) |
|
|
await delay(500) |
|
|
await resetLibcoreDatabase() |
|
|
await resetLibcore() |
|
|
reload() |
|
|
reload() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -38,7 +36,7 @@ export async function softReset({ cleanAccountsCache }: *) { |
|
|
cleanAccountsCache() |
|
|
cleanAccountsCache() |
|
|
await delay(500) |
|
|
await delay(500) |
|
|
await db.cleanCache() |
|
|
await db.cleanCache() |
|
|
await resetLibcoreDatabase() |
|
|
await resetLibcore() |
|
|
reload() |
|
|
reload() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|