Added db resetting.

Use built in signal warning view.
pull/155/head
Mikunj 6 years ago
parent e544cd4c88
commit ac59e1249f

@ -1777,6 +1777,12 @@
"unlock": { "unlock": {
"message": "Unlock" "message": "Unlock"
}, },
"resetDatabase": {
"message": "Reset Database",
"description":
"A button action that the user can click to reset the database"
},
"setPassword": { "setPassword": {
"message": "Set Password", "message": "Set Password",
"description": "Button action that the user can click to set a password" "description": "Button action that the user can click to set a password"

@ -643,6 +643,15 @@ let db;
let filePath; let filePath;
let indexedDBPath; let indexedDBPath;
function _initializePaths(configDir) {
indexedDBPath = path.join(configDir, 'IndexedDB');
const dbDir = path.join(configDir, 'sql');
mkdirp.sync(dbDir);
filePath = path.join(dbDir, 'db.sqlite');
}
async function initialize({ configDir, key }) { async function initialize({ configDir, key }) {
if (db) { if (db) {
throw new Error('Cannot initialize more than once!'); throw new Error('Cannot initialize more than once!');
@ -655,12 +664,7 @@ async function initialize({ configDir, key }) {
throw new Error('initialize: key` is required!'); throw new Error('initialize: key` is required!');
} }
indexedDBPath = path.join(configDir, 'IndexedDB'); _initializePaths(configDir);
const dbDir = path.join(configDir, 'sql');
mkdirp.sync(dbDir);
filePath = path.join(dbDir, 'db.sqlite');
const sqlInstance = await openDatabase(filePath); const sqlInstance = await openDatabase(filePath);
const promisified = promisify(sqlInstance); const promisified = promisify(sqlInstance);
@ -686,11 +690,15 @@ async function close() {
await dbRef.close(); await dbRef.close();
} }
async function removeDB() { async function removeDB(configDir = null) {
if (db) { if (db) {
throw new Error('removeDB: Cannot erase database when it is open!'); throw new Error('removeDB: Cannot erase database when it is open!');
} }
if (!filePath && configDir) {
_initializePaths(configDir);
}
rimraf.sync(filePath); rimraf.sync(filePath);
} }

@ -21,8 +21,9 @@
'click .cancel': 'onCancel', 'click .cancel': 'onCancel',
'click .delete-all-data': 'onDeleteAllData', 'click .delete-all-data': 'onDeleteAllData',
}, },
initialize() { initialize(onClear = null) {
this.step = CLEAR_DATA_STEPS.CHOICE; this.step = CLEAR_DATA_STEPS.CHOICE;
this.onClear = onClear;
}, },
onCancel() { onCancel() {
this.remove(); this.remove();
@ -35,6 +36,9 @@
await this.clearAllData(); await this.clearAllData();
}, },
async clearAllData() { async clearAllData() {
if (this.onClear) {
this.onClear();
} else {
try { try {
await Logs.deleteAll(); await Logs.deleteAll();
@ -50,6 +54,7 @@
); );
} }
window.restart(); window.restart();
}
}, },
render_attributes() { render_attributes() {
return { return {

@ -26,7 +26,7 @@
return { return {
title: i18n('passwordViewTitle'), title: i18n('passwordViewTitle'),
buttonText: i18n('unlock'), buttonText: i18n('unlock'),
resetText: 'Reset Database', resetText: i18n('resetDatabase'),
showReset: this.errorCount >= MIN_LOGIN_TRIES, showReset: this.errorCount >= MIN_LOGIN_TRIES,
}; };
}, },
@ -50,12 +50,11 @@
this.$('.error').text(string); this.$('.error').text(string);
}, },
onReset() { onReset() {
const dialog = new Whisper.ConfirmationDialogView({ const clearDataView = new window.Whisper.ClearDataView(() => {
title: 'Are you sure you want to reset the database?', window.resetDatabase();
message: 'Warning! You will lose all of your messages and contacts when you reset the database.',
okText: 'Reset',
}); });
this.$el.append(dialog.el); clearDataView.render();
this.$el.append(clearDataView.el);
}, },
}); });
})(); })();

