|
@ -1,23 +1,16 @@ |
|
|
// @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 withLibcore from 'helpers/withLibcore' |
|
|
|
|
|
|
|
|
async function resetLibcoreDatabase() { |
|
|
async function resetLibcore() { |
|
|
await killInternalProcess.send().toPromise() |
|
|
await killInternalProcess.send().toPromise() |
|
|
const dbpath = path.resolve(resolveUserDataDirectory(), 'sqlite/') |
|
|
withLibcore(core => core.freshResetAll()) |
|
|
rimraf.sync(dbpath, { glob: false }) |
|
|
|
|
|
if (fs.existsSync(dbpath)) { |
|
|
|
|
|
throw new DBNotReset() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function reload() { |
|
|
function reload() { |
|
@ -30,7 +23,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 +31,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() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|