You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-21 23:17:42 +02:00
Assets
CliClient
CliClientDemo
ElectronClient
ReactNativeClient
android
ios
lib
components
screens
shared
config-shared.js
encryption-config-shared.js
note-screen-shared.js
side-menu-shared.js
Dropdown.js
ItemList.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.js
side-menu.js
images
models
services
vendor
ArrayUtils.js
BaseApplication.js
BaseModel.js
BaseSyncTarget.js
Cache.js
JoplinError.js
MdToHtml.js
MdToHtml_Katex.js
ModelCache.js
SyncTargetFilesystem.js
SyncTargetMemory.js
SyncTargetNextcloud.js
SyncTargetOneDrive.js
SyncTargetOneDriveDev.js
SyncTargetRegistry.js
SyncTargetWebDAV.js
WebDavApi.js
database-driver-node.js
database-driver-react-native.js
database.js
dialogs.js
event-dispatcher.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-dummy.js
fs-driver-node.js
fs-driver-rn.js
geolocation-node.js
geolocation-react.js
import-enex-md-gen.js
import-enex.js
joplin-database.js
layout-utils.js
locale.js
log.js
logger.js
markdown-utils.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
react-logger.js
reducer.js
registry.js
shim-init-node.js
shim-init-react.js
shim.js
string-utils.js
synchronizer.js
time-utils.js
urlUtils.js
uuid.js
locales
.babelrc
.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
package-lock.json
package.json
root.js
start_emulator.bat
start_server.bat
start_server.sh
Tools
docs
.gitignore
.travis.yml
BUILD.md
CONTRIBUTING.md
LICENSE
LICENSE_fr
README.md
README_debugging.md
README_desktop.md
README_e2ee.md
README_faq.md
README_spec.md
README_terminal.md
_config.yml
appveyor.yml
joplin.sublime-project
linkToLocal.sh
86 lines
2.2 KiB
JavaScript
86 lines
2.2 KiB
JavaScript
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');
|
|
|
|
const shared = {};
|
|
|
|
shared.constructor = function(comp) {
|
|
comp.state = {
|
|
masterKeys: [],
|
|
passwords: {},
|
|
passwordChecks: {},
|
|
stats: {
|
|
encrypted: null,
|
|
total: null,
|
|
},
|
|
};
|
|
comp.isMounted_ = false;
|
|
|
|
comp.refreshStatsIID_ = null;
|
|
}
|
|
|
|
shared.initState = function(comp, props) {
|
|
comp.setState({
|
|
masterKeys: props.masterKeys,
|
|
passwords: props.passwords ? props.passwords : {},
|
|
}, () => {
|
|
comp.checkPasswords();
|
|
});
|
|
|
|
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);
|
|
}
|
|
|
|
shared.refreshStats = async function(comp) {
|
|
const stats = await BaseItem.encryptedItemsStats();
|
|
comp.setState({ stats: stats });
|
|
}
|
|
|
|
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 });
|
|
}
|
|
|
|
shared.decryptedStatText = function(comp) {
|
|
const stats = comp.state.stats;
|
|
return _('Decrypted items: %s / %s', stats.encrypted !== null ? (stats.total - stats.encrypted) : '-', stats.total !== null ? stats.total : '-');
|
|
}
|
|
|
|
shared.onSavePasswordClick = function(comp, mk) {
|
|
const password = comp.state.passwords[mk.id];
|
|
if (!password) {
|
|
Setting.deleteObjectKey('encryption.passwordCache', mk.id);
|
|
} else {
|
|
Setting.setObjectKey('encryption.passwordCache', mk.id, password);
|
|
}
|
|
|
|
comp.checkPasswords();
|
|
}
|
|
|
|
shared.onPasswordChange = function(comp, mk, password) {
|
|
const passwords = comp.state.passwords;
|
|
passwords[mk.id] = password;
|
|
comp.setState({ passwords: passwords });
|
|
}
|
|
|
|
module.exports = shared; |