@ -747,6 +747,18 @@ function getDefaultSQLKey() {
return key; return key;
} }
async function removeDB() {
const userDir = await getRealPath(app.getPath('userData'));
sql.removeDB(userDir);
try {
userConfig.remove();
ephemeralConfig.remove();
} catch (e) {
console.warn('Remove DB: Failed to remove configs.', e);
}
}
async function showMainWindow(sqlKey) { async function showMainWindow(sqlKey) {
const userDataPath = await getRealPath(app.getPath('userData')); const userDataPath = await getRealPath(app.getPath('userData'));
@ -939,6 +951,12 @@ ipc.on('restart', () => {
app.quit(); app.quit();
}); });
ipc.on('resetDatabase', async () => {
await removeDB();
app.relaunch();
app.quit();
});
ipc.on('set-auto-hide-menu-bar', (event, autoHide) => { ipc.on('set-auto-hide-menu-bar', (event, autoHide) => {
if (mainWindow) { if (mainWindow) {
mainWindow.setAutoHideMenuBar(autoHide); mainWindow.setAutoHideMenuBar(autoHide);

@ -34,25 +34,45 @@
</div> </div>
</script> </script>
<script type='text/x-tmpl-mustache' id='confirmation-dialog'> <script type='text/x-tmpl-mustache' id='clear-data'>
<div class="content"> {{#isStep1}}
{{ #title }} <div class='step'>
<h4>{{ title }}</h4> <div class='inner'>
{{ /title }} <div class='step-body'>
<div class='message'>{{ message }}</div> <span class='banner-icon alert-outline-red'></span>
<div class='buttons'> <div class='header'>{{ header }}</div>
{{ #showCancel }} <div class='body-text-wide'>{{ body }}</div>
<button class='cancel' tabindex='2'>{{ cancel }}</button>
{{ /showCancel }}
<button class='ok' tabindex='1'>{{ ok }}</button>
</div> </div>
<div class='nav'>
<div>
<a class='button neutral cancel'>{{ cancelButton }}</a>
<a class='button destructive delete-all-data'>{{ deleteButton }}</a>
</div> </div>
</div>
</div>
</div>
{{/isStep1}}
{{#isStep2}}
<div id='step3' class='step'>
<div class='inner'>
<div class='step-body'>
<span class='banner-icon delete'></span>
<div class='header'>{{ deleting }}</div>
</div>
<div class='progress'>
<div class='bar-container'>
<div class='bar progress-bar progress-bar-striped active'></div>
</div>
</div>
</div>
</div>
{{/isStep2}}
</script> </script>
<script type='text/javascript' src='js/components.js'></script> <script type='text/javascript' src='js/components.js'></script>
<script type='text/javascript' src='js/views/whisper_view.js'></script> <script type='text/javascript' src='js/views/whisper_view.js'></script>
<script type='text/javascript' src='js/views/password_view.js'></script> <script type='text/javascript' src='js/views/password_view.js'></script>
<script type='text/javascript' src='js/views/confirmation_dialog_view.js'></script> <script type='text/javascript' src='js/views/clear_data_view.js'></script>
</head> </head>
<body> <body>
<div class='app-loading-screen'> <div class='app-loading-screen'>

@ -26,6 +26,10 @@ window.getAppInstance = () => config.appInstance;
window.passwordUtil = require('./app/password_util'); window.passwordUtil = require('./app/password_util');
window.resetDatabase = () => {
window.log.info('reset database');
ipcRenderer.send('resetDatabase');
};
window.onLogin = passPhrase => window.onLogin = passPhrase =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
ipcRenderer.once('password-window-login-response', (event, error) => { ipcRenderer.once('password-window-login-response', (event, error) => {

@ -39,20 +39,12 @@
} }
} }
.confirmation-dialog { .overlay {
display: flex; color: $color-dark-05;
justify-content: center; background: $color-dark-85;
align-items: center;
.ok {
background-color: $color-core-red !important;
color: white;
}
.message { .step {
color: $color-core-red; padding: 0;
font-weight: bolder;
font-style: italic;
} }
} }
} }

Loading…
Cancel
Save