1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-18 23:07:45 +02:00
Files
.github
Assets
CliClient
Clipper
ElectronClient
ReactNativeClient
android
ios
lib
components
screens
shared
config-shared.js
dropbox-login-shared.js
encryption-config-shared.js
note-screen-shared.js
reduxSharedMiddleware.js
side-menu-shared.js
CameraView.js
Dropdown.js
ItemList.js
ModalDialog.js
SaveIcon.png
action-button.js
app-nav.js
base-screen.js
checkbox.js
global-style.js
note-body-viewer.js
note-item.js
note-list.js
screen-header.js
select-date-time-dialog.js
side-menu-content-note.js
side-menu-content.js
side-menu.js
images
migrations
models
renderers
services
vendor
ArrayUtils.js
BaseApplication.js
BaseModel.js
BaseSyncTarget.js
Cache.js
ClipperServer.js
DropboxApi.js
EventDispatcher.js
HtmlToMd.js
JoplinError.js
ModelCache.js
ObjectUtils.js
SyncTargetDropbox.js
SyncTargetFilesystem.js
SyncTargetMemory.js
SyncTargetNextcloud.js
SyncTargetOneDrive.js
SyncTargetOneDriveDev.js
SyncTargetRegistry.js
SyncTargetWebDAV.js
TaskQueue.js
TemplateUtils.js
WebDavApi.js
WelcomeUtils.js
database-driver-node.js
database-driver-react-native.js
database.js
dialogs.js
file-api-driver-dropbox.js
file-api-driver-local.js
file-api-driver-memory.js
file-api-driver-onedrive.js
file-api-driver-webdav.js
file-api.js
folders-screen-utils.js
fs-driver-base.js
fs-driver-dummy.js
fs-driver-node.js
fs-driver-rn.js
geolocation-node.js
geolocation-react.js
htmlUtils.js
import-enex-html-gen.js
import-enex-md-gen.js
import-enex.js
joplin-database.js
layout-utils.js
locale.js
logger.js
markJsUtils.js
markdownUtils.js
markupLanguageUtils.js
mime-utils.js
net-utils.js
onedrive-api.js
package.json
parameters.js
parseUri.js
path-utils.js
poor-man-intervals.js
promise-utils.js
randomClipperPort.js
react-logger.js
reducer.js
registry.js
resourceUtils.js
shim-init-node.js
shim-init-react.js
shim.js
string-utils-common.js
string-utils.js
synchronizer.js
time-utils.js
urlUtils.js
uuid.js
welcomeAssets.js
locales
.buckconfig
.flowconfig
.gitattributes
.gitignore
.watchmanconfig
app.json
build_android.bat
build_android_prod.bat
clean_build.bat
debug_log.bat
debug_log.sh
index.android.js
index.ios.js
index.js
main.js
metro.config.js
package-lock.json
package.json
root.js
run_ios.sh
start_server.bat
start_server.sh
Tools
docs
readme
.eslintignore
.eslintrc.js
.gitignore
.travis.yml
BUILD.md
CONTRIBUTING.md
Joplin_install_and_update.sh
LICENSE
README.md
SECURITY.md
_config.yml
appveyor.yml
joplin.code-workspace
joplin.sublime-project
linkToLocal.sh
package-lock.json
package.json
joplin/ReactNativeClient/lib/components/shared/encryption-config-shared.js

92 lines
2.3 KiB
JavaScript
Raw Normal View History

const EncryptionService = require('lib/services/EncryptionService');
const { _ } = require('lib/locale.js');
const BaseItem = require('lib/models/BaseItem.js');
const Setting = require('lib/models/Setting.js');
2017-12-30 20:57:34 +01:00
const shared = {};
shared.constructor = function(comp) {
comp.state = {
masterKeys: [],
passwords: {},
passwordChecks: {},
stats: {
encrypted: null,
total: null,
},
};
comp.isMounted_ = false;
comp.refreshStatsIID_ = null;
2019-07-29 15:43:53 +02:00
};
2017-12-30 20:57:34 +01:00
shared.initState = function(comp, props) {
2019-07-29 15:43:53 +02:00
comp.setState(
{
masterKeys: props.masterKeys,
passwords: props.passwords ? props.passwords : {},
},
() => {
comp.checkPasswords();
}
);
2017-12-30 20:57:34 +01:00
comp.refreshStats();
if (comp.refreshStatsIID_) {
clearInterval(comp.refreshStatsIID_);
comp.refreshStatsIID_ = null;
}
comp.refreshStatsIID_ = setInterval(() => {
if (!comp.isMounted_) {
clearInterval(comp.refreshStatsIID_);
comp.refreshStatsIID_ = null;
return;
}
comp.refreshStats();
}, 3000);
2019-07-29 15:43:53 +02:00
};
2017-12-30 20:57:34 +01:00
shared.refreshStats = async function(comp) {
const stats = await BaseItem.encryptedItemsStats();
comp.setState({ stats: stats });
2019-07-29 15:43:53 +02:00
};
2017-12-30 20:57:34 +01:00
shared.checkPasswords = async function(comp) {
const passwordChecks = Object.assign({}, comp.state.passwordChecks);
for (let i = 0; i < comp.state.masterKeys.length; i++) {
const mk = comp.state.masterKeys[i];
const password = comp.state.passwords[mk.id];
const ok = password ? await EncryptionService.instance().checkMasterKeyPassword(mk, password) : false;
passwordChecks[mk.id] = ok;
}
comp.setState({ passwordChecks: passwordChecks });
2019-07-29 15:43:53 +02:00
};
2017-12-30 20:57:34 +01:00
shared.decryptedStatText = function(comp) {
const stats = comp.state.stats;
2019-07-29 15:43:53 +02:00
const doneCount = stats.encrypted !== null ? stats.total - stats.encrypted : '-';
const totalCount = stats.total !== null ? stats.total : '-';
return _('Decrypted items: %s / %s', doneCount, totalCount);
2019-07-29 15:43:53 +02:00
};
2017-12-30 20:57:34 +01:00
shared.onSavePasswordClick = function(comp, mk) {
const password = comp.state.passwords[mk.id];
if (!password) {
Setting.deleteObjectKey('encryption.passwordCache', mk.id);
2017-12-30 20:57:34 +01:00
} else {
Setting.setObjectKey('encryption.passwordCache', mk.id, password);
2017-12-30 20:57:34 +01:00
}
comp.checkPasswords();
2019-07-29 15:43:53 +02:00
};
2017-12-30 20:57:34 +01:00
shared.onPasswordChange = function(comp, mk, password) {
const passwords = comp.state.passwords;
passwords[mk.id] = password;
comp.setState({ passwords: passwords });
2019-07-29 15:43:53 +02:00
};
2017-12-30 20:57:34 +01:00
2019-07-29 15:43:53 +02:00
module.exports = shared;