1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Mobile: Added support for ResourceFetcher service

This commit is contained in:
Laurent Cozic 2018-10-09 22:01:50 +01:00
parent 3bdf621026
commit 069dce69cd
3 changed files with 22 additions and 8 deletions

View File

@ -76,8 +76,6 @@ class NoteBodyViewer extends Component {
paddingBottom: '3.8em', // Extra bottom padding to make it possible to scroll past the action button (so that it doesn't overlap the text)
};
console.info('RRRRRRRRRRRR');
let html = this.mdToHtml_.render(note ? note.body : '', this.props.webViewStyle, mdOptions);
html = `

View File

@ -80,8 +80,21 @@ class ResourceFetcher extends BaseService {
if (this.fetchingItems_[resourceId]) return;
this.fetchingItems_[resourceId] = true;
const completeDownload = (emitDownloadComplete = true) => {
delete this.fetchingItems_[resource.id];
this.scheduleQueueProcess();
if (emitDownloadComplete) this.eventEmitter_.emit('downloadComplete', { id: resource.id });
}
const resource = await Resource.load(resourceId);
// Shouldn't happen, but just to be safe don't re-download the
// resource if it's already been downloaded.
if (resource.fetch_status === Resource.FETCH_STATUS_DONE) {
completeDownload(false);
return;
}
this.fetchingItems_[resourceId] = resource;
const localResourceContentPath = Resource.fullPath(resource);
@ -93,12 +106,6 @@ class ResourceFetcher extends BaseService {
this.logger().debug('ResourceFetcher: Downloading resource: ' + resource.id);
const completeDownload = () => {
delete this.fetchingItems_[resource.id];
this.scheduleQueueProcess();
this.eventEmitter_.emit('downloadComplete', { id: resource.id });
}
fileApi.get(remoteResourceContentPath, { path: localResourceContentPath, target: "file" }).then(async () => {
await Resource.saveFetchStatus(resource.id, Resource.FETCH_STATUS_DONE);
this.logger().debug('ResourceFetcher: Resource downloaded: ' + resource.id);

View File

@ -51,6 +51,7 @@ const { reducer, defaultState } = require('lib/reducer.js');
const { FileApiDriverLocal } = require('lib/file-api-driver-local.js');
const DropdownAlert = require('react-native-dropdownalert').default;
const ShareExtension = require('react-native-share-extension').default;
const ResourceFetcher = require('lib/services/ResourceFetcher');
const SyncTargetRegistry = require('lib/SyncTargetRegistry.js');
const SyncTargetOneDrive = require('lib/SyncTargetOneDrive.js');
@ -138,6 +139,10 @@ const generalMiddleware = store => next => async (action) => {
DecryptionWorker.instance().scheduleStart();
}
if (action.type === 'SYNC_CREATED_RESOURCE') {
ResourceFetcher.instance().queueDownload(action.id);
}
return result;
}
@ -488,6 +493,10 @@ async function initialize(dispatch) {
ResourceService.runInBackground();
ResourceFetcher.instance().setFileApi(() => { return reg.syncTarget().fileApi() });
ResourceFetcher.instance().setLogger(reg.logger());
ResourceFetcher.instance().start();
reg.scheduleSync().then(() => {
// Wait for the first sync before updating the notifications, since synchronisation
// might change the notifications.