You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-12 22:57:38 +02:00
All: getting encryption service and UI to work
This commit is contained in:
@ -8,6 +8,16 @@ class DecryptionWorker {
|
||||
this.dispatch = (action) => {
|
||||
console.warn('DecryptionWorker.dispatch is not defined');
|
||||
};
|
||||
|
||||
this.scheduleId_ = null;
|
||||
}
|
||||
|
||||
setLogger(l) {
|
||||
this.logger_ = l;
|
||||
}
|
||||
|
||||
logger() {
|
||||
return this.logger_;
|
||||
}
|
||||
|
||||
static instance() {
|
||||
@ -16,11 +26,24 @@ class DecryptionWorker {
|
||||
return this.instance_;
|
||||
}
|
||||
|
||||
static encryptionService() {
|
||||
setEncryptionService(v) {
|
||||
this.encryptionService_ = v;
|
||||
}
|
||||
|
||||
encryptionService() {
|
||||
if (!this.encryptionService_) throw new Error('DecryptionWorker.encryptionService_ is not set!!');
|
||||
return this.encryptionService_;
|
||||
}
|
||||
|
||||
async scheduleStart() {
|
||||
if (this.scheduleId_) return;
|
||||
|
||||
this.scheduleId_ = setTimeout(() => {
|
||||
this.scheduleId_ = null;
|
||||
this.start();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
async start() {
|
||||
if (this.state_ !== 'idle') return;
|
||||
|
||||
@ -28,30 +51,36 @@ class DecryptionWorker {
|
||||
|
||||
let excludedIds = [];
|
||||
|
||||
while (true) {
|
||||
const result = await BaseItem.itemsThatNeedDecryption(excludedIds);
|
||||
const items = result.items;
|
||||
try {
|
||||
while (true) {
|
||||
const result = await BaseItem.itemsThatNeedDecryption(excludedIds);
|
||||
const items = result.items;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
const ItemClass = BaseItem.itemClass(item);
|
||||
try {
|
||||
await ItemClass.decrypt(item);
|
||||
} catch (error) {
|
||||
if (error.code === 'missingMasterKey') {
|
||||
excludedIds.push(item.id);
|
||||
this.dispatch({
|
||||
type: 'MASTERKEY_ADD_MISSING',
|
||||
id: error.masterKeyId,
|
||||
});
|
||||
continue;
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
const ItemClass = BaseItem.itemClass(item);
|
||||
try {
|
||||
await ItemClass.decrypt(item);
|
||||
} catch (error) {
|
||||
if (error.code === 'missingMasterKey') {
|
||||
excludedIds.push(item.id);
|
||||
this.dispatch({
|
||||
type: 'MASTERKEY_ADD_MISSING',
|
||||
id: error.masterKeyId,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.hasMore) break;
|
||||
if (!result.hasMore) break;
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger().error('DecryptionWorker::start:', error);
|
||||
}
|
||||
|
||||
this.state_ = 'idle';
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user