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

Display number of resources being fetched in side bar

This commit is contained in:
Laurent Cozic 2018-11-13 22:25:23 +00:00
parent 06091933e1
commit e17f3051f0
6 changed files with 45 additions and 3 deletions

View File

@ -505,7 +505,13 @@ class SideBarComponent extends React.Component {
decryptionReportText = _('Decrypting items: %d/%d', this.props.decryptionWorker.itemIndex + 1, this.props.decryptionWorker.itemCount); decryptionReportText = _('Decrypting items: %d/%d', this.props.decryptionWorker.itemIndex + 1, this.props.decryptionWorker.itemCount);
} }
let resourceFetcherText = '';
if (this.props.resourceFetcher && this.props.resourceFetcher.toFetchCount) {
resourceFetcherText = _('Fetching resources: %d', this.props.resourceFetcher.toFetchCount);
}
let lines = Synchronizer.reportToLines(this.props.syncReport); let lines = Synchronizer.reportToLines(this.props.syncReport);
if (resourceFetcherText) lines.push(resourceFetcherText);
if (decryptionReportText) lines.push(decryptionReportText); if (decryptionReportText) lines.push(decryptionReportText);
const syncReportText = []; const syncReportText = [];
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
@ -547,6 +553,7 @@ const mapStateToProps = state => {
theme: state.settings.theme, theme: state.settings.theme,
collapsedFolderIds: state.collapsedFolderIds, collapsedFolderIds: state.collapsedFolderIds,
decryptionWorker: state.decryptionWorker, decryptionWorker: state.decryptionWorker,
resourceFetcher: state.resourceFetcher,
}; };
}; };

View File

@ -389,6 +389,7 @@ class BaseApplication {
reg.dispatch = this.store().dispatch; reg.dispatch = this.store().dispatch;
BaseSyncTarget.dispatch = this.store().dispatch; BaseSyncTarget.dispatch = this.store().dispatch;
DecryptionWorker.instance().dispatch = this.store().dispatch; DecryptionWorker.instance().dispatch = this.store().dispatch;
ResourceFetcher.instance().dispatch = this.store().dispatch;
} }
async readFlagsFromFile(flagPath) { async readFlagsFromFile(flagPath) {

View File

@ -37,6 +37,11 @@ class Resource extends BaseItem {
return this.modelSelectAll(sql, [Resource.FETCH_STATUS_IDLE]); return this.modelSelectAll(sql, [Resource.FETCH_STATUS_IDLE]);
} }
static async needToBeFetchedCount() {
const r = await this.db().selectOne('SELECT count(*) as total FROM resource_local_states WHERE fetch_status = ?', [Resource.FETCH_STATUS_IDLE]);
return r ? r['total'] : 0;
}
static fsDriver() { static fsDriver() {
if (!Resource.fsDriver_) Resource.fsDriver_ = new FsDriverDummy(); if (!Resource.fsDriver_) Resource.fsDriver_ = new FsDriverDummy();
return Resource.fsDriver_; return Resource.fsDriver_;

View File

@ -38,7 +38,10 @@ const defaultState = {
itemIndex: 0, itemIndex: 0,
itemCount: 0, itemCount: 0,
}, },
selectedNoteTags: [] selectedNoteTags: [],
resourceFetcher: {
toFetchCount: 0,
},
}; };
const stateUtils = {}; const stateUtils = {};
@ -604,6 +607,14 @@ const reducer = (state = defaultState, action) => {
newState.decryptionWorker = decryptionWorker; newState.decryptionWorker = decryptionWorker;
break; break;
case 'RESOURCE_FETCHER_SET':
newState = Object.assign({}, state);
const rf = Object.assign({}, action);
delete rf.type;
newState.resourceFetcher = rf;
break;
case 'LOAD_CUSTOM_CSS': case 'LOAD_CUSTOM_CSS':
newState = Object.assign({}, state); newState = Object.assign({}, state);

View File

@ -10,6 +10,8 @@ class ResourceFetcher extends BaseService {
constructor(fileApi = null) { constructor(fileApi = null) {
super(); super();
this.dispatch = (action) => {};
this.setFileApi(fileApi); this.setFileApi(fileApi);
this.logger_ = new Logger(); this.logger_ = new Logger();
this.queue_ = []; this.queue_ = [];
@ -59,6 +61,19 @@ class ResourceFetcher extends BaseService {
return -1; return -1;
} }
updateReport() {
if (this.updateReportIID_) return;
this.updateReportIID_ = setTimeout(async () => {
const toFetchCount = await Resource.needToBeFetchedCount();
this.dispatch({
type: 'RESOURCE_FETCHER_SET',
toFetchCount: toFetchCount,
});
this.updateReportIID_ = null;
}, 2000);
}
queueDownload(resourceId, priority = null) { queueDownload(resourceId, priority = null) {
if (priority === null) priority = 'normal'; if (priority === null) priority = 'normal';
@ -73,6 +88,8 @@ class ResourceFetcher extends BaseService {
this.queue_.push(item); this.queue_.push(item);
} }
this.updateReport();
this.scheduleQueueProcess(); this.scheduleQueueProcess();
return true; return true;
} }
@ -85,6 +102,7 @@ class ResourceFetcher extends BaseService {
delete this.fetchingItems_[resource.id]; delete this.fetchingItems_[resource.id];
this.scheduleQueueProcess(); this.scheduleQueueProcess();
if (emitDownloadComplete) this.eventEmitter_.emit('downloadComplete', { id: resource.id }); if (emitDownloadComplete) this.eventEmitter_.emit('downloadComplete', { id: resource.id });
this.updateReport();
} }
const resource = await Resource.load(resourceId); const resource = await Resource.load(resourceId);

View File

@ -74,7 +74,7 @@ class Synchronizer {
if (report.deleteLocal) lines.push(_("Deleted local items: %d.", report.deleteLocal)); if (report.deleteLocal) lines.push(_("Deleted local items: %d.", report.deleteLocal));
if (report.deleteRemote) lines.push(_("Deleted remote items: %d.", report.deleteRemote)); if (report.deleteRemote) lines.push(_("Deleted remote items: %d.", report.deleteRemote));
if (report.fetchingTotal && report.fetchingProcessed) lines.push(_("Fetched items: %d/%d.", report.fetchingProcessed, report.fetchingTotal)); if (report.fetchingTotal && report.fetchingProcessed) lines.push(_("Fetched items: %d/%d.", report.fetchingProcessed, report.fetchingTotal));
if (!report.completedTime && report.state) lines.push(_('State: %s.', Synchronizer.stateToLabel(report.state))); // if (!report.completedTime && report.state) lines.push(_('State: %s.', Synchronizer.stateToLabel(report.state)));
if (report.cancelling && !report.completedTime) lines.push(_("Cancelling...")); if (report.cancelling && !report.completedTime) lines.push(_("Cancelling..."));
if (report.completedTime) lines.push(_("Completed: %s", time.formatMsToLocal(report.completedTime))); if (report.completedTime) lines.push(_("Completed: %s", time.formatMsToLocal(report.completedTime)));
if (report.errors && report.errors.length) lines.push(_("Last error: %s", report.errors[report.errors.length - 1].toString().substr(0, 500))); if (report.errors && report.errors.length) lines.push(_("Last error: %s", report.errors[report.errors.length - 1].toString().substr(0, 500)));