Import/Export settings

This commit is contained in:
varjolintu 2019-10-16 15:09:05 +03:00
parent 9edf6d1956
commit f7b5a1ae5d
3 changed files with 103 additions and 3 deletions

View file

@ -531,10 +531,18 @@
"message": "Cancel",
"description": "Cancel button text when removing database key or custom login fields."
},
"optionsButtonReset": {
"optionsButtonReset": {
"message": "Reset",
"description": "Reset button text for keyboard shortcuts."
},
"optionsButtonImport": {
"message": "Import settings",
"description": "Import settings button text."
},
"optionsButtonExport": {
"message": "Export settings",
"description": "Export settings button text."
},
"optionsLabelDefaultGroup": {
"message": "Default group for saving new passwords:",
"description": "Default group options text."
@ -715,6 +723,18 @@
"message": "Error: Shortcut for $1 has not been changed!",
"description": "Error message for changing keyboard shortcuts."
},
"optionsImportExportSettings": {
"message": "Import/Export settings",
"description": "Settings page header text for import/export."
},
"optionsImportSettingsDialogTitle": {
"message": "Import settings from external file?",
"description": "Import settings confirmation dialog title text."
},
"optionsImportSettingsDialogText": {
"message": "Current settings will be overridden. Do you really want to import the settings file?",
"description": "Import settings confirmation dialog help text."
},
"optionsConnectedDatabasesText": {
"message": "The following KeePassXC databases are connected to KeePassXC-Browser.",
"description": "Info text about connected databases."

View file

@ -39,6 +39,12 @@
</p>
<p id="chrome-only"><button class="btn btn-sm btn-primary" id="configureCommands" type="button" data-i18n="[title]openNewTab"><span class="glyphicon glyphicon-cog"></span><span data-i18n="optionsConfigureShortcuts"></span></button></p>
<hr />
<h3 data-i18n="optionsImportExportSettings"></h3>
<p>
<button class="btn btn-sm btn-primary" id="importSettingsButton"><span class="glyphicon glyphicon-save"></span> <span data-i18n="optionsButtonImport"/></button>
<button class="btn btn-sm btn-primary" id="exportSettingsButton"><span class="glyphicon glyphicon-open"></span> <span data-i18n="optionsButtonExport"></span></button>
</p>
<hr />
<p>
<div class="form-group">
<label for="defaultGroup" data-i18n="optionsLabelDefaultGroup"></label>
@ -188,9 +194,25 @@
<span data-i18n="optionsAutoFillAndSendHelpTextSecond"></span>
</span>
</div>
<!--<img src="/options/http-auth-dialog.png" alt="http-auth-dialog" />-->
<img src="/options/http-auth-dialog.png" data-i18n="[alt]httpAuthDialog"/>
<img src="/options/http-auth-dialog.png" data-i18n="[alt]httpAuthDialog"/>
</p>
<div id="dialogImportSettings" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 class="modal-title" id="myModalLabel" data-i18n="optionsImportSettingsDialogTitle"></h3>
</div>
<div class="modal-body">
<p data-i18n="optionsImportSettingsDialogText"></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove"></span> <span data-i18n="optionsButtonCancel"></span></button>
<button class="btn yes btn-primary" autofocus><span class="glyphicon glyphicon-ok"></span> <span data-i18n="optionsButtonImport"></span></button>
</div>
</div>
</div>
</div>
</div>
<!-- Connected Databases -->

View file

@ -162,6 +162,64 @@ options.initGeneralSettings = function() {
options.settings['defaultGroup'] = '';
options.saveSettings();
});
let temporarySettings;
$('#dialogImportSettings').modal({ keyboard: true, show: false, backdrop: true });
$('#importSettingsButton').click(function() {
var link = document.createElement('input');
link.setAttribute('type', 'file');
link.onchange = function(e) {
const reader = new FileReader();
if (e.target.files.length > 0) {
reader.readAsText(e.target.files[0]);
}
reader.onloadend = function(e) {
try {
const contents = JSON.parse(e.target.result);
// A quick check that this is the KeePassXC-Browser settings file
if (!contents['checkUpdateKeePassXC'] ||
!contents['autoCompleteUsernames'] ||
!contents['autoFillAndSend']) {
console.log('Error: Not a KeePassXC-Browser settings file.');
return;
}
// Verify the import
temporarySettings = contents;
$('#dialogImportSettings').data('hash', $(this).closest('tr').data('hash'));
$('#dialogImportSettings .modal-body:first span:first').text($(this).closest('tr').children('td:first').text());
$('#dialogImportSettings').modal('show');
$('#dialogImportSettings').on('shown.bs.modal', () => {
$('#dialogImportSettings').find('[autofocus]').focus();
});
} catch (e) {
console.log('Error loading JSON settings file.');
}
};
};
link.click();
});
$('#exportSettingsButton').click(function() {
const link = document.createElement('a');
const file = new Blob([ JSON.stringify(options.settings)], { type: 'application/json' });
link.href = URL.createObjectURL(file);
link.download = 'keepassxc-browser_settings.json';
link.click();
});
$('#dialogImportSettings .modal-footer:first button.yes:first').click(function(e) {
$('#dialogImportSettings').modal('hide');
if (temporarySettings) {
options.settings = temporarySettings;
options.saveSettings();
}
});
};
options.showKeePassXCVersions = function(response) {