Gaëtan Renaudeau
7 years ago
8 changed files with 50 additions and 45 deletions
@ -1,19 +0,0 @@ |
|||||
// @flow
|
|
||||
|
|
||||
import { createCommand } from 'helpers/ipc' |
|
||||
import { fromPromise } from 'rxjs/observable/fromPromise' |
|
||||
import withLibcore from 'helpers/withLibcore' |
|
||||
import { HardResetFail } from 'config/errors' |
|
||||
|
|
||||
const cmd = createCommand('libcoreHardReset', () => |
|
||||
fromPromise( |
|
||||
withLibcore(async core => { |
|
||||
const result = await core.getPoolInstance().eraseDataSince(new Date(0)) |
|
||||
if (result !== core.ERROR_CODE.FUTURE_WAS_SUCCESSFULL) { |
|
||||
throw new HardResetFail(`Hard reset fail with ${result} (check core.ERROR_CODE)`) |
|
||||
} |
|
||||
}), |
|
||||
), |
|
||||
) |
|
||||
|
|
||||
export default cmd |
|
@ -1,13 +0,0 @@ |
|||||
import libcoreHardReset from 'commands/libcoreHardReset' |
|
||||
import { disable as disableDBMiddleware } from 'middlewares/db' |
|
||||
|
|
||||
import db from 'helpers/db' |
|
||||
import { delay } from 'helpers/promise' |
|
||||
|
|
||||
export default async function hardReset() { |
|
||||
await libcoreHardReset.send() |
|
||||
disableDBMiddleware() |
|
||||
db.resetAll() |
|
||||
await delay(500) |
|
||||
window.location.href = '' |
|
||||
} |
|
@ -0,0 +1,35 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import path from 'path' |
||||
|
import rimraf from 'rimraf' |
||||
|
import resolveUserDataDirectory from 'helpers/resolveUserDataDirectory' |
||||
|
import { disable as disableDBMiddleware } from 'middlewares/db' |
||||
|
import db from 'helpers/db' |
||||
|
import { delay } from 'helpers/promise' |
||||
|
|
||||
|
function resetLibcoreDatabase() { |
||||
|
const dbpath = path.resolve(resolveUserDataDirectory(), 'sqlite/') |
||||
|
rimraf.sync(dbpath, { glob: false }) |
||||
|
} |
||||
|
|
||||
|
function reload() { |
||||
|
require('electron') |
||||
|
.remote.getCurrentWindow() |
||||
|
.webContents.reload() |
||||
|
} |
||||
|
|
||||
|
export async function hardReset() { |
||||
|
resetLibcoreDatabase() |
||||
|
disableDBMiddleware() |
||||
|
db.resetAll() |
||||
|
await delay(500) |
||||
|
reload() |
||||
|
} |
||||
|
|
||||
|
export async function softReset({ cleanAccountsCache }: *) { |
||||
|
resetLibcoreDatabase() |
||||
|
cleanAccountsCache() |
||||
|
await delay(500) |
||||
|
db.cleanCache() |
||||
|
reload() |
||||
|
} |
Loading…
Reference in new issue