You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-12 22:57:38 +02:00
* Allow downloading resources automatically, on demand, or when loading note * Make needToBeFetched calls to return the right number of resources * All: Improved handling of resource downloading and decryption * Desktop: Click on resource to download it (and, optionally, to decrypt it) * Desktop: Better handling of resource state (not downloaded, downloading, encrypted) in front end * Renamed setting to sync.resourceDownloadMode * Download resources when changing setting * tweaks * removed duplicate cs * Better report resource download progress * Make sure resource cache is properly cleared when needed * Also handle manual download for non-image resources * More improvements to logic when downloading and decrypting resources
This commit is contained in:
@ -3,6 +3,8 @@ const Folder = require('lib/models/Folder.js');
|
||||
const BaseModel = require('lib/BaseModel.js');
|
||||
const Note = require('lib/models/Note.js');
|
||||
const Resource = require('lib/models/Resource.js');
|
||||
const ResourceFetcher = require('lib/services/ResourceFetcher.js');
|
||||
const DecryptionWorker = require('lib/services/DecryptionWorker.js');
|
||||
const Setting = require('lib/models/Setting.js');
|
||||
const Mutex = require('async-mutex').Mutex;
|
||||
|
||||
@ -154,7 +156,11 @@ shared.noteComponent_change = function(comp, propName, propValue) {
|
||||
comp.setState(newState);
|
||||
}
|
||||
|
||||
const resourceCache_ = {};
|
||||
let resourceCache_ = {};
|
||||
|
||||
shared.clearResourceCache = function() {
|
||||
resourceCache_ = {};
|
||||
}
|
||||
|
||||
shared.attachedResources = async function(noteBody) {
|
||||
if (!noteBody) return {};
|
||||
@ -163,14 +169,20 @@ shared.attachedResources = async function(noteBody) {
|
||||
const output = {};
|
||||
for (let i = 0; i < resourceIds.length; i++) {
|
||||
const id = resourceIds[i];
|
||||
|
||||
if (resourceCache_[id]) {
|
||||
output[id] = resourceCache_[id];
|
||||
} else {
|
||||
const resource = await Resource.load(id);
|
||||
const isReady = await Resource.isReady(resource);
|
||||
if (!isReady) continue;
|
||||
resourceCache_[id] = resource;
|
||||
output[id] = resource;
|
||||
const localState = await Resource.localState(resource);
|
||||
|
||||
const o = {
|
||||
item: resource,
|
||||
localState: localState,
|
||||
};
|
||||
|
||||
resourceCache_[id] = o;
|
||||
output[id] = o;
|
||||
}
|
||||
}
|
||||
|
||||
@ -269,4 +281,16 @@ shared.toggleCheckbox = function(ipcMessage, noteBody) {
|
||||
return newBody.join('\n')
|
||||
}
|
||||
|
||||
shared.installResourceHandling = function(refreshResourceHandler) {
|
||||
ResourceFetcher.instance().on('downloadComplete', refreshResourceHandler);
|
||||
ResourceFetcher.instance().on('downloadStarted', refreshResourceHandler);
|
||||
DecryptionWorker.instance().on('resourceDecrypted', refreshResourceHandler);
|
||||
}
|
||||
|
||||
shared.uninstallResourceHandling = function(refreshResourceHandler) {
|
||||
ResourceFetcher.instance().off('downloadComplete', refreshResourceHandler);
|
||||
ResourceFetcher.instance().off('downloadStarted', refreshResourceHandler);
|
||||
DecryptionWorker.instance().off('resourceDecrypted', refreshResourceHandler);
|
||||
}
|
||||
|
||||
module.exports = shared;
|
||||
|
Reference in New Issue
Block a user