1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-03-29 21:21:15 +02:00

All: Started resource fetcher service when a note has been decrypted

This commit is contained in:
Laurent Cozic 2020-04-19 10:11:46 +01:00
parent ab63316f83
commit 2b2ec2c655
4 changed files with 31 additions and 3 deletions

View File

@ -1,5 +1,6 @@
const Setting = require('lib/models/Setting'); const Setting = require('lib/models/Setting');
const Tag = require('lib/models/Tag'); const Tag = require('lib/models/Tag');
const BaseModel = require('lib/BaseModel');
const Note = require('lib/models/Note'); const Note = require('lib/models/Note');
const { reg } = require('lib/registry.js'); const { reg } = require('lib/registry.js');
const ResourceFetcher = require('lib/services/ResourceFetcher'); const ResourceFetcher = require('lib/services/ResourceFetcher');
@ -18,8 +19,14 @@ const reduxSharedMiddleware = async function(store, next, action) {
reg.resetSyncTarget(); reg.resetSyncTarget();
} }
let mustAutoAddResources = false;
if (action.type === 'SETTING_UPDATE_ONE' && action.key === 'sync.resourceDownloadMode') { if (action.type === 'SETTING_UPDATE_ONE' && action.key === 'sync.resourceDownloadMode') {
ResourceFetcher.instance().autoAddResources(); mustAutoAddResources = true;
}
if (action.type === 'DECRYPTION_WORKER_SET' && action.state === 'idle' && action.decryptedItemCounts && !!action.decryptedItemCounts[BaseModel.TYPE_NOTE]) {
mustAutoAddResources = true;
} }
// In general the DecryptionWorker is started via events, such as when an encrypted note // In general the DecryptionWorker is started via events, such as when an encrypted note
@ -70,6 +77,9 @@ const reduxSharedMiddleware = async function(store, next, action) {
}); });
} }
if (mustAutoAddResources) {
ResourceFetcher.instance().autoAddResources();
}
if (refreshTags) { if (refreshTags) {
store.dispatch({ store.dispatch({

View File

@ -45,6 +45,7 @@ const defaultState = {
state: 'idle', state: 'idle',
itemIndex: 0, itemIndex: 0,
itemCount: 0, itemCount: 0,
decryptedItemCounts: {},
}, },
selectedNoteTags: [], selectedNoteTags: [],
resourceFetcher: { resourceFetcher: {
@ -415,6 +416,8 @@ function removeItemFromArray(array, property, value) {
} }
const reducer = (state = defaultState, action) => { const reducer = (state = defaultState, action) => {
// if (!['SIDE_MENU_OPEN_PERCENT'].includes(action.type)) console.info('Action', action.type);
let newState = state; let newState = state;
try { try {

View File

@ -137,6 +137,7 @@ class DecryptionWorker {
this.state_ = 'started'; this.state_ = 'started';
const excludedIds = []; const excludedIds = [];
const decryptedItemCounts = {};
this.dispatch({ type: 'ENCRYPTION_HAS_DISABLED_ITEMS', value: false }); this.dispatch({ type: 'ENCRYPTION_HAS_DISABLED_ITEMS', value: false });
this.dispatchReport({ state: 'started' }); this.dispatchReport({ state: 'started' });
@ -179,6 +180,10 @@ class DecryptionWorker {
await clearDecryptionCounter(); await clearDecryptionCounter();
if (!decryptedItemCounts[decryptedItem.type_]) decryptedItemCounts[decryptedItem.type_] = 0;
decryptedItemCounts[decryptedItem.type_]++;
if (decryptedItem.type_ === Resource.modelType() && !!decryptedItem.encryption_blob_encrypted) { if (decryptedItem.type_ === Resource.modelType() && !!decryptedItem.encryption_blob_encrypted) {
// itemsThatNeedDecryption() will return the resource again if the blob has not been decrypted, // itemsThatNeedDecryption() will return the resource again if the blob has not been decrypted,
// but that will result in an infinite loop if the blob simply has not been downloaded yet. // but that will result in an infinite loop if the blob simply has not been downloaded yet.
@ -240,7 +245,10 @@ class DecryptionWorker {
this.state_ = 'idle'; this.state_ = 'idle';
this.dispatchReport({ state: 'idle' }); this.dispatchReport({
state: 'idle',
decryptedItemCounts: decryptedItemCounts,
});
if (downloadedButEncryptedBlobCount) { if (downloadedButEncryptedBlobCount) {
this.logger().info(`DecryptionWorker: Some resources have been downloaded but are not decrypted yet. Scheduling another decryption. Resource count: ${downloadedButEncryptedBlobCount}`); this.logger().info(`DecryptionWorker: Some resources have been downloaded but are not decrypted yet. Scheduling another decryption. Resource count: ${downloadedButEncryptedBlobCount}`);

View File

@ -8,7 +8,7 @@
// console.disableYellowBox = true // console.disableYellowBox = true
import { YellowBox, AppRegistry } from 'react-native'; import { YellowBox, AppRegistry, NativeModules } from 'react-native';
YellowBox.ignoreWarnings([ YellowBox.ignoreWarnings([
'Require cycle: node_modules/react-native-', 'Require cycle: node_modules/react-native-',
'Require cycle: node_modules/rn-fetch-blob', 'Require cycle: node_modules/rn-fetch-blob',
@ -18,6 +18,13 @@ YellowBox.ignoreWarnings([
]); ]);
const { Root } = require('./root.js'); const { Root } = require('./root.js');
// Disable buggy Fast Refresh
if (__DEV__) {
const { DevSettings } = NativeModules;
DevSettings.setHotLoadingEnabled(false);
DevSettings.setLiveReloadEnabled(false);
}
function main() { function main() {
AppRegistry.registerComponent('Joplin', () => Root); AppRegistry.registerComponent('Joplin', () => Root);
console.ignoredYellowBox = ['Remote debugger']; console.ignoredYellowBox = ['Remote debugger'];